Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message for transitive artifact dependencies with targets the package doesn't directly interact with #11643

Merged
merged 7 commits into from
Feb 25, 2023
16 changes: 14 additions & 2 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,10 +938,22 @@ impl<'cfg> RustcTargetData<'cfg> {
}

/// Information about the given target platform, learned by querying rustc.
///
/// # Panics
///
/// Panics, if the target platform described by `kind` can't be found.
/// See [`get_info`](Self::get_info) for a non-panicking alternative.
pub fn info(&self, kind: CompileKind) -> &TargetInfo {
self.get_info(kind).unwrap()
}

/// Information about the given target platform, learned by querying rustc.
///
/// Returns `None` if the target platform described by `kind` can't be found.
pub fn get_info(&self, kind: CompileKind) -> Option<&TargetInfo> {
match kind {
CompileKind::Host => &self.host_info,
CompileKind::Target(s) => &self.target_info[&s],
CompileKind::Host => Some(&self.host_info),
CompileKind::Target(s) => self.target_info.get(&s),
}
}

Expand Down
40 changes: 30 additions & 10 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,7 @@ impl<'cfg> Compilation<'cfg> {
.info(CompileKind::Host)
.sysroot_host_libdir
.clone(),
sysroot_target_libdir: bcx
.all_kinds
.iter()
.map(|&kind| {
(
kind,
bcx.target_data.info(kind).sysroot_target_libdir.clone(),
)
})
.collect(),
sysroot_target_libdir: get_sysroot_target_libdir(bcx)?,
tests: Vec::new(),
binaries: Vec::new(),
cdylibs: Vec::new(),
Expand Down Expand Up @@ -384,6 +375,35 @@ fn fill_rustc_tool_env(mut cmd: ProcessBuilder, unit: &Unit) -> ProcessBuilder {
cmd
}

fn get_sysroot_target_libdir(
bcx: &BuildContext<'_, '_>,
) -> CargoResult<HashMap<CompileKind, PathBuf>> {
bcx.all_kinds
.iter()
.map(|&kind| {
jofas marked this conversation as resolved.
Show resolved Hide resolved
let Some(info) = bcx.target_data.get_info(kind) else {
let target = match kind {
CompileKind::Host => "host".to_owned(),
CompileKind::Target(s) => s.short_name().to_owned(),
};

let dependency = bcx
.unit_graph
.iter()
.find_map(|(u, _)| (u.kind == kind).then_some(u.pkg.summary().package_id()))
.unwrap();

anyhow::bail!(
"could not find specification for target `{target}`.\n \
Dependency `{dependency}` requires to build for target `{target}`."
)
};

Ok((kind, info.sysroot_target_libdir.clone()))
})
.collect()
}

fn target_runner(
bcx: &BuildContext<'_, '_>,
kind: CompileKind,
Expand Down
Loading