Skip to content

Commit 91f7862

Browse files
committed
fix: Added handling for build-std when preparing build-script metadata
1 parent c9895a1 commit 91f7862

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

src/cargo/core/compiler/custom_build.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -464,20 +464,33 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul
464464
if dep.unit.mode.is_run_custom_build() {
465465
let dep_metadata = build_runner.get_run_build_script_metadata(&dep.unit);
466466

467-
let Some(dependency) = unit.pkg.dependencies().iter().find(|d| {
468-
d.package_name() == dep.unit.pkg.name()
469-
&& d.source_id() == dep.unit.pkg.package_id().source_id()
470-
&& d.version_req().matches(dep.unit.pkg.version())
471-
}) else {
472-
panic!(
473-
"Dependency `{}` not found in `{}`s dependencies",
474-
dep.unit.pkg.name(),
475-
unit.pkg.name()
476-
)
477-
};
467+
let dependency_name = unit
468+
.pkg
469+
.dependencies()
470+
.iter()
471+
.find(|d| {
472+
d.package_name() == dep.unit.pkg.name()
473+
&& d.source_id() == dep.unit.pkg.package_id().source_id()
474+
&& d.version_req().matches(dep.unit.pkg.version())
475+
})
476+
.map(|d| d.name_in_toml())
477+
.unwrap_or_else(|| {
478+
if dep.unit.is_std {
479+
// If the depenency is a build-std dependency, it might not be in
480+
// Cargo.toml. If its not present, we simply use the package name as we
481+
// know its not renamed.
482+
dep.unit.pkg.name()
483+
} else {
484+
panic!(
485+
"Dependency `{}` not found in `{}`s dependencies",
486+
dep.unit.pkg.name(),
487+
unit.pkg.name()
488+
)
489+
}
490+
});
478491

479492
Some((
480-
dependency.name_in_toml(),
493+
dependency_name,
481494
dep.unit
482495
.pkg
483496
.manifest()

0 commit comments

Comments
 (0)