Crate build

source
Expand description

A small crate used for supplying helpers to build.rs scripts.

This just simplifies writing build.rs scripts and helps to make them more generally readable.

This crate should not ever be included as a [dependency].

Macros§

  • The out_dir macro provides an easy mechanism for retrieving the OUT_DIR environment variable that is implicitly defined at runtime in build scripts.
  • The rerun_if_changed instruction tells Cargo to re-run the build script if the file at the given path has changed. Currently, Cargo only uses the filesystem last-modified “mtime” timestamp to determine if the file has changed. It compares against an internal cached timestamp of when the build script last ran.
  • The rerun_if_env_changed instruction tells Cargo to re-run the build script if the value of an environment variable of the given name has changed.
  • The rustc_cdylib_link_arg instruction tells Cargo to pass the -C link-arg=FLAG option to the compiler, but only when building a cdylib library target. Its usage is highly platform specific. It is useful to set the shared library version or the runtime-path.
  • The rustc_cfg instruction tells Cargo to pass the given value to the --cfg flag to the compiler. This may be used for compile-time detection of features to enable conditional compilation.
  • The rustc_env instruction tells Cargo to set the given environment variable when compiling the package. The value can be then retrieved by the env! macro in the compiled crate. This is useful for embedding additional metadata in crate’s code, such as the hash of git HEAD or the unique identifier of a continuous integration server.
  • The rustc_flags instruction tells Cargo to pass the given space-separated flags to the compiler. This only allows the -l and -L flags, and is equivalent to using rustc-link-lib and rustc-link-search.
  • The rustc_link_arg_benches instruction tells Cargo to pass the -C link-arg=FLAG option to the compiler, but only when building a benchmark target.
  • The rustc_link_arg_bin instruction tells Cargo to pass the -C link-arg=FLAG option to the compiler, but only when building the binary target with name BIN. Its usage is highly platform specific. It is useful to set a linker script or other linker options.
  • The rustc_link_arg_bins instruction tells Cargo to pass the -C link-arg=FLAG option to the compiler, but only when building a binary target. Its usage is highly platform specific. It is useful to set a linker script or other linker options.
  • The rustc_link_arg_examples instruction tells Cargo to pass the -C link-arg=FLAG option to the compiler, but only when building an examples target.
  • The rustc_link_arg_tests instruction tells Cargo to pass the -C link-arg=FLAG option to the compiler, but only when building a tests target.
  • The rustc_link_lib instruction tells Cargo to link the given library using the compiler’s -l flag. This is typically used to link a native library using FFI.
  • The rustc_link_search instruction tells Cargo to pass the -L flag to the compiler to add a directory to the library search path.
  • The warninginstruction tells Cargo to display a warning after the build script has finished running. Warnings are only shown for path dependencies (that is, those you’re working on locally), so for example warnings printed out in crates.io crates are not emitted by default. The-vv` “very verbose” flag may be used to have Cargo display warnings for all crates.