Skip to main content

ParsedRustcArgs

Struct ParsedRustcArgs 

Source
pub struct ParsedRustcArgs {
Show 23 fields pub crate_name: String, pub crate_types: Vec<String>, pub features: BTreeSet<String>, pub cfgs: BTreeSet<String>, pub emit: BTreeSet<String>, pub json: BTreeSet<String>, pub input_path: Option<PathBuf>, pub target: Option<String>, pub c_metadata: Option<String>, pub out_dir: Option<PathBuf>, pub extra_filename: String, pub opt_level: Option<String>, pub debuginfo: Option<String>, pub panic_strategy: Option<String>, pub debug_assertions: Option<bool>, pub overflow_checks: Option<bool>, pub strip: Option<String>, pub native_search_paths: Vec<PathBuf>, pub extern_crates: Vec<ParsedExternCrate>, pub embed_metadata: Option<bool>, pub embed_bitcode: bool, pub has_custom_codegen: bool, pub link_options: BTreeSet<String>,
}
Expand description

The subset of a rustc command line that determines cache identity and output layout.

Populated by ParsedRustcArgs::parse; fields are Option where the corresponding flag may be absent.

Fields§

§crate_name: String

--crate-name value; a parse without one fails.

§crate_types: Vec<String>

--crate-type list, split on ,.

§features: BTreeSet<String>

feature="…" values collected from --cfg flags.

§cfgs: BTreeSet<String>

Every other --cfg value: build-script cargo:rustc-cfg output and --cfg flags from RUSTFLAGS. They select code at compile time, so they are compile identity, kept separate from features because the semantic tuple registries index on is features only.

§emit: BTreeSet<String>

--emit kinds, deduplicated.

§json: BTreeSet<String>

--json kinds, deduplicated.

§input_path: Option<PathBuf>

The .rs input file, when one was passed.

§target: Option<String>

--target triple, or None for an implicit host target.

§c_metadata: Option<String>

-C metadata value.

§out_dir: Option<PathBuf>

--out-dir directory.

§extra_filename: String

-C extra-filename suffix (empty when absent).

§opt_level: Option<String>

-C opt-level value.

§debuginfo: Option<String>

-C debuginfo value.

§panic_strategy: Option<String>

-C panic value.

§debug_assertions: Option<bool>

-C debug-assertions value.

§overflow_checks: Option<bool>

-C overflow-checks value.

§strip: Option<String>

-C strip value.

§native_search_paths: Vec<PathBuf>

-L native=… search paths.

§extern_crates: Vec<ParsedExternCrate>

--extern pairs, sorted by crate name then path.

§embed_metadata: Option<bool>

-Z embed-metadata value. Nightly cargo passes this flag on every unit, so it is toolchain identity rather than custom codegen; it changes the produced rlib, so it participates in the compile key.

§embed_bitcode: bool

Whether the produced object files carry LLVM bitcode. rustc embeds bitcode unless -C embed-bitcode=no, the value cargo passes to every unit that no LTO consumer needs bitcode from; a unit compiled with bitcode is a different artifact, so this participates in the compile key.

§has_custom_codegen: bool

Whether the invocation (or RUSTFLAGS / CARGO_ENCODED_RUSTFLAGS) carries codegen flags stow does not model; such builds are never served from the public cache.

§link_options: BTreeSet<String>

The -C options that steer only the final link step, normalized to their key=value spelling and sorted. Inert for a unit that never reaches the linker, and part of the compile key for one that does — see ParsedRustcArgs::link_options_reaching_the_linker. An artifact linked with mold and one linked with lld are different bytes, so they are different keys rather than both being refused.

Implementations§

Source§

impl ParsedRustcArgs

Source

pub fn parse(args: &[OsString]) -> Result<Self, String>

Parse a captured rustc argv into ParsedRustcArgs.

Recognizes the flags cargo passes for dependency compilations. Unknown -C / -Z options set has_custom_codegen rather than failing, so the invocation is still parsed — it just will not be cacheable.

§Errors

Returns an error when an argument is not valid UTF-8, a flag that requires a value is the last argument, an --extern pair or codegen boolean is malformed, or --crate-name is missing.

Source

pub fn is_cacheable(&self) -> bool

Whether this invocation may be served from the public cache.

Requires a restorable artifact, no custom codegen flags, and no CARGO_PRIMARY_PACKAGE (workspace crates are never cached). The profile is not a restriction: opt-level, debuginfo, assertions, panic and strip are all part of the compile identity, so a unit built under any profile is served exactly when the pool holds an artifact built under the same one.

The link-only -C options that actually reach a link step here, which is what the compile key has to carry.

The cache stores two shapes (see Self::is_restorable_artifact): rlibs, which rustc never links, and dynamic libraries, which it does. For an rlib the options are inert — nothing in the archive depends on which linker would have been invoked — and that is where essentially all of a dependency graph lives, so an rlib’s key is exactly what it was before link options were modeled.

For a dynamic library they are not inert. -C link-arg carries arbitrary text: -L/opt/custom/lib changes which library is linked, -Wl,-rpath= changes what is found at run time, -lfoo links in something else entirely, and link-self-contained swaps the bundled runtime for the system one. Two such units are different artifacts, so they take different keys — serving one for the other would hand over a different program, and refusing to cache either would cost the cache every proc-macro in a build that chose its own linker.

Source

pub fn is_locally_cacheable(&self) -> bool

Whether this invocation’s outputs may be stored in the local artifact cache after a successful build.

The gate is deliberately narrower than Self::is_cacheable in one direction and wider in another: the artifacts are self-produced, so there is no profile restriction — dev and release outputs are worth keeping because cross-worktree release rebuilds are exactly where a local cache pays. What remains mandatory is a restorable artifact shape, no custom codegen flags, and not being the workspace’s primary package (CARGO_PRIMARY_PACKAGE): first-party code is never cached.

Source

pub fn is_restorable_artifact(&self) -> bool

Whether the invocation produces an artifact stow can restore: an rlib or dynamic library with both -C metadata and --out-dir present.

Source

pub fn is_proc_macro(&self) -> bool

Whether any --crate-type is proc-macro.

Source

pub fn produces_rlib(&self) -> bool

Whether any --crate-type is lib or rlib.

Source

pub fn produces_dynamic_library(&self) -> bool

Whether any --crate-type is proc-macro or dylib.

Source

pub fn is_binary(&self) -> bool

Whether any --crate-type is bin.

Source

pub fn is_build_script(&self) -> bool

Whether this is the build_script_build binary cargo compiles for build scripts.

Source

pub fn requests_json_artifact_notifications(&self) -> bool

Whether --json includes artifacts (cargo’s artifact-notification channel the capture wrapper relies on).

Source

pub fn output_rlib_path(&self) -> Option<PathBuf>

Path of the emitted .rlib under --out-dir (lib<name><extra-filename>.rlib), or None when the invocation does not produce an rlib or has no --out-dir.

Source

pub fn output_rmeta_path(&self) -> Option<PathBuf>

Path of the emitted .rmeta under --out-dir (lib<name><extra-filename>.rmeta), or None without --out-dir.

Source

pub fn output_dynamic_library_path(&self) -> Result<Option<PathBuf>, String>

Path of the emitted dynamic library under --out-dir, named per the target’s binary format (lib*.so / lib*.dylib / *.dll).

Returns Ok(None) when the invocation produces no dynamic library.

§Errors

Returns an error when a dynamic library is produced but --out-dir is absent, or when the --target triple is unparseable or has an unsupported binary format.

Source

pub fn output_dep_info_path(&self) -> Option<PathBuf>

Path of the emitted dep-info file under --out-dir (<name><extra-filename>.d), or None without --out-dir.

Source

pub fn output_binary_path(&self) -> Option<PathBuf>

Path of the emitted binary under --out-dir (<name><extra-filename><exe-suffix>), or None when the invocation is not a bin crate or has no --out-dir.

Path of the artifact a downstream crate would link against: the .rlib, then the binary, then the dynamic library.

§Errors

Propagates Self::output_dynamic_library_path’s error when the invocation produces a dynamic library without --out-dir or with an unparseable target.

Source

pub fn build_script_alias_path(&self) -> Option<PathBuf>

The build-script-build alias cargo creates next to the build script binary, or None when this is not a build script or --out-dir is absent.

Source

pub fn profile(&self) -> Result<Profile, String>

The cargo profile this invocation compiles with, defaulting absent flags to cargo’s debug values (opt-level=0, debug assertions and overflow checks on, panic=unwind).

§Errors

Returns an error when -C debuginfo, -C panic or -C strip carry values outside the set rustc documents.

Trait Implementations§

Source§

impl Clone for ParsedRustcArgs

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ParsedRustcArgs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ParsedRustcArgs

Source§

impl PartialEq for ParsedRustcArgs

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ParsedRustcArgs

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more