@@ -18,7 +18,7 @@ use crate::{cfg_flag::CfgFlag, CargoConfig, CargoWorkspace, Package};
18
18
19
19
#[ derive( Debug , Default , Clone , PartialEq , Eq ) ]
20
20
pub struct WorkspaceBuildScripts {
21
- pub ( crate ) outputs : ArenaMap < Package , BuildScriptOutput > ,
21
+ outputs : ArenaMap < Package , Option < BuildScriptOutput > > ,
22
22
error : Option < String > ,
23
23
}
24
24
@@ -72,6 +72,7 @@ impl WorkspaceBuildScripts {
72
72
73
73
cmd
74
74
}
75
+
75
76
pub ( crate ) fn run (
76
77
config : & CargoConfig ,
77
78
workspace : & CargoWorkspace ,
@@ -91,13 +92,13 @@ impl WorkspaceBuildScripts {
91
92
cmd. current_dir ( workspace. workspace_root ( ) ) ;
92
93
93
94
let mut res = WorkspaceBuildScripts :: default ( ) ;
95
+ let outputs = & mut res. outputs ;
94
96
// NB: Cargo.toml could have been modified between `cargo metadata` and
95
97
// `cargo check`. We shouldn't assume that package ids we see here are
96
98
// exactly those from `config`.
97
99
let mut by_id: FxHashMap < String , Package > = FxHashMap :: default ( ) ;
98
-
99
100
for package in workspace. packages ( ) {
100
- res . outputs . insert ( package, BuildScriptOutput :: default ( ) ) ;
101
+ outputs. insert ( package, None ) ;
101
102
by_id. insert ( workspace[ package] . id . clone ( ) , package) ;
102
103
}
103
104
@@ -141,7 +142,8 @@ impl WorkspaceBuildScripts {
141
142
}
142
143
acc
143
144
} ;
144
- let package_build_data = & mut res. outputs [ package] ;
145
+ let package_build_data =
146
+ outputs[ package] . get_or_insert_with ( Default :: default) ;
145
147
// cargo_metadata crate returns default (empty) path for
146
148
// older cargos, which is not absolute, so work around that.
147
149
if !message. out_dir . as_str ( ) . is_empty ( ) {
@@ -167,7 +169,9 @@ impl WorkspaceBuildScripts {
167
169
message. filenames . iter ( ) . find ( |name| is_dylib ( name) )
168
170
{
169
171
let filename = AbsPathBuf :: assert ( PathBuf :: from ( & filename) ) ;
170
- res. outputs [ package] . proc_macro_dylib_path = Some ( filename) ;
172
+ outputs[ package]
173
+ . get_or_insert_with ( Default :: default)
174
+ . proc_macro_dylib_path = Some ( filename) ;
171
175
}
172
176
}
173
177
}
@@ -189,17 +193,18 @@ impl WorkspaceBuildScripts {
189
193
) ?;
190
194
191
195
for package in workspace. packages ( ) {
192
- let package_build_data = & mut res. outputs [ package] ;
193
- tracing:: info!(
194
- "{} BuildScriptOutput: {:?}" ,
195
- workspace[ package] . manifest. parent( ) . display( ) ,
196
- package_build_data,
197
- ) ;
198
- // inject_cargo_env(package, package_build_data);
199
- if let Some ( out_dir) = & package_build_data. out_dir {
200
- // NOTE: cargo and rustc seem to hide non-UTF-8 strings from env! and option_env!()
201
- if let Some ( out_dir) = out_dir. as_os_str ( ) . to_str ( ) . map ( |s| s. to_owned ( ) ) {
202
- package_build_data. envs . push ( ( "OUT_DIR" . to_string ( ) , out_dir) ) ;
196
+ if let Some ( package_build_data) = & mut outputs[ package] {
197
+ tracing:: info!(
198
+ "{} BuildScriptOutput: {:?}" ,
199
+ workspace[ package] . manifest. parent( ) . display( ) ,
200
+ package_build_data,
201
+ ) ;
202
+ // inject_cargo_env(package, package_build_data);
203
+ if let Some ( out_dir) = & package_build_data. out_dir {
204
+ // NOTE: cargo and rustc seem to hide non-UTF-8 strings from env! and option_env!()
205
+ if let Some ( out_dir) = out_dir. as_os_str ( ) . to_str ( ) . map ( |s| s. to_owned ( ) ) {
206
+ package_build_data. envs . push ( ( "OUT_DIR" . to_string ( ) , out_dir) ) ;
207
+ }
203
208
}
204
209
}
205
210
}
@@ -218,6 +223,10 @@ impl WorkspaceBuildScripts {
218
223
pub fn error ( & self ) -> Option < & str > {
219
224
self . error . as_deref ( )
220
225
}
226
+
227
+ pub ( crate ) fn get_output ( & self , idx : Package ) -> Option < & BuildScriptOutput > {
228
+ self . outputs . get ( idx) ?. as_ref ( )
229
+ }
221
230
}
222
231
223
232
// FIXME: File a better way to know if it is a dylib.
0 commit comments