Skip to content

Commit

Permalink
Add CARGO_CFG_TARGET_OS and CARGO_CFG_TARGET_ARCH to rustc environmen…
Browse files Browse the repository at this point in the history
…t variables. (#230)
  • Loading branch information
johnedmonds authored and damienmg committed May 22, 2019
1 parent 8a098fd commit adccbba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ DepInfo = provider(
},
)

def _get_rustc_env(ctx):
def _get_rustc_env(ctx, toolchain):
version = ctx.attr.version if hasattr(ctx.attr, "version") else "0.0.0"
major, minor, patch = version.split(".", 2)
if "-" in patch:
Expand All @@ -64,6 +64,8 @@ def _get_rustc_env(ctx):
"CARGO_PKG_NAME": ctx.label.name,
"CARGO_PKG_DESCRIPTION": "",
"CARGO_PKG_HOMEPAGE": "",
"CARGO_CFG_TARGET_OS": toolchain.os,
"CARGO_CFG_TARGET_ARCH": toolchain.target_arch,
}

def _get_compilation_mode_opts(ctx, toolchain):
Expand Down Expand Up @@ -291,7 +293,7 @@ def rustc_compile_action(
command = command,
inputs = compile_inputs,
outputs = [crate_info.output],
env = _get_rustc_env(ctx),
env = _get_rustc_env(ctx, toolchain),
arguments = [args],
mnemonic = "Rustc",
progress_message = "Compiling Rust {} {} ({} files)".format(crate_info.type, ctx.label.name, len(crate_info.srcs)),
Expand Down
1 change: 1 addition & 0 deletions rust/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def _rust_toolchain_impl(ctx):
target_triple = ctx.attr.target_triple,
exec_triple = ctx.attr.exec_triple,
os = ctx.attr.os,
target_arch = ctx.attr.target_triple.split("-")[0],
default_edition = ctx.attr.default_edition,
compilation_mode_opts = compilation_mode_opts,
crosstool_files = ctx.files._crosstool,
Expand Down

0 comments on commit adccbba

Please sign in to comment.