Skip to content

Commit c80a1f4

Browse files
committed
map additional variables
1 parent e7b78eb commit c80a1f4

4 files changed

Lines changed: 43 additions & 31 deletions

File tree

util/process_wrapper/BUILD.bazel

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,7 @@
1-
load("@bazel_skylib//lib:selects.bzl", "selects")
2-
31
# buildifier: disable=bzl-visibility
42
load("//rust/private:rust.bzl", "rust_binary_without_process_wrapper", "rust_test_without_process_wrapper_test")
53
load("//util/process_wrapper/private:bootstrap_process_wrapper.bzl", "bootstrap_process_wrapper")
64

7-
config_setting(
8-
name = "compilation_mode_opt",
9-
values = {"compilation_mode": "opt"},
10-
)
11-
12-
selects.config_setting_group(
13-
name = "opt_linux",
14-
match_all = [
15-
":compilation_mode_opt",
16-
"@platforms//os:linux",
17-
],
18-
visibility = ["@rules_rust_tinyjson//:__pkg__"],
19-
)
20-
21-
selects.config_setting_group(
22-
name = "opt_macos",
23-
match_all = [
24-
":compilation_mode_opt",
25-
"@platforms//os:macos",
26-
],
27-
visibility = ["@rules_rust_tinyjson//:__pkg__"],
28-
)
29-
305
rust_binary_without_process_wrapper(
316
name = "process_wrapper",
327
srcs = glob(["*.rs"]),
@@ -37,10 +12,12 @@ rust_binary_without_process_wrapper(
3712
edition = "2018",
3813
# To ensure the process wrapper is produced deterministically
3914
# debug info, which is known to sometimes have host specific
40-
# paths embedded in this section, is stripped out.
15+
# paths embedded in this section, is stripped out. On macOS,
16+
# full symbol stripping is needed to also remove N_OSO stab
17+
# entries whose timestamps vary between builds.
4118
rustc_flags = select({
42-
":opt_linux": ["-Cstrip=debuginfo"],
43-
":opt_macos": ["-Cstrip=symbols"],
19+
"@platforms//os:linux": ["-Cstrip=debuginfo"],
20+
"@platforms//os:macos": ["-Cstrip=symbols"],
4421
"//conditions:default": [],
4522
}),
4623
visibility = ["//visibility:public"],

util/process_wrapper/BUILD.tinyjson.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ rust_library_without_process_wrapper(
1010
# debug info, which is known to sometimes have host specific
1111
# paths embedded in this section, is stripped out.
1212
rustc_flags = select({
13-
"@rules_rust//util/process_wrapper:opt_linux": ["-Cstrip=debuginfo"],
14-
"@rules_rust//util/process_wrapper:opt_macos": ["-Cstrip=debuginfo"],
13+
"@platforms//os:linux": ["-Cstrip=debuginfo"],
14+
"@platforms//os:macos": ["-Cstrip=debuginfo"],
1515
"//conditions:default": [],
1616
}),
1717
visibility = ["@rules_rust//util/process_wrapper:__pkg__"],

util/process_wrapper/private/process_wrapper.bat

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ SET command=%*
66
:: Resolve the `${pwd}` placeholders
77
SET command=!command:${pwd}=%CD%!
88

9+
:: Resolve the `${output_base}` and `${exec_root}` placeholders.
10+
:: The external directory is a junction/symlink to output_base\external.
11+
:: This mirrors the logic in options.rs used by the real process wrapper.
12+
FOR /F "delims=" %%i IN ('cd external\.. ^& cd') DO SET output_base=%%i
13+
FOR %%i IN ("%CD%") DO SET workspace_name=%%~nxi
14+
SET exec_root=!output_base!\execroot\!workspace_name!
15+
SET command=!command:${output_base}=%output_base%!
16+
SET command=!command:${exec_root}=%exec_root%!
17+
918
:: Strip out the leading `--` argument.
1019
SET command=!command:~3!
1120

util/process_wrapper/private/process_wrapper.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,41 @@ set -eu
55
# Skip the first argument which is expected to be `--`
66
shift
77

8+
# Derive output_base and exec_root so we can expand their placeholders
9+
# in rustc flags (e.g. --remap-path-prefix, -oso_prefix). This mirrors
10+
# the logic in options.rs used by the real process wrapper.
11+
phys_pwd=$(cd -P . && pwd)
12+
if [ -d "external" ]; then
13+
output_base=$(cd -P external/.. && pwd)
14+
else
15+
output_base="${phys_pwd%/*}"
16+
output_base="${output_base%/*}"
17+
fi
18+
workspace_name="${phys_pwd##*/}"
19+
exec_root="${output_base}/execroot/${workspace_name}"
20+
821
for arg in "$@"; do
922
case "$arg" in
1023
*'${pwd}'*)
11-
# Split on '${pwd}' and rejoin with the actual PWD value
1224
prefix="${arg%%\$\{pwd\}*}"
1325
suffix="${arg#*\$\{pwd\}}"
1426
arg="${prefix}${PWD}${suffix}"
1527
;;
1628
esac
29+
case "$arg" in
30+
*'${output_base}'*)
31+
prefix="${arg%%\$\{output_base\}*}"
32+
suffix="${arg#*\$\{output_base\}}"
33+
arg="${prefix}${output_base}${suffix}"
34+
;;
35+
esac
36+
case "$arg" in
37+
*'${exec_root}'*)
38+
prefix="${arg%%\$\{exec_root\}*}"
39+
suffix="${arg#*\$\{exec_root\}}"
40+
arg="${prefix}${exec_root}${suffix}"
41+
;;
42+
esac
1743
set -- "$@" "$arg"
1844
shift
1945
done

0 commit comments

Comments
 (0)