|
5 | 5 |
|
6 | 6 | set -euxo pipefail
|
7 | 7 |
|
| 8 | +host_arch="$(uname -m | sed 's/arm64/aarch64/')" |
| 9 | + |
8 | 10 | run() {
|
9 | 11 | local target="$1"
|
10 | 12 |
|
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 |
12 | 21 |
|
13 | 22 | # This directory needs to exist before calling docker, otherwise docker will create it but it
|
14 | 23 | # will be owned by root
|
15 | 24 | mkdir -p target
|
16 | 25 |
|
| 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 | + |
17 | 41 | 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" |
28 | 52 | 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" |
38 | 60 | fi
|
39 | 61 |
|
40 | 62 | if [ -d compiler-rt ]; then
|
41 |
| - export RUST_COMPILER_RT_ROOT="/checkout/compiler-rt" |
| 63 | + export RUST_COMPILER_RT_ROOT="/checkout/compiler-rt" |
42 | 64 | fi
|
43 | 65 |
|
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" |
57 | 67 |
|
58 | 68 | 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" |
62 | 72 | 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" |
73 | 87 | }
|
74 | 88 |
|
75 | 89 | if [ "${1:-}" = "--help" ] || [ "$#" -gt 1 ]; then
|
76 |
| - set +x |
77 |
| - echo "\ |
| 90 | + set +x |
| 91 | + echo "\ |
78 | 92 | usage: ./ci/run-docker.sh [target]
|
79 | 93 |
|
80 | 94 | you can also set DOCKER_BASE_IMAGE to use something other than the default
|
81 | 95 | ubuntu:24.04 (or rustlang/rust:nightly).
|
82 |
| - " |
83 |
| - exit |
| 96 | + " |
| 97 | + exit |
84 | 98 | fi
|
85 | 99 |
|
86 | 100 | 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 |
90 | 104 | else
|
91 |
| - run "$1" |
| 105 | + run "$1" |
92 | 106 | fi
|
0 commit comments