]>
Commit | Line | Data |
---|---|---|
e0bd9e23 EH |
1 | use crate::core::compiler::unit_graph::UnitGraph; |
2 | use crate::core::compiler::{BuildConfig, CompileKind, Unit}; | |
04ddd4d0 | 3 | use crate::core::profiles::Profiles; |
b6a4b074 | 4 | use crate::core::PackageSet; |
7f73a6c7 | 5 | use crate::core::Workspace; |
949eccac | 6 | use crate::util::config::Config; |
04ddd4d0 | 7 | use crate::util::errors::CargoResult; |
7f73a6c7 | 8 | use crate::util::interning::InternedString; |
381251aa | 9 | use crate::util::Rustc; |
593a02f2 | 10 | use std::collections::HashMap; |
381251aa | 11 | use std::path::PathBuf; |
509c5b44 DO |
12 | |
13 | mod target_info; | |
eac3b66b | 14 | pub use self::target_info::{FileFlavor, FileType, RustcTargetData, TargetInfo}; |
509c5b44 | 15 | |
f7c91ba6 | 16 | /// The build context, containing all information about a build task. |
bd31c081 EH |
17 | /// |
18 | /// It is intended that this is mostly static information. Stuff that mutates | |
19 | /// during the build can be found in the parent `Context`. (I say mostly, | |
20 | /// because this has internal caching, but nothing that should be observable | |
21 | /// or require &mut.) | |
46615d29 | 22 | pub struct BuildContext<'a, 'cfg> { |
f7c91ba6 | 23 | /// The workspace the build is for. |
509c5b44 | 24 | pub ws: &'a Workspace<'cfg>, |
f7c91ba6 | 25 | /// The cargo configuration. |
509c5b44 | 26 | pub config: &'cfg Config, |
77ee608d | 27 | pub profiles: Profiles, |
509c5b44 | 28 | pub build_config: &'a BuildConfig, |
1ef954ea | 29 | /// Extra compiler args for either `rustc` or `rustdoc`. |
c85ed044 | 30 | pub extra_compiler_args: HashMap<Unit, Vec<String>>, |
949eccac | 31 | /// Package downloader. |
e0bd9e23 EH |
32 | /// |
33 | /// This holds ownership of the `Package` objects. | |
34 | pub packages: PackageSet<'cfg>, | |
949eccac EH |
35 | /// Information about rustc and the target platform. |
36 | pub target_data: RustcTargetData, | |
e0bd9e23 | 37 | /// The root units of `unit_graph` (units requested on the command-line). |
c85ed044 | 38 | pub roots: Vec<Unit>, |
e0bd9e23 | 39 | /// The dependency graph of units to compile. |
c85ed044 | 40 | pub unit_graph: UnitGraph, |
509c5b44 DO |
41 | } |
42 | ||
43 | impl<'a, 'cfg> BuildContext<'a, 'cfg> { | |
44 | pub fn new( | |
45 | ws: &'a Workspace<'cfg>, | |
e0bd9e23 | 46 | packages: PackageSet<'cfg>, |
509c5b44 | 47 | build_config: &'a BuildConfig, |
77ee608d | 48 | profiles: Profiles, |
c85ed044 | 49 | extra_compiler_args: HashMap<Unit, Vec<String>>, |
949eccac | 50 | target_data: RustcTargetData, |
c85ed044 AC |
51 | roots: Vec<Unit>, |
52 | unit_graph: UnitGraph, | |
509c5b44 | 53 | ) -> CargoResult<BuildContext<'a, 'cfg>> { |
509c5b44 DO |
54 | Ok(BuildContext { |
55 | ws, | |
e0bd9e23 | 56 | config: ws.config(), |
509c5b44 | 57 | packages, |
509c5b44 DO |
58 | build_config, |
59 | profiles, | |
509c5b44 | 60 | extra_compiler_args, |
949eccac | 61 | target_data, |
e0bd9e23 EH |
62 | roots, |
63 | unit_graph, | |
509c5b44 DO |
64 | }) |
65 | } | |
66 | ||
949eccac EH |
67 | pub fn rustc(&self) -> &Rustc { |
68 | &self.target_data.rustc | |
509c5b44 DO |
69 | } |
70 | ||
f7c91ba6 | 71 | /// Gets the user-specified linker for a particular host or target. |
381251aa | 72 | pub fn linker(&self, kind: CompileKind) -> Option<PathBuf> { |
949eccac EH |
73 | self.target_data |
74 | .target_config(kind) | |
381251aa EH |
75 | .linker |
76 | .as_ref() | |
77 | .map(|l| l.val.clone().resolve_program(self.config)) | |
509c5b44 DO |
78 | } |
79 | ||
f7c91ba6 | 80 | /// Gets the host architecture triple. |
46533783 | 81 | /// |
f7c91ba6 AR |
82 | /// For example, x86_64-unknown-linux-gnu, would be |
83 | /// - machine: x86_64, | |
84 | /// - hardware-platform: unknown, | |
85 | /// - operating system: linux-gnu. | |
593a02f2 | 86 | pub fn host_triple(&self) -> InternedString { |
949eccac | 87 | self.target_data.rustc.host |
509c5b44 DO |
88 | } |
89 | ||
f7c91ba6 | 90 | /// Gets the number of jobs specified for this build. |
509c5b44 DO |
91 | pub fn jobs(&self) -> u32 { |
92 | self.build_config.jobs | |
93 | } | |
94 | ||
c85ed044 | 95 | pub fn rustflags_args(&self, unit: &Unit) -> &[String] { |
949eccac | 96 | &self.target_data.info(unit.kind).rustflags |
509c5b44 DO |
97 | } |
98 | ||
c85ed044 | 99 | pub fn rustdocflags_args(&self, unit: &Unit) -> &[String] { |
949eccac | 100 | &self.target_data.info(unit.kind).rustdocflags |
509c5b44 DO |
101 | } |
102 | ||
c85ed044 | 103 | pub fn extra_args_for(&self, unit: &Unit) -> Option<&Vec<String>> { |
1ef954ea | 104 | self.extra_compiler_args.get(unit) |
509c5b44 | 105 | } |
46533783 | 106 | } |