Skip to content

Commit d2c3a16

Browse files
committed
Add a way to run tests on non-linux machines
Allow using the `rust-lang/rust:nightly` docker image to run tests in cases where the host rust and cargo cannot be used, such as non-linux hosts.
1 parent 2978bdd commit d2c3a16

File tree

24 files changed

+176
-68
lines changed

24 files changed

+176
-68
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
*.rs.bk
22
Cargo.lock
33
target
4+
compiler-rt
5+
*.tar.gz

README.md

+20
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ features = ["c"]
7878
[8]: http://en.cppreference.com/w/cpp/language/implicit_conversion
7979
[9]: https://doc.rust-lang.org/std/primitive.i32.html
8080

81+
## Testing
82+
83+
The easiest way to test locally is using Docker. This can be done by running
84+
`./ci/run-docker.sh [target]`. If no target is specified, all targets will be
85+
run.
86+
87+
In order to run the full test suite, you will also need the C compiler runtime
88+
to test against, located in a directory called `compiler-rt`. This can be
89+
obtained with the following:
90+
91+
```sh
92+
curl -L -o rustc-llvm-18.0.tar.gz https://github.com/rust-lang/llvm-project/archive/rustc/18.0-2024-02-13.tar.gz
93+
tar xzf rustc-llvm-18.0.tar.gz --strip-components 1 llvm-project-rustc-18.0-2024-02-13/compiler-rt
94+
````
95+
96+
Local targets may also be tested with `./ci/run.sh [target]`.
97+
98+
Note that testing may not work on all hosts, in which cases it is acceptable to
99+
rely on CI.
100+
81101
## Progress
82102

83103
- [x] adddf3.c

build.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,9 @@ mod c {
572572
// rust-lang/rust.
573573
let root = match env::var_os("RUST_COMPILER_RT_ROOT") {
574574
Some(s) => PathBuf::from(s),
575-
None => panic!("RUST_COMPILER_RT_ROOT is not set"),
575+
None => {
576+
panic!("RUST_COMPILER_RT_ROOT is not set. You may need to download compiler-rt.")
577+
}
576578
};
577579
if !root.exists() {
578580
panic!("RUST_COMPILER_RT_ROOT={} does not exist", root.display());

ci/docker/aarch64-unknown-linux-gnu/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23
RUN apt-get update && \
34
apt-get install -y --no-install-recommends \
45
gcc libc6-dev ca-certificates \

ci/docker/arm-unknown-linux-gnueabi/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23
RUN apt-get update && \
34
apt-get install -y --no-install-recommends \
45
gcc libc6-dev ca-certificates \

ci/docker/arm-unknown-linux-gnueabihf/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23
RUN apt-get update && \
34
apt-get install -y --no-install-recommends \
45
gcc libc6-dev ca-certificates \

ci/docker/armv7-unknown-linux-gnueabihf/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23
RUN apt-get update && \
34
apt-get install -y --no-install-recommends \
45
gcc libc6-dev ca-certificates \
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23
RUN apt-get update && \
34
apt-get install -y --no-install-recommends \
45
gcc-multilib libc6-dev ca-certificates
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23
RUN apt-get update && \
34
apt-get install -y --no-install-recommends \
45
gcc-multilib libc6-dev ca-certificates

ci/docker/mips-unknown-linux-gnu/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23

34
RUN apt-get update && \
45
apt-get install -y --no-install-recommends \

ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23
RUN apt-get update && \
34
apt-get install -y --no-install-recommends \
45
ca-certificates \

ci/docker/mips64el-unknown-linux-gnuabi64/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23
RUN apt-get update && \
34
apt-get install -y --no-install-recommends \
45
ca-certificates \

ci/docker/mipsel-unknown-linux-gnu/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23

34
RUN apt-get update && \
45
apt-get install -y --no-install-recommends \

ci/docker/powerpc-unknown-linux-gnu/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23

34
RUN apt-get update && \
45
apt-get install -y --no-install-recommends \

ci/docker/powerpc64-unknown-linux-gnu/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23

34
RUN apt-get update && \
45
apt-get install -y --no-install-recommends \

ci/docker/powerpc64le-unknown-linux-gnu/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23

34
RUN apt-get update && \
45
apt-get install -y --no-install-recommends \

ci/docker/thumbv6m-none-eabi/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23
RUN apt-get update && \
34
apt-get install -y --no-install-recommends \
45
gcc libc6-dev ca-certificates \

ci/docker/thumbv7em-none-eabi/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23
RUN apt-get update && \
34
apt-get install -y --no-install-recommends \
45
gcc libc6-dev ca-certificates \

ci/docker/thumbv7em-none-eabihf/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23
RUN apt-get update && \
34
apt-get install -y --no-install-recommends \
45
gcc libc6-dev ca-certificates \

ci/docker/thumbv7m-none-eabi/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23
RUN apt-get update && \
34
apt-get install -y --no-install-recommends \
45
gcc libc6-dev ca-certificates \

ci/docker/wasm32-unknown-unknown/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:20.04
1+
ARG IMAGE=ubuntu:20.04
2+
FROM $IMAGE
23
RUN apt-get update && \
34
apt-get install -y --no-install-recommends \
45
gcc clang libc6-dev ca-certificates
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM ubuntu:18.04
1+
ARG IMAGE=ubuntu:18.04
2+
FROM $IMAGE
23
RUN apt-get update && \
34
apt-get install -y --no-install-recommends \
45
gcc libc6-dev ca-certificates

ci/run-docker.sh

+56-17
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,77 @@
1+
#!/bin/bash
2+
13
# Small script to run tests for a target (or all targets) inside all the
24
# respective docker images.
35

4-
set -ex
6+
set -eux
57

68
run() {
7-
local target=$1
9+
local target="$1"
810

9-
echo $target
11+
echo "TESTING TARGET: $target"
1012

1113
# This directory needs to exist before calling docker, otherwise docker will create it but it
1214
# will be owned by root
1315
mkdir -p target
1416

15-
docker build -t $target ci/docker/$target
17+
if [ $(uname -s) = "Linux" ] && [ -z "${DOCKER_BASE_IMAGE:-}" ]; then
18+
# Share the host rustc and target. Do this only on Linux and if the image
19+
# isn't overridden
20+
run_args=(
21+
--user "$(id -u):$(id -g)"
22+
-e "CARGO_HOME=/cargo"
23+
-v "${HOME}/.cargo:/cargo"
24+
-v "$(pwd)/target:/builtins-target"
25+
-v "$(rustc --print sysroot):/rust:ro"
26+
)
27+
run_cmd="HOME=/tmp PATH=\$PATH:/rust/bin ci/run.sh $target"
28+
else
29+
# Use rustc provided by a docker image
30+
docker volume create compiler-builtins-cache
31+
build_args=(
32+
"--build-arg" "IMAGE=${DOCKER_BASE_IMAGE:-rustlang/rust:nightly}"
33+
)
34+
run_args=(
35+
-v "compiler-builtins-cache:/builtins-target"
36+
)
37+
run_cmd="HOME=/tmp USING_CONTAINER_RUSTC=1 ci/run.sh $target"
38+
fi
39+
40+
if [ -d compiler-rt ]; then
41+
export RUST_COMPILER_RT_ROOT=./compiler-rt
42+
fi
43+
44+
docker build \
45+
-t "builtins-$target" \
46+
${build_args[@]:-} \
47+
"ci/docker/$target"
1648
docker run \
1749
--rm \
18-
--user $(id -u):$(id -g) \
19-
-e CARGO_HOME=/cargo \
20-
-e CARGO_TARGET_DIR=/target \
2150
-e RUST_COMPILER_RT_ROOT \
22-
-v "${HOME}/.cargo":/cargo \
23-
-v `pwd`/target:/target \
24-
-v `pwd`:/checkout:ro \
25-
-v `rustc --print sysroot`:/rust:ro \
51+
-e "CARGO_TARGET_DIR=/builtins-target" \
52+
-v "$(pwd):/checkout:ro" \
2653
-w /checkout \
54+
${run_args[@]:-} \
2755
--init \
28-
$target \
29-
sh -c "HOME=/tmp PATH=\$PATH:/rust/bin ci/run.sh $target"
56+
"builtins-$target" \
57+
sh -c "$run_cmd"
3058
}
3159

32-
if [ -z "$1" ]; then
33-
for d in `ls ci/docker/`; do
34-
run $d
60+
if [ "${1:-}" = "--help" ] || [ "$#" -gt 1 ]; then
61+
set +x
62+
echo "\
63+
usage: ./ci/run-docker.sh [target]
64+
65+
you can also set DOCKER_BASE_IMAGE to use something other than the default
66+
ubuntu:18.04 (or rustlang/rust:nightly).
67+
"
68+
exit
69+
fi
70+
71+
if [ -z "${1:-}" ]; then
72+
for d in ci/docker/*; do
73+
run $(basename "$d")
3574
done
3675
else
37-
run $1
76+
run "$1"
3877
fi

0 commit comments

Comments
 (0)