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:
BuildContext
is a static context containing all information you need before a build gets started.BuildRunner
is the center of the world, coordinating a running build and collecting information from it.custom_build
is the home of build script executions and output parsing.fingerprint
not only defines but also executes a set of rules to determine if a re-compile is needed.job_queue
is where the parallelism, job scheduling, and communication machinery happen between Cargo and the compiler.layout
defines and manages output artifacts of a build in the filesystem.unit_dependencies
is for building a dependency graph for compilation from a result of dependency resolution.Unit
contains sufficient information to build something, usually turning into a compiler invocation in a later phase.
Maybe
-Zbuild-plan
was 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 🔒 BuildContext
is 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 🔒 BuildRunner
is 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
cargo
and 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_depinfo
for 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
UnitGraph
for 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
DefaultExecutor
calls 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
Metadata
tracks severalUnitHash
s, 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
rustc
and 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
Unit
under specific circumstances, seeMetadata
for more. - Unit
Interner - A small structure used to “intern”
Unit
values. - Unit
Output - Information about the output of a unit.
Enums§
- Compile
Kind - Indicator for how a unit is being compiled.
- Compile
Mode - The general “mode” for what to do.
- 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.
- 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.
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-features
if it is set for cargo. - add_
cap_ 🔒lints - Adds
--cap-lints
to 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-format
to 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
-L
and--extern
. - check_
cfg_ 🔒args - Generates the
--check-cfg
arguments for theunit
. - compile 🔒
- Builds up and enqueue a list of pending jobs onto the
job
queue. - 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
--extern
arguments. - features_
args 🔒 - All active features for the unit passed as
--cfg features=<feature-name>
. - filter_
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
rustc
invocation before the job queue starts compiling any unit. - prepare_
rustdoc 🔒 - Prepares flags and environments we can compute for a
rustdoc
invocation 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
rustc
for building theunit
. - rustdoc 🔒
- Creates a unit of work invoking
rustdoc
for documenting theunit
. - 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-scope
and--remap-path-prefix
for RFC 3127. See also unstable feature-Ztrim-paths
. - trim_
paths_ 🔒args_ rustdoc - Like
trim_paths_args
but for rustdoc invocations. - verbose_
if_ 🔒simple_ exit_ code