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 done. 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.
Re-exportsΒ§
use cargo_util::collections::HashMap;πuse cargo_util::collections::HashSet;πuse std::borrow::Cow;πuse std::cell::OnceCell;πuse std::env;πuse std::env;πuse std::ffi::OsStr;πuse std::ffi::OsString;πuse std::fmt::Display;πuse std::fs;πuse std::fs::File;πuse std::io::BufRead;πuse std::io::BufWriter;πuse std::io::Write;πuse std::ops::Deref;πuse std::ops::Range;πuse std::path::Path;πuse std::path::PathBuf;πuse std::sync::Arc;πuse std::sync::LazyLock;πuse anyhow::Context as _;πuse anyhow::Error;πuse cargo_platform::Cfg;πuse cargo_platform::Platform;πuse cargo_util_schemas::core::CrateType;πuse cargo_util_terminal::report::AnnotationKind;πuse cargo_util_terminal::report::Group;πuse cargo_util_terminal::report::Level;πuse cargo_util_terminal::report::Renderer;πuse cargo_util_terminal::report::Snippet;πuse regex::Regex;πuse tracing::debug;πuse tracing::instrument;πuse tracing::instrument;πuse tracing::trace;πpub use self::build_config::UserIntent;pub use self::build_config::BuildConfig;pub use self::build_config::CompileMode;pub use self::build_config::MessageFormat;pub use self::build_context::BuildContext;pub use self::build_context::DepKindSet;pub use self::build_context::FileFlavor;pub use self::build_context::FileType;pub use self::build_context::RustcTargetData;pub use self::build_context::TargetInfo;pub use self::build_runner::BuildRunner;pub use self::build_runner::Metadata;pub use self::build_runner::UnitHash;pub use self::compilation::Compilation;pub use self::compilation::Doctest;pub use self::compilation::UnitOutput;pub use self::compile_kind::CompileKind;pub use self::compile_kind::CompileKindFallback;pub use self::compile_kind::CompileTarget;pub use self::crate_type::CrateTypeExt;pub use self::custom_build::LinkArgTarget;pub use self::custom_build::BuildOutput;pub use self::custom_build::BuildScriptOutputs;pub use self::custom_build::BuildScripts;pub use self::custom_build::LibraryPath;pub(crate) use self::fingerprint::DirtyReason;πpub use self::fingerprint::RustdocFingerprint;pub use self::job_queue::Freshness;use self::job_queue::Job;πuse self::job_queue::JobQueue;πuse self::job_queue::JobState;πuse self::job_queue::Work;πpub(crate) use self::layout::Layout;πpub use self::lto::Lto;use self::output_depinfo::output_depinfo;πuse self::output_sbom::build_sbom;πuse self::trim_paths::trim_paths_args;πuse self::trim_paths::trim_paths_args_rustdoc;πuse self::unit_graph::UnitDep;πuse crate::compiler::future_incompat::FutureIncompatReport;πuse crate::compiler::locking::LockKey;πuse crate::compiler::timings::SectionTiming;πpub use crate::compiler::unit::Unit;pub use crate::compiler::unit::UnitIndex;pub use crate::compiler::unit::UnitInterner;use crate::context::FingerprintMethod;πuse crate::diagnostics::get_key_value;πuse crate::util::OnceExt;πuse crate::util::errors::CargoResult;πuse crate::util::errors::VerboseError;πuse crate::util::interning::InternedString;πuse crate::util::machine_message;πuse crate::util::machine_message::Message;πuse crate::util::add_path_args;πuse crate::util::internal;πuse crate::util::path_args;πuse crate::workspace::Feature;πuse crate::workspace::PackageId;πuse crate::workspace::Target;πuse crate::workspace::TargetKind;πuse crate::workspace::manifest::TargetSourcePath;πuse crate::workspace::profiles::PanicStrategy;πuse crate::workspace::profiles::Profile;πuse crate::workspace::profiles::StripInner;πuse cargo_util::ExecStats;πuse cargo_util::ProcessBuilder;πuse cargo_util::ProcessError;πuse cargo_util::paths;πuse cargo_util_schemas::manifest::TomlDebugInfo;πuse cargo_util_terminal::Verbosity;πuse rustfix::diagnostics::Applicability;π
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_
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 π
- locking π
- This module handles the locking logic during compilation.
- 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.
- trim_
paths π - Path prefix remapping for RFC 3127
trim-paths. - unit π
- Types and impls for
Unit. - unit_
dependencies - Constructs the dependency graph for compilation.
- unit_
graph - Serialization of
UnitGraphfor unstable option--unit-graph. - unused_
deps
StructsΒ§
- Default
Executor - A
DefaultExecutorcalls rustc without doing anything else. It is Cargoβs default behaviour. - Manifest
Error πContext - Cloned and sendable context about the manifest file.
- Output
Options π - Configuration of the display of messages emitted by the compiler, e.g. diagnostics, warnings, errors, and message caching.
EnumsΒ§
- CapLints π
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_
codegen_ πincremental - Adds
-C incremental=<path>. - add_
codegen_ πlinker - Adds
-C linker=<path>if specified. - 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. - check_
cfg_ πargs - Generates the
--check-cfgarguments for theunit. - compile π
- Builds up and enqueue a list of pending jobs onto the
jobqueue. - compute_
cap_ πlints - crate_
version_ πflag_ already_ present - dep_
paths_ πfor_ args - Generate a list of paths for the rustc
-Largs. - descriptive_
pkg_ πname - Provides a package name with descriptive target information,
e.g., β
foo(bin βbarβ test)β, βfoo(lib doctest)β. - downgrade_
lock_ πto_ shared - 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 - is_
public_ πdependency_ enabled - lib_
search_ paths - Generate a list of
-Larguments - 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 - prebuild_
lock_ πexclusive - 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.
- verbose_
if_ πsimple_ exit_ code