@@ -1273,7 +1273,7 @@ def create_test_rust_tasks():
12731273 tags .append ("pr" ) # Run on PRs for latest Python
12741274 task_name = get_task_name ("test-rust" , python = python )
12751275 test_func = FunctionCall (
1276- func = "run tests" ,
1276+ func = "run rust tests" ,
12771277 vars = dict (
12781278 TOOLCHAIN_VERSION = python ,
12791279 TEST_NAME = "test_bson" ,
@@ -1305,14 +1305,53 @@ def create_test_rust_variants() -> list[BuildVariant]:
13051305
13061306
13071307def create_test_rust_func ():
1308- """Create function for running Rust extension tests."""
1308+ """Create function for running Rust extension tests.
1309+
1310+ This function installs Rust if needed, then runs the test setup and execution.
1311+ The Rust installation and PATH setup happens in a single shell session to ensure
1312+ cargo is available for the package build.
1313+ """
13091314 includes = ["TOOLCHAIN_VERSION" , "PYMONGO_BUILD_RUST" , "PYMONGO_USE_RUST" , "TEST_ARGS" ]
1310- args = [".evergreen/just.sh" , "setup-tests" , "${TEST_NAME}" , "" ]
1311- setup_cmd = get_subprocess_exec (include_expansions_in_env = includes , args = args )
1312- test_cmd = get_subprocess_exec (
1313- include_expansions_in_env = includes , args = [".evergreen/just.sh" , "run-tests" ]
1315+
1316+ # Run everything in a single shell session to ensure Rust is available
1317+ # This combines: Rust installation + setup-tests + run-tests
1318+ # Note: get_subprocess_exec defaults to binary="bash", so we only need args
1319+ combined_cmd = get_subprocess_exec (
1320+ include_expansions_in_env = includes ,
1321+ args = [
1322+ "-c" ,
1323+ # Source env.sh first to get the base PATH
1324+ "if [ -f .evergreen/scripts/env.sh ]; then "
1325+ ". .evergreen/scripts/env.sh; "
1326+ "fi; "
1327+ # Determine cargo path based on OS
1328+ 'if [ "Windows_NT" = "${OS:-}" ]; then '
1329+ 'CARGO_BIN="$USERPROFILE/.cargo/bin"; '
1330+ "else "
1331+ 'CARGO_BIN="$HOME/.cargo/bin"; '
1332+ "fi; "
1333+ # Install Rust if needed
1334+ "if ! command -v cargo &> /dev/null; then "
1335+ 'echo "Installing Rust..."; '
1336+ 'curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y; '
1337+ "fi; "
1338+ # Ensure cargo is in PATH for all subsequent commands
1339+ 'export PATH="$CARGO_BIN:$PATH"; '
1340+ 'echo "Rust toolchain: $(rustc --version 2>/dev/null || echo not found)"; '
1341+ 'echo "Cargo: $(cargo --version 2>/dev/null || echo not found)"; '
1342+ 'echo "Cargo path: $(command -v cargo || echo not found)"; '
1343+ # Update env.sh to include cargo in PATH for subsequent shell sessions
1344+ "if [ -f .evergreen/scripts/env.sh ]; then "
1345+ 'echo "export PATH=\\ "$CARGO_BIN:\\ $PATH\\ "" >> .evergreen/scripts/env.sh; '
1346+ "fi; "
1347+ # Run setup-tests
1348+ 'bash .evergreen/just.sh setup-tests "${TEST_NAME}" ""; '
1349+ # Run tests
1350+ "bash .evergreen/just.sh run-tests" ,
1351+ ],
13141352 )
1315- return "run rust tests" , [setup_cmd , test_cmd ]
1353+
1354+ return "run rust tests" , [combined_cmd ]
13161355
13171356
13181357mod = sys .modules [__name__ ]
0 commit comments