Skip to content

Commit

Permalink
Add the CARGO_CRATE_NAME env var
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Dec 16, 2020
1 parent 22d6730 commit 883a04c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cargo/cargo_build_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def _build_script_impl(ctx):
crate_name = ctx.label.name
if crate_name.endswith("_build_script"):
crate_name = crate_name.replace("_build_script", "")
crate_name = crate_name.replace("_", "-")

pkg_name = crate_name.replace("_", "-")

toolchain_tools = [
# Needed for rustc to function.
Expand All @@ -68,7 +69,8 @@ def _build_script_impl(ctx):

env.update({
"CARGO_MANIFEST_DIR": manifest_dir,
"CARGO_PKG_NAME": crate_name,
"CARGO_PKG_NAME": pkg_name,
"CARGO_CRATE_NAME": crate_name,
"HOST": toolchain.exec_triple,
"OPT_LEVEL": compilation_mode_opt_level,
"RUSTC": toolchain.rustc.path,
Expand Down Expand Up @@ -134,7 +136,7 @@ def _build_script_impl(ctx):
# See https://doc.rust-lang.org/cargo/reference/build-scripts.html#-sys-packages
# for details.
args = ctx.actions.args()
args.add_all([script.path, crate_name, links, out_dir.path, env_out.path, flags_out.path, link_flags.path, dep_env_out.path])
args.add_all([script.path, pkg_name, links, out_dir.path, env_out.path, flags_out.path, link_flags.path, dep_env_out.path])
build_script_inputs = []
for dep in ctx.attr.deps:
if DepInfo in dep and dep[DepInfo].dep_env:
Expand Down
1 change: 1 addition & 0 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def _get_rustc_env(ctx, toolchain):
"CARGO_PKG_DESCRIPTION": "",
"CARGO_PKG_HOMEPAGE": "",
"CARGO_PKG_NAME": ctx.label.name,
"CARGO_CRATE_NAME": ctx.label.name.replace("_", "-"),
"CARGO_PKG_VERSION_MAJOR": major,
"CARGO_PKG_VERSION_MINOR": minor,
"CARGO_PKG_VERSION_PATCH": patch,
Expand Down

0 comments on commit 883a04c

Please sign in to comment.