Trevor Gross 683485cda2 Switch repository layout to use a virtual manifest
The current setup has the `Cargo.toml` for `compiler-builtins` at the
repository root, which means all support crates and other files are
located within the package root. This works for now but is not the
cleanest setup since files that should or shouldn't be included in the
package need to be configured in `Cargo.toml`. If we eventually merge
`libm` development into this repository, it would be nice to make this
separation more straightforward.

Begin cleaning things up by moving the crate source to a new
`compiler-builtins` directory and adding a virtual manifest. For now the
`libm` submodule is also moved, but in the future it can likely move
back to the top level (ideally `compiler-builtins/src` would contain a
symlink to `libm/src/math`, but unfortunately it seems like Cargo does
not like something about the submodule + symlink combination).
2025-03-19 00:49:34 -05:00

93 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# Small script to run tests for a target (or all targets) inside all the
# respective docker images.
set -euxo pipefail
run() {
local target="$1"
echo "TESTING TARGET: $target"
# This directory needs to exist before calling docker, otherwise docker will create it but it
# will be owned by root
mkdir -p target
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="/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
docker "${build_cmd[@]:-build}" \
-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"
}
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:24.04 (or rustlang/rust:nightly).
"
exit
fi
if [ -z "${1:-}" ]; then
for d in ci/docker/*; do
run $(basename "$d")
done
else
run "$1"
fi