Skip to content

Commit 0eb7edf

Browse files
committed
Run rustc for information fewer times
Currently if you pass `--target` the same as rustc's host Cargo will run `rustc` on extra time to learn information, but we only need to run it once to learn such information!
1 parent 311a5ed commit 0eb7edf

File tree

1 file changed

+24
-15
lines changed
  • src/cargo/ops/cargo_rustc/context

1 file changed

+24
-15
lines changed

src/cargo/ops/cargo_rustc/context/mod.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ struct TargetInfo {
120120
crate_type_process: Option<ProcessBuilder>,
121121
crate_types: RefCell<HashMap<String, Option<(String, String)>>>,
122122
cfg: Option<Vec<Cfg>>,
123+
sysroot_libdir: Option<PathBuf>,
123124
}
124125

125126
impl TargetInfo {
@@ -246,16 +247,25 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
246247
/// all the units mentioned in `units`.
247248
pub fn probe_target_info(&mut self) -> CargoResult<()> {
248249
debug!("probe_target_info");
249-
self.probe_target_info_kind(Kind::Target)?;
250-
if self.requested_target().is_none() {
251-
self.host_info = self.target_info.clone();
250+
let host_target_same = match self.requested_target() {
251+
Some(s) if s != self.config.rustc()?.host => false,
252+
_ => true,
253+
};
254+
255+
if host_target_same {
256+
let info = self.probe_target_info_kind(Kind::Target)?;
257+
self.host_info = info.clone();
258+
self.target_info = info;
252259
} else {
253-
self.probe_target_info_kind(Kind::Host)?;
260+
self.host_info = self.probe_target_info_kind(Kind::Host)?;
261+
self.target_info = self.probe_target_info_kind(Kind::Target)?;
254262
}
263+
self.compilation.host_dylib_path = self.host_info.sysroot_libdir.clone();
264+
self.compilation.target_dylib_path = self.target_info.sysroot_libdir.clone();
255265
Ok(())
256266
}
257267

258-
fn probe_target_info_kind(&mut self, kind: Kind) -> CargoResult<()> {
268+
fn probe_target_info_kind(&self, kind: Kind) -> CargoResult<TargetInfo> {
259269
let rustflags = env_args(
260270
self.config,
261271
&self.build_config,
@@ -305,6 +315,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
305315
map.insert(crate_type.to_string(), out);
306316
}
307317

318+
let mut sysroot_libdir = None;
308319
if has_cfg_and_sysroot {
309320
let line = match lines.next() {
310321
Some(line) => line,
@@ -320,13 +331,13 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
320331
} else {
321332
rustlib.push("lib");
322333
}
323-
self.compilation.host_dylib_path = Some(rustlib);
334+
sysroot_libdir = Some(rustlib);
324335
} else {
325336
rustlib.push("lib");
326337
rustlib.push("rustlib");
327338
rustlib.push(self.target_triple());
328339
rustlib.push("lib");
329-
self.compilation.target_dylib_path = Some(rustlib);
340+
sysroot_libdir = Some(rustlib);
330341
}
331342
}
332343

@@ -336,14 +347,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
336347
None
337348
};
338349

339-
let info = match kind {
340-
Kind::Target => &mut self.target_info,
341-
Kind::Host => &mut self.host_info,
342-
};
343-
info.crate_type_process = Some(crate_type_process);
344-
info.crate_types = RefCell::new(map);
345-
info.cfg = cfg;
346-
Ok(())
350+
Ok(TargetInfo {
351+
crate_type_process: Some(crate_type_process),
352+
crate_types: RefCell::new(map),
353+
cfg,
354+
sysroot_libdir,
355+
})
347356
}
348357

349358
/// Builds up the `used_in_plugin` internal to this context from the list of

0 commit comments

Comments
 (0)