Skip to content

Commit 2b6a40c

Browse files
authored
Update the Visual Studio project (#4606)
# Description - Add a script to build the Rust library that picks up the correct version from the toolchain - Prevent re-generating the rust bridge files that caused re-compilation - Fix some broken configurations - Remove some unnecessary duplication # Checklist - [ ] Reviewed the [contributing](https://github.com/stellar/stellar-core/blob/master/CONTRIBUTING.md#submitting-changes) document - [ ] Rebased on top of master (no merge commits) - [ ] Ran `clang-format` v8.0.0 (via `make format` or the Visual Studio extension) - [ ] Compiles - [ ] Ran all tests - [ ] If change impacts performance, include supporting evidence per the [performance document](https://github.com/stellar/stellar-core/blob/master/performance-eval/performance-eval.md)
2 parents 8565a39 + 1af1a3d commit 2b6a40c

File tree

4 files changed

+106
-83
lines changed

4 files changed

+106
-83
lines changed

Builds/VisualStudio/build_rust.bat

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
:: Builds the Rust libraries for all the host versions.
2+
:: Expects the first argument to be the path to the Visual Studio's `$OutDir` varible, the second argment to be `debug`/`release` for the respective build modes, and the third argument may be `curr`/`next` for vcurr/vnext builds of the host.
3+
@echo off
4+
5+
set "project_dir=%~dp0..\.."
6+
set "toolchain_file=%project_dir%\rust-toolchain.toml"
7+
set "out_dir=%1\rust"
8+
set features=
9+
set release_profile=
10+
set "set_linker_flags=cd ."
11+
if "%2"=="debug" set "set_linker_flags=(set CFLAGS=-MDd) & (set CXXFLAGS=-MDd)"
12+
if "%2"=="release" set "release_profile=--release"
13+
if "%3"=="next" set "features=--features next"
14+
15+
if not exist "%toolchain_file%" (
16+
echo Error: "%toolchain_file%" not found.
17+
exit /b 1
18+
)
19+
20+
:: Read the channel version from the file
21+
for /f "tokens=2 delims==" %%A in ('findstr "channel" "%toolchain_file%"') do (
22+
set "version=%%~A"
23+
)
24+
:: Remove quotes from the version string
25+
set "version=%version:~2,-1%"
26+
27+
if "%version%"=="" (
28+
echo Error: Failed to extract the toolchain channel version.
29+
exit /b 1
30+
)
31+
32+
%set_linker_flags% & cd %project_dir%\src\rust\soroban\p21 & (set RUSTFLAGS=-Cmetadata=p21) & cargo +%version% build %release_profile% --package soroban-env-host --locked --target-dir %out_dir%\soroban-p21-target
33+
%set_linker_flags% & cd %project_dir%\src\rust\soroban\p22 & (set RUSTFLAGS=-Cmetadata=p22) & cargo +%version% build %release_profile% --package soroban-env-host %features% --locked --target-dir %out_dir%\soroban-p22-target
34+
cd %project_dir% & cargo +%version% rustc %release_profile% --package stellar-core --locked --target-dir %out_dir%\target -- --extern soroban_env_host_p21=%out_dir%\soroban-p21-target\%2\libsoroban_env_host.rlib --extern soroban_env_host_p22=%out_dir%\soroban-p22-target\%2\libsoroban_env_host.rlib -L dependency=%out_dir%\soroban-p21-target\%2\deps -L dependency=%out_dir%\soroban-p22-target\%2\deps
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
:: Generates rust bridge header and source files in the src directory.
2+
:: Expects the first argument to be the command line for `cxxbridge.cpp`
3+
@echo off
4+
5+
set "out_dir=src\generated\rust"
6+
set "temp_header=%out_dir%\temp\RustBridge.h"
7+
set "temp_source=%out_dir%\temp\RustBridge.cpp"
8+
set "final_header=%out_dir%\RustBridge.h"
9+
set "final_source=%out_dir%\RustBridge.cpp"
10+
11+
mkdir "%out_dir%\temp" >nul 2>nul
12+
13+
%1 ..\..\src\rust\src\lib.rs --cfg test=false --header --output "%temp_header%"
14+
if %errorlevel% neq 0 (
15+
echo Error generating temporary header file.
16+
exit /b %errorlevel%
17+
)
18+
19+
%1 ..\..\src\rust\src\lib.rs --cfg test=false --output "%temp_source%"
20+
if %errorlevel% neq 0 (
21+
echo Error generating temporary source file.
22+
exit /b %errorlevel%
23+
)
24+
25+
fc /b "%temp_header%" "%final_header%" >nul 2>nul
26+
if %errorlevel% neq 0 (
27+
copy /y "%temp_header%" "%final_header%" >nul
28+
)
29+
30+
fc /b "%temp_source%" "%final_source%" >nul 2>nul
31+
if %errorlevel% neq 0 (
32+
copy /y "%temp_source%" "%final_source%" >nul
33+
)
34+
35+
del "%temp_header%" >nul 2>nul
36+
del "%temp_source%" >nul 2>nul
37+
38+
:: Make sure we exit without an error
39+
exit 0

0 commit comments

Comments
 (0)