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

Add support for passing a custom target specification. #836

Merged
merged 13 commits into from
Jul 22, 2021
Merged
4 changes: 2 additions & 2 deletions cargo/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _build_script_impl(ctx):
# This isn't exactly right, but Bazel doesn't have exact views of "debug" and "release", so...
"PROFILE": {"dbg": "debug", "fastbuild": "debug", "opt": "release"}.get(ctx.var["COMPILATION_MODE"], "unknown"),
"RUSTC": toolchain.rustc.path,
"TARGET": toolchain.target_triple,
"TARGET": toolchain.target_flag_value,
# OUT_DIR is set by the runner itself, rather than on the action.
})

Expand Down Expand Up @@ -129,7 +129,7 @@ def _build_script_impl(ctx):
script,
ctx.executable._cargo_build_script_runner,
toolchain.rustc,
] + ctx.files.data,
] + ctx.files.data + ([] if toolchain.target_json == None else [toolchain.target_json]),
transitive = toolchain_tools,
)

Expand Down
3 changes: 2 additions & 1 deletion rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def collect_inputs(
[toolchain.rustc] +
toolchain.crosstool_files +
([build_info.rustc_env, build_info.flags] if build_info else []) +
([] if toolchain.target_json == None else [toolchain.target_json]) +
([] if linker_script == None else [linker_script]),
transitive = [
toolchain.rustc_lib.files,
Expand Down Expand Up @@ -429,7 +430,7 @@ def construct_arguments(

args.add("--emit=" + ",".join(emit_with_paths))
args.add("--color=always")
args.add("--target=" + toolchain.target_triple)
args.add("--target=" + toolchain.target_flag_value)
if hasattr(attr, "crate_features"):
args.add_all(getattr(attr, "crate_features"), before_each = "--cfg", format_each = 'feature="%s"')
if linker_script:
Expand Down
7 changes: 7 additions & 0 deletions rust/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ def _rust_toolchain_impl(ctx):
rustfmt = ctx.file.rustfmt,
cargo = ctx.file.cargo,
clippy_driver = ctx.file.clippy_driver,
target_json = ctx.file.target_json,
davidskidmore marked this conversation as resolved.
Show resolved Hide resolved
target_flag_value = ctx.file.target_json.path if ctx.file.target_json != None else ctx.attr.target_triple,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
target_flag_value = ctx.file.target_json.path if ctx.file.target_json != None else ctx.attr.target_triple,
target_flag_value = ctx.file.target_json.path if ctx.file.target_json else ctx.attr.target_triple,

rustc_lib = ctx.attr.rustc_lib,
rustc_srcs = ctx.attr.rustc_srcs,
rust_lib = ctx.attr.rust_lib,
Expand Down Expand Up @@ -296,6 +298,11 @@ rust_toolchain = rule(
),
mandatory = True,
),
"target_json": attr.label(
davidskidmore marked this conversation as resolved.
Show resolved Hide resolved
doc = ("Override the target_triple with a custom target specification. " +
"For more details see: https://doc.rust-lang.org/rustc/targets/custom.html"),
allow_single_file = True,
),
"target_triple": attr.string(
doc = (
"The platform triple for the toolchains target environment. " +
Expand Down