Skip to content

Commit

Permalink
Multiple rust libraries with submodules (#4456)
Browse files Browse the repository at this point in the history
This modifies the approach we use to linking multiple sorobans. The new
approach builds each soroban separately into its own `rlib` using a
`--locked` cargo build, followed by manually providing them as
`--extern` definitions to the top-level rust build of
libstellar_core.rlib.

It is an approach to solving problems of cargo solving/merging/advancing
dependency versions when doing soroban multi-versioning (a.k.a.
#4278).

The approach here is deeply indebted to @leighmcculloch -- he both had
the initial idea and overcame almost every obstacle I encountered along
the way. I am just the automake-wrestling keyboard monkey in this PR.

Advantages:
- We get the soroban lockfiles that were tested upstream, no more no
less.
- We get to use git submodules to just point directly to the soroban
source trees.
- Cargo treats all the builds separately: each soroban, then
stellar-core itself. Never merges deps of any of them.

Disadvantages:
  - Submodules make a lot of people sad
  - The necessary automake code _definitely_ makes me sad
- It breaks vscode or any other IDE trying to edit contract.rs (which,
granted, is only 500 lines of code)

## Dep-tree checking

There's some existing machinery in stellar-core that bakes-in the
Cargo.lock file and then compares the dep-tree of each soroban host in
it to fixed (manually maintained) dep-tree files we generate with the
`cargo lock tree` cargo-extension.

This machinery no longer works with this new scheme:
  - There is no single lockfile anymore
- The lockfiles in the submodules contain lots of additional deps and
churn (dev-deps especially)

So instead I've decided to redo this task using a _slightly_ weaker
tool: `cargo tree`, which is built-in to cargo (not `cargo lock tree`).
This loses some precision (`cargo tree` only outputs package version
numbers, not checksums) but it allows us to specify the features, and
exclude the dev-deps, of each submodule. Along the way I've changed it
from a dynamic check to a static one: the build just won't succeed if
the expected deptrees (checked-in to the stellar-core repo) don't match
the actual ones (extracted at build time from the submodules). The
resulting errors look like this:

```
--- rust/src/dep-trees/p21-expect.txt	2024-09-07 20:38:22.056593002 -0700
+++ ../src/rust/src/dep-trees/p21-actual.txt	2024-09-07 20:38:11.852700915 -0700
@@ -5,7 +5,7 @@
 │   ├── curve25519-dalek-derive v0.1.0 (proc-macro)
 │   │   ├── proc-macro2 v1.0.69
 │   │   │   └── unicode-ident v1.0.9
-│   │   ├── quote v1.0.32
+│   │   ├── quote v1.0.33
 │   │   │   └── proc-macro2 v1.0.69 (*)
 │   │   └── syn v2.0.39
 │   │       ├── proc-macro2 v1.0.69 (*)
dep trees differ, please update p21-expect.txt or roll back submodule
```

I think this is a generally superior developer experience for us,
despite the minor loss in precision around dep identities. In practice I
think the package version numbers are precise enough.

## Dep-tree differences

If you take a look at the dep tree being checked in with this change for
the p21 host and compare to the dep tree baked into master's current
lockfile for the `[email protected]` package, you will see some
slight differences: specifically you'll see that this PR _downgrades_
`smallvec 1.13.2 -> 1.10.0`, `libm 0.2.8 -> 0.2.7` and `wasmparser-nostd
0.100.2 -> 0.100.1`, and the removal of `ahash`. These downgrades are
actually a _revert_ of changes that happened recently in
e967b18 where I generalized support for
multiple versions of soroban and simultaneously brought the p22 env into
core: at that point I was forced (by cargo's aggressive version
unification) to allow those _upgrades_ to the dep-tree of the p21 host,
even though I kinda didn't want to. I accepted them at the time as
"probably unobservable and worth the bet" but, in fact, the presence of
such unwanted upgrades was one of the motivating factors for _this PR_,
that reverts them by downgrading them.

Luckily we have not _released_ anything with those unwanted-upgrades
yet, so reverting and downgrading them to the exact versions that (a)
shipped in p21 and (b) are baked into the lockfile of the env git repo
at the point in history when p21 was released is the right thing to do
here. But it was good to check!
  • Loading branch information
sisuresh authored Sep 19, 2024
2 parents 92e6ed0 + 44a568b commit 61e8d53
Show file tree
Hide file tree
Showing 26 changed files with 768 additions and 3,001 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

complete:
if: always()
needs: [fmt, cackle, cargo-deny, rust-check-git-rev-deps, build]
needs: [fmt, cargo-deny, rust-check-git-rev-deps, build]
runs-on: ubuntu-latest
steps:
- if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
Expand All @@ -28,13 +28,6 @@ jobs:
- run: rustup update
- run: cargo fmt --all --check

cackle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cackle-rs/cackle-action@997327f77e59d9cda7b0b6217f0fbdbd3f3ca904
- run: cargo acl -n test

cargo-deny:
runs-on: ubuntu-latest
strategy:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ compile_commands.json
/src/archtmp-*
/src/main/StellarCoreVersion.cpp
/src/main/XDRFilesSha256.cpp
/src/rust/soroban/tmp
/src/rust/src/dep-trees/*-actual.txt

/src/testdata/*
# Make an exception for ledger-close-meta files, which should be created and committed on every protocol bump.
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@
path = src/protocol-curr/xdr
url = https://github.com/stellar/stellar-xdr
branch = curr
[submodule "src/rust/soroban/p21"]
path = src/rust/soroban/p21
url = https://github.com/stellar/rs-soroban-env
[submodule "src/rust/soroban/p22"]
path = src/rust/soroban/p22
url = https://github.com/stellar/rs-soroban-env
32 changes: 26 additions & 6 deletions Builds/VisualStudio/stellar-core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;psapi.lib;Credui.lib;userenv.lib;bcrypt.lib;ntdll.lib;$(OutDir)\rust\target\release\rust_stellar_core.lib;C:\Program Files\PostgreSQL\15\lib\libpq.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cargo build --release --target-dir $(OutDir)\rust\target --features tracy --features core-vnext</Command>
<Command>
(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cd $(MSBuildProjectDirectory)\..\..\src\rust\soroban\p21 &amp; (set RUSTFLAGS=-Cmetadata=p21) &amp; cargo build --release --package soroban-env-host --locked --target-dir $(OutDir)\rust\soroban-p21-target
(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cd $(MSBuildProjectDirectory)\..\..\src\rust\soroban\p22 &amp; (set RUSTFLAGS=-Cmetadata=p22) &amp; cargo build --release --package soroban-env-host --locked --features next --target-dir $(OutDir)\rust\soroban-p22-target
(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cd $(MSBuildProjectDirectory)\..\..\ &amp; cargo rustc --release --package stellar-core --locked --features next --target-dir $(OutDir)\rust\target -- --extern soroban_env_host_p21=$(OutDir)\rust\soroban-p21-target\release\libsoroban_env_host.rlib --extern soroban_env_host_p22=$(OutDir)\rust\soroban-p22-target\release\libsoroban_env_host.rlib -L dependency=$(OutDir)\rust\soroban-p21-target\release\deps -L dependency=$(OutDir)\rust\soroban-p22-target\release\deps
</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Rust</Message>
Expand Down Expand Up @@ -204,7 +208,11 @@ exit /b 0
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;psapi.lib;Credui.lib;userenv.lib;bcrypt.lib;ntdll.lib;$(OutDir)\rust\target\release\rust_stellar_core.lib;C:\Program Files\PostgreSQL\15\lib\libpq.lib;%(AdditionalDependencies);</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cargo build --release --target-dir $(OutDir)\rust\target --features tracy</Command>
<Command>
(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cd $(MSBuildProjectDirectory)\..\..\src\rust\soroban\p21 &amp; (set RUSTFLAGS=-Cmetadata=p21) &amp; cargo build --release --package soroban-env-host --locked --target-dir $(OutDir)\rust\soroban-p21-target
(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cd $(MSBuildProjectDirectory)\..\..\src\rust\soroban\p22 &amp; (set RUSTFLAGS=-Cmetadata=p22) &amp; cargo build --release --package soroban-env-host --locked --target-dir $(OutDir)\rust\soroban-p22-target
(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cd $(MSBuildProjectDirectory)\..\..\ &amp; cargo rustc --release --package stellar-core --locked --target-dir $(OutDir)\rust\target -- --extern soroban_env_host_p21=$(OutDir)\rust\soroban-p21-target\release\libsoroban_env_host.rlib --extern soroban_env_host_p22=$(OutDir)\rust\soroban-p22-target\release\libsoroban_env_host.rlib -L dependency=$(OutDir)\rust\soroban-p21-target\release\deps -L dependency=$(OutDir)\rust\soroban-p22-target\release\deps
</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Rust</Message>
Expand Down Expand Up @@ -268,7 +276,11 @@ exit /b 0
</IgnoreSpecificDefaultLibraries>
</Link>
<PreBuildEvent>
<Command>(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cargo build --release --target-dir $(OutDir)\rust\target --features tracy --features core-vnext</Command>
<Command>
(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cd $(MSBuildProjectDirectory)\..\..\src\rust\soroban\p21 &amp; (set RUSTFLAGS=-Cmetadata=p21) &amp; cargo build --release --package soroban-env-host --locked --target-dir $(OutDir)\rust\soroban-p21-target
(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cd $(MSBuildProjectDirectory)\..\..\src\rust\soroban\p22 &amp; (set RUSTFLAGS=-Cmetadata=p22) &amp; cargo build --release --package soroban-env-host --locked --features next --target-dir $(OutDir)\rust\soroban-p22-target
(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cd $(MSBuildProjectDirectory)\..\..\ &amp; cargo rustc --release --package stellar-core --locked --features next --target-dir $(OutDir)\rust\target -- --extern soroban_env_host_p21=$(OutDir)\rust\soroban-p21-target\release\libsoroban_env_host.rlib --extern soroban_env_host_p22=$(OutDir)\rust\soroban-p22-target\release\libsoroban_env_host.rlib -L dependency=$(OutDir)\rust\soroban-p21-target\release\deps -L dependency=$(OutDir)\rust\soroban-p22-target\release\deps
</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Rust</Message>
Expand Down Expand Up @@ -330,7 +342,11 @@ exit /b 0
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;psapi.lib;Credui.lib;userenv.lib;bcrypt.lib;ntdll.lib;$(OutDir)\rust\target\release\rust_stellar_core.lib;C:\Program Files\PostgreSQL\15\lib\libpq.lib;%(AdditionalDependencies);</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>cargo build --release --target-dir $(OutDir)\rust\target --features tracy --features core-vnext</Command>
<Command>
(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cd $(MSBuildProjectDirectory)\..\..\src\rust\soroban\p21 &amp; (set RUSTFLAGS=-Cmetadata=p21) &amp; cargo build --release --package soroban-env-host --locked --target-dir $(OutDir)\rust\soroban-p21-target
(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cd $(MSBuildProjectDirectory)\..\..\src\rust\soroban\p22 &amp; (set RUSTFLAGS=-Cmetadata=p22) &amp; cargo build --release --package soroban-env-host --locked --features tracy --features next --target-dir $(OutDir)\rust\soroban-p22-target
(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cd $(MSBuildProjectDirectory)\..\..\ &amp; cargo rustc --release --package stellar-core --locked --features tracy --features next --target-dir $(OutDir)\rust\target -- --extern soroban_env_host_p21=$(OutDir)\rust\soroban-p21-target\release\libsoroban_env_host.rlib --extern soroban_env_host_p22=$(OutDir)\rust\soroban-p22-target\release\libsoroban_env_host.rlib -L dependency=$(OutDir)\rust\soroban-p21-target\release\deps -L dependency=$(OutDir)\rust\soroban-p22-target\release\deps
</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Rust</Message>
Expand Down Expand Up @@ -391,7 +407,11 @@ exit /b 0
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;psapi.lib;Credui.lib;userenv.lib;bcrypt.lib;ntdll.lib;$(OutDir)\rust\target\release\rust_stellar_core.lib;C:\Program Files\PostgreSQL\15\lib\libpq.lib;%(AdditionalDependencies);</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>cargo build --release --target-dir $(OutDir)\rust\target --features tracy</Command>
<Command>
(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cd $(MSBuildProjectDirectory)\..\..\src\rust\soroban\p21 &amp; (set RUSTFLAGS=-Cmetadata=p21) &amp; cargo build --release --package soroban-env-host --locked --target-dir $(OutDir)\rust\soroban-p21-target
(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cd $(MSBuildProjectDirectory)\..\..\src\rust\soroban\p22 &amp; (set RUSTFLAGS=-Cmetadata=p22) &amp; cargo build --release --package soroban-env-host --locked --features tracy --target-dir $(OutDir)\rust\soroban-p22-target
(set CFLAGS=-MDd) &amp; (set CXXFLAGS=-MDd) &amp; cd $(MSBuildProjectDirectory)\..\..\ &amp; cargo rustc --release --package stellar-core --locked --features tracy --target-dir $(OutDir)\rust\target -- --extern soroban_env_host_p21=$(OutDir)\rust\soroban-p21-target\release\libsoroban_env_host.rlib --extern soroban_env_host_p22=$(OutDir)\rust\soroban-p22-target\release\libsoroban_env_host.rlib -L dependency=$(OutDir)\rust\soroban-p21-target\release\deps -L dependency=$(OutDir)\rust\soroban-p22-target\release\deps
</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Rust</Message>
Expand Down Expand Up @@ -1720,4 +1740,4 @@ $(OutDir)\bin\cxxbridge.exe ..\..\src\rust\src\lib.rs --cfg test=false --output
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
5 changes: 1 addition & 4 deletions Builds/VisualStudio/stellar-core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1305,9 +1305,6 @@
<ClCompile Include="..\..\src\transactions\RestoreFootprintOpFrame.cpp">
<Filter>transactions</Filter>
</ClCompile>
<ClCompile Include="..\..\lib\tracy\public\TracyClient.cpp">
<Filter>lib\tracy</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ledger\LedgerTxnTTLSQL.cpp">
<Filter>ledger</Filter>
</ClCompile>
Expand Down Expand Up @@ -2653,4 +2650,4 @@
<Text Include="..\..\INSTALL-Windows.md" />
<Text Include="..\..\LICENSE-APACHE.txt" />
</ItemGroup>
</Project>
</Project>
Loading

0 comments on commit 61e8d53

Please sign in to comment.