Skip to content

Commit 6987825

Browse files
committed
Script for vendoring dependencies of rust std libs
1 parent 0337053 commit 6987825

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ RUN rustup component add clippy
132132
RUN CARGO_HOME=/opt/cargo cargo install cbindgen --version 0.26.0 --locked
133133
RUN CARGO_HOME=/opt/cargo cargo install bindgen-cli --version 0.69.4 --locked
134134

135+
# Until cargo vendor supports vendoring dependencies of the rust std libs we
136+
# need a copy of this file next to the toml file. It also has to be world
137+
# writable so that invocations of `cargo vendor` can update it. Below is the
138+
# tracking issue for `cargo vendor` to support rust std libs.
139+
# https://github.com/rust-lang/wg-cargo-std-aware/issues/23
140+
RUN cp "$(rustc --print=sysroot)/lib/rustlib/src/rust/Cargo.lock" "$(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/"
141+
RUN chmod 777 $(rustc --print=sysroot)/lib/rustlib/src/rust/library/test/Cargo.lock
142+
135143
COPY tools/prost-build-proto prost-build-proto
136144
RUN CARGO_HOME=/opt/cargo cargo install --path prost-build-proto --locked
137145

src/rust/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ The bottom-most layer are bindings generated from C header files:
3535

3636
We generate one header file `rust.h` and ever product specific function is `#ifdeffed` with
3737
`RUST_PRODUCT_*` macro.
38+
39+
# Vendoring
40+
41+
Run the vendoring script `vendor.sh` to vendor dependencies from crates.io. The
42+
script will ensure that also rust std libs dependencies are vendored.

src/rust/vendor.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Script for vendoring our dependencies, including the deps of core/alloc.
4+
#
5+
# This script must be called from the <git-project-root>/src/rust directory. It will place the
6+
# dependencies in a directory called "vendor" in the current working directory.
7+
#
8+
# For some reason Cargo needs to find the dependencies of all rust std libs. Since "test" depends
9+
# on all the other ones, we take the toml-file from it. This means that we vendor libs that we
10+
# don't use in the end (like hashbrown and getopts).
11+
#
12+
# The invocation below depends on the fact that rust std libs "Cargo.lock" has been manually copied
13+
# to be next to the Cargo.toml file in the test directory.
14+
#
15+
# Copying the Cargo.lock file in the rust sysroot image requires root permissions. Therefore it is
16+
# done in the Dockerfile in our setup.
17+
18+
RUST_SYSROOT="$(rustc --print=sysroot)"
19+
20+
RUSTC_BOOTSTRAP=1 cargo vendor \
21+
--manifest-path Cargo.toml \
22+
--sync "$RUST_SYSROOT/lib/rustlib/src/rust/library/test/Cargo.toml" \
23+
vendor

0 commit comments

Comments
 (0)