Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow cargo_build_script to forward rustc args to build scripts #1165

Merged
merged 9 commits into from
Mar 4, 2022
14 changes: 8 additions & 6 deletions cargo/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ def _build_script_impl(ctx):

pkg_name = _name_to_pkg_name(ctx.label.name)

toolchain_tools = [
# Needed for rustc to function.
toolchain.rustc_lib,
toolchain.rust_std,
]
toolchain_tools = [toolchain.all_files]

cc_toolchain = find_cpp_toolchain(ctx)

Expand Down Expand Up @@ -121,6 +117,13 @@ def _build_script_impl(ctx):
if cc_toolchain.sysroot:
env["SYSROOT"] = cc_toolchain.sysroot

# In form build scripts of rustc flags
UebelAndre marked this conversation as resolved.
Show resolved Hide resolved
# https://github.com/rust-lang/cargo/issues/9600
env["CARGO_ENCODED_RUSTFLAGS"] = " ".join([
UebelAndre marked this conversation as resolved.
Show resolved Hide resolved
UebelAndre marked this conversation as resolved.
Show resolved Hide resolved
# Allow build scripts to locate the generated sysroot
"--sysroot=${{pwd}}/{}".format(toolchain.sysroot),
])

for f in ctx.attr.crate_features:
env["CARGO_FEATURE_" + f.upper().replace("-", "_")] = "1"

Expand All @@ -136,7 +139,6 @@ def _build_script_impl(ctx):
direct = [
script,
ctx.executable._cargo_build_script_runner,
toolchain.rustc,
] + ctx.files.data + ctx.files.tools + ([toolchain.target_json] if toolchain.target_json else []),
transitive = toolchain_tools,
)
Expand Down