Skip to content

Commit 3357b18

Browse files
Pass all environment variables to vendoring (#3964)
I have been struggling for a long time with getting private registries and git repositories to work with vendoring. CARGO_REGISTR* is currently broken due to a typo. Private git repositories don't work because the ssh auth socket is not forwarded. And custom .ssh/config blow up if all env variables referenced in the config are not forwarded. There is no great way to forward all the right environment variables. This does not appear to affect repinning directly in bzlmod.
1 parent fa96218 commit 3357b18

1 file changed

Lines changed: 6 additions & 21 deletions

File tree

crate_universe/private/crates_vendor.bzl

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,19 @@ set -euo pipefail
2424
2525
export RUNTIME_PWD="$(pwd)"
2626
if [[ -z "${{BAZEL_REAL:-}}" ]]; then
27-
BAZEL_REAL="$(which bazel || echo 'bazel')"
27+
export BAZEL_REAL="$(which bazel || echo 'bazel')"
2828
fi
2929
3030
_BIN="$(rlocation "{bin}")"
3131
32-
_ENVIRON=()
33-
_ENVIRON+=(BAZEL_REAL="${{BAZEL_REAL}}")
34-
_ENVIRON+=(BUILD_WORKSPACE_DIRECTORY="${{BUILD_WORKSPACE_DIRECTORY}}")
35-
_ENVIRON+=(PATH="${{PATH}}")
3632
{env}
3733
38-
if [[ -n "${{CARGO_BAZEL_DEBUG:-}}" ]]; then
39-
_ENVIRON+=(CARGO_BAZEL_DEBUG="${{CARGO_BAZEL_DEBUG}}")
40-
fi
41-
42-
# Pass on CARGO_REGISTRIES_* and CARGO_REGISTRY*
43-
while IFS= read -r line; do _ENVIRON+=("${{line}}"); done < <(env | grep ^CARGO_REGISTER)
44-
4534
# The path needs to be preserved to prevent bazel from starting with different
4635
# startup options (requiring a restart of bazel).
4736
# If you provide an empty path, bazel starts itself with
4837
# --default_system_javabase set to the empty string, but if you provide a path,
4938
# it may set it to a value (eg. "/usr/local/buildtools/java/jdk11").
50-
exec env - \\
51-
"${{_ENVIRON[@]}}" \\
39+
exec env -u OUTPUT_BASE \\
5240
"${{_BIN}}" \\
5341
{args} \\
5442
--nonhermetic-root-bazel-workspace-dir="${{BUILD_WORKSPACE_DIRECTORY}}" \\
@@ -143,13 +131,10 @@ def _sys_runfile_env(ctx, name, file, is_windows):
143131
name,
144132
)
145133

146-
return "\n".join([
147-
"export {}=\"$(rlocation \"{}\")\"".format(
148-
name,
149-
_rlocationpath(file, ctx.workspace_name),
150-
),
151-
"_ENVIRON+=({0}=\"${{{0}}}\")".format(name),
152-
])
134+
return "export {}=\"$(rlocation \"{}\")\"".format(
135+
name,
136+
_rlocationpath(file, ctx.workspace_name),
137+
)
153138

154139
def _expand_env(value, is_windows):
155140
if is_windows:

0 commit comments

Comments
 (0)