Skip to content

Commit 3a2411a

Browse files
committed
Add --enable-fastdev-unsafe-for-production, subsuming unified buid
1 parent ade8c25 commit 3a2411a

9 files changed

Lines changed: 168 additions & 69 deletions

CONTRIBUTING.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ See https://clang.llvm.org/docs/AddressSanitizer.html for more information.
116116

117117
*Note*: ASan will ignore any memory errors in Rust code unless you build with
118118
Rust's ASan support. And building with Rust's ASan support requires configuring
119-
with `--enable-unified-rust-unsafe-for-production`. See below on "unified Rust
119+
with `--enable-fastdev-unsafe-for-production`. See below on "fastdev Rust
120120
builds".
121121

122122
*Note*: Rust's ASan support also requires a nightly compiler and the rust-src
@@ -156,7 +156,7 @@ See https://clang.llvm.org/docs/ThreadSanitizer.html for more information.
156156
*Note*: Since Rust code is run on multiple threads and those threads are
157157
launched _from C++_ TSan will report races in Rust code unless you build with
158158
Rust's TSan support. And building with Rust's TSan support requires configuring
159-
with `--enable-unified-rust-unsafe-for-production`.
159+
with `--enable-fastdev-unsafe-for-production`.
160160

161161
*Note*: Rust's ASan support also requires a nightly compiler and the rust-src
162162
component. Install these with:
@@ -294,7 +294,7 @@ files. You should then inspect to see that only the transactions you expected to
294294
see change did so. If so, commit the changes as a new set of baselines for
295295
future tests.
296296

297-
## Unified and non-unified Rust builds
297+
## Fastdev and non-unified Rust builds
298298

299299
As of protocol 20, some components of stellar-core are written in Rust (notably
300300
soroban).
@@ -331,21 +331,21 @@ and it _usually_ works. But there are two cases you might not want it.
331331
the stdlib and producing some sort of link-time dependency on crates that
332332
are only used as procedural macros).
333333

334-
For both of these cases, we've added the ability to (optionally) switch back to
335-
the normal way Rust expects you to build a crate that links multiple versions of
336-
a dependency: with a single "unified" cargo invocation, at the top level. There
337-
are two different ways to enable this:
334+
For both of these cases, we've added a fastdev mode that switches back to the
335+
normal way Rust expects you to build a crate, with a single cargo invocation at
336+
the top level and only the current and next Soroban hosts compiled in. There are
337+
two different ways to enable this:
338338

339-
- By configuring with `--enable-unified-rust-unsafe-for-production`, if one
340-
wants to _build_ a stellar-core with unified rust.
339+
- By configuring with `--enable-fastdev-unsafe-for-production`, if one wants
340+
to _build_ a stellar-core with fastdev rust.
341341

342-
- By toggling the "unified" feature flag in the IDE (eg. using the "Rust
342+
- By toggling the "fastdev" feature flag in the IDE (eg. using the "Rust
343343
Feature Toggler" editor extension in VS code) if one merely wants to _edit_
344-
a stellar-core with unified rust.
344+
a stellar-core with fastdev rust.
345345

346346
The configure flag has got such a long and unwieldy name because _it will build
347-
soroban with slightly different versions of transitive dependencies_, a
348-
configuration we do _not_ want to ship in production builds.
347+
soroban with fewer host versions and slightly different versions of transitive
348+
dependencies_, a configuration we do _not_ want to ship in production builds.
349349

350350
It is fine for debugging though. In practice those different versions of
351351
transitive dependencies are rarely "all that different". You will _probably_ not

Cargo.lock

Lines changed: 20 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ lto = true
1212
# (or you can build with `make RUST_PROFILE=dev` to get them built with
1313
# debug-and-no-opt).
1414
debug = true
15+
16+
[profile.fastdev]
17+
inherits = "release"
18+
lto = false
19+
debug = "line-tables-only"
20+
codegen-units = 16
21+
split-debuginfo = "unpacked"

configure.ac

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,24 @@ AX_APPEND_COMPILE_FLAGS($WFLAGS)
9797
AX_APPEND_COMPILE_FLAGS([-pthread])
9898
AC_LANG_POP(C)
9999

100-
AC_ARG_ENABLE(unified-rust-unsafe-for-production,
101-
AS_HELP_STRING([--enable-unified-rust-unsafe-for-production],
102-
[Build rust crates as a single cargo library, risking version drift]))
103-
AM_CONDITIONAL(UNIFIED_RUST, [test "x$enable_unified_rust_unsafe_for_production" = "xyes"])
100+
AC_ARG_ENABLE(fastdev-unsafe-for-production,
101+
AS_HELP_STRING([--enable-fastdev-unsafe-for-production],
102+
[Build in fast development mode UNSAFE FOR PRODUCTION]))
103+
AS_IF([test "x$enable_fastdev_unsafe_for_production" = "xyes"], [
104+
AC_MSG_NOTICE([enabling fastdev build profile UNSAFE FOR PRODUCTION])
105+
fastdev_cxx_version=`$CXX --version 2>/dev/null`
106+
case "$fastdev_cxx_version" in
107+
*clang*)
108+
CXXFLAGS="$CXXFLAGS -gline-tables-only"
109+
AC_MSG_NOTICE([added -gline-tables-only to CXXFLAGS])
110+
;;
111+
*)
112+
AC_MSG_ERROR([fastdev build requires clang compiler])
113+
;;
114+
esac
115+
])
116+
AM_CONDITIONAL(ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION,
117+
[test "x$enable_fastdev_unsafe_for_production" = "xyes"])
104118

105119
unset sanitizeopts
106120

@@ -110,8 +124,8 @@ AC_ARG_ENABLE([asan],
110124
AS_IF([test "x$enable_asan" = "xyes"], [
111125
AC_MSG_NOTICE([ Enabling asan, see https://clang.llvm.org/docs/AddressSanitizer.html ])
112126
113-
AS_IF([test "xyes" != "x$enable_unified_rust_unsafe_for_production"], [
114-
AC_MSG_WARN(Asan will not instrument rust without --enable-unified-rust-unsafe-for-production)
127+
AS_IF([test "xyes" != "x$enable_fastdev_unsafe_for_production"], [
128+
AC_MSG_WARN(Asan will not instrument rust without --enable-fastdev-unsafe-for-production)
115129
])
116130
117131
sanitizeopts="address"
@@ -134,8 +148,8 @@ AC_ARG_ENABLE([threadsanitizer],
134148
AS_IF([test "x$enable_threadsanitizer" = "xyes"], [
135149
AC_MSG_NOTICE([ enabling thread-sanitizer, see https://clang.llvm.org/docs/ThreadSanitizer.html ])
136150
137-
AS_IF([test "xyes" != "x$enable_unified_rust_unsafe_for_production"], [
138-
AC_MSG_ERROR(Enabling tsan requires --enable-unified-rust-unsafe-for-production)
151+
AS_IF([test "xyes" != "x$enable_fastdev_unsafe_for_production"], [
152+
AC_MSG_ERROR(Enabling tsan requires --enable-fastdev-unsafe-for-production)
139153
])
140154
AS_IF([test x != "x$sanitizeopts"], [
141155
AC_MSG_ERROR(Cannot enable multiple sanitizers at once)

src/Makefile.am

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ else
7777
CARGO_FEATURE_NEXT =
7878
endif
7979

80+
if ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION
81+
CARGO_FEATURE_FASTDEV = --features fastdev
82+
else
83+
CARGO_FEATURE_FASTDEV =
84+
endif
85+
8086
main/XDRFilesSha256.cpp: $(SRC_X_FILES) Makefile $(top_srcdir)/hash-xdrs.sh
8187
$(top_srcdir)/hash-xdrs.sh $(top_srcdir)/src/protocol-curr >$@
8288

@@ -131,7 +137,7 @@ stellar_core_SOURCES += $(GENERATED_XDRQUERY_SOURCES) util/xdrquery/XDRQueryPars
131137
BUILT_SOURCES += rust/RustBridge.h $(GENERATED_RUST_SOURCES)
132138
stellar_core_SOURCES += rust/RustBridge.h $(GENERATED_RUST_SOURCES)
133139

134-
if UNIFIED_RUST
140+
if ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION
135141
RUST_TOOLCHAIN_CHANNEL=nightly
136142
else
137143
RUST_TOOLCHAIN_FILE=$(top_srcdir)/rust-toolchain.toml
@@ -151,22 +157,27 @@ RUST_BUILD_DIR=$(top_builddir)/src/rust
151157
RUST_BIN_DIR=$(RUST_BUILD_DIR)/bin
152158
RUST_TARGET_DIR=$(top_builddir)/target
153159
RUST_CXXBRIDGE=$(RUST_BIN_DIR)/cxxbridge
160+
161+
if ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION
162+
RUST_PROFILE=fastdev
163+
else
154164
RUST_PROFILE=release
165+
endif
155166

156167
check-rust-profile: Makefile
157168
@case "$(RUST_PROFILE)" in \
158-
release|dev) ;; \
159-
*) echo "Error: RUST_PROFILE must be 'release' or 'dev', got '$(RUST_PROFILE)'" >&2; exit 1;; \
169+
release|dev|fastdev) ;; \
170+
*) echo "Error: RUST_PROFILE must be 'release', 'dev', or 'fastdev', got '$(RUST_PROFILE)'" >&2; exit 1;; \
160171
esac
161172

162173
# Of course, RUST_PROFILE can't be used as an argument directly because cargo
163174
# doesn't let you pass --debug, that's the default! you can only pass --release.
164175
# So we have to derive a new variable here.
165-
RUST_PROFILE_ARG := $(if $(findstring release,$(RUST_PROFILE)),--release,)
176+
RUST_PROFILE_ARG := $(if $(findstring fastdev,$(RUST_PROFILE)),--profile fastdev,$(if $(findstring release,$(RUST_PROFILE)),--release,))
166177

167178
# Also for even more nonsense reasons the debug profile name is actually `dev`
168179
# but only in the command line, the target subdirectory gets called `debug`.
169-
RUST_PROFILE_DIR := $(if $(findstring release,$(RUST_PROFILE)),release,debug)
180+
RUST_PROFILE_DIR := $(if $(findstring fastdev,$(RUST_PROFILE)),fastdev,$(if $(findstring release,$(RUST_PROFILE)),release,debug))
170181

171182
RUST_DEP_TREE_STAMP=$(RUST_BUILD_DIR)/src/dep-trees/equal-trees.stamp
172183
SOROBAN_LIBS_STAMP=$(RUST_BUILD_DIR)/soroban/soroban-libs.stamp
@@ -201,7 +212,11 @@ SOROBAN_BUILD_DIR=$(abspath $(RUST_BUILD_DIR))/soroban
201212
# variable empty (and include or exclude submodules from the list of
202213
# ALL_SOROBAN_PROTOCOLS as you see fit).
203214

215+
if ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION
216+
ALL_SOROBAN_PROTOCOLS=p26
217+
else
204218
ALL_SOROBAN_PROTOCOLS=p21 p22 p23 p24 p25 p26
219+
endif
205220
WIP_SOROBAN_PROTOCOL=p27
206221

207222
CARGO_XDR_FEATURE_FLAGS =
@@ -287,23 +302,23 @@ $(SOROBAN_BUILD_DIR)/%/target/git-state.txt: $(top_srcdir)/.git/modules/src/rust
287302
printf '%s\n' "$$state" > $@.tmp; \
288303
if cmp -s $@.tmp $@; then rm -f $@.tmp; else mv -f $@.tmp $@; fi
289304

290-
# The "unified" rust build is a special non-production mode that builds all of
305+
# The fastdev rust build is a special non-production mode that builds all of
291306
# the rust dependencies of librust_stellar_core.a through a single cargo
292307
# invocation, which is actually the "normal" way cargo operates, but which also
293308
# has the negative side effect of resolving (merging) different point releases
294309
# and pre-release minor versions across transitive dependencies, which means we
295310
# can't control the _exact_ transitive dependencies as well as we'd like.
296311
#
297-
# So we only use the unified rust build for certain special cases such as
312+
# So we only use the fastdev rust build for certain special cases such as
298313
# testing with asan/tsan (they seem to only work well when built this way) and
299314
# use the non-unified build (with separate .a files for each separate soroban
300315
# version) for production builds.
301316

302-
if UNIFIED_RUST
317+
if ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION
303318

304-
# In the unified build, we have to pass the --target flag. This actually breaks
319+
# In the fastdev build, we have to pass the --target flag. This actually breaks
305320
# the non-unified build, so we wind up setting LIBRUST_STELLAR_CORE separately
306-
# in unified and non-unified builds.
321+
# in fastdev and non-unified builds.
307322
RUST_TARGET=$(shell rustc -vV | sed -n 's/host: //p')
308323
LIBRUST_STELLAR_CORE=$(RUST_TARGET_DIR)/$(RUST_TARGET)/$(RUST_PROFILE_DIR)/librust_stellar_core.a
309324

@@ -323,14 +338,13 @@ $(LIBRUST_STELLAR_CORE): $(RUST_HOST_DEPFILES) $(SRC_RUST_FILES) Makefile $(RUST
323338
$(CARGOFLAGS_BUILDSTD) \
324339
--package stellar-core \
325340
--target $(RUST_TARGET) \
326-
--features unified \
327341
$(RUST_PROFILE_ARG) \
328342
--locked \
329343
--target-dir $(abspath $(RUST_TARGET_DIR)) \
330-
$(CARGO_FEATURE_TRACY) $(CARGO_FEATURE_NEXT) $(CARGO_FEATURE_TESTUTILS)
344+
$(CARGO_FEATURE_FASTDEV) $(CARGO_FEATURE_TRACY) $(CARGO_FEATURE_NEXT) $(CARGO_FEATURE_TESTUTILS)
331345
ranlib $@
332346

333-
else # !UNIFIED_RUST
347+
else # !ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION
334348

335349
# This next build command looks a little weird but it's necessary. We have to
336350
# provide an auxiliary metadata string (using RUSTFLAGS=-Cmetadata=$*)
@@ -444,7 +458,7 @@ $(LIBRUST_STELLAR_CORE): $(RUST_HOST_DEPFILES) $(SRC_RUST_FILES) $(ALL_SOROBAN_L
444458
$(ALL_SOROBAN_DEPEND_ARGS)
445459
ranlib $@
446460

447-
endif # UNIFIED_RUST
461+
endif # ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION
448462

449463
stellar_core_LDADD += $(LIBRUST_STELLAR_CORE) -ldl
450464

src/rust/Cargo.toml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,27 +93,27 @@ tracy-client = { version = "=0.17.0", features = [
9393
# makes it difficult to use an IDE to work on this crate since the IDE will not
9494
# be able to resolve the hosts to anything at all. So we keep some _optional_
9595
# copies of the host dependencies here, and allow enabling them with the
96-
# `unified` feature here.
96+
# `fastdev` feature here.
9797
#
9898
# To reiterate: the soroban-env-host-p{21,22,23}... dependency blocks listed
9999
# here are NOT part of the default build. The default build relies on the
100100
# versions pinned as git submodules.
101101
#
102-
# However, you can _manually_ switch the default build by enabling the `unified`
102+
# However, you can _manually_ switch the default build by enabling the `fastdev`
103103
# feature using a feature-toggle in an IDE (eg. using the VS Code "Rust Feature
104104
# Toggler" extension), and the build system (src/Makefile.am) can be configured
105-
# to use the `unified` feature if you configure with
106-
# --enable-unified-rust-unsafe-for-production.
105+
# to use the `fastdev` feature if you configure with
106+
# --enable-fastdev-unsafe-for-production.
107107
#
108-
# If you do a unified build, be careful to reset any changes the IDE makes to
108+
# If you do a fastdev build, be careful to reset any changes the IDE makes to
109109
# Cargo.lock! The unified build will re-resolve transitive dependencies and
110110
# unify them, perturbing the contents of the lockfile.
111111

112112
[dependencies.soroban-env-host-p27]
113113
version = "=26.1.2"
114114
git = "https://github.com/stellar/rs-soroban-env"
115115
package = "soroban-env-host"
116-
rev = "c0e58f94ff2983a09440cef6a54253349fd3c4db"
116+
rev = "7fb0a840812fe8921bb48bebf7b4aa7160467ec8"
117117
optional = true
118118

119119
[dependencies.soroban-env-host-p26]
@@ -189,14 +189,9 @@ rev = "8b04a2b7a92b96ad90c09a9151ef97aa9a04a9f8"
189189

190190
[features]
191191

192-
# Turn on the optional unified build. This is typically only useful in an IDE or when
192+
# Turn on the optional fastdev build. This is typically only useful in an IDE or when
193193
# orchestrated by the build system. See note above and in docs/CONTRIBUTING.md.
194-
unified = ["dep:soroban-env-host-p21",
195-
"dep:soroban-env-host-p22",
196-
"dep:soroban-env-host-p23",
197-
"dep:soroban-env-host-p24",
198-
"dep:soroban-env-host-p25",
199-
"dep:soroban-env-host-p26",
194+
fastdev = ["dep:soroban-env-host-p26",
200195
"dep:soroban-env-host-p27"]
201196

202197
tracy = ["dep:tracy-client"]

0 commit comments

Comments
 (0)