Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions crates/once-frontend/prelude/rust.star
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,14 @@ def _rust_unix_tool_dirs():
# inheriting the host's PATH would make the action depend on whatever happens
# to be installed. The standard system directories are the same everywhere the
# platform runs, so they stay part of the action key without importing the
# host's configuration.
def _rust_process_path():
# host's configuration. Windows processes also need `SystemRoot`: without it
# Winsock cannot initialize and every socket fails with os error 10106.
def _rust_process_env():
if host_os() == "windows":
return _rust_windows_tool_env().get("PATH") or ""
return ":".join(_rust_unix_tool_dirs())
tools = _rust_windows_tool_env()
return {key: tools[key] for key in ["PATH", "SystemRoot"] if tools.get(key)}
path = ":".join(_rust_unix_tool_dirs())
return {"PATH": path} if path else {}

def _rust_tool_path(tools):
dirs = []
Expand Down Expand Up @@ -2032,9 +2035,8 @@ def _rust_run_args(ctx):

def _rust_binary_run_env(ctx, run_dir):
env = {"HOME": execution_path(run_dir + "/home")}
process_path = _rust_process_path()
if process_path:
env["PATH"] = process_path
for key, value in _rust_process_env().items():
env[key] = value
_rust_merge_env_lower_precedence(env, _rust_cargo_config_env(ctx))
for key, value in _rust_host_env(_rust_attr(ctx, "env_inherit", [])).items():
env[key] = value
Expand Down Expand Up @@ -2102,9 +2104,8 @@ def _rust_cargo_runtime_env(ctx):

def _rust_test_env(ctx, test_dir):
env = {"HOME": execution_path(_rust_scratch_dir(ctx) + "/test-home")}
process_path = _rust_process_path()
if process_path:
env["PATH"] = process_path
for key, value in _rust_process_env().items():
env[key] = value
for key, value in _rust_cargo_runtime_env(ctx).items():
env[key] = value
for key, value in _rust_bin_exe_env(ctx).items():
Expand Down
34 changes: 34 additions & 0 deletions crates/once-frontend/tests/prelude/rust_build_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,37 @@ result = repr("ok")
.iter()
.any(|arg| arg == "-Ctarget-cpu=cortex-a76"));
}

#[test]
fn processes_launched_from_rust_artifacts_keep_windows_system_root() {
let env = |os: &str| {
let source = format!(
r#"{prelude}
def host_os():
return {os:?}
def host_env(name):
return {{"Path": "C:\\Windows\\system32", "SystemRoot": "C:\\Windows", "INCLUDE": "C:\\sdk\\include"}}.get(name, "")
ctx = {{
"label": {{"package": "", "name": "app", "id": "app"}},
"attr": {{"crate_root": "main.rs"}},
"deps": [],
"srcs": ["*.rs"],
}}
result = repr([
{{key: value for key, value in env.items() if key in ["PATH", "SystemRoot", "INCLUDE"]}}
for env in [_rust_test_env(ctx, ""), _rust_binary_run_env(ctx, ".once/run")]
])
"#,
prelude = all_prelude_source(),
);
let workspace = TempDir::new().unwrap();
let store = store_for(workspace.path(), "");
with_active_store(store, || eval_prelude_source_to_repr(source))
.1
.unwrap()
};
let windows = r#"{"PATH": "C:\\Windows\\system32", "SystemRoot": "C:\\Windows"}"#;
assert_eq!(env("windows"), format!("[{windows}, {windows}]"));
let linux = r#"{"PATH": "/usr/bin:/bin:/usr/sbin:/sbin"}"#;
assert_eq!(env("linux"), format!("[{linux}, {linux}]"));
}
Loading