Skip to content

Commit

Permalink
Fixed crate_universe when using Rust >= 1.85.0 (#3251)
Browse files Browse the repository at this point in the history
This change uses frewsxcv/rust-crates-index#184
to fix issues around locating crate files.
  • Loading branch information
UebelAndre authored Feb 20, 2025
1 parent acac3e5 commit 12598a6
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 61 deletions.
4 changes: 2 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ use_repo(
"cui",
"cui__anyhow-1.0.95",
"cui__camino-1.1.9",
"cui__cargo-lock-10.0.1",
"cui__cargo-lock-10.1.0",
"cui__cargo-platform-0.1.9",
"cui__cargo_metadata-0.19.1",
"cui__cargo_toml-0.21.0",
"cui__cfg-expr-0.17.2",
"cui__clap-4.5.26",
"cui__crates-index-3.5.0",
"cui__crates-index-3.6.0",
"cui__glob-0.3.2",
"cui__hex-0.4.3",
"cui__indoc-2.0.5",
Expand Down
12 changes: 6 additions & 6 deletions crate_universe/3rdparty/crates/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions crate_universe/3rdparty/crates/BUILD.rustc-stable-hash-0.1.1.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 24 additions & 14 deletions crate_universe/3rdparty/crates/defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions crate_universe/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crate_universe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ anyhow = "1.0.95"
camino = "1.1.9"
cargo_metadata = "0.19.1"
cargo_toml = "0.21.0"
cargo-lock = "10.0.1"
cargo-lock = "10.1.0"
cargo-platform = "0.1.9"
cfg-expr = "0.17.2"
clap = { version = "4.5.26", features = ["derive", "env"] }
crates-index = { version = "3.5.0", default-features = false, features = [
crates-index = { version = "3.6.0", default-features = false, features = [
"git",
] }
hex = "0.4.3"
Expand Down
10 changes: 10 additions & 0 deletions crate_universe/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ impl LockGenerator {

// Ensure the Cargo cache is up to date to simulate the behavior
// of having just generated a new one
tracing::debug!("Fetching crates for {}", manifest_path);
let output = self
.cargo_bin
.command()?
Expand All @@ -230,6 +231,7 @@ impl LockGenerator {
.arg("fetch")
.arg("--manifest-path")
.arg(manifest_path.as_std_path())
.arg("--verbose")
.output()
.context(format!(
"Error running cargo to fetch crates '{}'",
Expand All @@ -244,6 +246,14 @@ impl LockGenerator {
output.status
))
}
tracing::trace!(
"Cargo fetch stderr:\n{}",
String::from_utf8_lossy(&output.stderr)
);
tracing::trace!(
"Cargo fetch stdout:\n{}",
String::from_utf8_lossy(&output.stdout)
);
} else {
debug!("Generating new lockfile");
// Simply invoke `cargo generate-lockfile`
Expand Down
12 changes: 12 additions & 0 deletions crate_universe/src/metadata/cargo_bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ impl Cargo {
bail!("Couldn't parse cargo version");
}

/// Determine if Cargo is on a version which uses new hashing behavior
/// introduced in Rust 1.86.0. For details see <https://github.com/frewsxcv/rust-crates-index/issues/182>
pub(crate) fn uses_stable_registry_hash(&self) -> Result<bool> {
let full_version = self.full_version()?;
let version_str = full_version.split(' ').nth(1);
if let Some(version_str) = version_str {
let version = Version::parse(version_str).context("Failed to parse cargo version")?;
return Ok(version.major >= 1 && version.minor >= 85);
}
bail!("Couldn't parse cargo version");
}

fn env(&self) -> Result<BTreeMap<String, OsString>> {
let mut map = BTreeMap::new();

Expand Down
2 changes: 1 addition & 1 deletion crate_universe/src/metadata/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ fn get_library_target_name(package: &Package, potential_name: &str) -> Result<St
)
}

let target = lib_targets.into_iter().last().unwrap();
let target = lib_targets.into_iter().next_back().unwrap();
Ok(target.name.clone())
}

Expand Down
6 changes: 1 addition & 5 deletions crate_universe/src/metadata/workspace_discoverer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,7 @@ impl ManifestCache<'_> {
if let Some(maybe_manifest) = self.cache.get(path) {
return maybe_manifest.clone();
}
let maybe_manifest = if let Ok(manifest) = Manifest::from_path(path) {
Some(manifest)
} else {
None
};
let maybe_manifest = Manifest::from_path(path).ok();
self.cache.insert(path.clone(), maybe_manifest.clone());
maybe_manifest
}
Expand Down
Loading

0 comments on commit 12598a6

Please sign in to comment.