1
- use std:: collections:: HashMap ;
2
- use std:: path:: { Path , PathBuf } ;
3
- use std:: str;
4
-
5
- use cargo_platform:: Cfg ;
6
- use log:: debug;
7
-
8
1
use crate :: core:: compiler:: unit:: UnitInterner ;
9
2
use crate :: core:: compiler:: { BuildConfig , BuildOutput , Kind , Unit } ;
10
3
use crate :: core:: profiles:: Profiles ;
11
- use crate :: core:: { Dependency , Workspace } ;
4
+ use crate :: core:: { Dependency , InternedString , Workspace } ;
12
5
use crate :: core:: { PackageId , PackageSet } ;
13
6
use crate :: util:: errors:: CargoResult ;
14
- use crate :: util:: { profile, Config , Rustc } ;
7
+ use crate :: util:: { Config , Rustc } ;
8
+ use cargo_platform:: Cfg ;
9
+ use std:: collections:: HashMap ;
10
+ use std:: path:: { Path , PathBuf } ;
11
+ use std:: str;
15
12
16
13
mod target_info;
17
14
pub use self :: target_info:: { FileFlavor , TargetInfo } ;
@@ -36,11 +33,11 @@ pub struct BuildContext<'a, 'cfg> {
36
33
/// Information about the compiler.
37
34
pub rustc : Rustc ,
38
35
/// Build information for the host arch.
39
- pub host_config : TargetConfig ,
36
+ host_config : TargetConfig ,
40
37
/// Build information for the target.
41
- pub target_config : TargetConfig ,
42
- pub target_info : TargetInfo ,
43
- pub host_info : TargetInfo ,
38
+ target_config : HashMap < InternedString , TargetConfig > ,
39
+ target_info : HashMap < InternedString , TargetInfo > ,
40
+ host_info : TargetInfo ,
44
41
pub units : & ' a UnitInterner < ' a > ,
45
42
}
46
43
@@ -57,19 +54,16 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
57
54
let rustc = config. load_global_rustc ( Some ( ws) ) ?;
58
55
59
56
let host_config = TargetConfig :: new ( config, & rustc. host ) ?;
60
- let target_config = match build_config. requested_target . as_ref ( ) {
61
- Some ( triple) => TargetConfig :: new ( config, triple) ?,
62
- None => host_config. clone ( ) ,
63
- } ;
64
- let ( host_info, target_info) = {
65
- let _p = profile:: start ( "BuildContext::probe_target_info" ) ;
66
- debug ! ( "probe_target_info" ) ;
67
- let host_info =
68
- TargetInfo :: new ( config, & build_config. requested_target , & rustc, Kind :: Host ) ?;
69
- let target_info =
70
- TargetInfo :: new ( config, & build_config. requested_target , & rustc, Kind :: Target ) ?;
71
- ( host_info, target_info)
72
- } ;
57
+ let host_info = TargetInfo :: new ( config, build_config. requested_target , & rustc, Kind :: Host ) ?;
58
+ let mut target_config = HashMap :: new ( ) ;
59
+ let mut target_info = HashMap :: new ( ) ;
60
+ if let Some ( target) = build_config. requested_target {
61
+ target_config. insert ( target, TargetConfig :: new ( config, & target) ?) ;
62
+ target_info. insert (
63
+ target,
64
+ TargetInfo :: new ( config, Some ( target) , & rustc, Kind :: Target ( target) ) ?,
65
+ ) ;
66
+ }
73
67
74
68
Ok ( BuildContext {
75
69
ws,
@@ -96,11 +90,8 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
96
90
Some ( p) => p,
97
91
None => return true ,
98
92
} ;
99
- let ( name, info) = match kind {
100
- Kind :: Host => ( self . host_triple ( ) , & self . host_info ) ,
101
- Kind :: Target => ( self . target_triple ( ) , & self . target_info ) ,
102
- } ;
103
- platform. matches ( name, info. cfg ( ) )
93
+ let name = self . target_triple ( kind) ;
94
+ platform. matches ( & name, self . cfg ( kind) )
104
95
}
105
96
106
97
/// Gets the user-specified linker for a particular host or target.
@@ -115,11 +106,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
115
106
116
107
/// Gets the list of `cfg`s printed out from the compiler for the specified kind.
117
108
pub fn cfg ( & self , kind : Kind ) -> & [ Cfg ] {
118
- let info = match kind {
119
- Kind :: Host => & self . host_info ,
120
- Kind :: Target => & self . target_info ,
121
- } ;
122
- info. cfg ( )
109
+ self . info ( kind) . cfg ( )
123
110
}
124
111
125
112
/// Gets the host architecture triple.
@@ -128,23 +115,23 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
128
115
/// - machine: x86_64,
129
116
/// - hardware-platform: unknown,
130
117
/// - operating system: linux-gnu.
131
- pub fn host_triple ( & self ) -> & str {
132
- & self . rustc . host
118
+ pub fn host_triple ( & self ) -> InternedString {
119
+ self . rustc . host
133
120
}
134
121
135
- pub fn target_triple ( & self ) -> & str {
136
- self . build_config
137
- . requested_target
138
- . as_ref ( )
139
- . map ( |s| s . as_str ( ) )
140
- . unwrap_or_else ( || self . host_triple ( ) )
122
+ /// Returns the target triple associated with a `Kind`
123
+ pub fn target_triple ( & self , kind : Kind ) -> InternedString {
124
+ match kind {
125
+ Kind :: Host => self . host_triple ( ) ,
126
+ Kind :: Target ( name ) => name ,
127
+ }
141
128
}
142
129
143
130
/// Gets the target configuration for a particular host or target.
144
- fn target_config ( & self , kind : Kind ) -> & TargetConfig {
131
+ pub fn target_config ( & self , kind : Kind ) -> & TargetConfig {
145
132
match kind {
146
133
Kind :: Host => & self . host_config ,
147
- Kind :: Target => & self . target_config ,
134
+ Kind :: Target ( s ) => & self . target_config [ & s ] ,
148
135
}
149
136
}
150
137
@@ -165,10 +152,10 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
165
152
pkg. source_id ( ) . is_path ( ) || self . config . extra_verbose ( )
166
153
}
167
154
168
- fn info ( & self , kind : Kind ) -> & TargetInfo {
155
+ pub fn info ( & self , kind : Kind ) -> & TargetInfo {
169
156
match kind {
170
157
Kind :: Host => & self . host_info ,
171
- Kind :: Target => & self . target_info ,
158
+ Kind :: Target ( s ) => & self . target_info [ & s ] ,
172
159
}
173
160
}
174
161
@@ -181,10 +168,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
181
168
/// `lib_name` is the `links` library name and `kind` is whether it is for
182
169
/// Host or Target.
183
170
pub fn script_override ( & self , lib_name : & str , kind : Kind ) -> Option < & BuildOutput > {
184
- match kind {
185
- Kind :: Host => self . host_config . overrides . get ( lib_name) ,
186
- Kind :: Target => self . target_config . overrides . get ( lib_name) ,
187
- }
171
+ self . target_config ( kind) . overrides . get ( lib_name)
188
172
}
189
173
}
190
174
0 commit comments