Skip to content

Commit

Permalink
Extract rust-toolchain.toml channel, pass to submodules (stellar#4518)
Browse files Browse the repository at this point in the history
This is a somewhat crude but straightforward fix to the problem of
version mismatches between the rust-toolchain.toml files stored in the
stellar-core repo and those stored in the rs-soroban-env submodules: the
makefile now extracts the channel name and appends it, explicitly, to
all cargo invocations it makes.

I.e. if stellar-core's `rust-toolchain.toml` file says `channel =
"1.81.0"`, the makefile will run `cargo +1.81.0 build` in all the
submodules, overriding whatever they have in their own
`rust-toolchain.toml` files.

We may wish to tweak this further, or to add additional build variants
to the CI matrix of either this repo or rs-soroban-env, but I think this
sort of "make sure they're all the same" step is basically going to be a
part of any correct solution to the problem anyways, so I think we
should probably at least start with it.
  • Loading branch information
graydon authored Oct 24, 2024
2 parents 0d1f034 + 8ca3e6d commit 4203de9
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ stellar_core_SOURCES += util/xdrquery/XDRQueryScanner.cpp util/xdrquery/XDRQuery
BUILT_SOURCES += rust/RustBridge.h rust/RustBridge.cpp
stellar_core_SOURCES += rust/RustBridge.h rust/RustBridge.cpp

RUST_TOOLCHAIN_FILE=$(top_srcdir)/rust-toolchain.toml
RUST_TOOLCHAIN_CHANNEL=$(shell sed -n 's/channel *= *"\([^"]*\)"/\1/p' $(RUST_TOOLCHAIN_FILE))
CARGO=cargo +$(RUST_TOOLCHAIN_CHANNEL)

RUST_BUILD_DIR=$(top_builddir)/src/rust
RUST_BIN_DIR=$(RUST_BUILD_DIR)/bin
RUST_TARGET_DIR=$(top_builddir)/target
Expand Down Expand Up @@ -157,9 +161,9 @@ ALL_SOROBAN_LIBS=$(foreach proto,$(ALL_SOROBAN_PROTOCOLS),$(call soroban_rlib,$(
ALL_SOROBAN_EXTERN_ARGS=$(foreach proto,$(ALL_SOROBAN_PROTOCOLS),$(call soroban_extern_flag,$(proto)))
ALL_SOROBAN_DEPEND_ARGS=$(foreach proto,$(ALL_SOROBAN_PROTOCOLS),$(call soroban_depend_flag,$(proto)))

$(RUST_CXXBRIDGE):
$(RUST_CXXBRIDGE): Makefile $(RUST_TOOLCHAIN_FILE)
mkdir -p $(RUST_BIN_DIR)
CARGO_HTTP_MULTIPLEXING=false $(CARGO) install --locked --root $(RUST_BUILD_DIR) cxxbridge-cmd --version 1.0.68
CARGO_HTTP_MULTIPLEXING=false $(CARGO) install --force --locked --root $(RUST_BUILD_DIR) cxxbridge-cmd --version 1.0.68

rust/RustBridge.h: rust/src/lib.rs $(SRC_RUST_FILES) Makefile $(RUST_CXXBRIDGE)
$(RUST_CXXBRIDGE) $< --cfg test=false --header --output $@.tmp
Expand All @@ -173,11 +177,11 @@ rust/RustBridge.cpp: rust/src/lib.rs $(SRC_RUST_FILES) Makefile $(RUST_CXXBRIDGE
# check in to this repo as a secondary check on the lockfiles in the soroban
# submodules. You should still carefully inspect them if they change!

$(RUST_DEP_TREE_STAMP): $(wildcard rust/soroban/*/Cargo.*) Makefile
$(RUST_DEP_TREE_STAMP): $(wildcard rust/soroban/*/Cargo.*) Makefile $(RUST_TOOLCHAIN_FILE)
rm -f $@
for proto in $(ALL_SOROBAN_PROTOCOLS); \
do \
cargo tree --manifest-path rust/soroban/$${proto}/Cargo.toml --locked --package soroban-env-host --edges no-dev --target all \
$(CARGO) tree --manifest-path rust/soroban/$${proto}/Cargo.toml --locked --package soroban-env-host --edges no-dev --target all \
| sed -e "s@$(abspath $(top_srcdir))/@@g" > $(RUST_BUILD_DIR)/src/dep-trees/$${proto}-actual.txt ; \
if ! diff -u rust/src/dep-trees/$${proto}-expect.txt $(RUST_BUILD_DIR)/src/dep-trees/$${proto}-actual.txt; \
then \
Expand Down Expand Up @@ -229,7 +233,7 @@ $(RUST_DEP_TREE_STAMP): $(wildcard rust/soroban/*/Cargo.*) Makefile
# We also have to pass CXXSTDLIB to those build.rs files, because they are
# sensitive to CXXFLAGS but also don't inspect them to see if they're setting
# -stdlib=libc++ or -stdlib=libstdc++
$(SOROBAN_LIBS_STAMP): $(wildcard rust/soroban/p*/Cargo.lock) Makefile $(RUST_DEP_TREE_STAMP) $(SRC_RUST_FILES)
$(SOROBAN_LIBS_STAMP): $(wildcard rust/soroban/p*/Cargo.lock) Makefile $(RUST_DEP_TREE_STAMP) $(SRC_RUST_FILES) $(RUST_TOOLCHAIN_FILE)
rm -f $@
for proto in $(ALL_SOROBAN_PROTOCOLS) ; \
do \
Expand All @@ -248,7 +252,8 @@ $(SOROBAN_LIBS_STAMP): $(wildcard rust/soroban/p*/Cargo.lock) Makefile $(RUST_DE
cd $(abspath $(RUST_BUILD_DIR))/soroban/$$proto && \
CC="$(CC)" CXX="$(CXX)" LD="$(LD)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CXXSTDLIB="$(CXXSTDLIB)" LDFLAGS="$(LDFLAGS)" \
RUSTFLAGS="-Cmetadata=$$proto $(RUSTFLAGS_ASAN)" \
CARGO_NET_GIT_FETCH_WITH_CLI=true cargo build \
CARGO_NET_GIT_FETCH_WITH_CLI=true \
$(CARGO) build \
--package soroban-env-host \
--$(RUST_PROFILE) \
--locked \
Expand All @@ -270,11 +275,12 @@ $(SOROBAN_LIBS_STAMP): $(wildcard rust/soroban/p*/Cargo.lock) Makefile $(RUST_DE
# them in as separate `--extern` arguments to a slightly-more-manual `cargo
# rustc` invocation, along with `-L dependency=...` flags to tell cargo where to
# find indirect deps of those .rlibs.
$(LIBRUST_STELLAR_CORE): $(RUST_HOST_DEPFILES) $(SRC_RUST_FILES) Makefile $(SOROBAN_LIBS_STAMP)
$(LIBRUST_STELLAR_CORE): $(RUST_HOST_DEPFILES) $(SRC_RUST_FILES) Makefile $(SOROBAN_LIBS_STAMP) $(RUST_TOOLCHAIN_FILE)
rm -rf $(abspath $(RUST_TARGET_DIR))
CC="$(CC)" CXX="$(CXX)" LD="$(LD)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CXXSTDLIB="$(CXXSTDLIB)" LDFLAGS="$(LDFLAGS)" \
RUSTFLAGS="$(RUSTFLAGS_ASAN)" \
CARGO_NET_GIT_FETCH_WITH_CLI=true cargo rustc \
CARGO_NET_GIT_FETCH_WITH_CLI=true \
$(CARGO) rustc \
--package stellar-core \
--$(RUST_PROFILE) \
--locked \
Expand Down

0 comments on commit 4203de9

Please sign in to comment.