From 1bce8c5e1613e4f778e20121f43006868480cd58 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Fri, 14 Aug 2026 14:18:08 -0700 Subject: [PATCH] fix(rust): skip path mapping for unsandboxed actions Assisted-by: OpenAI Codex --- rust/private/rustc.bzl | 6 +++++- test/path_mapping/BUILD.bazel | 7 +++++++ test/path_mapping/no_sandbox_test.rs | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/path_mapping/BUILD.bazel create mode 100644 test/path_mapping/no_sandbox_test.rs diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 1ad6a5f5be..a97dd12eea 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -1535,12 +1535,16 @@ def construct_arguments( if rustc_env_attr: target_has_location_expansion = has_location_expansion(rustc_env_attr.values()) + # Path mapping requires sandboxed execution, which these tags disable. + tags = getattr(attr, "tags", []) + requires_unsandboxed_execution = "no-sandbox" in tags or "local" in tags + args = struct( process_wrapper_flags = process_wrapper_flags, rustc_path = rustc_path, rustc_flags = rustc_flags, extra_rustc_flags = rust_flags_args, - supports_path_mapping = not target_has_location_expansion, + supports_path_mapping = not target_has_location_expansion and not requires_unsandboxed_execution, all = all_args, ) diff --git a/test/path_mapping/BUILD.bazel b/test/path_mapping/BUILD.bazel new file mode 100644 index 0000000000..a3f67bf12b --- /dev/null +++ b/test/path_mapping/BUILD.bazel @@ -0,0 +1,7 @@ +load("@rules_rust//rust:defs.bzl", "rust_test") + +rust_test( + name = "no_sandbox_test", + srcs = ["no_sandbox_test.rs"], + tags = ["no-sandbox"], +) diff --git a/test/path_mapping/no_sandbox_test.rs b/test/path_mapping/no_sandbox_test.rs new file mode 100644 index 0000000000..1e5dd2c549 --- /dev/null +++ b/test/path_mapping/no_sandbox_test.rs @@ -0,0 +1,4 @@ +#[test] +fn runs_without_sandboxing() { + assert_eq!(2 + 2, 4); +}