This module provides a single place for all aspects, rules, and macros that are meant to have stardoc generated documentation.
Macros and Functions
cargo_build_script
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
:
[workspace]/
hello_lib/
BUILD
build.rs
src/
lib.rs
Then you want to use the build script in the following:
hello_lib/BUILD
:
package(default_visibility = ["//visibility:public"])
load("@rules_rust//rust:rust.bzl", "rust_binary", "rust_library")
load("@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"],
# 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(
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.
name
The name for the underlying rule. This should be the name of the package being compiled, optionally with a suffix of _build_script.
crate_features
A list of features to enable for the build script.
version
The semantic version (semver) of the crate.
deps
The dependencies of the crate.
build_script_env
Environment variables for build scripts.
data
Files or tools needed by the build script.
links
Name of the native library this crate links against.
rustc_env
Environment variables to set in rustc when compiling the build script.
kwargs
Forwards to the underlying rust_binary
rule.