about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTrevor Gross <tmgross@umich.edu>2025-04-19 04:55:59 +0000
committerTrevor Gross <t.gross35@gmail.com>2025-04-19 01:04:33 -0400
commitb0d6024f203fbf80c090e829115b2dbf459a8464 (patch)
tree761b8af4b70d8f9d4acf51e040ee05f2de553f8b
parent01c58882462bb721b755c765507cdcd335b481d8 (diff)
downloadrust-b0d6024f203fbf80c090e829115b2dbf459a8464.tar.gz
rust-b0d6024f203fbf80c090e829115b2dbf459a8464.zip
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.
-rwxr-xr-xlibrary/compiler-builtins/ci/run-docker.sh124
1 files changed, 69 insertions, 55 deletions
diff --git a/library/compiler-builtins/ci/run-docker.sh b/library/compiler-builtins/ci/run-docker.sh
index 5e19cf4d0cb..2c27ab7955b 100755
--- a/library/compiler-builtins/ci/run-docker.sh
+++ b/library/compiler-builtins/ci/run-docker.sh
@@ -5,88 +5,102 @@
 
 set -euxo pipefail
 
+host_arch="$(uname -m | sed 's/arm64/aarch64/')"
+
 run() {
     local target="$1"
 
-    echo "TESTING TARGET: $target"
+    echo "testing target: $target"
+
+    emulated=""
+    target_arch="$(echo "$target" | cut -d'-' -f1)"
+    if [ "$target_arch" != "$host_arch" ]; then
+        emulated=1
+        echo "target is emulated"
+    fi
 
     # This directory needs to exist before calling docker, otherwise docker will create it but it
     # will be owned by root
     mkdir -p target
 
+    run_cmd="HOME=/tmp"
+
+    if [ "${GITHUB_ACTIONS:-}" = "true" ]; then
+        # Enable Docker image caching on GHA
+        build_cmd=("buildx" "build")
+        build_args=(
+            "--cache-from" "type=local,src=/tmp/.buildx-cache"
+            "--cache-to" "type=local,dest=/tmp/.buildx-cache-new"
+            # This is the beautiful bash syntax for expanding an array but neither
+            # raising an error nor returning an empty string if the array is empty.
+            "${build_args[@]:+"${build_args[@]}"}"
+            "--load"
+        )
+    fi
+
     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"
+        # 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="$run_cmd PATH=\$PATH:/rust/bin"
     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"
+        # 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="$run_cmd HOME=/tmp" "USING_CONTAINER_RUSTC=1"
     fi
 
     if [ -d compiler-rt ]; then
-      export RUST_COMPILER_RT_ROOT="/checkout/compiler-rt"
+        export RUST_COMPILER_RT_ROOT="/checkout/compiler-rt"
     fi
 
-    if [ "${GITHUB_ACTIONS:-}" = "true" ]; then
-      # Enable Docker image caching on GHA
-
-      build_cmd=("buildx" "build")
-      build_args=(
-        "--cache-from" "type=local,src=/tmp/.buildx-cache"
-        "--cache-to" "type=local,dest=/tmp/.buildx-cache-new"
-        # This is the beautiful bash syntax for expanding an array but neither
-        # raising an error nor returning an empty string if the array is empty.
-        "${build_args[@]:+"${build_args[@]}"}"
-        "--load"
-      )
-    fi
+    run_cmd="$run_cmd ci/run.sh $target"
 
     docker "${build_cmd[@]:-build}" \
-           -t "builtins-$target" \
-           "${build_args[@]:-}" \
-           "ci/docker/$target"
+        -t "builtins-$target" \
+        "${build_args[@]:-}" \
+        "ci/docker/$target"
     docker run \
-           --rm \
-           -e RUST_COMPILER_RT_ROOT \
-           -e RUSTFLAGS \
-           -e "CARGO_TARGET_DIR=/builtins-target" \
-           -v "$(pwd):/checkout:ro" \
-           -w /checkout \
-           "${run_args[@]:-}" \
-           --init \
-           "builtins-$target" \
-           sh -c "$run_cmd"
+        --rm \
+        -e CI \
+        -e CARGO_TARGET_DIR=/builtins-target \
+        -e CARGO_TERM_COLOR \
+        -e RUSTFLAGS \
+        -e RUST_BACKTRACE \
+        -e RUST_COMPILER_RT_ROOT \
+        -e "EMULATED=$emulated" \
+        -v "$(pwd):/checkout:ro" \
+        -w /checkout \
+        "${run_args[@]:-}" \
+        --init \
+        "builtins-$target" \
+        sh -c "$run_cmd"
 }
 
 if [ "${1:-}" = "--help" ] || [ "$#" -gt 1 ]; then
-  set +x
-  echo "\
+    set +x
+    echo "\
     usage: ./ci/run-docker.sh [target]
 
     you can also set DOCKER_BASE_IMAGE to use something other than the default
     ubuntu:24.04 (or rustlang/rust:nightly).
-  "
-  exit
+    "
+    exit
 fi
 
 if [ -z "${1:-}" ]; then
-  for d in ci/docker/*; do
-    run $(basename "$d")
-  done
+    for d in ci/docker/*; do
+        run $(basename "$d")
+    done
 else
-  run "$1"
+    run "$1"
 fi