Skip to content

Commit 3ec14e0

Browse files
committed
Inline creation of TargetInfos in Context::new()
1 parent eb45a62 commit 3ec14e0

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

src/cargo/core/compiler/context/mod.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,31 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
125125
None => Client::new(build_config.jobs as usize - 1)
126126
.chain_err(|| "failed to create jobserver")?,
127127
};
128+
129+
let (host_info, target_info) = {
130+
let _p = profile::start("Context::probe_target_info");
131+
debug!("probe_target_info");
132+
let host_target_same = match build_config.requested_target {
133+
Some(ref s) if s != &config.rustc()?.host => false,
134+
_ => true,
135+
};
136+
137+
let host_info = TargetInfo::new(config, &build_config, Kind::Host)?;
138+
let target_info = if host_target_same {
139+
host_info.clone()
140+
} else {
141+
TargetInfo::new(config, &build_config, Kind::Target)?
142+
};
143+
(host_info, target_info)
144+
};
145+
128146
let mut cx = Context {
129147
ws,
130148
resolve,
131149
packages,
132150
config,
133-
target_info: TargetInfo::default(),
134-
host_info: TargetInfo::default(),
151+
target_info,
152+
host_info,
135153
compilation: Compilation::new(config),
136154
build_state: Arc::new(BuildState::new(&build_config)),
137155
build_config,
@@ -150,7 +168,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
150168
files: None,
151169
};
152170

153-
cx.probe_target_info()?;
171+
cx.compilation.host_dylib_path = cx.host_info.sysroot_libdir.clone();
172+
cx.compilation.target_dylib_path = cx.target_info.sysroot_libdir.clone();
154173
Ok(cx)
155174
}
156175

@@ -341,27 +360,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
341360
Ok(())
342361
}
343362

344-
/// Ensure that we've collected all target-specific information to compile
345-
/// all the units mentioned in `units`.
346-
fn probe_target_info(&mut self) -> CargoResult<()> {
347-
let _p = profile::start("Context::probe_target_info");
348-
debug!("probe_target_info");
349-
let host_target_same = match self.build_config.requested_target {
350-
Some(ref s) if s != &self.config.rustc()?.host => false,
351-
_ => true,
352-
};
353-
354-
self.host_info = TargetInfo::new(self.config, &self.build_config, Kind::Host)?;
355-
self.target_info = if host_target_same {
356-
self.host_info.clone()
357-
} else {
358-
TargetInfo::new(self.config, &self.build_config, Kind::Target)?
359-
};
360-
self.compilation.host_dylib_path = self.host_info.sysroot_libdir.clone();
361-
self.compilation.target_dylib_path = self.target_info.sysroot_libdir.clone();
362-
Ok(())
363-
}
364-
365363
/// Builds up the `used_in_plugin` internal to this context from the list of
366364
/// top-level units.
367365
///

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use util::{CargoResult, CargoResultExt, Cfg, Config, ProcessBuilder};
88
use core::TargetKind;
99
use super::Kind;
1010

11-
#[derive(Clone, Default)]
11+
#[derive(Clone)]
1212
pub struct TargetInfo {
1313
crate_type_process: Option<ProcessBuilder>,
1414
crate_types: RefCell<HashMap<String, Option<(String, String)>>>,

0 commit comments

Comments
 (0)