Skip to content

Commit 51fd373

Browse files
committed
translate-libs: Revert to using package ids
Cargo bug was fixed in rust-lang/cargo#15447
1 parent 3d0c155 commit 51fd373

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

src/bin/mir-json-translate-libs.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::{
2121

2222
use cargo_metadata::{
2323
camino::{Utf8Path, Utf8PathBuf},
24-
Artifact, Edition, Message, Target,
24+
Artifact, Edition, Message, PackageId, Target,
2525
};
2626
use serde::Deserialize;
2727
use shell_escape::escape;
@@ -53,12 +53,7 @@ struct UnitGraph {
5353

5454
#[derive(Debug, Deserialize)]
5555
struct UnitGraphUnit {
56-
/// This is not `PackageId` since its format is incompatible with the one
57-
/// from cargo metadata. This has been fixed in
58-
/// https://github.com/rust-lang/cargo/pull/15447, so the next time we
59-
/// upgrade the Rust version we can change this back to `PackageId` and key
60-
/// `artifact_outputs` with it instead of `src_path`.
61-
pkg_id: String,
56+
pkg_id: PackageId,
6257
target: Target,
6358
#[serde(default)]
6459
is_std: bool,
@@ -217,13 +212,12 @@ impl UnitGraphUnit {
217212
/// artifact output map and custom sources directory.
218213
fn get_pkg_path_info<'a>(
219214
&self,
220-
artifact_outputs: &'a HashMap<Utf8PathBuf, Artifact>,
215+
artifact_outputs: &'a HashMap<PackageId, Artifact>,
221216
sources_dir: &Utf8Path,
222217
) -> CustomTarget<LibPathInfo<'a>> {
223218
custom_kind_of_target(&self.target).map_lib(|()| {
224-
let artifact = artifact_outputs
225-
.get(&self.target.src_path)
226-
.unwrap_or_else(|| {
219+
let artifact =
220+
artifact_outputs.get(&self.pkg_id).unwrap_or_else(|| {
227221
panic!(
228222
"library {} (src_path {}) \
229223
should have a compiler artifact",
@@ -567,7 +561,7 @@ fn main() {
567561
if let CustomTarget::TargetLib(()) =
568562
custom_kind_of_target(&art.target)
569563
{
570-
artifact_outputs.insert(art.target.src_path.clone(), art);
564+
artifact_outputs.insert(art.package_id.clone(), art);
571565
}
572566
}
573567
Message::BuildScriptExecuted(bs) => {
@@ -689,9 +683,7 @@ fn main() {
689683
"source file should be inside directory of Cargo.toml",
690684
);
691685
let (linked_libs, linked_paths, cfgs, env) =
692-
match build_script_outputs
693-
.remove(&path_info.artifact.package_id)
694-
{
686+
match build_script_outputs.remove(&unit.pkg_id) {
695687
Some(bs) => {
696688
// Certain packages rely on `cargo` defining the
697689
// `OUT_DIR` environment variable (e.g.,

0 commit comments

Comments
 (0)