| # Rust rules |
| * [cargo_build_script](#cargo_build_script) |
| |
| <a id="#cargo_build_script"></a> |
| |
| ## cargo_build_script |
| |
| <pre> |
| cargo_build_script(<a href="#cargo_build_script-name">name</a>, <a href="#cargo_build_script-crate_name">crate_name</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-build_script_env">build_script_env</a>, <a href="#cargo_build_script-kwargs">kwargs</a>) |
| </pre> |
| |
| Compile and execute a rust build script to generate build attributes |
| |
| This rules take the same arguments as rust_binary. |
| |
| Example: |
| |
| Suppose you have a crate with a cargo build script `build.rs`: |
| |
| ```output |
| [workspace]/ |
| hello_lib/ |
| BUILD |
| build.rs |
| src/ |
| lib.rs |
| ``` |
| |
| Then you want to use the build script in the following: |
| |
| `hello_lib/BUILD`: |
| ```python |
| package(default_visibility = ["//visibility:public"]) |
| |
| load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary", "rust_library") |
| load("@io_bazel_rules_rust//cargo:cargo_build_script.bzl", "cargo_build_script") |
| |
| # This will run the build script from the root of the workspace, and |
| # collect the outputs. |
| 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"}, |
| ) |
| |
| rust_library( |
| name = "hello_lib", |
| srcs = [ |
| "src/lib.rs", |
| ], |
| deps = [":build_script"], |
| ) |
| ``` |
| |
| The `hello_lib` target will be build with the flags and the environment variables declared by the build script in addition to the file generated by it. |
| |
| |
| **PARAMETERS** |
| |
| |
| | Name | Description | Default Value | |
| | :------------- | :------------- | :------------- | |
| | <a id="cargo_build_script-name"></a>name | The target name for the underlying rule | none | |
| | <a id="cargo_build_script-crate_name"></a>crate_name | Name of the crate associated with this build script target. | <code>""</code> | |
| | <a id="cargo_build_script-crate_features"></a>crate_features | A list of features to enable for the build script. | <code>[]</code> | |
| | <a id="cargo_build_script-version"></a>version | The semantic version (semver) of the crate. | <code>None</code> | |
| | <a id="cargo_build_script-deps"></a>deps | The dependencies of the crate defined by <code>crate_name</code>. | <code>[]</code> | |
| | <a id="cargo_build_script-build_script_env"></a>build_script_env | Environment variables for build scripts. | <code>{}</code> | |
| | <a id="cargo_build_script-kwargs"></a>kwargs | Forwards to the underlying <code>rust_binary</code> rule. | none | |
| |
| |