diff --git a/docs/cargo_build_script.md b/docs/cargo_build_script.md index 51477960fc..f210c7c2f6 100644 --- a/docs/cargo_build_script.md +++ b/docs/cargo_build_script.md @@ -6,7 +6,7 @@ ## cargo_build_script
-cargo_build_script(name, crate_name, crate_features, version, deps, build_script_env, kwargs)
+cargo_build_script(name, crate_name, crate_features, version, deps, build_script_env, data, kwargs)
 
Compile and execute a rust build script to generate build attributes @@ -40,10 +40,19 @@ load("@io_bazel_rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script") cargo_build_script( name = "build_script", srcs = ["build.rs"], - # Data are shipped during execution. - data = ["src/lib.rs"], - # Environment variables passed during build.rs execution - build_script_env = {"CARGO_PKG_VERSION": "0.1.2"}, + # Optional environment variables passed during build.rs compilation + rustc_env = { + "CARGO_PKG_VERSION": "0.1.2", + }, + # Optional environment variables passed during build.rs execution. + # Note that as the build script's working directory is not execroot, + # execpath/location will return an absolute path, instead of a relative + # one. + build_script_env = { + "SOME_TOOL_OR_FILE": "$(execpath @tool//:binary)" + } + # Optional data/tool dependencies + data = ["@tool//:binary"], ) rust_library( @@ -69,6 +78,7 @@ The `hello_lib` target will be build with the flags and the environment variable | version | The semantic version (semver) of the crate. | None | | deps | The dependencies of the crate defined by crate_name. | [] | | build_script_env | Environment variables for build scripts. | {} | +| data | Files or tools needed by the build script. | [] | | kwargs | Forwards to the underlying rust_binary rule. | none | diff --git a/docs/flatten.md b/docs/flatten.md index 17c41d6bc2..9f7909ce18 100644 --- a/docs/flatten.md +++ b/docs/flatten.md @@ -122,7 +122,7 @@ Run the benchmark test using: `bazel run //fibonacci:fibonacci_bench`. | edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | "" | | out_dir_tar | __Deprecated__, do not use, see [#cargo_build_script] instead. | Label | optional | None | | proc_macro_deps | List of rust_library targets with kind proc-macro used to help build this library target. | List of labels | optional | [] | -| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc. | Dictionary: String -> String | optional | {} | +| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc.

rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more. | Dictionary: String -> String | optional | {} | | rustc_flags | List of compiler flags passed to rustc. | List of strings | optional | [] | | srcs | List of Rust .rs source files used to build the library.

If srcs contains more than one file, then there must be a file either named lib.rs. Otherwise, crate_root must be set to the source file that is the root of the crate to be passed to rustc to build this crate. | List of labels | optional | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -239,7 +239,7 @@ Hello world | out_binary | - | Boolean | optional | False | | out_dir_tar | __Deprecated__, do not use, see [#cargo_build_script] instead. | Label | optional | None | | proc_macro_deps | List of rust_library targets with kind proc-macro used to help build this library target. | List of labels | optional | [] | -| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc. | Dictionary: String -> String | optional | {} | +| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc.

rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more. | Dictionary: String -> String | optional | {} | | rustc_flags | List of compiler flags passed to rustc. | List of strings | optional | [] | | srcs | List of Rust .rs source files used to build the library.

If srcs contains more than one file, then there must be a file either named lib.rs. Otherwise, crate_root must be set to the source file that is the root of the crate to be passed to rustc to build this crate. | List of labels | optional | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -535,7 +535,7 @@ INFO: Elapsed time: 1.245s, Critical Path: 1.01s | edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | "" | | out_dir_tar | __Deprecated__, do not use, see [#cargo_build_script] instead. | Label | optional | None | | proc_macro_deps | List of rust_library targets with kind proc-macro used to help build this library target. | List of labels | optional | [] | -| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc. | Dictionary: String -> String | optional | {} | +| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc.

rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more. | Dictionary: String -> String | optional | {} | | rustc_flags | List of compiler flags passed to rustc. | List of strings | optional | [] | | srcs | List of Rust .rs source files used to build the library.

If srcs contains more than one file, then there must be a file either named lib.rs. Otherwise, crate_root must be set to the source file that is the root of the crate to be passed to rustc to build this crate. | List of labels | optional | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -792,7 +792,7 @@ Run the test with `bazel build //hello_lib:hello_lib_test`. | edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | "" | | out_dir_tar | __Deprecated__, do not use, see [#cargo_build_script] instead. | Label | optional | None | | proc_macro_deps | List of rust_library targets with kind proc-macro used to help build this library target. | List of labels | optional | [] | -| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc. | Dictionary: String -> String | optional | {} | +| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc.

rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more. | Dictionary: String -> String | optional | {} | | rustc_flags | List of compiler flags passed to rustc. | List of strings | optional | [] | | srcs | List of Rust .rs source files used to build the library.

If srcs contains more than one file, then there must be a file either named lib.rs. Otherwise, crate_root must be set to the source file that is the root of the crate to be passed to rustc to build this crate. | List of labels | optional | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -963,7 +963,7 @@ The tools required for the `rust_wasm_bindgen` rule. | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | -| bindgen | The label of a bindgen executable. | Label | optional | None | +| bindgen | The label of a wasm-bindgen executable. | Label | optional | None | @@ -971,7 +971,7 @@ The tools required for the `rust_wasm_bindgen` rule. ## cargo_build_script
-cargo_build_script(name, crate_name, crate_features, version, deps, build_script_env, kwargs)
+cargo_build_script(name, crate_name, crate_features, version, deps, build_script_env, data, kwargs)
 
Compile and execute a rust build script to generate build attributes @@ -1005,10 +1005,19 @@ load("@io_bazel_rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script") cargo_build_script( name = "build_script", srcs = ["build.rs"], - # Data are shipped during execution. - data = ["src/lib.rs"], - # Environment variables passed during build.rs execution - build_script_env = {"CARGO_PKG_VERSION": "0.1.2"}, + # Optional environment variables passed during build.rs compilation + rustc_env = { + "CARGO_PKG_VERSION": "0.1.2", + }, + # Optional environment variables passed during build.rs execution. + # Note that as the build script's working directory is not execroot, + # execpath/location will return an absolute path, instead of a relative + # one. + build_script_env = { + "SOME_TOOL_OR_FILE": "$(execpath @tool//:binary)" + } + # Optional data/tool dependencies + data = ["@tool//:binary"], ) rust_library( @@ -1034,6 +1043,7 @@ The `hello_lib` target will be build with the flags and the environment variable | version | The semantic version (semver) of the crate. | None | | deps | The dependencies of the crate defined by crate_name. | [] | | build_script_env | Environment variables for build scripts. | {} | +| data | Files or tools needed by the build script. | [] | | kwargs | Forwards to the underlying rust_binary rule. | none | diff --git a/docs/rust.md b/docs/rust.md index d85c2fe970..405af98da1 100644 --- a/docs/rust.md +++ b/docs/rust.md @@ -103,7 +103,7 @@ Run the benchmark test using: `bazel run //fibonacci:fibonacci_bench`. | edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | "" | | out_dir_tar | __Deprecated__, do not use, see [#cargo_build_script] instead. | Label | optional | None | | proc_macro_deps | List of rust_library targets with kind proc-macro used to help build this library target. | List of labels | optional | [] | -| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc. | Dictionary: String -> String | optional | {} | +| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc.

rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more. | Dictionary: String -> String | optional | {} | | rustc_flags | List of compiler flags passed to rustc. | List of strings | optional | [] | | srcs | List of Rust .rs source files used to build the library.

If srcs contains more than one file, then there must be a file either named lib.rs. Otherwise, crate_root must be set to the source file that is the root of the crate to be passed to rustc to build this crate. | List of labels | optional | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -220,7 +220,7 @@ Hello world | out_binary | - | Boolean | optional | False | | out_dir_tar | __Deprecated__, do not use, see [#cargo_build_script] instead. | Label | optional | None | | proc_macro_deps | List of rust_library targets with kind proc-macro used to help build this library target. | List of labels | optional | [] | -| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc. | Dictionary: String -> String | optional | {} | +| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc.

rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more. | Dictionary: String -> String | optional | {} | | rustc_flags | List of compiler flags passed to rustc. | List of strings | optional | [] | | srcs | List of Rust .rs source files used to build the library.

If srcs contains more than one file, then there must be a file either named lib.rs. Otherwise, crate_root must be set to the source file that is the root of the crate to be passed to rustc to build this crate. | List of labels | optional | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -314,7 +314,7 @@ INFO: Elapsed time: 1.245s, Critical Path: 1.01s | edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | "" | | out_dir_tar | __Deprecated__, do not use, see [#cargo_build_script] instead. | Label | optional | None | | proc_macro_deps | List of rust_library targets with kind proc-macro used to help build this library target. | List of labels | optional | [] | -| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc. | Dictionary: String -> String | optional | {} | +| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc.

rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more. | Dictionary: String -> String | optional | {} | | rustc_flags | List of compiler flags passed to rustc. | List of strings | optional | [] | | srcs | List of Rust .rs source files used to build the library.

If srcs contains more than one file, then there must be a file either named lib.rs. Otherwise, crate_root must be set to the source file that is the root of the crate to be passed to rustc to build this crate. | List of labels | optional | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | @@ -473,7 +473,7 @@ Run the test with `bazel build //hello_lib:hello_lib_test`. | edition | The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain. | String | optional | "" | | out_dir_tar | __Deprecated__, do not use, see [#cargo_build_script] instead. | Label | optional | None | | proc_macro_deps | List of rust_library targets with kind proc-macro used to help build this library target. | List of labels | optional | [] | -| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc. | Dictionary: String -> String | optional | {} | +| rustc_env | Dictionary of additional "key": "value" environment variables to set for rustc.

rust_test()/rust_binary() rules can use $(rootpath //package:target) to pass in the location of a generated file or external tool. Cargo build scripts that wish to expand locations should use cargo_build_script()'s build_script_env argument instead, as build scripts are run in a different environment - see cargo_build_script()'s documentation for more. | Dictionary: String -> String | optional | {} | | rustc_flags | List of compiler flags passed to rustc. | List of strings | optional | [] | | srcs | List of Rust .rs source files used to build the library.

If srcs contains more than one file, then there must be a file either named lib.rs. Otherwise, crate_root must be set to the source file that is the root of the crate to be passed to rustc to build this crate. | List of labels | optional | [] | | version | A version to inject in the cargo environment variable. | String | optional | "0.0.0" | diff --git a/docs/rust_wasm_bindgen.md b/docs/rust_wasm_bindgen.md index 7713f6f299..58e1daff24 100644 --- a/docs/rust_wasm_bindgen.md +++ b/docs/rust_wasm_bindgen.md @@ -38,6 +38,6 @@ The tools required for the `rust_wasm_bindgen` rule. | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | -| bindgen | The label of a bindgen executable. | Label | optional | None | +| bindgen | The label of a wasm-bindgen executable. | Label | optional | None |