Skip to content

fix(rust): keep SystemRoot for Windows test and run processes - #425

Merged
fortmarek merged 1 commit into
mainfrom
fix/windows-test-systemroot
Nov 9, 2026
Merged

fortmarek merged 1 commit into
mainfrom
fix/windows-test-systemroot

Conversation

@fortmarek

Copy link
Copy Markdown
Member

What changed

On Windows, processes Once starts from a Rust target's own build outputs now get SystemRoot alongside PATH. These are rust_test runs (_rust_test_env) and once run (_rust_binary_run_env). _rust_process_path becomes _rust_process_env, which returns both variables on Windows and the fixed system PATH elsewhere, as before.

Why

The tuist desktop Windows build on Once 0.77.4 now builds every crate, but 13 tests fail as soon as they open a socket (job):

called `Result::unwrap()` on an `Err` value: Os { code: 10106, kind: Uncategorized,
message: "The requested service provider could not be loaded or initialized." }

Root cause

Rust test and run actions get a cleared environment: HOME, PATH, and the CARGO_* runtime variables. Winsock (WSAStartup) needs SystemRoot to load its service providers, so without it every TcpListener::bind or TcpStream::connect fails with error 10106. Compile and build-script actions already get SystemRoot through _rust_windows_tool_env, but _rust_cargo_runtime_env keeps only CARGO_* keys for tests, and the process PATH helper only forwarded PATH.

Approach and alternatives

Forward exactly one more variable, read from the same Windows tool environment that compile actions already use. Like PATH, SystemRoot is fixed for a given host, so the action key stays stable. I didn't forward the whole Windows tool environment: compiler variables such as INCLUDE/LIB would make test results depend on the installed toolchain without any runtime need. Users could set env_inherit = ["SystemRoot"] on a rust_test target, but cargo_workspace doesn't pass it through to the tests it generates, and every Windows test that uses networking would need it.

Impact

Windows Rust tests and once run binaries can use sockets. Windows test action keys change once. Linux and macOS environments are unchanged.

Validation

  • New prelude test processes_launched_from_rust_artifacts_keep_windows_system_root. On a simulated Windows host, both test and run environments contain PATH and SystemRoot but not INCLUDE; on Linux they contain only the fixed PATH. It fails without the change (SystemRoot missing).
  • cargo test -p once-frontend --test prelude rust (52 passed) and ... cargo (44 passed).
  • cargo clippy -p once-frontend --tests -- -D warnings and cargo fmt --all --check are clean.

I couldn't run Windows locally; Once's Windows CI and the tuist desktop Windows job on the next release are the end-to-end checks.

Rust test and run actions get a cleared environment with only HOME,
PATH, and Cargo variables. On Windows, Winsock cannot initialize without
SystemRoot, so any test that opens a socket fails with os error 10106
("The requested service provider could not be loaded or initialized").

Pass SystemRoot alongside PATH on Windows. It is fixed per host, like
the PATH Once already forwards there.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1bf6d-95f0-76f7-9a26-c062fe0363e1
Co-authored-by: Marek Fort <marek@tuist.dev>
@fortmarek
fortmarek merged commit c24c3f7 into main Nov 9, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants