Skip to content

Commit 30fd719

Browse files
committed
Script for vendoring dependencies of rust std libs
This commit creates a script `vendor.sh` that can be used to vendor our dependencies from crates.io. In addition to vendoring the direct dependencies of our rust crates, it also vendors the dependencies of the rust standard libraries. This script requires a minor update to the Dockerfile because we need to install the sources of the rust standard libraries and copy a file when we are the "root" user.
1 parent 73ec580 commit 30fd719

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

.ci/run-container-ci

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
set -e
2626
set -x
2727

28-
CONTAINER=shiftcrypto/firmware_v2:40
28+
CONTAINER=shiftcrypto/firmware_v2:41
2929

3030
if [ "$1" == "pull" ] ; then
3131
docker pull "$CONTAINER"

Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,18 @@ RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | CARGO_HOME=/opt/
129129
RUN rustup target add thumbv7em-none-eabi
130130
RUN rustup component add rustfmt
131131
RUN rustup component add clippy
132+
RUN rustup component add rust-src
132133
RUN CARGO_HOME=/opt/cargo cargo install cbindgen --version 0.26.0 --locked
133134
RUN CARGO_HOME=/opt/cargo cargo install bindgen-cli --version 0.69.4 --locked
134135

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

src/rust/README.md

+5
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

+23
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)