Fix panic with build-std of a proc-macro.

This commit is contained in:
Eric Huss 2021-08-23 12:06:32 -07:00
parent 835d5576e1
commit 00e925f61f
2 changed files with 37 additions and 4 deletions

View file

@ -142,6 +142,7 @@ fn attach_std_deps(
std_unit_deps: UnitGraph,
) {
// Attach the standard library as a dependency of every target unit.
let mut found = false;
for (unit, deps) in state.unit_dependencies.iter_mut() {
if !unit.kind.is_host() && !unit.mode.is_run_custom_build() {
deps.extend(std_roots[&unit.kind].iter().map(|unit| UnitDep {
@ -152,12 +153,16 @@ fn attach_std_deps(
public: true,
noprelude: true,
}));
found = true;
}
}
// And also include the dependencies of the standard library itself.
for (unit, deps) in std_unit_deps.into_iter() {
if let Some(other_unit) = state.unit_dependencies.insert(unit, deps) {
panic!("std unit collision with existing unit: {:?}", other_unit);
// And also include the dependencies of the standard library itself. Don't
// include these if no units actually needed the standard library.
if found {
for (unit, deps) in std_unit_deps.into_iter() {
if let Some(other_unit) = state.unit_dependencies.insert(unit, deps) {
panic!("std unit collision with existing unit: {:?}", other_unit);
}
}
}
}

View file

@ -662,3 +662,31 @@ fn no_roots() {
.with_stderr_contains("[FINISHED] [..]")
.run();
}
#[cargo_test]
fn proc_macro_only() {
// Checks for a bug where it would panic if building a proc-macro only
let setup = match setup() {
Some(s) => s,
None => return,
};
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "pm"
version = "0.1.0"
[lib]
proc-macro = true
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("build")
.build_std(&setup)
.target_host()
.with_stderr_contains("[FINISHED] [..]")
.run();
}