Skip to content

Commit 56a404f

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 7240849 commit 56a404f

File tree

23 files changed

+130
-39
lines changed

23 files changed

+130
-39
lines changed

.gitignore

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

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ 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]`.
85+
86+
In order to run the full test suite, you will also need the C compiler runtime
87+
to test against, located in a directory called `compiler-rt`. This can be
88+
obtained with the following:
89+
90+
```sh
91+
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
92+
tar xzf rustc-llvm-18.0.tar.gz --strip-components 1 llvm-project-rustc-18.0-2024-02-13/compiler-rt
93+
````
94+
95+
Local targets may also be tested with `./ci/run.sh [target]`.
96+
97+
Note that testing may not work on all hosts, in which cases it is acceptable to
98+
rely on CI.
99+
81100
## Progress
82101

83102
- [x] adddf3.c

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

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

46
set -ex
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_NAME" ]; 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

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+
3271
if [ -z "$1" ]; then
33-
for d in `ls ci/docker/`; do
34-
run $d
72+
for d in ci/docker/*; do
73+
run $(basename "$d")
3574
done
3675
else
3776
run $1

ci/run.sh

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
set -ex
22

3+
if [ "$USING_CONTAINER_RUSTC" = 1 ]; then
4+
# Install nonstandard components if we have control of the environment
5+
rustup target list --installed |
6+
grep -E "^$1\$" ||
7+
rustup target add "$1"
8+
fi
9+
310
# Test our implementation
411
if [ "$NO_STD" = "1" ]; then
5-
echo nothing to do
12+
echo "nothing to do for no_std"
613
else
714
run="cargo test --manifest-path testcrate/Cargo.toml --target $1"
815
$run
@@ -13,8 +20,8 @@ else
1320
$run --features no-asm --release
1421
fi
1522

16-
if [ -d /target ]; then
17-
path=/target/${1}/debug/deps/libcompiler_builtins-*.rlib
23+
if [ -d /builtins-target ]; then
24+
path=/builtins-target/${1}/debug/deps/libcompiler_builtins-*.rlib
1825
else
1926
path=target/${1}/debug/deps/libcompiler_builtins-*.rlib
2027
fi
@@ -100,11 +107,15 @@ for rlib in $(echo $path); do
100107
echo checking $rlib for references to core
101108
echo "================================================================"
102109

103-
$NM --quiet -U $rlib | grep 'T _ZN4core' | awk '{print $3}' | sort | uniq > defined_symbols.txt
104-
$NM --quiet -u $rlib | grep 'U _ZN4core' | awk '{print $2}' | sort | uniq > undefined_symbols.txt
105-
grep -v -F -x -f defined_symbols.txt undefined_symbols.txt
110+
$NM --quiet -U $rlib | grep 'T _ZN4core' | awk '{print $3}' |
111+
sort | uniq > "$CARGO_TARGET_DIR/defined_symbols.txt"
112+
$NM --quiet -u $rlib | grep 'U _ZN4core' | awk '{print $2}' |
113+
sort | uniq > "$CARGO_TARGET_DIR/undefined_symbols.txt"
114+
grep -v -F -x -f "$CARGO_TARGET_DIR/defined_symbols.txt" \
115+
"$CARGO_TARGET_DIR/undefined_symbols.txt"
106116

107117
if test $? = 0; then
118+
echo "error: found unexpected references to core"
108119
exit 1
109120
fi
110121
set -ex

0 commit comments

Comments
 (0)