Skip to content

Commit 8ee1aa9

Browse files
committed
ci: Update ci/run-docker.sh to match libm
Prepare for having the repositories combined by ensuring EMULATED, RUST_BACKTRACE, and CI are set or forwarded as applicable. Also re-indent the file to four spaces and do some reorganization.
1 parent 4f2dde8 commit 8ee1aa9

File tree

1 file changed

+69
-55
lines changed

1 file changed

+69
-55
lines changed

ci/run-docker.sh

+69-55
Original file line numberDiff line numberDiff line change
@@ -5,88 +5,102 @@
55

66
set -euxo pipefail
77

8+
host_arch="$(uname -m | sed 's/arm64/aarch64/')"
9+
810
run() {
911
local target="$1"
1012

11-
echo "TESTING TARGET: $target"
13+
echo "testing target: $target"
14+
15+
emulated=""
16+
target_arch="$(echo "$target" | cut -d'-' -f1)"
17+
if [ "$target_arch" != "$host_arch" ]; then
18+
emulated=1
19+
echo "target is emulated"
20+
fi
1221

1322
# This directory needs to exist before calling docker, otherwise docker will create it but it
1423
# will be owned by root
1524
mkdir -p target
1625

26+
run_cmd="HOME=/tmp"
27+
28+
if [ "${GITHUB_ACTIONS:-}" = "true" ]; then
29+
# Enable Docker image caching on GHA
30+
build_cmd=("buildx" "build")
31+
build_args=(
32+
"--cache-from" "type=local,src=/tmp/.buildx-cache"
33+
"--cache-to" "type=local,dest=/tmp/.buildx-cache-new"
34+
# This is the beautiful bash syntax for expanding an array but neither
35+
# raising an error nor returning an empty string if the array is empty.
36+
"${build_args[@]:+"${build_args[@]}"}"
37+
"--load"
38+
)
39+
fi
40+
1741
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"
42+
# Share the host rustc and target. Do this only on Linux and if the image
43+
# isn't overridden
44+
run_args=(
45+
--user "$(id -u):$(id -g)"
46+
-e "CARGO_HOME=/cargo"
47+
-v "${HOME}/.cargo:/cargo"
48+
-v "$(pwd)/target:/builtins-target"
49+
-v "$(rustc --print sysroot):/rust:ro"
50+
)
51+
run_cmd="$run_cmd PATH=\$PATH:/rust/bin"
2852
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"
53+
# Use rustc provided by a docker image
54+
docker volume create compiler-builtins-cache
55+
build_args=(
56+
"--build-arg" "IMAGE=${DOCKER_BASE_IMAGE:-rustlang/rust:nightly}"
57+
)
58+
run_args=(-v "compiler-builtins-cache:/builtins-target")
59+
run_cmd="$run_cmd HOME=/tmp" "USING_CONTAINER_RUSTC=1"
3860
fi
3961

4062
if [ -d compiler-rt ]; then
41-
export RUST_COMPILER_RT_ROOT="/checkout/compiler-rt"
63+
export RUST_COMPILER_RT_ROOT="/checkout/compiler-rt"
4264
fi
4365

44-
if [ "${GITHUB_ACTIONS:-}" = "true" ]; then
45-
# Enable Docker image caching on GHA
46-
47-
build_cmd=("buildx" "build")
48-
build_args=(
49-
"--cache-from" "type=local,src=/tmp/.buildx-cache"
50-
"--cache-to" "type=local,dest=/tmp/.buildx-cache-new"
51-
# This is the beautiful bash syntax for expanding an array but neither
52-
# raising an error nor returning an empty string if the array is empty.
53-
"${build_args[@]:+"${build_args[@]}"}"
54-
"--load"
55-
)
56-
fi
66+
run_cmd="$run_cmd ci/run.sh $target"
5767

5868
docker "${build_cmd[@]:-build}" \
59-
-t "builtins-$target" \
60-
"${build_args[@]:-}" \
61-
"ci/docker/$target"
69+
-t "builtins-$target" \
70+
"${build_args[@]:-}" \
71+
"ci/docker/$target"
6272
docker run \
63-
--rm \
64-
-e RUST_COMPILER_RT_ROOT \
65-
-e RUSTFLAGS \
66-
-e "CARGO_TARGET_DIR=/builtins-target" \
67-
-v "$(pwd):/checkout:ro" \
68-
-w /checkout \
69-
"${run_args[@]:-}" \
70-
--init \
71-
"builtins-$target" \
72-
sh -c "$run_cmd"
73+
--rm \
74+
-e CI \
75+
-e CARGO_TARGET_DIR=/builtins-target \
76+
-e CARGO_TERM_COLOR \
77+
-e RUSTFLAGS \
78+
-e RUST_BACKTRACE \
79+
-e RUST_COMPILER_RT_ROOT \
80+
-e "EMULATED=$emulated" \
81+
-v "$(pwd):/checkout:ro" \
82+
-w /checkout \
83+
"${run_args[@]:-}" \
84+
--init \
85+
"builtins-$target" \
86+
sh -c "$run_cmd"
7387
}
7488

7589
if [ "${1:-}" = "--help" ] || [ "$#" -gt 1 ]; then
76-
set +x
77-
echo "\
90+
set +x
91+
echo "\
7892
usage: ./ci/run-docker.sh [target]
7993
8094
you can also set DOCKER_BASE_IMAGE to use something other than the default
8195
ubuntu:24.04 (or rustlang/rust:nightly).
82-
"
83-
exit
96+
"
97+
exit
8498
fi
8599

86100
if [ -z "${1:-}" ]; then
87-
for d in ci/docker/*; do
88-
run $(basename "$d")
89-
done
101+
for d in ci/docker/*; do
102+
run $(basename "$d")
103+
done
90104
else
91-
run "$1"
105+
run "$1"
92106
fi

0 commit comments

Comments
 (0)