Cargo settings

Definitions for all @rules_rust//cargo settings

cargo_manifest_dir_filename_suffixes_to_retain

--@rules_rust//cargo/settings:cargo_manifest_dir_filename_suffixes_to_retain

A flag which determines what files are retained in CARGO_MANIFEST_DIR directories that are created in CargoBuildScriptRun actions.

debug_std_streams_output_group

--@rules_rust//cargo/settings:debug_std_streams_output_group

A flag which adds a streams output group to cargo_build_script targets that contain the raw stderr and stdout streams from the build script.

emit_build_script_warnings

--@rules_rust//cargo/settings:emit_build_script_warnings

A flag which controls whether cargo_build_script warnings (cargo::warning=) are printed to stderr.

Supported values:

  • on: emit warnings for every cargo_build_script target, overriding any per-target emit_warnings = False.
  • auto (default): respect the per-target emit_warnings attribute. crate_universe-generated targets set it to False, so registry/git crates stay quiet (matching Cargo); first-party targets emit by default.
  • off: silence warnings build-wide.

--@rules_rust//cargo/settings:experimental_symlink_execroot

A flag for which causes cargo_build_script to symlink the execroot of the action to the CARGO_MANIFEST_DIR where the scripts are run.

out_dir_volatile_file_basenames

--@rules_rust//cargo/settings:out_dir_volatile_file_basenames

A flag which determines what file basenames are removed from OUT_DIR by cargo_build_script actions to make the _bs.out_dir TreeArtifact deterministic.

Files whose names appear in this list, as well as files with a .d or .pc extension, are deleted from OUT_DIR after the build script runs and before Bazel captures the directory. Files like config.log and Makefile embed the Bazel sandbox path, so their content changes on every action invocation, causing cache misses for all downstream rustc compilations.

use_cc_toolchain

--@rules_rust//cargo/settings:use_cc_toolchain

A flag which controls the global default of whether cargo_build_script targets should pull in the resolved cc_toolchain.

When enabled (the default), each cargo_build_script action gets the resolved cc_toolchain's all_files added to its inputs and picks up the CC, CXX, AR, CFLAGS, CXXFLAGS, LDFLAGS, and INCLUDE environment variables derived from that toolchain. This matches Cargo's behavior and is required for build scripts that shell out to a C/C++ compiler (e.g. those using cc-rs or cmake-rs).

When disabled, the cc_toolchain is omitted from cargo_build_script actions. This can significantly reduce action input sizes when using a hermetic sysroot but breaks any build script that needs to compile C/C++ code. Individual targets may override this default via the cargo_build_script.use_cc_toolchain attribute.

use_default_shell_env

--@rules_rust//cargo/settings:use_default_shell_env

A flag which controls the global default of ctx.actions.run.use_default_shell_env for cargo_build_script targets.