2024-04-13 04:42:36 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-09-27 05:22:10 +00:00
|
|
|
# Small script to run tests for a target (or all targets) inside all the
|
|
|
|
# respective docker images.
|
|
|
|
|
2024-04-15 18:44:39 +00:00
|
|
|
set -euxo pipefail
|
2016-09-27 05:22:10 +00:00
|
|
|
|
|
|
|
run() {
|
2024-04-13 04:42:36 +00:00
|
|
|
local target="$1"
|
2016-09-30 22:21:54 +00:00
|
|
|
|
2024-04-13 04:42:36 +00:00
|
|
|
echo "TESTING TARGET: $target"
|
2016-09-30 23:37:41 +00:00
|
|
|
|
|
|
|
# This directory needs to exist before calling docker, otherwise docker will create it but it
|
|
|
|
# will be owned by root
|
|
|
|
mkdir -p target
|
|
|
|
|
2024-04-13 04:42:36 +00:00
|
|
|
if [ $(uname -s) = "Linux" ] && [ -z "${DOCKER_BASE_IMAGE:-}" ]; then
|
|
|
|
# Share the host rustc and target. Do this only on Linux and if the image
|
|
|
|
# isn't overridden
|
|
|
|
run_args=(
|
|
|
|
--user "$(id -u):$(id -g)"
|
|
|
|
-e "CARGO_HOME=/cargo"
|
|
|
|
-v "${HOME}/.cargo:/cargo"
|
|
|
|
-v "$(pwd)/target:/builtins-target"
|
|
|
|
-v "$(rustc --print sysroot):/rust:ro"
|
|
|
|
)
|
|
|
|
run_cmd="HOME=/tmp PATH=\$PATH:/rust/bin ci/run.sh $target"
|
|
|
|
else
|
|
|
|
# Use rustc provided by a docker image
|
|
|
|
docker volume create compiler-builtins-cache
|
|
|
|
build_args=(
|
|
|
|
"--build-arg" "IMAGE=${DOCKER_BASE_IMAGE:-rustlang/rust:nightly}"
|
|
|
|
)
|
|
|
|
run_args=(
|
|
|
|
-v "compiler-builtins-cache:/builtins-target"
|
|
|
|
)
|
|
|
|
run_cmd="HOME=/tmp USING_CONTAINER_RUSTC=1 ci/run.sh $target"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -d compiler-rt ]; then
|
|
|
|
export RUST_COMPILER_RT_ROOT=./compiler-rt
|
|
|
|
fi
|
|
|
|
|
2024-05-24 09:23:06 +00:00
|
|
|
if [ "$GITHUB_ACTIONS" = "true" ]; then
|
|
|
|
# Enable Docker image caching on GHA
|
|
|
|
|
|
|
|
buildx="buildx"
|
|
|
|
build_args=(
|
|
|
|
"--cache-from" "type=local,src=/tmp/.buildx-cache"
|
|
|
|
"--cache-to" "type=local,dest=/tmp/.buildx-cache-new"
|
|
|
|
"${build_args[@]:-}"
|
|
|
|
"--load"
|
|
|
|
)
|
|
|
|
fi
|
|
|
|
|
|
|
|
docker "${buildx:-}" build \
|
2024-04-13 04:42:36 +00:00
|
|
|
-t "builtins-$target" \
|
|
|
|
${build_args[@]:-} \
|
|
|
|
"ci/docker/$target"
|
2016-09-27 05:22:10 +00:00
|
|
|
docker run \
|
2016-09-30 22:21:54 +00:00
|
|
|
--rm \
|
2019-05-16 14:30:36 +00:00
|
|
|
-e RUST_COMPILER_RT_ROOT \
|
2024-05-06 07:49:35 +00:00
|
|
|
-e RUSTFLAGS \
|
2024-04-13 04:42:36 +00:00
|
|
|
-e "CARGO_TARGET_DIR=/builtins-target" \
|
|
|
|
-v "$(pwd):/checkout:ro" \
|
2016-09-30 22:21:54 +00:00
|
|
|
-w /checkout \
|
2024-04-13 04:42:36 +00:00
|
|
|
${run_args[@]:-} \
|
2019-05-02 19:47:51 +00:00
|
|
|
--init \
|
2024-04-13 04:42:36 +00:00
|
|
|
"builtins-$target" \
|
|
|
|
sh -c "$run_cmd"
|
2016-09-27 05:22:10 +00:00
|
|
|
}
|
|
|
|
|
2024-04-13 04:42:36 +00:00
|
|
|
if [ "${1:-}" = "--help" ] || [ "$#" -gt 1 ]; then
|
|
|
|
set +x
|
|
|
|
echo "\
|
|
|
|
usage: ./ci/run-docker.sh [target]
|
|
|
|
|
|
|
|
you can also set DOCKER_BASE_IMAGE to use something other than the default
|
|
|
|
ubuntu:18.04 (or rustlang/rust:nightly).
|
|
|
|
"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "${1:-}" ]; then
|
|
|
|
for d in ci/docker/*; do
|
|
|
|
run $(basename "$d")
|
2016-09-27 05:22:10 +00:00
|
|
|
done
|
|
|
|
else
|
2024-04-13 04:42:36 +00:00
|
|
|
run "$1"
|
2016-09-27 05:22:10 +00:00
|
|
|
fi
|