Skip to content

Commit 8f361d9

Browse files
authored
Vendor dependencies (#2883)
This allows us to simplify the logic which ensures that we never depend on crate versions which are incompatible with our MSRV. It also avoids a performance bottleneck on our MSRV in which updating the crates.io index is very slow. Closes #1595 gherrit-pr-id: Gd8dc83951469fd1467ddb65d2ac524b709fe9503
1 parent 43736bd commit 8f361d9

3,045 files changed

Lines changed: 1239648 additions & 41 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.cargo/config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[source.crates-io]
2+
replace-with = "vendored-sources"
3+
4+
[source.vendored-sources]
5+
directory = "vendor"
6+

.github/workflows/ci.yml

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,6 @@ jobs:
261261
- name: Populate cache
262262
uses: ./.github/actions/cache
263263

264-
# Ensure that Cargo resolves the minimum possible syn version so that if we
265-
# accidentally make a change which depends upon features added in more
266-
# recent versions of syn, we'll catch it in CI.
267-
#
268-
# TODO(#1595): Debug why this step is still necessary after #1564 and maybe
269-
# remove it.
270-
- name: Pin syn dependency
271-
run: |
272-
set -eo pipefail
273-
# Override the exising `syn` dependency with one which requires an exact
274-
# version.
275-
cargo add -p zerocopy-derive 'syn@=2.0.46'
276-
277264
- name: Configure environment variables
278265
env:
279266
TOOLCHAIN: ${{ matrix.toolchain }}
@@ -460,6 +447,15 @@ jobs:
460447
run: |
461448
set -eo pipefail
462449
450+
# FIXME(#2906): We do this because `cargo vendor` doesn't currently
451+
# support vendoring std's dependencies (required in order to build std
452+
# from source, which Miri does). As a workaround, we simply temporarily
453+
# remove the cargo config and bypass vendoring altogether. Eventually,
454+
# we should get vendoring working for std's dependencies too.
455+
#
456+
# See also: https://github.com/rust-lang/wg-cargo-std-aware/issues/23
457+
mv .cargo/config.toml .cargo/config.toml.bak
458+
463459
# Work around https://github.com/rust-lang/miri/issues/3125
464460
[ "$TARGET" == "aarch64-unknown-linux-gnu" ] && cargo clean
465461
@@ -479,6 +475,8 @@ jobs:
479475
--target $TARGET \
480476
$FEATURES
481477
done
478+
479+
mv .cargo/config.toml.bak .cargo/config.toml
482480
# Only nightly has a working Miri, so we skip installing on all other
483481
# toolchains.
484482
#
@@ -567,6 +565,18 @@ jobs:
567565
echo "ZC_SKIP_CARGO_SEMVER_CHECKS=1" >> $GITHUB_ENV
568566
fi
569567
568+
# FIXME(#2906): We do this because `cargo semver-checks` fetches the latest
569+
# zerocopy from crates.io, but `.cargo/config.toml` causes that to resolve
570+
# in our vendor directory, and we don't vendor zerocopy. Removing this file
571+
# has the effect of causing the subsequent build to use crates.io rather
572+
# than vendored dependencies, which is fine since we only run this on the
573+
# stable toolchain. Eventually, we should update this job to use the
574+
# `--baseline-rev` option to use a previous git commit as the baseline for
575+
# checking compatibility (rather than the most recent published version),
576+
# which will make this unnecessary.
577+
- name: Remove Cargo config
578+
run: rm .cargo/config.toml
579+
570580
# Check semver compatibility with the most recently-published version on
571581
# crates.io. We do this in the matrix rather than in its own job so that it
572582
# gets run on different targets. Some of our API is target-specific (e.g.,
@@ -685,7 +695,19 @@ jobs:
685695
toolchain: ${{ env.ZC_TOOLCHAIN }}
686696
components: clippy, rust-src
687697
- name: Check big endian for aarch64_be-unknown-linux-gnu target
688-
run: ./cargo.sh +nightly build --target=aarch64_be-unknown-linux-gnu -Zbuild-std --features simd
698+
run: |
699+
set -eo pipefail
700+
701+
# FIXME(#2906): We do this because `cargo vendor` doesn't currently
702+
# support vendoring std's dependencies (required in order to build
703+
# std from source, as we do here). As a workaround, we simply nuke
704+
# the cargo config and bypass vendoring altogether. Eventually, we
705+
# should get vendoring working for std's dependencies too.
706+
#
707+
# See also: https://github.com/rust-lang/wg-cargo-std-aware/issues/23
708+
rm .cargo/config.toml
709+
710+
./cargo.sh +nightly build --target=aarch64_be-unknown-linux-gnu -Zbuild-std --features simd
689711
690712
# We can't use this as part of the build matrix because rustup doesn't support
691713
# the `avr-none` target.
@@ -716,6 +738,15 @@ jobs:
716738
with:
717739
toolchain: ${{ env.ZC_TOOLCHAIN }}
718740
components: clippy, rust-src
741+
# FIXME(#2906): We do this because `cargo vendor` doesn't currently
742+
# support vendoring std's dependencies (required in order to build std
743+
# from source, as we do here). As a workaround, we simply nuke the cargo
744+
# config and bypass vendoring altogether. Eventually, we should get
745+
# vendoring working for std's dependencies too.
746+
#
747+
# See also: https://github.com/rust-lang/wg-cargo-std-aware/issues/23
748+
- name: Remove Cargo config
749+
run: rm .cargo/config.toml
719750
# NOTE: We cannot check tests because of a number of different issues (at
720751
# the time of writing):
721752
# - No `alloc::sync`
@@ -851,14 +882,6 @@ jobs:
851882
#
852883
# [1] https://stackoverflow.com/a/42139535/836390
853884
854-
# See comment on "Pin syn dependency" job for why we do this. It needs
855-
# to happen before the subsequent `cargo check`, so we don't
856-
# background it.
857-
#
858-
# TODO(#1595): Debug why this step is still necessary after #1564 and
859-
# maybe remove it.
860-
cargo add -p zerocopy-derive 'syn@=2.0.46' &> /dev/null
861-
862885
cargo check --workspace --tests &> /dev/null &
863886
# On our MSRV toolchain, updating the Cargo index takes a long time, so
864887
# it is worth specifically caching the MSRV index.
@@ -947,6 +970,8 @@ jobs:
947970
persist-credentials: false
948971
- uses: zizmorcore/zizmor-action@e639db99335bc9038abc0e066dfcd72e23d26fb4 # v0.3.0
949972
with:
973+
# Only scan the .github directory to avoid scanning vendored dependencies
974+
inputs: .github
950975
# We don't want to use GitHub Advanced Security because we want to
951976
# block the merge on zizmor failure, and the only way to do that
952977
# (without manually configuring a ruleset) is to fail the job, which

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ lcov.info
1313

1414
# VSCode workspace files
1515
*.code-workspace
16+
17+
# Unconditionally commit everything inside vendor directories (overrides
18+
# previous rules)
19+
!vendor/**
20+
!tools/vendor/**

.rgignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor/
2+
tools/vendor/
3+

Cargo.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,11 @@ zerocopy-derive = { version = "=0.8.33", path = "zerocopy-derive", optional = tr
121121
zerocopy-derive = { version = "=0.8.33", path = "zerocopy-derive" }
122122

123123
[dev-dependencies]
124-
# More recent versions of `either` have an MSRV higher than ours.
125-
either = "=1.13.0"
126124
# FIXME(#381) Remove this dependency once we have our own layout gadgets.
127125
elain = "0.3.0"
128-
# More recent versions of `glob` have an MSRV higher than ours.
129-
glob = "=0.3.2"
130126
itertools = "0.11"
131-
# More recent versions of `itoa` have an MSRV higher than ours.
132-
itoa = "=1.0.15"
133127
rand = { version = "0.8.5", default-features = false, features = ["small_rng"] }
134128
rustversion = "1.0"
135-
# More recent versions of `ryu` have an MSRV higher than ours.
136-
ryu = "=1.0.20"
137129
static_assertions = "1.1"
138130
testutil = { path = "testutil" }
139131
# Pinned to a specific version so that the version used for local development

Cargo.toml.std

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[package]
2+
name = "std-deps"
3+
version = "0.0.0"
4+
edition = "2021"
5+
publish = false
6+
7+
# This manifest exists solely to force `cargo vendor` to vendor dependencies
8+
# required by `std` when building with `-Zbuild-std[=core]`. When running
9+
# `cargo vendor`, make sure to include this manifest using `--sync`.
10+
#
11+
# See: https://github.com/rust-lang/wg-cargo-std-aware/issues/23
12+
13+
[workspace]
14+
15+
[dependencies]
16+
# Dependencies from std/Cargo.toml and transitive deps from library/Cargo.lock
17+
addr2line = { version = "=0.25.1", default-features = false }
18+
adler2 = { version = "=2.0.1", default-features = false }
19+
cc = { version = "=1.2.0", default-features = false }
20+
cfg-if = { version = "=1.0.4", default-features = false }
21+
dlmalloc = { version = "=0.2.11", default-features = false }
22+
foldhash = { version = "=0.2.0", default-features = false }
23+
fortanix-sgx-abi = { version = "=0.6.1", default-features = false }
24+
getopts = { version = "=0.2.24", default-features = false }
25+
gimli = { version = "=0.32.3", default-features = false }
26+
hashbrown = { version = "=0.16.1", default-features = false }
27+
hermit-abi = { version = "=0.5.2", default-features = false }
28+
libc = { version = "=0.2.178", default-features = false }
29+
memchr = { version = "=2.7.6", default-features = false }
30+
miniz_oxide = { version = "=0.8.9", default-features = false }
31+
moto-rt = { version = "=0.16.0", default-features = false }
32+
object = { version = "=0.37.3", default-features = false }
33+
r-efi = { version = "=5.3.0", default-features = false }
34+
r-efi-alloc = { version = "=2.1.0", default-features = false }
35+
rand = { version = "=0.9.2", default-features = false }
36+
rand_core = { version = "=0.9.3", default-features = false }
37+
rand_xorshift = { version = "=0.4.0", default-features = false }
38+
rustc-demangle = "=0.1.26"
39+
rustc-literal-escaper = { version = "=0.0.7", default-features = false }
40+
shlex = { version = "=1.3.0", default-features = false }
41+
unwinding = { version = "=0.2.8", default-features = false }
42+
vex-sdk = { version = "=0.27.1", default-features = false }
43+
wasi-snapshot-preview1 = { package = "wasi", version = "=0.11.1+wasi-snapshot-preview1", default-features = false }
44+
wasi-p2 = { package = "wasi", version = "=0.14.4+wasi-0.2.4", default-features = false }
45+
windows-link = { version = "=0.2.1", default-features = false }
46+
windows-sys = { version = "=0.60.2", default-features = false }
47+
windows-targets = { version = "=0.53.5", default-features = false }
48+
wit-bindgen = { version = "=0.45.1", default-features = false }
49+
50+
# Windows targets dependencies (transitive via windows-targets)
51+
windows_aarch64_gnullvm = { version = "=0.53.1", default-features = false }
52+
windows_aarch64_msvc = { version = "=0.53.1", default-features = false }
53+
windows_i686_gnu = { version = "=0.53.1", default-features = false }
54+
windows_i686_gnullvm = { version = "=0.53.1", default-features = false }
55+
windows_i686_msvc = { version = "=0.53.1", default-features = false }
56+
windows_x86_64_gnu = { version = "=0.53.1", default-features = false }
57+
windows_x86_64_gnullvm = { version = "=0.53.1", default-features = false }
58+
windows_x86_64_msvc = { version = "=0.53.1", default-features = false }

cargo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ set -eo pipefail
1010

1111
# Build `cargo-zerocopy` without any RUSTFLAGS or CARGO_TARGET_DIR set in the
1212
# environment
13-
env -u RUSTFLAGS -u CARGO_TARGET_DIR cargo +stable build --manifest-path tools/Cargo.toml -p cargo-zerocopy -q
13+
env -u RUSTFLAGS -u CARGO_TARGET_DIR cargo +stable build --config tools/.cargo/config.toml --manifest-path tools/Cargo.toml -p cargo-zerocopy -q
1414
# Thin wrapper around the `cargo-zerocopy` binary in `tools/cargo-zerocopy`
1515
./tools/target/debug/cargo-zerocopy $@

ci/check_fmt.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# those terms.
1010

1111
set -eo pipefail
12-
files=$(find . -iname '*.rs' -type f -not -path './target/*' -not -iname '*.expected.rs')
12+
files=$(find . -iname '*.rs' -type f -not -path './target/*' -not -iname '*.expected.rs' -not -path './vendor/*' -not -path './tools/vendor/*')
1313
# check that find succeeded
1414
if [[ -z $files ]]
1515
then

ci/check_readme.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ set -eo pipefail
1515
# suppress all errors from it.
1616
cargo install -q cargo-readme --version 3.2.0
1717

18-
diff <(cargo -q run --manifest-path tools/Cargo.toml -p generate-readme) README.md >&2
18+
diff <(cargo -q run --config tools/.cargo/config.toml --manifest-path tools/Cargo.toml -p generate-readme) README.md >&2
1919
exit $?

tools/.cargo/config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[source.crates-io]
2+
replace-with = "vendored-sources"
3+
4+
[source.vendored-sources]
5+
directory = "vendor"
6+

0 commit comments

Comments
 (0)