Expand description
Β§Interact with the compiler
If you consider ops::cargo_compile::compile as a rustc driver but on
Cargo side, this module is kinda the rustc_interface for that merits.
It contains all the interaction between Cargo and the rustc compiler,
from preparing the context for the entire build process, to scheduling
and executing each unit of work (e.g. running rustc), to managing and
caching the output artifact of a build.
However, it hasnβt yet exposed a clear definition of each phase or session, like what rustc has done1. Also, no one knows if Cargo really needs that. To be pragmatic, here we list a handful of items you may want to learn:
BuildContextis a static context containing all information you need before a build gets started.BuildRunneris the center of the world, coordinating a running build and collecting information from it.custom_buildis the home of build script executions and output parsing.fingerprintnot only defines but also executes a set of rules to determine if a re-compile is needed.job_queueis where the parallelism, job scheduling, and communication machinery happen between Cargo and the compiler.layoutdefines and manages output artifacts of a build in the filesystem.unit_dependenciesis for building a dependency graph for compilation from a result of dependency resolution.Unitcontains sufficient information to build something, usually turning into a compiler invocation in a later phase.
Maybe
-Zbuild-planwas designed to serve that purpose but still in flux. β©
ModulesΒ§
- artifact
- Generate artifact information from unit dependencies for configuring the compiler environment.
- build_
config π - build_
context π BuildContextis a (mostly) static information about a build task.- build_
plan π - A graph-like structure used to represent the rustc commands to build the package and the interdependencies between them.
- build_
runner π BuildRunneris the mutable state used during the build process.- compilation π
- Type definitions for the result of a compilation.
- compile_
kind π - Type definitions for cross-compilation.
- crate_
type π - custom_
build π - How to execute a build script and parse its output.
- fingerprint π
- Tracks changes to determine if something needs to be recompiled.
- future_
incompat - Support for future-incompatible warning reporting.
- job_
queue π - Management of the interaction between the main
cargoand all spawned jobs. - layout π
- Management of the directory layout of a build
- links π
- lto π
- output_
depinfo π - dep-info files for external build system integration.
See
output_depinfofor more. - output_
sbom π - cargo-sbom precursor files for external tools to create SBOM files from.
See
build_sbom_graphfor more. - rustdoc
- Utilities for building with rustdoc.
- standard_
lib - Code for building the standard library.
- timings π
- Timing tracking.
- unit π
- Types and impls for
Unit. - unit_
dependencies - Constructs the dependency graph for compilation.
- unit_
graph - Serialization of
UnitGraphfor unstable option--unit-graph.
StructsΒ§
- Build
Config - Configuration information for a rustc build.
- Build
Context - The build context, containing complete information needed for a build task before it gets started.
- Build
Output - Contains the parsed output of a custom build script.
- Build
Runner - Collection of all the stuff that is needed to perform a build.
- Build
Script Outputs - Map of packages to build script output.
- Build
Scripts - Linking information for a
Unit. - Compilation
- A structure returning the result of a compilation.
- Compile
Target - Abstraction for the representation of a compilation target that Cargo has.
- Default
Executor - A
DefaultExecutorcalls rustc without doing anything else. It is Cargoβs default behaviour. - Doctest
- Structure with enough information to run
rustdoc --test. - File
Type - Type of each file generated by a Unit.
- Metadata
Metadatatracks severalUnitHashs, includingMetadata::unit_id,Metadata::c_metadata, andMetadata::c_extra_filename.- Output
Options π - Configuration of the display of messages emitted by the compiler, e.g. diagnostics, warnings, errors, and message caching.
- Rust
DocFingerprint - Structure used to deal with Rustdoc fingerprinting
- Rustc
Target Data - Collection of information about
rustcand the host and target. - Target
Info - Information about the platform target gleaned from querying rustc.
- Unit
- All information needed to define a unit.
- Unit
Hash - Uniquely identify a
Unitunder specific circumstances, seeMetadatafor more. - Unit
Interner - A small structure used to βinternβ
Unitvalues. - Unit
Output - Information about the output of a unit.
EnumsΒ§
- Compile
Kind - Indicator for how a unit is being compiled.
- Compile
Kind Fallback - Fallback behavior in the
CompileKind::from_requested_targets_with_fallbackfunction when no targets are specified. - Compile
Mode - The specific action to be performed on each
Unitof work. - Crate
Type - Types of the output artifact that the compiler emits. Usually distributable or linkable either statically or dynamically.
- File
Flavor - Kind of each file generated by a Unit, part of
FileType. - Freshness
- Indication of the freshness of a package.
- Library
Path - Represents a path added to the library search path.
- Link
ArgTarget - Represents one of the instructions from
cargo::rustc-link-arg-*build script instruction family. - Lto
- Possible ways to run rustc and request various parts of LTO.
- Message
Format - Timing
Output - Kinds of build timings we can output.
- User
Intent - Represents the high-level operation requested by the user.
ConstantsΒ§
TraitsΒ§
- Executor
- A glorified callback for executing calls to rustc. Rather than calling rustc
directly, weβll use an
Executor, giving clients an opportunity to intercept the build calls.
FunctionsΒ§
- add_
allow_ πfeatures - Forwards
-Zallow-featuresif it is set for cargo. - add_
cap_ πlints - Adds
--cap-lintsto the command to execute. - add_
custom_ πflags - Adds extra rustc flags and environment variables collected from the output
of a build-script to the command to execute, include custom environment
variables and
cfg. - add_
error_ πformat_ and_ color - Adds
--error-formatto the command to execute. - add_
plugin_ πdeps - append_
crate_ πversion_ flag - apply_
env_ πconfig - Applies environment variables from config
[env]toProcessBuilder. - build_
base_ πargs - Adds essential rustc flags and environment variables to the command to execute.
- build_
deps_ πargs - Adds dependency-relevant rustc flags and environment variables
to the command to execute, such as
-Land--extern. - build_
dir_ πremap - Remap all paths pointing to
build.build-dir, i.e.,[BUILD_DIR]/debug/deps/foo-[HASH].dwowould be remapped to/cargo/build-dir/debug/deps/foo-[HASH].dwo(note the/cargo/build-dirprefix). - check_
cfg_ πargs - Generates the
--check-cfgarguments for theunit. - compile π
- Builds up and enqueue a list of pending jobs onto the
jobqueue. - crate_
version_ πflag_ already_ present - descriptive_
pkg_ πname - Provides a package name with descriptive target information,
e.g., β
foo(bin βbarβ test)β, βfoo(lib doctest)β. - envify π
- extern_
args - Generates a list of
--externarguments. - features_
args π - All active features for the unit passed as
--cfg features=<feature-name>. - filter_
dynamic_ πsearch_ path - get_
dynamic_ πsearch_ path - link_
targets π - Link the compiled target (often of form
foo-{metadata_hash}) to the final target. This must happen during both βFreshβ and βCompileβ. - lto_
args π - Adds LTO related codegen flags.
- make_
failed_ πscrape_ diagnostic - Generates the warning message used when fallible doc-scrape units fail, either for rustdoc or rustc.
- on_
stderr_ πline - on_
stderr_ πline_ inner - Returns true if the line should be cached.
- on_
stdout_ πline - package_
remap π - Path prefix remap rules for dependencies.
- prepare_
rustc π - Prepares flags and environments we can compute for a
rustcinvocation before the job queue starts compiling any unit. - prepare_
rustdoc π - Prepares flags and environments we can compute for a
rustdocinvocation before the job queue starts compiling any unit. - replay_
output_ πcache - Creates a unit of work that replays the cached compiler message.
- rustc π
- Creates a unit of work invoking
rustcfor building theunit. - rustdoc π
- Creates a unit of work invoking
rustdocfor documenting theunit. - rustdoc_
dep_ πinfo_ loc - Gets the dep-info file emitted by rustdoc.
- scrape_
output_ πpath - Gets the file path of function call information output from
rustdoc. - should_
include_ πscrape_ units - Checks if there are some scrape units waiting to be processed.
- sysroot_
remap π - Path prefix remap rules for sysroot.
- trim_
paths_ πargs - Generates the
--remap-path-scopeand--remap-path-prefixfor RFC 3127. See also unstable feature-Ztrim-paths. - trim_
paths_ πargs_ rustdoc - Like
trim_paths_argsbut for rustdoc invocations. - verbose_
if_ πsimple_ exit_ code