Skip to content

Commit

Permalink
Add build scripts HOST and OPT_LEVEL env vars (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
a1ph committed Jun 15, 2020
1 parent dc4d3d7 commit 77ad6cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
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 _construct_arguments(
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

0 comments on commit 77ad6cc

Please sign in to comment.