1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use crate::core::compiler::unit_graph::UnitGraph;
use crate::core::compiler::{BuildConfig, CompileKind, Unit};
use crate::core::profiles::Profiles;
use crate::core::PackageSet;
use crate::core::Workspace;
use crate::util::config::Config;
use crate::util::errors::CargoResult;
use crate::util::interning::InternedString;
use crate::util::Rustc;
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
mod target_info;
pub use self::target_info::{FileFlavor, FileType, RustcTargetData, TargetInfo};
pub struct BuildContext<'a, 'cfg> {
pub ws: &'a Workspace<'cfg>,
pub config: &'cfg Config,
pub profiles: Profiles,
pub build_config: &'a BuildConfig,
pub extra_compiler_args: HashMap<Unit, Vec<String>>,
pub packages: PackageSet<'cfg>,
pub target_data: RustcTargetData,
pub roots: Vec<Unit>,
pub unit_graph: UnitGraph,
pub all_kinds: HashSet<CompileKind>,
}
impl<'a, 'cfg> BuildContext<'a, 'cfg> {
pub fn new(
ws: &'a Workspace<'cfg>,
packages: PackageSet<'cfg>,
build_config: &'a BuildConfig,
profiles: Profiles,
extra_compiler_args: HashMap<Unit, Vec<String>>,
target_data: RustcTargetData,
roots: Vec<Unit>,
unit_graph: UnitGraph,
) -> CargoResult<BuildContext<'a, 'cfg>> {
let all_kinds = unit_graph
.keys()
.map(|u| u.kind)
.chain(build_config.requested_kinds.iter().copied())
.chain(std::iter::once(CompileKind::Host))
.collect();
Ok(BuildContext {
ws,
config: ws.config(),
packages,
build_config,
profiles,
extra_compiler_args,
target_data,
roots,
unit_graph,
all_kinds,
})
}
pub fn rustc(&self) -> &Rustc {
&self.target_data.rustc
}
pub fn linker(&self, kind: CompileKind) -> Option<PathBuf> {
self.target_data
.target_config(kind)
.linker
.as_ref()
.map(|l| l.val.clone().resolve_program(self.config))
}
pub fn host_triple(&self) -> InternedString {
self.target_data.rustc.host
}
pub fn jobs(&self) -> u32 {
self.build_config.jobs
}
pub fn rustflags_args(&self, unit: &Unit) -> &[String] {
&self.target_data.info(unit.kind).rustflags
}
pub fn rustdocflags_args(&self, unit: &Unit) -> &[String] {
&self.target_data.info(unit.kind).rustdocflags
}
pub fn extra_args_for(&self, unit: &Unit) -> Option<&Vec<String>> {
self.extra_compiler_args.get(unit)
}
}