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 build scripts HOST and OPT_LEVEL env vars #336

Merged
merged 1 commit into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cargo/cargo_build_script.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_rust//rust:private/rustc.bzl", "BuildInfo", "rustc_compile_action")
load("@io_bazel_rules_rust//rust:private/rustc.bzl", "BuildInfo", "get_compilation_mode_opts")
load("@io_bazel_rules_rust//rust:private/utils.bzl", "find_toolchain")
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary")

Expand All @@ -8,13 +8,16 @@ def _cargo_build_script_run(ctx, script):
env_out = ctx.actions.declare_file(ctx.label.name + ".env")
flags_out = ctx.actions.declare_file(ctx.label.name + ".flags")
manifest_dir = "%s.runfiles/%s" % (script.path, ctx.label.workspace_name or ctx.workspace_name)
compilation_mode_opt_level = get_compilation_mode_opts(ctx, toolchain).opt_level
env = {
"CARGO_MANIFEST_DIR": manifest_dir,
"RUSTC": toolchain.rustc.path,
"TARGET": toolchain.target_triple,
"CARGO_CFG_TARGET_ARCH": toolchain.target_arch,
"CARGO_MANIFEST_DIR": manifest_dir,
"HOST": toolchain.exec_triple,
"OPT_LEVEL": compilation_mode_opt_level,
"OUT_DIR": out_dir.path,
"RUSTC": toolchain.rustc.path,
"RUST_BACKTRACE": "full",
"TARGET": toolchain.target_triple,
}

for f in ctx.attr.crate_features:
Expand Down
4 changes: 2 additions & 2 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _get_rustc_env(ctx, toolchain):
"CARGO_CFG_TARGET_ARCH": toolchain.target_arch,
}

def _get_compilation_mode_opts(ctx, toolchain):
def get_compilation_mode_opts(ctx, toolchain):
comp_mode = ctx.var["COMPILATION_MODE"]
if not comp_mode in toolchain.compilation_mode_opts:
fail("Unrecognized compilation mode {} for toolchain.".format(comp_mode))
Expand Down Expand Up @@ -296,7 +296,7 @@ def rustc_compile_action(
args.add("--out-dir=" + output_dir)
args.add("--codegen=extra-filename=" + extra_filename)

compilation_mode = _get_compilation_mode_opts(ctx, toolchain)
compilation_mode = get_compilation_mode_opts(ctx, toolchain)
args.add("--codegen=opt-level=" + compilation_mode.opt_level)
args.add("--codegen=debuginfo=" + compilation_mode.debug_info)

Expand Down