Skip to content

Commit

Permalink
Update the Visual Studio project (#4606)
Browse files Browse the repository at this point in the history
# 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)
  • Loading branch information
dmkozh authored Jan 7, 2025
2 parents 8565a39 + 1af1a3d commit 2b6a40c
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 83 deletions.
34 changes: 34 additions & 0 deletions Builds/VisualStudio/build_rust.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
:: Builds the Rust libraries for all the host versions.
:: 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.
@echo off

set "project_dir=%~dp0..\.."
set "toolchain_file=%project_dir%\rust-toolchain.toml"
set "out_dir=%1\rust"
set features=
set release_profile=
set "set_linker_flags=cd ."
if "%2"=="debug" set "set_linker_flags=(set CFLAGS=-MDd) & (set CXXFLAGS=-MDd)"
if "%2"=="release" set "release_profile=--release"
if "%3"=="next" set "features=--features next"

if not exist "%toolchain_file%" (
echo Error: "%toolchain_file%" not found.
exit /b 1
)

:: Read the channel version from the file
for /f "tokens=2 delims==" %%A in ('findstr "channel" "%toolchain_file%"') do (
set "version=%%~A"
)
:: Remove quotes from the version string
set "version=%version:~2,-1%"

if "%version%"=="" (
echo Error: Failed to extract the toolchain channel version.
exit /b 1
)

%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
%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
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
39 changes: 39 additions & 0 deletions Builds/VisualStudio/generate_rust_bridge.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
:: Generates rust bridge header and source files in the src directory.
:: Expects the first argument to be the command line for `cxxbridge.cpp`
@echo off

set "out_dir=src\generated\rust"
set "temp_header=%out_dir%\temp\RustBridge.h"
set "temp_source=%out_dir%\temp\RustBridge.cpp"
set "final_header=%out_dir%\RustBridge.h"
set "final_source=%out_dir%\RustBridge.cpp"

mkdir "%out_dir%\temp" >nul 2>nul

%1 ..\..\src\rust\src\lib.rs --cfg test=false --header --output "%temp_header%"
if %errorlevel% neq 0 (
echo Error generating temporary header file.
exit /b %errorlevel%
)

%1 ..\..\src\rust\src\lib.rs --cfg test=false --output "%temp_source%"
if %errorlevel% neq 0 (
echo Error generating temporary source file.
exit /b %errorlevel%
)

fc /b "%temp_header%" "%final_header%" >nul 2>nul
if %errorlevel% neq 0 (
copy /y "%temp_header%" "%final_header%" >nul
)

fc /b "%temp_source%" "%final_source%" >nul 2>nul
if %errorlevel% neq 0 (
copy /y "%temp_source%" "%final_source%" >nul
)

del "%temp_header%" >nul 2>nul
del "%temp_source%" >nul 2>nul

:: Make sure we exit without an error
exit 0
Loading

0 comments on commit 2b6a40c

Please sign in to comment.