Build in bootstrap - Rust
Description: Global configuration for the build system.

Skip to main content

## Build

# Struct Build

Source

    pub struct Build {Show 35 fields
        pub(crate) config: Config,
        pub(crate) version: String,
        pub(crate) src: PathBuf,
        pub(crate) out: PathBuf,
        pub(crate) bootstrap_out: PathBuf,
        pub(crate) cargo_info: GitInfo,
        pub(crate) rust_analyzer_info: GitInfo,
        pub(crate) clippy_info: GitInfo,
        pub(crate) miri_info: GitInfo,
        pub(crate) rustfmt_info: GitInfo,
        pub(crate) enzyme_info: GitInfo,
        pub(crate) in_tree_llvm_info: GitInfo,
        pub(crate) in_tree_gcc_info: GitInfo,
        pub(crate) local_rebuild: bool,
        pub(crate) fail_fast: bool,
        pub(crate) test_target: TestTarget,
        pub(crate) verbosity: usize,
        pub(crate) host_target: TargetSelection,
        pub(crate) hosts: Vec<TargetSelection>,
        pub(crate) targets: Vec<TargetSelection>,
        pub(crate) initial_rustc: PathBuf,
        pub(crate) initial_rustdoc: PathBuf,
        pub(crate) initial_cargo: PathBuf,
        pub(crate) initial_lld: PathBuf,
        pub(crate) initial_relative_libdir: PathBuf,
        pub(crate) initial_sysroot: PathBuf,
        pub(crate) cc: HashMap<TargetSelection, Tool>,
        pub(crate) cxx: HashMap<TargetSelection, Tool>,
        pub(crate) ar: HashMap<TargetSelection, PathBuf>,
        pub(crate) ranlib: HashMap<TargetSelection, PathBuf>,
        pub(crate) wasi_sdk_path: Option<PathBuf>,
        pub(crate) crates: HashMap<String, Crate>,
        pub(crate) crate_paths: HashMap<PathBuf, String>,
        pub(crate) is_sudo: bool,
        pub(crate) prerelease_version: Cell<Option<u32>>,
    }

Expand description

Global configuration for the build system.

This structure transitively contains all configuration for the build system. All filesystem-encoded configuration is in `config`, all flags are in `flags`, and then parsed or probed information is listed in the keys below.

This structure is a parameter of almost all methods in the build system, although most functions are implemented as free functions rather than methods specifically on this structure itself (to make it easier to organize).

## Fields§

§`config: Config`

User-specified configuration from `bootstrap.toml`.

§`version: String`§`src: PathBuf`§`out: PathBuf`§`bootstrap_out: PathBuf`§`cargo_info: GitInfo`§`rust_analyzer_info: GitInfo`§`clippy_info: GitInfo`§`miri_info: GitInfo`§`rustfmt_info: GitInfo`§`enzyme_info: GitInfo`§`in_tree_llvm_info: GitInfo`§`in_tree_gcc_info: GitInfo`§`local_rebuild: bool`§`fail_fast: bool`§`test_target: TestTarget`§`verbosity: usize`§`host_target: TargetSelection`

Build triple for the pre-compiled snapshot compiler.

§`hosts: Vec<TargetSelection>`

Which triples to produce a compiler toolchain for.

§`targets: Vec<TargetSelection>`

Which triples to build libraries (core/alloc/std/test/proc_macro) for.

§`initial_rustc: PathBuf`§`initial_rustdoc: PathBuf`§`initial_cargo: PathBuf`§`initial_lld: PathBuf`§`initial_relative_libdir: PathBuf`§`initial_sysroot: PathBuf`§`cc: HashMap<TargetSelection, Tool>`§`cxx: HashMap<TargetSelection, Tool>`§`ar: HashMap<TargetSelection, PathBuf>`§`ranlib: HashMap<TargetSelection, PathBuf>`§`wasi_sdk_path: Option<PathBuf>`§`crates: HashMap<String, Crate>`§`crate_paths: HashMap<PathBuf, String>`§`is_sudo: bool`§`prerelease_version: Cell<Option<u32>>`

## Implementations§

Source§

### impl Build

Source

#### pub(crate) fn do_if_verbose(&self, f: impl Fn())

Source

#### pub(crate) fn is_verbose(&self) -> bool

Source

#### pub(crate) fn create(&self, path: &Path, s: &str)

Source

#### pub(crate) fn remove(&self, f: &Path)

Source

#### pub(crate) fn tempdir(&self) -> PathBuf

Source

#### pub(crate) fn llvm_link_shared(&self) -> bool

Source

#### pub(crate) fn download_rustc(&self) -> bool

Source§

### impl Build

Source

#### pub fn new(config: Config) -> Build

Creates a new set of build configuration from the `flags` on the command line and the filesystem `config`.

By default all build output will be placed in the current directory.

Source

#### pub fn require_submodule(&self, submodule: &str, err_hint: Option<&str>)

Updates a submodule, and exits with a failure if submodule management is disabled and the submodule does not exist.

The given submodule name should be its path relative to the root of the main repository.

The given `err_hint` will be shown to the user if the submodule is not checked out and submodule management is disabled.

Source

#### pub(crate) fn update_existing_submodules(&self)

If any submodule has been initialized already, sync it unconditionally. This avoids contributors checking in a submodule change by accident.

Source

#### pub fn update_existing_submodule(config: &Config, submodule: &str)

Updates the given submodule only if it’s initialized already; nothing happens otherwise.

Source

#### pub fn build(&mut self)

Executes the entire build, as configured by the flags and configuration.

Source

#### pub(crate) fn rust_info(&self) -> &GitInfo

Source

#### pub(crate) fn std_features(&self, target: TargetSelection) -> String

Gets the space-separated set of activated features for the standard library. This can be configured with the `std-features` key in bootstrap.toml.

Source

#### pub(crate) fn rustc_features( &self, kind: Kind, target: TargetSelection, crates: &[String], ) -> String

Gets the space-separated set of activated features for the compiler.

Source

#### pub(crate) fn cargo_dir(&self, mode: Mode) -> &'static str

Component directory that Cargo will produce output into (e.g. release/debug)

Source

#### pub(crate) fn tools_dir(&self, build_compiler: Compiler) -> PathBuf

Source

#### pub(crate) fn stage_out(&self, build_compiler: Compiler, mode: Mode) -> PathBuf

Returns the root directory for all output generated in a particular stage when being built with a particular build compiler.

The mode indicates what the root directory is for.

Source

#### pub(crate) fn cargo_out( &self, build_compiler: Compiler, mode: Mode, target: TargetSelection, ) -> PathBuf

Returns the root output directory for all Cargo output in a given stage, running a particular compiler, whether or not we’re building the standard library, and targeting the specified architecture.

Source

#### pub(crate) fn llvm_out(&self, target: TargetSelection) -> PathBuf

Root output directory of LLVM for `target`

Note that if LLVM is configured externally then the directory returned will likely be empty.

Source

#### pub(crate) fn enzyme_out(&self, target: TargetSelection) -> PathBuf

Source

#### pub(crate) fn offload_out(&self, target: TargetSelection) -> PathBuf

Source

#### pub(crate) fn lld_out(&self, target: TargetSelection) -> PathBuf

Source

#### pub(crate) fn doc_out(&self, target: TargetSelection) -> PathBuf

Output directory for all documentation for a target

Source

#### pub(crate) fn json_doc_out(&self, target: TargetSelection) -> PathBuf

Output directory for all JSON-formatted documentation for a target

Source

#### pub(crate) fn test_out(&self, target: TargetSelection) -> PathBuf

Source

#### pub(crate) fn compiler_doc_out(&self, target: TargetSelection) -> PathBuf

Output directory for all documentation for a target

Source

#### pub(crate) fn md_doc_out(&self, target: TargetSelection) -> PathBuf

Output directory for some generated md crate documentation for a target (temporary)

Source

#### pub(crate) fn vendored_crates_path(&self) -> Option<PathBuf>

Path to the vendored Rust crates.

Source

#### pub(crate) fn llvm_filecheck(&self, target: TargetSelection) -> PathBuf

Returns the path to `FileCheck` binary for the specified target

Source

#### pub(crate) fn native_dir(&self, target: TargetSelection) -> PathBuf

Directory for libraries built from C/C++ code and shared between stages.

Source

#### pub(crate) fn test_helpers_out(&self, target: TargetSelection) -> PathBuf

Root output directory for rust_test_helpers library compiled for `target`

Source

#### pub(crate) fn add_rust_test_threads(&self, cmd: &mut BootstrapCommand)

Adds the `RUST_TEST_THREADS` env var if necessary

Source

#### pub(crate) fn rustc_snapshot_libdir(&self) -> PathBuf

Returns the libdir of the snapshot compiler.

Source

#### pub(crate) fn rustc_snapshot_sysroot(&self) -> &Path

Returns the sysroot of the snapshot compiler.

Source

#### pub(crate) fn info(&self, msg: &str)

Source

#### pub(crate) fn msg( &self, action: impl Into<Kind>, what: impl Display, mode: impl Into<Option<Mode>>, target_and_stage: impl Into<TargetAndStage>, target: impl Into<Option<TargetSelection>>, ) -> Option<Group>

Return a `Group` guard for a `Step` that:

- Performs `action`
  - If the action is `Kind::Test`, use `Build::msg_test` instead.
- On `what`
  - Where `what` possibly corresponds to a `mode`
- `action` is performed with/on the given compiler (`target_and_stage`).
  - Since for some steps it is not possible to pass a single compiler here, it is also possible to pass the host and stage explicitly.
- With a given `target`.

Source

#### pub(crate) fn msg_test( &self, what: impl Display, target: TargetSelection, stage: u32, ) -> Option<Group>

Return a `Group` guard for a `Step` that tests `what` with the given `stage` and `target`. Use this instead of `Build::msg` for test steps, because for them it is not always clear what exactly is a build compiler.

Source

#### pub(crate) fn msg_unstaged( &self, action: impl Into<Kind>, what: impl Display, target: TargetSelection, ) -> Option<Group>

Return a `Group` guard for a `Step` that is only built once and isn’t affected by `--stage`.

Source

#### pub(crate) fn group(&self, msg: &str) -> Option<Group>

Source

#### pub(crate) fn jobs(&self) -> u32

Returns the number of parallel jobs that have been configured for this build.

Source

#### pub(crate) fn debuginfo_map_to( &self, which: GitRepo, remap_scheme: RemapScheme, ) -> Option<String>

Source

#### pub(crate) fn cc(&self, target: TargetSelection) -> PathBuf

Returns the path to the C compiler for the target specified.

Source

#### pub(crate) fn cc_tool(&self, target: TargetSelection) -> Tool

Returns the internal `cc::Tool` for the C compiler.

Source

#### pub(crate) fn cxx_tool(&self, target: TargetSelection) -> Tool

Returns the internal `cc::Tool` for the C++ compiler.

Source

#### pub(crate) fn cc_handled_clags( &self, target: TargetSelection, c: CLang, ) -> Vec<String>

Returns C flags that `cc-rs` thinks should be enabled for the specified target by default.

Source

#### pub(crate) fn cc_unhandled_cflags( &self, target: TargetSelection, which: GitRepo, c: CLang, ) -> Vec<String>

Returns extra C flags that `cc-rs` doesn’t handle.

Source

#### pub(crate) fn ar(&self, target: TargetSelection) -> Option<PathBuf>

Returns the path to the `ar` archive utility for the target specified.

Source

#### pub(crate) fn ranlib(&self, target: TargetSelection) -> Option<PathBuf>

Returns the path to the `ranlib` utility for the target specified.

Source

#### pub(crate) fn cxx(&self, target: TargetSelection) -> Result<PathBuf, String>

Returns the path to the C++ compiler for the target specified.

Source

#### pub(crate) fn linker(&self, target: TargetSelection) -> Option<PathBuf>

Returns the path to the linker for the given target if it needs to be overridden.

Source

#### pub(crate) fn is_lld_direct_linker(&self, target: TargetSelection) -> bool

Source

#### pub(crate) fn crt_static(&self, target: TargetSelection) -> Option<bool>

Returns if this target should statically link the C runtime, if specified

Source

#### pub(crate) fn musl_root(&self, target: TargetSelection) -> Option<&Path>

Returns the “musl root” for this `target`, if defined.

If this is a native target (host is also musl) and no musl-root is given, it falls back to the system toolchain in /usr.

Source

#### pub(crate) fn musl_libdir(&self, target: TargetSelection) -> Option<PathBuf>

Returns the “musl libdir” for this `target`.

Source

#### pub(crate) fn wasi_libdir(&self, target: TargetSelection) -> Option<PathBuf>

Returns the `lib` directory for the WASI target specified, if configured.

This first consults `wasi-root` as configured in per-target configuration, and failing that it assumes that `$WASI_SDK_PATH` is set in the environment, and failing that `None` is returned.

Source

#### pub(crate) fn no_std(&self, target: TargetSelection) -> Option<bool>

Returns `true` if this is a no-std `target`, if defined

Source

#### pub(crate) fn remote_tested(&self, target: TargetSelection) -> bool

Returns `true` if the target will be tested using the `remote-test-client` and `remote-test-server` binaries.

Source

#### pub(crate) fn runner(&self, target: TargetSelection) -> Option<String>

Returns an optional “runner” to pass to `compiletest` when executing test binaries.

An example of this would be a WebAssembly runtime when testing the wasm targets.

Source

#### pub(crate) fn default_wasi_runner( &self, target: TargetSelection, ) -> Option<String>

When a `runner` configuration is not provided and a WASI-looking target is being tested this is consulted to prove the environment to see if there’s a runtime already lying around that seems reasonable to use.

Source

#### pub(crate) fn tool_enabled(&self, tool: &str) -> bool

Returns whether the specified tool is configured as part of this build.

This requires that both the `extended` key is set and the `tools` key is either unset or specifically contains the specified tool.

Source

#### pub(crate) fn qemu_rootfs(&self, target: TargetSelection) -> Option<&Path>

Returns the root of the “rootfs” image that this target will be using, if one was configured.

If `Some` is returned then that means that tests for this target are emulated with QEMU and binaries will need to be shipped to the emulator.

Source

#### pub(crate) fn extended_error_dir(&self) -> PathBuf

Temporary directory that extended error information is emitted to.

Source

#### pub(crate) fn force_use_stage1( &self, stage: u32, target: TargetSelection, ) -> bool

Tests whether the `compiler` compiling for `target` should be forced to use a stage1 compiler instead.

Currently, by default, the build system does not perform a “full bootstrap” by default where we compile the compiler three times. Instead, we compile the compiler two times. The final stage (stage2) just copies the libraries from the previous stage, which is what this method detects.

Here we return `true` if:

- The build isn’t performing a full bootstrap
- The `compiler` is in the final stage, 2
- We’re not cross-compiling, so the artifacts are already available in stage1

When all of these conditions are met the build will lift artifacts from the previous stage forward.

Source

#### pub(crate) fn force_use_stage2(&self, stage: u32) -> bool

Checks whether the `compiler` compiling for `target` should be forced to use a stage2 compiler instead.

When we download the pre-compiled version of rustc and compiler stage is >= 2, it should be forced to use a stage2 compiler.

Source

#### pub(crate) fn release(&self, num: &str) -> String

Given `num` in the form “a.b.c” return a “release string” which describes the release version number.

For example on nightly this returns “a.b.c-nightly”, on beta it returns “a.b.c-beta.1” and on stable it just returns “a.b.c”.

Source

#### pub(crate) fn beta_prerelease_version(&self) -> u32

Source

#### pub(crate) fn rust_release(&self) -> String

Returns the value of `release` above for Rust itself.

Source

#### pub(crate) fn rust_package_vers(&self) -> String

Returns the “package version” for a component.

The package version is typically what shows up in the names of tarballs. For channels like beta/nightly it’s just the channel name, otherwise it’s the release version.

Source

#### pub(crate) fn rust_version(&self) -> String

Returns the `version` string associated with this compiler for Rust itself.

Note that this is a descriptive string which includes the commit date, sha, version, etc.

Source

#### pub(crate) fn rust_sha(&self) -> Option<&str>

Returns the full commit hash.

Source

#### pub(crate) fn release_num(&self, package: &str) -> String

Returns the `a.b.c` version that the given package is at.

Source

#### pub(crate) fn unstable_features(&self) -> bool

Returns `true` if unstable features should be enabled for the compiler we’re building.

Source

#### pub(crate) fn in_tree_crates( &self, root: &str, target: Option<TargetSelection>, ) -> Vec<&Crate>

Returns a Vec of all the dependencies of the given root crate, including transitive dependencies and the root itself. Only includes “local” crates (those in the local source tree, not from a registry).

Source

#### pub(crate) fn read_stamp_file( &self, stamp: &BuildStamp, ) -> Vec<(PathBuf, DependencyType)>

Source

#### pub fn resolve_symlink_and_copy(&self, src: &Path, dst: &Path)

Copies a file from `src` to `dst`.

If `src` is a symlink, `src` will be resolved to the actual path and copied to `dst` instead of the symlink itself.

Source

#### pub fn copy_link(&self, src: &Path, dst: &Path, file_type: FileType)

Links a file from `src` to `dst`. Attempts to use hard links if possible, falling back to copying. You can neither rely on this being a copy nor it being a link, so do not write to dst.

Source

#### pub(crate) fn copy_link_internal( &self, src: &Path, dst: &Path, dereference_symlinks: bool, )

Source

#### pub fn cp_link_r(&self, src: &Path, dst: &Path)

Links the `src` directory recursively to `dst`. Both are assumed to exist when this function is called. Will attempt to use hard links if possible and fall back to copying.

Source

#### pub fn cp_link_filtered( &self, src: &Path, dst: &Path, filter: &dyn Fn(&Path) -> bool, )

Copies the `src` directory recursively to `dst`. Both are assumed to exist when this function is called. Will attempt to use hard links if possible and fall back to copying. Unwanted files or directories can be skipped by returning `false` from the filter function.

Source

#### pub(crate) fn cp_link_filtered_recurse( &self, src: &Path, dst: &Path, relative: &Path, filter: &dyn Fn(&Path) -> bool, )

Source

#### pub(crate) fn copy_link_to_folder(&self, src: &Path, dest_folder: &Path)

Source

#### pub(crate) fn install(&self, src: &Path, dstdir: &Path, file_type: FileType)

Source

#### pub(crate) fn read(&self, path: &Path) -> String

Source

#### pub(crate) fn create_dir(&self, dir: &Path)

Source

#### pub(crate) fn remove_dir(&self, dir: &Path)

Source

#### pub(crate) fn clear_dir(&self, dir: &Path)

Make sure that `dir` will be an empty existing directory after this function ends. If it existed before, it will be first deleted.

Source

#### pub(crate) fn read_dir(&self, dir: &Path) -> impl Iterator<Item = DirEntry>

Source

#### pub(crate) fn symlink_file<P: AsRef<Path>, Q: AsRef<Path>>( &self, src: P, link: Q, ) -> Result<()>

Source

#### pub(crate) fn ninja(&self) -> bool

Returns if config.ninja is enabled, and checks for ninja existence, exiting with a nicer error message if not.

Source

#### pub fn colored_stdout<R, F: FnOnce(&mut dyn WriteColor) -> R>(&self, f: F) -> R

Source

#### pub fn colored_stderr<R, F: FnOnce(&mut dyn WriteColor) -> R>(&self, f: F) -> R

Source

#### pub(crate) fn colored_stream_inner<R, F, C>( &self, constructor: C, is_tty: bool, f: F, ) -> R
where C: Fn(ColorChoice) -> StandardStream, F: FnOnce(&mut dyn WriteColor) -> R,

Source

#### pub fn exec_ctx(&self) -> &ExecutionContext

Source

#### pub fn report_summary(&self, path: &Path, start_time: Instant)

## Trait Implementations§

Source§

### impl AsRef<ExecutionContext> for Build

Source§

#### fn as_ref(&self) -> &ExecutionContext

Converts this type into a shared reference of the (usually inferred) input type.

## Auto Trait Implementations§

§

### impl !Freeze for Build

§

### impl !RefUnwindSafe for Build

§

### impl !Sync for Build

§

### impl Send for Build

§

### impl Unpin for Build

§

### impl UnsafeUnpin for Build

§

### impl UnwindSafe for Build

## Blanket Implementations§

Source§

### impl<T> Any for T
where T: 'static + ?Sized,

Source§

#### fn type_id(&self) -> TypeId

Gets the `TypeId` of `self`. Read more
Source§

### impl<T> Borrow<T> for T
where T: ?Sized,

Source§

#### fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

### impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

#### fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

### impl<T> From<T> for T

Source§

#### fn from(t: T) -> T

Returns the argument unchanged.

Source§

### impl<T, U> Into<U> for T
where U: From<T>,

Source§

#### fn into(self) -> U

Calls `U::from(self)`.

That is, this conversion is whatever the implementation of `From<T> for U` chooses to do.

§

### impl<T> Pointable for T

§

#### const ALIGN: usize

The alignment of pointer.
§

#### type Init = T

The type for initializers.
§

#### unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

#### unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

#### unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

#### unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

### impl<T> Same for T

Source§

#### type Output = T

Should always be `Self`
Source§

### impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

#### type Error = Infallible

The type returned in the event of a conversion error.
Source§

#### fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

### impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

#### type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

#### fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

## Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain `repr(...)` attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 4616 bytes