Skip to content

Commit 72f787a

Browse files
committed
More updates to VS Rust build, change detection is tricky on Windows.
1 parent c47ce47 commit 72f787a

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ compile_commands.json
4949
/src/main/StellarCoreVersion.cpp
5050
/src/main/XDRFilesSha256.cpp
5151
/src/rust/soroban/tmp
52+
/src/rust/.soroban-revs
5253
/src/rust/src/dep-trees/*-actual.txt
5354

5455
/src/testdata/*

Builds/VisualStudio/build_rust.bat

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ set LATEST_P=26
4040
rem ---- Accumulators for final rustc link flags ----
4141
set "EXTERNS="
4242
set "LPATHS="
43+
set "ALL_REVS="
4344
set "SOURCE_STAMP=.source-rev"
4445

4546
rem ---- Build protocols MIN_P..MAX_P ----
@@ -52,6 +53,7 @@ for /l %%P in (%MIN_P%,1,%MAX_P%) do (
5253
rem -- Resolve current submodule rev --
5354
set "current_rev="
5455
for /f %%R in ('git -C "!proto_dir!" rev-parse HEAD 2^>nul') do set "current_rev=%%R"
56+
set "ALL_REVS=!ALL_REVS!p%%P-!current_rev:~0,12!_"
5557

5658
rem -- Compare stamp to decide if cargo needs to run --
5759
set "stamp_ok="
@@ -125,9 +127,25 @@ rem Clear RUSTFLAGS so that metadata from soroban-protocol builds above does
125127
rem not leak into the stellar-core build and cause cargo to invalidate its
126128
rem fingerprints on the next run (where the soroban builds may be skipped).
127129
set "RUSTFLAGS="
130+
131+
rem Write submodule revisions to a file that build.rs watches via
132+
rem cargo:rerun-if-changed. Only update the file when content actually
133+
rem changes so that the mtime (which cargo uses for freshness) stays
134+
rem stable across no-op builds.
135+
set "REVS_FILE=%project_dir%\src\rust\.soroban-revs"
136+
set "revs_changed="
137+
if exist "!REVS_FILE!" (
138+
set "saved_revs="
139+
set /p saved_revs=<"!REVS_FILE!"
140+
if not "!saved_revs!"=="!ALL_REVS!" set "revs_changed=1"
141+
) else (
142+
set "revs_changed=1"
143+
)
144+
if defined revs_changed >"!REVS_FILE!" echo(!ALL_REVS!
145+
128146
rem Always invoke cargo here: cargo's own incremental-build tracking will
129-
rem no-op quickly when nothing changed, and the submodule-stamp mechanism
130-
rem above does not detect changes to local Rust sources (src\rust\src\*.rs).
147+
rem no-op quickly when nothing changed, and the .soroban-revs file
148+
rem (tracked via build.rs) forces a rebuild when submodules change.
131149
echo Building stellar-core Rust library...
132150
%set_linker_flags% & cd /d "%project_dir%" & cargo +%version% rustc %release_profile% --package stellar-core --locked %features% --target-dir "%out_dir%\target" -- %EXTERNS% %LPATHS%
133151

src/rust/build.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
fn main() {
2+
// On Windows (build_rust.bat), soroban submodule revisions are written to
3+
// .soroban-revs before invoking cargo. Watching this file causes cargo to
4+
// mark the crate dirty when a submodule changes, so it re-links against
5+
// the updated extern rlibs (which are passed via --extern after "--" and
6+
// not tracked by cargo's own dependency graph).
7+
//
8+
// On Unix (Makefile.am), the rebuild is instead driven by Make
9+
// prerequisites and -Cmetadata in RUSTFLAGS, so the file won't exist;
10+
// we only register it when it's actually present.
11+
if std::path::Path::new(".soroban-revs").exists() {
12+
println!("cargo:rerun-if-changed=.soroban-revs");
13+
}
14+
}

0 commit comments

Comments
 (0)