Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions src/cargo/ops/cargo_rustc/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ struct TargetInfo {
crate_type_process: Option<ProcessBuilder>,
crate_types: RefCell<HashMap<String, Option<(String, String)>>>,
cfg: Option<Vec<Cfg>>,
sysroot_libdir: Option<PathBuf>,
}

impl TargetInfo {
Expand Down Expand Up @@ -246,16 +247,25 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
/// all the units mentioned in `units`.
pub fn probe_target_info(&mut self) -> CargoResult<()> {
debug!("probe_target_info");
self.probe_target_info_kind(Kind::Target)?;
if self.requested_target().is_none() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, interesting, so the previous logic kinda handled this in the case where target was not passed at all....

Perhaps add a helper Context::is_cross_compiling which handles both "no target" and "explicit target the same as the host", so that we don't duplicated this logic incorrectly elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna hold off on this suggestion for now because the deduction here is different than Cargo's historical deduction of "am I cross compiling?" (aka is --target passed?). I'd hope though we could improve this in the future!

self.host_info = self.target_info.clone();
let host_target_same = match self.requested_target() {
Some(s) if s != self.config.rustc()?.host => false,
_ => true,
};

if host_target_same {
let info = self.probe_target_info_kind(Kind::Target)?;
self.host_info = info.clone();
self.target_info = info;
} else {
self.probe_target_info_kind(Kind::Host)?;
self.host_info = self.probe_target_info_kind(Kind::Host)?;
self.target_info = self.probe_target_info_kind(Kind::Target)?;
}
self.compilation.host_dylib_path = self.host_info.sysroot_libdir.clone();
self.compilation.target_dylib_path = self.target_info.sysroot_libdir.clone();
Ok(())
}

fn probe_target_info_kind(&mut self, kind: Kind) -> CargoResult<()> {
fn probe_target_info_kind(&self, kind: Kind) -> CargoResult<TargetInfo> {
let rustflags = env_args(
self.config,
&self.build_config,
Expand Down Expand Up @@ -305,6 +315,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
map.insert(crate_type.to_string(), out);
}

let mut sysroot_libdir = None;
if has_cfg_and_sysroot {
let line = match lines.next() {
Some(line) => line,
Expand All @@ -320,13 +331,13 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
} else {
rustlib.push("lib");
}
self.compilation.host_dylib_path = Some(rustlib);
sysroot_libdir = Some(rustlib);
} else {
rustlib.push("lib");
rustlib.push("rustlib");
rustlib.push(self.target_triple());
rustlib.push("lib");
self.compilation.target_dylib_path = Some(rustlib);
sysroot_libdir = Some(rustlib);
}
}

Expand All @@ -336,14 +347,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
None
};

let info = match kind {
Kind::Target => &mut self.target_info,
Kind::Host => &mut self.host_info,
};
info.crate_type_process = Some(crate_type_process);
info.crate_types = RefCell::new(map);
info.cfg = cfg;
Ok(())
Ok(TargetInfo {
crate_type_process: Some(crate_type_process),
crate_types: RefCell::new(map),
cfg,
sysroot_libdir,
})
}

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