Skip to content

Commit a677a8d

Browse files
authored
remap crates fetched via sparse registry as well (#1888)
on Rust nightlies since about 2023-03-09: https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-168-2023-03-09 it seems the default (-on-nightly?) Cargo protocol switched to "sparse". this has a side effect of caching fetched crates at a different path, so the `github.com` path remapping is no longer sufficient to normalize all crate paths. we then picked that change up back at v1.0.14, bumping nightly forward a year and change: 24bdff6#diff-2b1bde2cf3a858b7bf7424cb8bcbf01f35b94dc80b925d9432cbab3319ca9b4e so local builds of hubris between then and v1.0.26 have source paths that are not actually remapped :( thankfully, to make it sufficient we only have to handle the new `index.crates.io-6f17d22bba15001f` path as well. this in fact is where *all* cargo-fetched crates.io dependencies end up now. technically we could forget about `github.com-1ecc6299db9ec823` at this point, but by keeping it we'll still be correct in the unlikely event someone were to flip away from `sparse` to `git` for the Cargo protocol. when i built `gimlet-v1.0.26` with this patch the resulting images no longer have my home directory in them. ... i am deeply perplexed that with this change the resulting `gimlet-b` image is 0x2200 bytes larger though??? a funny consequence of this is that to reproduce the hubris releases from 1.0.14 to ... now ... you actually have to remap the index.crates.io directory to `/home/runner/.cargo/registry/src/index.crates.io-6f16d22bba15001f`. by doing this i just built a `gimlet-b` that matches the one [here](https://github.com/oxidecomputer/hubris/releases/tag/gimlet-v1.0.26).
1 parent b2b108f commit a677a8d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

build/xtask/src/dist.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl PackageConfig {
167167
remap_paths.insert(cargo_git, "/git");
168168

169169
// This hash is canonical-ish: Cargo tries hard not to change it
170-
// https://github.com/rust-lang/cargo/blob/master/src/cargo/core/source/source_id.rs#L607-L630
170+
// https://github.com/rust-lang/cargo/blob/5dfdd59/src/cargo/core/source_id.rs#L755-L794
171171
//
172172
// It depends on system architecture, so this won't work on (for example)
173173
// a Raspberry Pi, but the only downside is that panic messages will
@@ -177,6 +177,15 @@ impl PackageConfig {
177177
.join("src")
178178
.join("github.com-1ecc6299db9ec823");
179179
remap_paths.insert(cargo_registry, "/crates.io");
180+
// If Cargo uses the sparse registry (stabilized since ~1.72) it caches fetched crates
181+
// in a slightly different path. Remap that one as well.
182+
//
183+
// This path has the same canonical-ish properties as above.
184+
let cargo_sparse_registry = cargo_home
185+
.join("registry")
186+
.join("src")
187+
.join("index.crates.io-6f17d22bba15001f");
188+
remap_paths.insert(cargo_sparse_registry, "/crates.io");
180189
}
181190

182191
if let Ok(dir) = std::env::var("CARGO_MANIFEST_DIR") {

0 commit comments

Comments
 (0)