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

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

Merged
merged 1 commit into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
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
13 changes: 9 additions & 4 deletions src/cargo/core/compiler/unit_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions tests/testsuite/standard_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}