Struct cargo::core::compiler::build_context::BuildContext

source ·
pub struct BuildContext<'a, 'gctx> {
    pub ws: &'a Workspace<'gctx>,
    pub gctx: &'gctx GlobalContext,
    pub profiles: Profiles,
    pub build_config: &'a BuildConfig,
    pub extra_compiler_args: HashMap<Unit, Vec<String>>,
    pub packages: PackageSet<'gctx>,
    pub target_data: RustcTargetData<'gctx>,
    pub roots: Vec<Unit>,
    pub unit_graph: UnitGraph,
    pub scrape_units: Vec<Unit>,
    pub all_kinds: HashSet<CompileKind>,
}
Expand description

The build context, containing complete information needed for a build task before it gets started.

It is intended that this is mostly static information. Stuff that mutates during the build can be found in the parent BuildRunner. (I say mostly, because this has internal caching, but nothing that should be observable or require &mut.)

As a result, almost every field on BuildContext is public, including

just to name a few. Learn more on each own documentation.

§How to use

To prepare a build task, you may not want to use BuildContext::new directly, since it is often too lower-level. Instead, ops::create_bcx is usually what you are looking for.

After a BuildContext is built, the next stage of building is handled in BuildRunner.

Fields§

§ws: &'a Workspace<'gctx>

The workspace the build is for.

§gctx: &'gctx GlobalContext

The cargo context.

§profiles: Profiles

This contains a collection of compiler flags presets.

§build_config: &'a BuildConfig

Configuration information for a rustc build.

§extra_compiler_args: HashMap<Unit, Vec<String>>

Extra compiler args for either rustc or rustdoc.

§packages: PackageSet<'gctx>

Package downloader.

This holds ownership of the Package objects.

§target_data: RustcTargetData<'gctx>

Information about rustc and the target platform.

§roots: Vec<Unit>

The root units of unit_graph (units requested on the command-line).

§unit_graph: UnitGraph

The dependency graph of units to compile.

§scrape_units: Vec<Unit>

Reverse-dependencies of documented units, used by the rustdoc --scrape-examples flag.

§all_kinds: HashSet<CompileKind>

The list of all kinds that are involved in this build

Implementations§

source§

impl<'a, 'gctx> BuildContext<'a, 'gctx>

source

pub fn new( ws: &'a Workspace<'gctx>, packages: PackageSet<'gctx>, build_config: &'a BuildConfig, profiles: Profiles, extra_compiler_args: HashMap<Unit, Vec<String>>, target_data: RustcTargetData<'gctx>, roots: Vec<Unit>, unit_graph: UnitGraph, scrape_units: Vec<Unit> ) -> CargoResult<BuildContext<'a, 'gctx>>

source

pub fn rustc(&self) -> &Rustc

Information of the rustc this build task will use.

source

pub fn host_triple(&self) -> InternedString

Gets the host architecture triple.

For example, x86_64-unknown-linux-gnu, would be

  • machine: x86_64,
  • hardware-platform: unknown,
  • operating system: linux-gnu.
source

pub fn jobs(&self) -> u32

Gets the number of jobs specified for this build.

source

pub fn rustflags_args(&self, unit: &Unit) -> &[String]

Extra compiler flags to pass to rustc for a given unit.

Although it depends on the caller, in the current Cargo implementation, these flags take precedence over those from BuildContext::extra_args_for.

As of now, these flags come from environment variables and configurations. See TargetInfo.rustflags for more on how Cargo collects them.

source

pub fn rustdocflags_args(&self, unit: &Unit) -> &[String]

Extra compiler flags to pass to rustdoc for a given unit.

Although it depends on the caller, in the current Cargo implementation, these flags take precedence over those from BuildContext::extra_args_for.

As of now, these flags come from environment variables and configurations. See TargetInfo.rustdocflags for more on how Cargo collects them.

source

pub fn extra_args_for(&self, unit: &Unit) -> Option<&Vec<String>>

Extra compiler args for either rustc or rustdoc.

As of now, these flags come from the trailing args of either cargo rustc or cargo rustdoc.

source§

impl BuildContext<'_, '_>

source

pub fn scrape_units_have_dep_on<'a>(&'a self, unit: &'a Unit) -> Vec<&'a Unit>

Returns the set of Docscrape units that have a direct dependency on unit.

RunCustomBuild units are excluded because we allow failures from type checks but not build script executions. A plain old cargo doc would just die if a build script execution fails, there is no reason for -Zrustdoc-scrape-examples to keep going.

source

pub fn unit_can_fail_for_docscraping(&self, unit: &Unit) -> bool

Returns true if this unit is needed for doing doc-scraping and is also allowed to fail without killing the build.

Auto Trait Implementations§

§

impl<'a, 'gctx> !Freeze for BuildContext<'a, 'gctx>

§

impl<'a, 'gctx> !RefUnwindSafe for BuildContext<'a, 'gctx>

§

impl<'a, 'gctx> !Send for BuildContext<'a, 'gctx>

§

impl<'a, 'gctx> !Sync for BuildContext<'a, 'gctx>

§

impl<'a, 'gctx> Unpin for BuildContext<'a, 'gctx>

§

impl<'a, 'gctx> !UnwindSafe for BuildContext<'a, 'gctx>

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.

§

impl<T> Instrument for T

§

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

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

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.

§

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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

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: 1656 bytes