Skip to content

Commit afd04a7

Browse files
committed
WIP tsan support for rust
1 parent 3e3b117 commit afd04a7

File tree

3 files changed

+65
-24
lines changed

3 files changed

+65
-24
lines changed

configure.ac

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ AX_APPEND_COMPILE_FLAGS($WFLAGS)
9494
AX_APPEND_COMPILE_FLAGS([-pthread])
9595
AC_LANG_POP(C)
9696

97+
AC_ARG_ENABLE(unified-rust-unsafe-for-production,
98+
AS_HELP_STRING([--enable-unified-rust-unsafe-for-production],
99+
[Build rust crates as a single cargo library, risking version drift]))
100+
AM_CONDITIONAL(UNIFIED_RUST, [test "x$enable_unified_rust_unsafe_for_production" = "xyes"])
101+
97102
unset sanitizeopts
98103

99104
AC_ARG_ENABLE([asan],

src/Makefile.am

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,15 @@ BUILT_SOURCES += rust/RustBridge.h rust/RustBridge.cpp
117117
stellar_core_SOURCES += rust/RustBridge.h rust/RustBridge.cpp
118118

119119
RUST_TOOLCHAIN_FILE=$(top_srcdir)/rust-toolchain.toml
120-
RUST_TOOLCHAIN_CHANNEL=$(shell sed -n 's/channel *= *"\([^"]*\)"/\1/p' $(RUST_TOOLCHAIN_FILE))
120+
RUST_TOOLCHAIN_FILE_CHANNEL=$(shell sed -n 's/channel *= *"\([^"]*\)"/\1/p' $(RUST_TOOLCHAIN_FILE))
121+
RUST_TOOLCHAIN_CHANNEL=$(if $(findstring sanitize,$(CXXFLAGS)),nightly,$(RUST_TOOLCHAIN_FILE_CHANNEL))
121122
CARGO=cargo +$(RUST_TOOLCHAIN_CHANNEL)
122123

123124
# we pass RUST_TOOLCHAIN_CHANNEL by environment variable
124125
# to tests since they can't take command-line arguments.
125126
export RUST_TOOLCHAIN_CHANNEL
126127

128+
RUST_TARGET=$(shell rustc -vV | sed -n 's/host: //p')
127129
RUST_BUILD_DIR=$(top_builddir)/src/rust
128130
RUST_BIN_DIR=$(RUST_BUILD_DIR)/bin
129131
RUST_TARGET_DIR=$(top_builddir)/target
@@ -132,7 +134,7 @@ RUST_PROFILE=release
132134
RUST_DEP_TREE_STAMP=$(RUST_BUILD_DIR)/src/dep-trees/equal-trees.stamp
133135
SOROBAN_LIBS_STAMP=$(RUST_BUILD_DIR)/soroban/soroban-libs.stamp
134136
RUST_HOST_DEPFILES=rust/Cargo.toml $(top_srcdir)/Cargo.toml $(top_srcdir)/Cargo.lock $(RUST_DEP_TREE_STAMP)
135-
LIBRUST_STELLAR_CORE=$(RUST_TARGET_DIR)/$(RUST_PROFILE)/librust_stellar_core.a
137+
LIBRUST_STELLAR_CORE=$(RUST_TARGET_DIR)/$(RUST_TARGET)/$(RUST_PROFILE)/librust_stellar_core.a
136138
stellar_core_LDADD += $(LIBRUST_STELLAR_CORE) -ldl
137139

138140
SOROBAN_BUILD_DIR=$(abspath $(RUST_BUILD_DIR))/soroban
@@ -178,7 +180,7 @@ endif
178180
SOROBAN_MAX_PROTOCOL=$(lastword $(sort $(ALL_SOROBAN_PROTOCOLS)))
179181

180182
define soroban_lib_dir
181-
$(shell printf '$(SOROBAN_BUILD_DIR)/%s/target/$(RUST_PROFILE)' $(1))
183+
$(shell printf '$(SOROBAN_BUILD_DIR)/%s/target/$(RUST_TARGET)/$(RUST_PROFILE)' $(1))
182184
endef
183185

184186
define soroban_rlib
@@ -232,6 +234,32 @@ $(RUST_DEP_TREE_STAMP): $(wildcard rust/soroban/*/Cargo.*) Makefile $(RUST_TOOLC
232234
# So we have to derive a new variable here.
233235
RUST_PROFILE_ARG := $(if $(findstring release,$(RUST_PROFILE)),--release,)
234236

237+
RUSTFLAGS_ASAN := $(if $(findstring -fsanitize=address,$(CXXFLAGS)),-Zsanitizer=address,)
238+
RUSTFLAGS_TSAN := $(if $(findstring -fsanitize=thread,$(CXXFLAGS)),-Zsanitizer=thread,)
239+
RUSTFLAGS_SANI := $(RUSTFLAGS_ASAN) $(RUSTFLAGS_TSAN)
240+
CARGOFLAGS_BUILDSTD := $(if $(findstring sanitizer,$(RUSTFLAGS_SANI)),-Zbuild-std,)
241+
RUSTFLAGS_CFGS := $(if $(findstring sanitizer,$(RUSTFLAGS_SANI)),--cfg curve25519_dalek_backend=\"serial\",)
242+
243+
if UNIFIED_RUST
244+
245+
$(LIBRUST_STELLAR_CORE): $(RUST_HOST_DEPFILES) $(SRC_RUST_FILES) Makefile $(RUST_TOOLCHAIN_FILE)
246+
rm -rf $(abspath $(RUST_TARGET_DIR))
247+
CC="$(CC)" CXX="$(CXX)" LD="$(LD)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CXXSTDLIB="$(CXXSTDLIB)" LDFLAGS="$(LDFLAGS)" \
248+
RUSTFLAGS="$(RUSTFLAGS_SANI) $(RUSTFLAGS_CFGS)" \
249+
CARGO_NET_GIT_FETCH_WITH_CLI=true \
250+
$(CARGO) rustc \
251+
$(CARGOFLAGS_BUILDSTD) \
252+
--package stellar-core \
253+
--target $(RUST_TARGET) \
254+
--features unified \
255+
$(RUST_PROFILE_ARG) \
256+
--locked \
257+
--target-dir $(abspath $(RUST_TARGET_DIR)) \
258+
$(CARGO_FEATURE_TRACY) $(CARGO_FEATURE_NEXT) $(CARGO_FEATURE_TESTUTILS)
259+
ranlib $@
260+
261+
else # !UNIFIED_RUST
262+
235263
# This next build command looks a little weird but it's necessary. We have to
236264
# provide an auxiliary metadata string (using RUSTFLAGS=-Cmetadata=$*)
237265
# essentially manually marking-as-different the separate dependency trees
@@ -292,10 +320,11 @@ $(SOROBAN_LIBS_STAMP): $(wildcard rust/soroban/p*/Cargo.lock) Makefile $(RUST_DE
292320
esac ; \
293321
cd $(abspath $(RUST_BUILD_DIR))/soroban/$$proto && \
294322
CC="$(CC)" CXX="$(CXX)" LD="$(LD)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CXXSTDLIB="$(CXXSTDLIB)" LDFLAGS="$(LDFLAGS)" \
295-
RUSTFLAGS="-Cmetadata=$$proto $(RUSTFLAGS_ASAN)" \
323+
RUSTFLAGS="-Cmetadata=$$proto" \
296324
CARGO_NET_GIT_FETCH_WITH_CLI=true \
297325
$(CARGO) build \
298326
--package soroban-env-host \
327+
--target $(RUST_TARGET) \
299328
$(RUST_PROFILE_ARG) \
300329
--locked \
301330
$$FEATURE_FLAGS \
@@ -319,10 +348,10 @@ $(SOROBAN_LIBS_STAMP): $(wildcard rust/soroban/p*/Cargo.lock) Makefile $(RUST_DE
319348
$(LIBRUST_STELLAR_CORE): $(RUST_HOST_DEPFILES) $(SRC_RUST_FILES) Makefile $(SOROBAN_LIBS_STAMP) $(RUST_TOOLCHAIN_FILE)
320349
rm -rf $(abspath $(RUST_TARGET_DIR))
321350
CC="$(CC)" CXX="$(CXX)" LD="$(LD)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CXXSTDLIB="$(CXXSTDLIB)" LDFLAGS="$(LDFLAGS)" \
322-
RUSTFLAGS="$(RUSTFLAGS_ASAN)" \
323351
CARGO_NET_GIT_FETCH_WITH_CLI=true \
324352
$(CARGO) rustc \
325353
--package stellar-core \
354+
--target $(RUST_TARGET) \
326355
$(RUST_PROFILE_ARG) \
327356
--locked \
328357
--target-dir $(abspath $(RUST_TARGET_DIR)) \
@@ -332,6 +361,8 @@ $(LIBRUST_STELLAR_CORE): $(RUST_HOST_DEPFILES) $(SRC_RUST_FILES) Makefile $(SORO
332361
$(ALL_SOROBAN_DEPEND_ARGS)
333362
ranlib $@
334363

364+
endif # UNIFIED_RUST
365+
335366
$(srcdir)/src.mk: $(top_srcdir)/make-mks
336367
cd $(top_srcdir) && ./make-mks
337368

src/rust/Cargo.toml

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,36 +93,39 @@ tracy-client = { version = "=0.17.0", features = [
9393
# the host dependencies. Make sure they are commented back out before committing
9494
# (and be careful to reset any changes the IDE makes to Cargo.lock)
9595

96-
# [dependencies.soroban-env-host-p23]
97-
# version = "=23.0.0"
98-
# git = "https://github.com/stellar/rs-soroban-env"
99-
# package = "soroban-env-host"
100-
# rev = "31cb455b87a25a1c049360b5422c411deae63ba2"
101-
102-
# [dependencies.soroban-env-host-p22]
103-
# version = "=22.0.0"
104-
# git = "https://github.com/stellar/rs-soroban-env"
105-
# package = "soroban-env-host"
106-
# rev = "1cd8b8dca9aeeca9ce45b129cd923992b32dc258"
107-
108-
# [dependencies.soroban-env-host-p21]
109-
# version = "=21.2.2"
110-
# git = "https://github.com/stellar/rs-soroban-env"
111-
# package = "soroban-env-host"
112-
# rev = "7eeddd897cfb0f700f938b0c8d6f0541150d1fcb"
96+
[dependencies.soroban-env-host-p23]
97+
version = "=23.0.0-rc.2"
98+
git = "https://github.com/stellar/rs-soroban-env"
99+
package = "soroban-env-host"
100+
rev = "339d5957d2a258ca888d2f7eb50e92e425555256"
101+
optional = true
102+
103+
[dependencies.soroban-env-host-p22]
104+
version = "=22.0.0"
105+
git = "https://github.com/stellar/rs-soroban-env"
106+
package = "soroban-env-host"
107+
rev = "80ebd78a53d608f76f4a5955fd9b03248efcb7c1"
108+
optional = true
109+
110+
[dependencies.soroban-env-host-p21]
111+
version = "=21.2.2"
112+
git = "https://github.com/stellar/rs-soroban-env"
113+
package = "soroban-env-host"
114+
rev = "7eeddd897cfb0f700f938b0c8d6f0541150d1fcb"
115+
optional = true
113116

114117
# The test wasms and synth-wasm crate should usually be taken from the highest
115118
# supported host, since test material usually just grows over time.
116119

117120
[dependencies.soroban-test-wasms]
118121
version = "=22.0.0"
119122
git = "https://github.com/stellar/rs-soroban-env"
120-
rev = "a3f7fca9c2ad89796c7525a648da086543502dd5"
123+
rev = "80ebd78a53d608f76f4a5955fd9b03248efcb7c1"
121124

122125
[dependencies.soroban-synth-wasm]
123126
version = "=22.0.0"
124127
git = "https://github.com/stellar/rs-soroban-env"
125-
rev = "a3f7fca9c2ad89796c7525a648da086543502dd5"
128+
rev = "80ebd78a53d608f76f4a5955fd9b03248efcb7c1"
126129

127130
[dependencies.stellar-quorum-analyzer]
128131
version = "0.1.0"
@@ -131,6 +134,8 @@ rev = "678acf18ee635c4270e241030d6e83bb0b98b5d5"
131134

132135
[features]
133136

137+
unified = ["dep:soroban-env-host-p21", "dep:soroban-env-host-p22", "dep:soroban-env-host-p23"]
138+
134139
tracy = ["dep:tracy-client"]
135140

136141
# The "next" feature enables not-yet-released features that (a) break protocol

0 commit comments

Comments
 (0)