Skip to content

Commit bdc6635

Browse files
committed
Disable mandatory cargo file checksums for vendored crates
Dependency downloads can be separated from the build phase of a rust package using cargo vendor. However, cargo obstructs patching of vendored crates by enforcing file checksums on their contents during compilation. Like many other distributions, we have worked around this with an ugly sed hack, rewriting the .cargo-checksum.json files to remove the file checksums when they are invalidated. Instead, fix the obnoxious upstream behaviour properly by ignoring file checksums for vendored crates unless verification is specifically requested by setting CARGO_VENDOR_VERIFY=1 in the environment.
1 parent 6a8a959 commit bdc6635

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

rust/build

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ check() {
77

88
prepare() {
99
unpack https://static.rust-lang.org/dist/rustc-1.81.0-src.tar.gz
10-
sed -i -E 'H;1h;$!d;x;s/("files"\s*:\s*\{)("([^"\\]|\\.)*"|[^"}])*/\1/' \
11-
vendor/*/.cargo-checksum.json
1210
apply curl.diff
1311
apply libexec.diff
1412
apply libressl.diff
1513
apply system.diff
1614
apply target.diff
15+
apply verify.diff
1716
apply version.diff
18-
tree cd8c873858b19e4981735e42cbd05f750f3467c662a8f45c75f9fc24584ccccc
17+
tree cab116209fd67c0e218f3a68b4da36a3d0867a32abe18b6755821bb6d38c03a8
1918
}
2019

2120
build() {

rust/verify.diff

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
diff --git a/src/tools/cargo/src/cargo/sources/directory.rs b/src/tools/cargo/src/cargo/sources/directory.rs
2+
index 6fff8ed2..a21555b3 100644
3+
--- a/src/tools/cargo/src/cargo/sources/directory.rs
4+
+++ b/src/tools/cargo/src/cargo/sources/directory.rs
5+
@@ -1,4 +1,5 @@
6+
use std::collections::HashMap;
7+
+use std::env;
8+
use std::fmt::{self, Debug, Formatter};
9+
use std::path::{Path, PathBuf};
10+
use std::task::Poll;
11+
@@ -230,6 +231,10 @@ impl<'gctx> Source for DirectorySource<'gctx> {
12+
anyhow::bail!("failed to find entry for `{}` in directory source", id);
13+
};
14+
15+
+ if env::var("CARGO_VENDOR_VERIFY").map_or(true, |v| v == "0") {
16+
+ return Ok(())
17+
+ }
18+
+
19+
for (file, cksum) in cksum.files.iter() {
20+
let file = pkg.root().join(file);
21+
let actual = Sha256::new()

0 commit comments

Comments
 (0)