Skip to content

Commit

Permalink
Auto merge of rust-lang#133912 - MarcoIeni:test-codebuild-runner, r=<…
Browse files Browse the repository at this point in the history
…try>

[experiment] test code build runner

try-job: x86_64-fuchsia
try-job: x86_64-gnu
try-job: dist-arm-linux
try-job: dist-powerpc64le-linux
try-job: dist-x86_64-linux
try-job: dist-x86_64-linux-alt
  • Loading branch information
bors committed Jan 29, 2025
2 parents ccc9ba5 + 5933eef commit 9b9d0fb
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 24 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ jobs:
run: src/ci/scripts/free-disk-space.sh
if: matrix.free_disk

- name: free up more disk space
if: matrix.free_disk
run: |
sudo apt purge -y --autoremove \
'^java-*' \
'groff' \
'groff-base' \
'^libllvm.*' \
'^llvm.*' \
'gcc' \
'gcc-11' \
'libicu-dev' \
'^vim.*' \
'python3-breezy' \
&& sudo rm -rf /var/lib/apt/lists/*
df -h /
- name: Show installed packages ordered by size
run: dpkg-query -W --showformat='${Installed-Size} ${Package}\n' | sort -nr

# Rust Log Analyzer can't currently detect the PR number of a GitHub
# Actions build on its own, so a hint in the log message is needed to
# point it in the right direction.
Expand Down Expand Up @@ -174,6 +194,8 @@ jobs:

- name: enable ipv6 on Docker
run: src/ci/scripts/enable-docker-ipv6.sh
# Don't run on codebuild because systemctl is not available
if: ${{ !contains(matrix.os, 'codebuild-ubuntu') }}

# Disable automatic line ending conversion (again). On Windows, when we're
# installing dependencies, something switches the git configuration directory or
Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,10 +1002,14 @@ def build_bootstrap(self):
env = os.environ.copy()
if "GITHUB_ACTIONS" in env:
print("::group::Building bootstrap")
print("Current home directory:", os.path.expanduser("~"))
print("Current working directory:", os.getcwd())
print("Current HOME:", env["HOME"])
else:
eprint("Building bootstrap")

args = self.build_bootstrap_cmd(env)
print("Running", args, "in", self.rust_root)
# Run this from the source directory so cargo finds .cargo/config
run(args, env=env, verbose=self.verbose, cwd=self.rust_root)

Expand All @@ -1015,6 +1019,7 @@ def build_bootstrap(self):
def build_bootstrap_cmd(self, env):
"""For tests."""
build_dir = os.path.join(self.build_dir, "bootstrap")
print("Building bootstrap in", build_dir)
if self.clean and os.path.exists(build_dir):
shutil.rmtree(build_dir)
# `CARGO_BUILD_TARGET` breaks bootstrap build.
Expand Down
2 changes: 1 addition & 1 deletion src/ci/docker/host-x86_64/dist-arm-linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:22.04
FROM ghcr.io/marcoieni/ubuntu:22.04

COPY scripts/cross-apt-packages.sh /scripts/
RUN sh /scripts/cross-apt-packages.sh
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:22.04
FROM ghcr.io/marcoieni/ubuntu:22.04

COPY scripts/cross-apt-packages.sh /scripts/
RUN sh /scripts/cross-apt-packages.sh
Expand Down
2 changes: 1 addition & 1 deletion src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# CentOS 7 has headers for kernel 3.10, but that's fine as long as we don't
# actually use newer APIs in rustc or std without a fallback. It's more
# important that we match glibc for ELF symbol versioning.
FROM centos:7
FROM ghcr.io/marcoieni/centos:7

WORKDIR /build

Expand Down
4 changes: 3 additions & 1 deletion src/ci/docker/host-x86_64/x86_64-fuchsia/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Fuchsia as an integration test of the toolchain. See the build-fuchsia.sh
# script in this directory for more details.

FROM ubuntu:22.04
FROM ghcr.io/marcoieni/ubuntu:22.04

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
Expand Down Expand Up @@ -75,5 +75,7 @@ ENV RUST_CONFIGURE_ARGS \
--set target.x86_64-unknown-fuchsia.linker=/usr/local/bin/ld.lld

ENV SCRIPT \
echo "x install" && df -h / && \
python3 ../x.py install --target $TARGETS compiler/rustc library/std clippy && \
echo "build fuchsia" && df -h / && \
bash ../src/ci/docker/host-x86_64/x86_64-fuchsia/build-fuchsia.sh
22 changes: 21 additions & 1 deletion src/ci/docker/host-x86_64/x86_64-fuchsia/build-fuchsia.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jiri=.jiri_root/bin/jiri
set -x

if [ -z "$KEEP_CHECKOUT" ]; then
echo "downloading jiri" && df -h /
# This script will:
# - create a directory named "fuchsia" if it does not exist
# - download "jiri" to "fuchsia/.jiri_root/bin"
Expand All @@ -52,11 +53,13 @@ if [ -z "$KEEP_CHECKOUT" ]; then

cd $checkout

echo "running jiri init" && df -h /
$jiri init \
-partial=true \
-analytics-opt=false \
.

echo "running jiri import" && df -h /
$jiri import \
-name=integration \
-revision=$INTEGRATION_SHA \
Expand All @@ -65,24 +68,41 @@ if [ -z "$KEEP_CHECKOUT" ]; then
"https://fuchsia.googlesource.com/integration"

if [ -d ".git" ]; then
echo "Wipe out any local changes" && df -h /
# Wipe out any local changes if we're reusing a checkout.
git checkout --force JIRI_HEAD
fi

echo "running jiri update" && df -h /
$jiri update -autoupdate=false

echo integration commit = $(git -C integration rev-parse HEAD)

for git_ref in "${PICK_REFS[@]}"; do
echo "running git fetch" && df -h /
git fetch https://fuchsia.googlesource.com/fuchsia $git_ref
echo "running git cherry-pick" && df -h /
git cherry-pick --no-commit FETCH_HEAD
done
else
echo Reusing existing Fuchsia checkout
echo Reusing existing Fuchsia checkout && df -h /
cd $checkout
fi

# Run the script inside the Fuchsia checkout responsible for building Fuchsia.
# You can change arguments to the build by setting KEEP_CHECKOUT=1 above and
# modifying them in build_fuchsia_from_rust_ci.sh.
echo "running build_fuchsia_from_rust_ci.sh" && df -h /

# Start background monitoring of disk space
(
while true; do
df -h /
sleep 20
done
) &
MONITOR_PID=$!

bash scripts/rust/build_fuchsia_from_rust_ci.sh

kill $MONITOR_PID
2 changes: 1 addition & 1 deletion src/ci/docker/host-x86_64/x86_64-gnu/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:22.04
FROM ghcr.io/marcoieni/ubuntu:22.04

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
Expand Down
35 changes: 25 additions & 10 deletions src/ci/docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ root_dir="`dirname $src_dir`"
source "$ci_dir/shared.sh"

if isCI; then
echo "CI detected"
objdir=$root_dir/obj
else
objdir=$root_dir/obj/$image
Expand All @@ -53,6 +54,7 @@ fi
CACHE_DOMAIN="${CACHE_DOMAIN:-ci-caches.rust-lang.org}"

if [ -f "$docker_dir/$image/Dockerfile" ]; then
echo "Dockerfile found for $image"
hash_key=/tmp/.docker-hash-key.txt
rm -f "${hash_key}"
echo $image >> $hash_key
Expand Down Expand Up @@ -153,6 +155,7 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
--output=type=docker
# On auto/try builds, we can also write to the cache.
else
echo "Logging into the Docker registry"
# Log into the Docker registry, so that we can read/write cache and the final image
echo ${DOCKER_TOKEN} | docker login ${REGISTRY} \
--username ${REGISTRY_USERNAME} \
Expand All @@ -163,6 +166,7 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
docker buildx create --use --driver docker-container \
--driver-opt image=${GHCR_BUILDKIT_IMAGE}

echo "Building Docker image with cache"
# Build the image using registry caching backend
retry docker \
buildx \
Expand All @@ -171,11 +175,13 @@ if [ -f "$docker_dir/$image/Dockerfile" ]; then
--cache-to type=registry,ref=${CACHE_IMAGE_TAG},compression=zstd \
--output=type=docker

echo "Docker image built"
# Print images for debugging purposes
docker images

# Tag the built image and push it to the registry
docker tag rust-ci "${IMAGE_TAG}"
echo "Pushing Docker image to the registry"
docker push "${IMAGE_TAG}"

# Record the container registry tag/url for reuse, e.g. by rustup.rs builds
Expand Down Expand Up @@ -227,6 +233,7 @@ else
exit 1
fi

echo "Creating directories"
mkdir -p $HOME/.cargo
mkdir -p $objdir/tmp
mkdir -p $objdir/cores
Expand Down Expand Up @@ -282,24 +289,32 @@ args="$args --privileged"
# `LOCAL_USER_ID` (recognized in `src/ci/run.sh`) to ensure that files are all
# read/written as the same user as the bare-metal user.
if [ -f /.dockerenv ]; then
docker create -v /checkout --name checkout alpine:3.4 /bin/true
echo "Dockerenv detected. We are in docker-in-docker scenario."
docker create -v /checkout --name checkout ghcr.io/marcoieni/alpine:3.4 /bin/true
docker cp . checkout:/checkout
args="$args --volumes-from checkout"
else
args="$args --volume $root_dir:/checkout$SRC_MOUNT_OPTION"
args="$args --volume $objdir:/checkout/obj"
args="$args --volume $HOME/.cargo:/cargo"
args="$args --volume /tmp/toolstate:/tmp/toolstate"
fi

id=$(id -u)
if [[ "$id" != 0 && "$(docker version)" =~ Podman ]]; then
# Rootless podman creates a separate user namespace, where an inner
# LOCAL_USER_ID will map to a different subuid range on the host.
# The "keep-id" mode maps the current UID directly into the container.
args="$args --env NO_CHANGE_USER=1 --userns=keep-id"
else
args="$args --env LOCAL_USER_ID=$id"
fi
id=$(id -u)
if [[ "$id" != 0 && "$(docker version)" =~ Podman ]]; then
# Rootless podman creates a separate user namespace, where an inner
# LOCAL_USER_ID will map to a different subuid range on the host.
# The "keep-id" mode maps the current UID directly into the container.
echo "Running in rootless podman"
args="$args --env NO_CHANGE_USER=1 --userns=keep-id"
elif [[ "$id" != 0 ]]; then
echo "Running in docker as non-root"
args="$args --env LOCAL_USER_ID=$id"
else
echo "Running in docker as root. Using id 1001."
# If we're running as root, we don't want to run the container as root,
# so we set id `1001` instead of `0`.
args="$args --env LOCAL_USER_ID=1001"
fi

if [ "$dev" = "1" ]
Expand Down
14 changes: 14 additions & 0 deletions src/ci/github-actions/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ def format_run_type(run_type: WorkflowRunType) -> str:
raise AssertionError()


# Add new function before main:
def substitute_github_vars(jobs: list) -> list:
"""Replace GitHub context variables with environment variables in job configs."""
for job in jobs:
if "os" in job:
job["os"] = (
job["os"]
.replace("${{ github.run_id }}", os.environ["GITHUB_RUN_ID"])
.replace("${{ github.run_attempt }}", os.environ["GITHUB_RUN_ATTEMPT"])
)
return jobs


def get_job_image(job: Job) -> str:
"""
By default, the Docker image of a job is based on its name.
Expand Down Expand Up @@ -265,6 +278,7 @@ def calculate_job_matrix(job_data: Dict[str, Any]):
if run_type is not None:
jobs = calculate_jobs(run_type, job_data)
jobs = skip_jobs(jobs, channel)
jobs = substitute_github_vars(jobs)

if not jobs:
raise Exception("Scheduled job list is empty, this is an error")
Expand Down
26 changes: 18 additions & 8 deletions src/ci/github-actions/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ runners:
free_disk: true
os: ubuntu-22.04-arm

- &job-linux-8c-codebuild
free_disk: true
os: codebuild-ubuntu-22-8c-${{ github.run_id }}-${{ github.run_attempt }}
<<: *base-job

- &job-linux-36c-codebuild
free_disk: true
os: codebuild-ubuntu-22-36c-${{ github.run_id }}-${{ github.run_attempt }}
<<: *base-job

- &job-aarch64-linux-8c
os: ubuntu-22.04-arm64-8core-32gb
envs:
Expand Down Expand Up @@ -152,7 +162,7 @@ auto:
<<: *job-linux-4c

- name: dist-arm-linux
<<: *job-linux-8c
<<: *job-linux-8c-codebuild

- name: dist-armhf-linux
<<: *job-linux-4c
Expand Down Expand Up @@ -182,7 +192,7 @@ auto:
<<: *job-linux-4c

- name: dist-powerpc64le-linux
<<: *job-linux-4c-largedisk
<<: *job-linux-36c-codebuild

- name: dist-riscv64-linux
<<: *job-linux-4c
Expand All @@ -205,13 +215,13 @@ auto:
- name: dist-x86_64-linux
env:
CODEGEN_BACKENDS: llvm,cranelift
<<: *job-linux-16c
<<: *job-linux-36c-codebuild

- name: dist-x86_64-linux-alt
env:
IMAGE: dist-x86_64-linux
CODEGEN_BACKENDS: llvm,cranelift
<<: *job-linux-16c
<<: *job-linux-36c-codebuild

- name: dist-x86_64-musl
env:
Expand Down Expand Up @@ -264,15 +274,15 @@ auto:
# nightly features to compile, and this job would fail if
# executed on beta and stable.
only_on_channel: nightly
<<: *job-linux-8c
<<: *job-linux-36c-codebuild

# Tests integration with Rust for Linux.
# Builds stage 1 compiler and tries to compile a few RfL examples with it.
- name: x86_64-rust-for-linux
<<: *job-linux-4c

- name: x86_64-gnu
<<: *job-linux-4c
<<: *job-linux-8c-codebuild

# This job ensures commits landing on nightly still pass the full
# test suite on the stable channel. There are some UI tests that
Expand All @@ -295,10 +305,10 @@ auto:
- name: x86_64-gnu-debug
# This seems to be needed because a full stage 2 build + run-make tests
# overwhelms the storage capacity of the standard 4c runner.
<<: *job-linux-4c-largedisk
<<: *job-linux-8c-codebuild

- name: x86_64-gnu-distcheck
<<: *job-linux-8c
<<: *job-linux-8c-codebuild

# The x86_64-gnu-llvm-19 job is split into multiple jobs to run tests in parallel.
# x86_64-gnu-llvm-19-1 skips tests that run in x86_64-gnu-llvm-19-{2,3}.
Expand Down
Loading

0 comments on commit 9b9d0fb

Please sign in to comment.