diff --git a/MODULE.bazel b/MODULE.bazel index cf30b2938a..02b2d6c2d9 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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", diff --git a/crate_universe/3rdparty/crates/BUILD.bazel b/crate_universe/3rdparty/crates/BUILD.bazel index 568c0a3c37..7f93ce7d86 100644 --- a/crate_universe/3rdparty/crates/BUILD.bazel +++ b/crate_universe/3rdparty/crates/BUILD.bazel @@ -56,14 +56,14 @@ alias( ) alias( - name = "cargo-lock-10.0.1", - actual = "@cui__cargo-lock-10.0.1//:cargo_lock", + name = "cargo-lock-10.1.0", + actual = "@cui__cargo-lock-10.1.0//:cargo_lock", tags = ["manual"], ) alias( name = "cargo-lock", - actual = "@cui__cargo-lock-10.0.1//:cargo_lock", + actual = "@cui__cargo-lock-10.1.0//:cargo_lock", tags = ["manual"], ) @@ -128,14 +128,14 @@ alias( ) alias( - name = "crates-index-3.5.0", - actual = "@cui__crates-index-3.5.0//:crates_index", + name = "crates-index-3.6.0", + actual = "@cui__crates-index-3.6.0//:crates_index", tags = ["manual"], ) alias( name = "crates-index", - actual = "@cui__crates-index-3.5.0//:crates_index", + actual = "@cui__crates-index-3.6.0//:crates_index", tags = ["manual"], ) diff --git a/crate_universe/3rdparty/crates/BUILD.cargo-lock-10.0.1.bazel b/crate_universe/3rdparty/crates/BUILD.cargo-lock-10.1.0.bazel similarity index 99% rename from crate_universe/3rdparty/crates/BUILD.cargo-lock-10.0.1.bazel rename to crate_universe/3rdparty/crates/BUILD.cargo-lock-10.1.0.bazel index c85740da48..6f753d95de 100644 --- a/crate_universe/3rdparty/crates/BUILD.cargo-lock-10.0.1.bazel +++ b/crate_universe/3rdparty/crates/BUILD.cargo-lock-10.1.0.bazel @@ -79,7 +79,7 @@ rust_library( "@rules_rust//rust/platform:x86_64-unknown-uefi": [], "//conditions:default": ["@platforms//:incompatible"], }), - version = "10.0.1", + version = "10.1.0", deps = [ "@cui__semver-1.0.24//:semver", "@cui__serde-1.0.217//:serde", diff --git a/crate_universe/3rdparty/crates/BUILD.crates-index-3.5.0.bazel b/crate_universe/3rdparty/crates/BUILD.crates-index-3.6.0.bazel similarity index 98% rename from crate_universe/3rdparty/crates/BUILD.crates-index-3.5.0.bazel rename to crate_universe/3rdparty/crates/BUILD.crates-index-3.6.0.bazel index db97961d06..7a4f3149b8 100644 --- a/crate_universe/3rdparty/crates/BUILD.crates-index-3.5.0.bazel +++ b/crate_universe/3rdparty/crates/BUILD.crates-index-3.6.0.bazel @@ -85,13 +85,14 @@ rust_library( "@rules_rust//rust/platform:x86_64-unknown-uefi": [], "//conditions:default": ["@platforms//:incompatible"], }), - version = "3.5.0", + version = "3.6.0", deps = [ "@cui__gix-0.69.1//:gix", "@cui__hex-0.4.3//:hex", "@cui__home-0.5.5//:home", "@cui__memchr-2.6.4//:memchr", "@cui__rustc-hash-2.0.0//:rustc_hash", + "@cui__rustc-stable-hash-0.1.1//:rustc_stable_hash", "@cui__semver-1.0.24//:semver", "@cui__serde-1.0.217//:serde", "@cui__serde_json-1.0.135//:serde_json", diff --git a/crate_universe/3rdparty/crates/BUILD.rustc-stable-hash-0.1.1.bazel b/crate_universe/3rdparty/crates/BUILD.rustc-stable-hash-0.1.1.bazel new file mode 100644 index 0000000000..1a247fc5a7 --- /dev/null +++ b/crate_universe/3rdparty/crates/BUILD.rustc-stable-hash-0.1.1.bazel @@ -0,0 +1,83 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @@//crate_universe/3rdparty:crates_vendor +############################################################################### + +load("@rules_rust//rust:defs.bzl", "rust_library") + +package(default_visibility = ["//visibility:public"]) + +rust_library( + name = "rustc_stable_hash", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_root = "src/lib.rs", + edition = "2021", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=rustc-stable-hash", + "manual", + "noclippy", + "norustfmt", + ], + target_compatible_with = select({ + "@rules_rust//rust/platform:aarch64-apple-darwin": [], + "@rules_rust//rust/platform:aarch64-apple-ios": [], + "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], + "@rules_rust//rust/platform:aarch64-linux-android": [], + "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], + "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], + "@rules_rust//rust/platform:aarch64-unknown-uefi": [], + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:armv7-linux-androideabi": [], + "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:i686-apple-darwin": [], + "@rules_rust//rust/platform:i686-linux-android": [], + "@rules_rust//rust/platform:i686-pc-windows-msvc": [], + "@rules_rust//rust/platform:i686-unknown-freebsd": [], + "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], + "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], + "@rules_rust//rust/platform:thumbv7em-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], + "@rules_rust//rust/platform:wasm32-unknown-unknown": [], + "@rules_rust//rust/platform:wasm32-wasip1": [], + "@rules_rust//rust/platform:x86_64-apple-darwin": [], + "@rules_rust//rust/platform:x86_64-apple-ios": [], + "@rules_rust//rust/platform:x86_64-linux-android": [], + "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], + "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], + "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-none": [], + "@rules_rust//rust/platform:x86_64-unknown-uefi": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + version = "0.1.1", +) diff --git a/crate_universe/3rdparty/crates/defs.bzl b/crate_universe/3rdparty/crates/defs.bzl index b3e5e4bb7b..7c6661637a 100644 --- a/crate_universe/3rdparty/crates/defs.bzl +++ b/crate_universe/3rdparty/crates/defs.bzl @@ -297,13 +297,13 @@ _NORMAL_DEPENDENCIES = { _COMMON_CONDITION: { "anyhow": Label("@cui//:anyhow-1.0.95"), "camino": Label("@cui//:camino-1.1.9"), - "cargo-lock": Label("@cui//:cargo-lock-10.0.1"), + "cargo-lock": Label("@cui//:cargo-lock-10.1.0"), "cargo-platform": Label("@cui//:cargo-platform-0.1.9"), "cargo_metadata": Label("@cui//:cargo_metadata-0.19.1"), "cargo_toml": Label("@cui//:cargo_toml-0.21.0"), "cfg-expr": Label("@cui//:cfg-expr-0.17.2"), "clap": Label("@cui//:clap-4.5.26"), - "crates-index": Label("@cui//:crates-index-3.5.0"), + "crates-index": Label("@cui//:crates-index-3.6.0"), "glob": Label("@cui//:glob-0.3.2"), "hex": Label("@cui//:hex-0.4.3"), "itertools": Label("@cui//:itertools-0.14.0"), @@ -725,12 +725,12 @@ def crate_repositories(): maybe( http_archive, - name = "cui__cargo-lock-10.0.1", - sha256 = "6469776d007022d505bbcc2be726f5f096174ae76d710ebc609eb3029a45b551", + name = "cui__cargo-lock-10.1.0", + sha256 = "c06acb4f71407ba205a07cb453211e0e6a67b21904e47f6ba1f9589e38f2e454", type = "tar.gz", - urls = ["https://static.crates.io/crates/cargo-lock/10.0.1/download"], - strip_prefix = "cargo-lock-10.0.1", - build_file = Label("//crate_universe/3rdparty/crates:BUILD.cargo-lock-10.0.1.bazel"), + urls = ["https://static.crates.io/crates/cargo-lock/10.1.0/download"], + strip_prefix = "cargo-lock-10.1.0", + build_file = Label("//crate_universe/3rdparty/crates:BUILD.cargo-lock-10.1.0.bazel"), ) maybe( @@ -865,12 +865,12 @@ def crate_repositories(): maybe( http_archive, - name = "cui__crates-index-3.5.0", - sha256 = "13058139052295533e5f7b0ed22ecf3eb7d7a5c2cd5657d6a7c8b4d8d8e093e6", + name = "cui__crates-index-3.6.0", + sha256 = "b4460df75a81c9714b02c6ff4d1f2645e457d80eab69f528ce2cce980acf0b18", type = "tar.gz", - urls = ["https://static.crates.io/crates/crates-index/3.5.0/download"], - strip_prefix = "crates-index-3.5.0", - build_file = Label("//crate_universe/3rdparty/crates:BUILD.crates-index-3.5.0.bazel"), + urls = ["https://static.crates.io/crates/crates-index/3.6.0/download"], + strip_prefix = "crates-index-3.6.0", + build_file = Label("//crate_universe/3rdparty/crates:BUILD.crates-index-3.6.0.bazel"), ) maybe( @@ -2183,6 +2183,16 @@ def crate_repositories(): build_file = Label("//crate_universe/3rdparty/crates:BUILD.rustc-hash-2.0.0.bazel"), ) + maybe( + http_archive, + name = "cui__rustc-stable-hash-0.1.1", + sha256 = "2febf9acc5ee5e99d1ad0afcdbccc02d87aa3f857a1f01f825b80eacf8edfcd1", + type = "tar.gz", + urls = ["https://static.crates.io/crates/rustc-stable-hash/0.1.1/download"], + strip_prefix = "rustc-stable-hash-0.1.1", + build_file = Label("//crate_universe/3rdparty/crates:BUILD.rustc-stable-hash-0.1.1.bazel"), + ) + maybe( http_archive, name = "cui__rustix-0.38.41", @@ -3186,13 +3196,13 @@ def crate_repositories(): return [ struct(repo = "cui__anyhow-1.0.95", is_dev_dep = False), struct(repo = "cui__camino-1.1.9", is_dev_dep = False), - struct(repo = "cui__cargo-lock-10.0.1", is_dev_dep = False), + struct(repo = "cui__cargo-lock-10.1.0", is_dev_dep = False), struct(repo = "cui__cargo-platform-0.1.9", is_dev_dep = False), struct(repo = "cui__cargo_metadata-0.19.1", is_dev_dep = False), struct(repo = "cui__cargo_toml-0.21.0", is_dev_dep = False), struct(repo = "cui__cfg-expr-0.17.2", is_dev_dep = False), struct(repo = "cui__clap-4.5.26", is_dev_dep = False), - struct(repo = "cui__crates-index-3.5.0", is_dev_dep = False), + struct(repo = "cui__crates-index-3.6.0", is_dev_dep = False), struct(repo = "cui__glob-0.3.2", is_dev_dep = False), struct(repo = "cui__hex-0.4.3", is_dev_dep = False), struct(repo = "cui__indoc-2.0.5", is_dev_dep = False), diff --git a/crate_universe/Cargo.lock b/crate_universe/Cargo.lock index 3d91ff7dc5..034a70126c 100644 --- a/crate_universe/Cargo.lock +++ b/crate_universe/Cargo.lock @@ -198,9 +198,9 @@ dependencies = [ [[package]] name = "cargo-lock" -version = "10.0.1" +version = "10.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6469776d007022d505bbcc2be726f5f096174ae76d710ebc609eb3029a45b551" +checksum = "c06acb4f71407ba205a07cb453211e0e6a67b21904e47f6ba1f9589e38f2e454" dependencies = [ "semver", "serde", @@ -325,15 +325,16 @@ dependencies = [ [[package]] name = "crates-index" -version = "3.5.0" +version = "3.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13058139052295533e5f7b0ed22ecf3eb7d7a5c2cd5657d6a7c8b4d8d8e093e6" +checksum = "b4460df75a81c9714b02c6ff4d1f2645e457d80eab69f528ce2cce980acf0b18" dependencies = [ "gix", "hex", "home", "memchr", "rustc-hash", + "rustc-stable-hash", "semver", "serde", "serde_derive", @@ -1850,6 +1851,12 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" +[[package]] +name = "rustc-stable-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2febf9acc5ee5e99d1ad0afcdbccc02d87aa3f857a1f01f825b80eacf8edfcd1" + [[package]] name = "rustix" version = "0.38.41" diff --git a/crate_universe/Cargo.toml b/crate_universe/Cargo.toml index f41e78836a..b11a49c00a 100644 --- a/crate_universe/Cargo.toml +++ b/crate_universe/Cargo.toml @@ -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" diff --git a/crate_universe/src/metadata.rs b/crate_universe/src/metadata.rs index 729c88228c..dce766f667 100644 --- a/crate_universe/src/metadata.rs +++ b/crate_universe/src/metadata.rs @@ -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()? @@ -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 '{}'", @@ -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` diff --git a/crate_universe/src/metadata/cargo_bin.rs b/crate_universe/src/metadata/cargo_bin.rs index 7d00dc72e2..c0b0cb17c5 100644 --- a/crate_universe/src/metadata/cargo_bin.rs +++ b/crate_universe/src/metadata/cargo_bin.rs @@ -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 + pub(crate) fn uses_stable_registry_hash(&self) -> Result { + 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> { let mut map = BTreeMap::new(); diff --git a/crate_universe/src/splicing.rs b/crate_universe/src/splicing.rs index 92f7d6e05a..4417386bea 100644 --- a/crate_universe/src/splicing.rs +++ b/crate_universe/src/splicing.rs @@ -307,6 +307,12 @@ impl WorkspaceMetadata { } }; + let crate_index_hash_kind = if cargo.uses_stable_registry_hash()? { + crates_index::HashKind::Stable + } else { + crates_index::HashKind::Legacy + }; + // Load each index for easy access let crate_indexes = index_urls .into_iter() @@ -320,20 +326,27 @@ impl WorkspaceMetadata { let index = if cargo.use_sparse_registries_for_crates_io()? && index_url == utils::CRATES_IO_INDEX_URL { - CrateIndexLookup::Http(crates_index::SparseIndex::from_url( + CrateIndexLookup::Http(crates_index::SparseIndex::from_url_with_hash_kind( "sparse+https://index.crates.io/", + &crate_index_hash_kind, )?) } else if index_url.starts_with("sparse+") { - CrateIndexLookup::Http(crates_index::SparseIndex::from_url(index_url)?) + CrateIndexLookup::Http(crates_index::SparseIndex::from_url_with_hash_kind( + index_url, + &crate_index_hash_kind, + )?) } else { match source_kind { SourceKind::Registry => { let index = { // Load the index for the current url - let index = crates_index::GitIndex::from_url(index_url) - .with_context(|| { - format!("Failed to load index for url: {index_url}") - })?; + let index = crates_index::GitIndex::from_url_with_hash_kind( + index_url, + &crate_index_hash_kind, + ) + .with_context(|| { + format!("Failed to load index for url: {index_url}") + })?; // Ensure each index has a valid index config index.index_config().with_context(|| { @@ -344,11 +357,12 @@ impl WorkspaceMetadata { }; CrateIndexLookup::Git(index) } - SourceKind::SparseRegistry => { - CrateIndexLookup::Http(crates_index::SparseIndex::from_url( + SourceKind::SparseRegistry => CrateIndexLookup::Http( + crates_index::SparseIndex::from_url_with_hash_kind( format!("sparse+{}", index_url).as_str(), - )?) - } + &crate_index_hash_kind, + )?, + ), unknown => { return Err(anyhow!( "'{:?}' crate index type is not supported (caused by '{}')", diff --git a/crate_universe/src/splicing/crate_index_lookup.rs b/crate_universe/src/splicing/crate_index_lookup.rs index 05bd34f79f..2c26e0558d 100644 --- a/crate_universe/src/splicing/crate_index_lookup.rs +++ b/crate_universe/src/splicing/crate_index_lookup.rs @@ -16,11 +16,11 @@ impl CrateIndexLookup { let crate_ = match self { // The crates we care about should all be in the cache already, // because `cargo metadata` ran which should have fetched them. - Self::Http(index) => Some( - index - .crate_from_cache(pkg.name.as_str()) - .with_context(|| format!("Failed to get crate from cache for {pkg:?}"))?, - ), + Self::Http(index) => { + Some(index.crate_from_cache(pkg.name.as_str()).with_context(|| { + format!("Failed to get crate from cache: {:?}\n{:?}", index, pkg) + })?) + } Self::Git(index) => index.crate_(pkg.name.as_str()), }; let source_info = crate_.and_then(|crate_idx| { @@ -97,7 +97,7 @@ mod test { ); } { - let _e = EnvVarResetter::set("CARGO_HOME", + let _e = EnvVarResetter::set("CARGO_HOME", runfiles::rlocation!(runfiles, "rules_rust/crate_universe/test_data/crate_indexes/rewritten_lazy_static/cargo_home").unwrap()); let index = CrateIndexLookup::Http( diff --git a/examples/crate_universe/MODULE.bazel b/examples/crate_universe/MODULE.bazel index 468a0b9c1a..122ff8729b 100644 --- a/examples/crate_universe/MODULE.bazel +++ b/examples/crate_universe/MODULE.bazel @@ -59,7 +59,7 @@ alias_rule_global_alias_annotation_none.spec( repositories = ["alias_rule_global_alias_annotation_none"], version = "0.1.0", ) -alias_rule_global_alias_annotation_none.from_cargo( +alias_rule_global_alias_annotation_none.from_specs( name = "alias_rule_global_alias_annotation_none", cargo_lockfile = "//alias_rule:Cargo.lock", lockfile = "//alias_rule:cargo-bazel-lock_global_alias_annotation_none.json", diff --git a/rust/private/common.bzl b/rust/private/common.bzl index a34d6b145d..c0e56f882d 100644 --- a/rust/private/common.bzl +++ b/rust/private/common.bzl @@ -33,7 +33,7 @@ load(":providers.bzl", "CrateGroupInfo", "CrateInfo", "DepInfo", "DepVariantInfo # you remove it or change its format, you will also need to update that code. DEFAULT_RUST_VERSION = "1.84.1" -DEFAULT_NIGHTLY_ISO_DATE = "2024-11-28" +DEFAULT_NIGHTLY_ISO_DATE = "2025-01-30" def _create_crate_info(**kwargs): """A constructor for a `CrateInfo` provider