Skip to content
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
4 changes: 4 additions & 0 deletions cargo/private/cargo_build_script_wrapper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def cargo_build_script(
links = None,
rundir = None,
rustc_env = {},
rustc_env_files = [],
rustc_flags = [],
visibility = None,
tags = None,
Expand Down Expand Up @@ -113,6 +114,8 @@ def cargo_build_script(

If set to `.`, the cargo build script will run in the exec root.
rustc_env (dict, optional): Environment variables to set in rustc when compiling the build script.
rustc_env_files (list of label, optional): Files containing additional environment variables to set for rustc
when building the build script.
rustc_flags (list, optional): List of compiler flags passed to `rustc`.
visibility (list of label, optional): Visibility to apply to the generated build script output.
tags: (list of str, optional): Tags to apply to the generated build script output.
Expand Down Expand Up @@ -149,6 +152,7 @@ def cargo_build_script(
data = data,
compile_data = compile_data,
rustc_env = rustc_env,
rustc_env_files = rustc_env_files,
rustc_flags = rustc_flags,
edition = edition,
tags = binary_tags,
Expand Down
3 changes: 2 additions & 1 deletion docs/cargo.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ A rule for generating variables for dependent `cargo_build_script`s without a bu
<pre>
cargo_build_script(<a href="#cargo_build_script-name">name</a>, <a href="#cargo_build_script-edition">edition</a>, <a href="#cargo_build_script-crate_name">crate_name</a>, <a href="#cargo_build_script-crate_root">crate_root</a>, <a href="#cargo_build_script-srcs">srcs</a>, <a href="#cargo_build_script-crate_features">crate_features</a>, <a href="#cargo_build_script-version">version</a>, <a href="#cargo_build_script-deps">deps</a>,
<a href="#cargo_build_script-link_deps">link_deps</a>, <a href="#cargo_build_script-proc_macro_deps">proc_macro_deps</a>, <a href="#cargo_build_script-build_script_env">build_script_env</a>, <a href="#cargo_build_script-data">data</a>, <a href="#cargo_build_script-compile_data">compile_data</a>, <a href="#cargo_build_script-tools">tools</a>, <a href="#cargo_build_script-links">links</a>,
<a href="#cargo_build_script-rundir">rundir</a>, <a href="#cargo_build_script-rustc_env">rustc_env</a>, <a href="#cargo_build_script-rustc_flags">rustc_flags</a>, <a href="#cargo_build_script-visibility">visibility</a>, <a href="#cargo_build_script-tags">tags</a>, <a href="#cargo_build_script-aliases">aliases</a>, <a href="#cargo_build_script-kwargs">kwargs</a>)
<a href="#cargo_build_script-rundir">rundir</a>, <a href="#cargo_build_script-rustc_env">rustc_env</a>, <a href="#cargo_build_script-rustc_env_files">rustc_env_files</a>, <a href="#cargo_build_script-rustc_flags">rustc_flags</a>, <a href="#cargo_build_script-visibility">visibility</a>, <a href="#cargo_build_script-tags">tags</a>, <a href="#cargo_build_script-aliases">aliases</a>, <a href="#cargo_build_script-kwargs">kwargs</a>)
</pre>

Compile and execute a rust build script to generate build attributes
Expand Down Expand Up @@ -149,6 +149,7 @@ The `hello_lib` target will be build with the flags and the environment variable
| <a id="cargo_build_script-links"></a>links | Name of the native library this crate links against. | `None` |
| <a id="cargo_build_script-rundir"></a>rundir | A directory to <code>cd</code> to before the cargo_build_script is run. This should be a path relative to the exec root.<br><br>The default behaviour (and the behaviour if rundir is set to the empty string) is to change to the relative path corresponding to the cargo manifest directory, which replicates the normal behaviour of cargo so it is easy to write compatible build scripts.<br><br>If set to <code>.</code>, the cargo build script will run in the exec root. | `None` |
| <a id="cargo_build_script-rustc_env"></a>rustc_env | Environment variables to set in rustc when compiling the build script. | `{}` |
| <a id="cargo_build_script-rustc_env_files"></a>rustc_env_files | Files containing additional environment variables to set for rustc when building the build script. | `[]` |
| <a id="cargo_build_script-rustc_flags"></a>rustc_flags | List of compiler flags passed to <code>rustc</code>. | `[]` |
| <a id="cargo_build_script-visibility"></a>visibility | Visibility to apply to the generated build script output. | `None` |
| <a id="cargo_build_script-tags"></a>tags | (list of str, optional): Tags to apply to the generated build script output. | `None` |
Expand Down
3 changes: 2 additions & 1 deletion docs/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@ A collection of files either found within the `rust-stdlib` artifact or generate
<pre>
cargo_build_script(<a href="#cargo_build_script-name">name</a>, <a href="#cargo_build_script-edition">edition</a>, <a href="#cargo_build_script-crate_name">crate_name</a>, <a href="#cargo_build_script-crate_root">crate_root</a>, <a href="#cargo_build_script-srcs">srcs</a>, <a href="#cargo_build_script-crate_features">crate_features</a>, <a href="#cargo_build_script-version">version</a>, <a href="#cargo_build_script-deps">deps</a>,
<a href="#cargo_build_script-link_deps">link_deps</a>, <a href="#cargo_build_script-proc_macro_deps">proc_macro_deps</a>, <a href="#cargo_build_script-build_script_env">build_script_env</a>, <a href="#cargo_build_script-data">data</a>, <a href="#cargo_build_script-compile_data">compile_data</a>, <a href="#cargo_build_script-tools">tools</a>, <a href="#cargo_build_script-links">links</a>,
<a href="#cargo_build_script-rundir">rundir</a>, <a href="#cargo_build_script-rustc_env">rustc_env</a>, <a href="#cargo_build_script-rustc_flags">rustc_flags</a>, <a href="#cargo_build_script-visibility">visibility</a>, <a href="#cargo_build_script-tags">tags</a>, <a href="#cargo_build_script-aliases">aliases</a>, <a href="#cargo_build_script-kwargs">kwargs</a>)
<a href="#cargo_build_script-rundir">rundir</a>, <a href="#cargo_build_script-rustc_env">rustc_env</a>, <a href="#cargo_build_script-rustc_env_files">rustc_env_files</a>, <a href="#cargo_build_script-rustc_flags">rustc_flags</a>, <a href="#cargo_build_script-visibility">visibility</a>, <a href="#cargo_build_script-tags">tags</a>, <a href="#cargo_build_script-aliases">aliases</a>, <a href="#cargo_build_script-kwargs">kwargs</a>)
</pre>

Compile and execute a rust build script to generate build attributes
Expand Down Expand Up @@ -1630,6 +1630,7 @@ The `hello_lib` target will be build with the flags and the environment variable
| <a id="cargo_build_script-links"></a>links | Name of the native library this crate links against. | `None` |
| <a id="cargo_build_script-rundir"></a>rundir | A directory to <code>cd</code> to before the cargo_build_script is run. This should be a path relative to the exec root.<br><br>The default behaviour (and the behaviour if rundir is set to the empty string) is to change to the relative path corresponding to the cargo manifest directory, which replicates the normal behaviour of cargo so it is easy to write compatible build scripts.<br><br>If set to <code>.</code>, the cargo build script will run in the exec root. | `None` |
| <a id="cargo_build_script-rustc_env"></a>rustc_env | Environment variables to set in rustc when compiling the build script. | `{}` |
| <a id="cargo_build_script-rustc_env_files"></a>rustc_env_files | Files containing additional environment variables to set for rustc when building the build script. | `[]` |
| <a id="cargo_build_script-rustc_flags"></a>rustc_flags | List of compiler flags passed to <code>rustc</code>. | `[]` |
| <a id="cargo_build_script-visibility"></a>visibility | Visibility to apply to the generated build script output. | `None` |
| <a id="cargo_build_script-tags"></a>tags | (list of str, optional): Tags to apply to the generated build script output. | `None` |
Expand Down
Empty file.
31 changes: 31 additions & 0 deletions test/cargo_build_script/rustc_env_files/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("//cargo:defs.bzl", "cargo_build_script")
load("//rust:defs.bzl", "rust_library", "rust_test")

write_file(
name = "generate_rustc_env_file",
out = "rustc_env_file",
content = [
"GREETING=Howdy",
"",
],
)

cargo_build_script(
name = "cargo_build_script",
srcs = ["build.rs"],
edition = "2018",
rustc_env_files = [":generate_rustc_env_file"],
)

rust_library(
name = "test_lib",
srcs = ["test_lib.rs"],
edition = "2018",
deps = [":cargo_build_script"],
)

rust_test(
name = "consume_build_script",
crate = ":test_lib",
)
3 changes: 3 additions & 0 deletions test/cargo_build_script/rustc_env_files/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("cargo:rustc-env=FROM_BUILD_SCRIPT={}", env!("GREETING"));
}
4 changes: 4 additions & 0 deletions test/cargo_build_script/rustc_env_files/test_lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn check_env_set() {
assert_eq!("Howdy", env!("FROM_BUILD_SCRIPT"));
}