Skip to content

Commit 8c33e20

Browse files
committed
Replace rustc --print=cfg parsing with handrolled loop
1 parent bca136b commit 8c33e20

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,29 @@ impl TargetInfo {
253253
res
254254
};
255255

256-
let cfg = lines
257-
.map(|line| Ok(Cfg::from_str(line)?))
258-
.filter(TargetInfo::not_user_specific_cfg)
259-
.collect::<CargoResult<Vec<_>>>()
260-
.with_context(|| {
261-
format!(
262-
"failed to parse the cfg from `rustc --print=cfg`, got:\n{}",
263-
output
264-
)
265-
})?;
256+
let cfg = {
257+
let mut res = Vec::new();
258+
loop {
259+
match lines.next() {
260+
Some(line) => {
261+
let cfg = Cfg::from_str(line).with_context(|| {
262+
format!(
263+
"failed to parse the cfg from `rustc --print=cfg`, got:\n{}",
264+
output
265+
)
266+
})?;
267+
if TargetInfo::not_user_specific_cfg(&cfg) {
268+
res.push(cfg);
269+
}
270+
}
271+
None if res.is_empty() => {
272+
return error_missing_print_output("cfgs", &process, &output, &error)
273+
}
274+
None => break,
275+
}
276+
}
277+
res
278+
};
266279

267280
// recalculate `rustflags` from above now that we have `cfg`
268281
// information
@@ -315,8 +328,8 @@ impl TargetInfo {
315328
}
316329
}
317330

318-
fn not_user_specific_cfg(cfg: &CargoResult<Cfg>) -> bool {
319-
if let Ok(Cfg::Name(cfg_name)) = cfg {
331+
fn not_user_specific_cfg(cfg: &Cfg) -> bool {
332+
if let Cfg::Name(cfg_name) = cfg {
320333
// This should also include "debug_assertions", but it causes
321334
// regressions. Maybe some day in the distant future it can be
322335
// added (and possibly change the warning to an error).

0 commit comments

Comments
 (0)