diff --git a/.github/actions/binary-compatible-builds/README.md b/.github/actions/binary-compatible-builds/README.md deleted file mode 100644 index 8368fd4f1a9e..000000000000 --- a/.github/actions/binary-compatible-builds/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# binary-compatible-builds - -A small (ish) action which is intended to be used and will configure builds of -Rust projects to be "more binary compatible". On Windows and macOS this -involves setting a few env vars, and on Linux this involves spinning up a CentOS -6 container which is running in the background. - -All subsequent build commands need to be wrapped in `$CENTOS` to optionally run -on `$CENTOS` on Linux to ensure builds happen inside the container. diff --git a/.github/actions/binary-compatible-builds/action.yml b/.github/actions/binary-compatible-builds/action.yml deleted file mode 100644 index 8abc72d63742..000000000000 --- a/.github/actions/binary-compatible-builds/action.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: 'Set up a CentOS 6 container to build releases in' -description: 'Set up a CentOS 6 container to build releases in' - -runs: - using: node20 - main: 'main.js' -inputs: - name: - required: true - description: "Name of the build" diff --git a/.github/actions/binary-compatible-builds/main.js b/.github/actions/binary-compatible-builds/main.js deleted file mode 100755 index 1101d78e4a41..000000000000 --- a/.github/actions/binary-compatible-builds/main.js +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/env node - -const child_process = require('child_process'); -const stdio = { stdio: 'inherit' }; -const fs = require('fs'); - -function set_env(name, val) { - fs.appendFileSync(process.env['GITHUB_ENV'], `${name}=${val}\n`) -} - -// On OSX all we need to do is configure our deployment target as old as -// possible. For now 10.9 is the limit. -if (process.platform == 'darwin') { - set_env("MACOSX_DEPLOYMENT_TARGET", "10.9"); - return; -} - -// On Windows we build against the static CRT to reduce dll dependencies -if (process.platform == 'win32') { - set_env("RUSTFLAGS", "-Ctarget-feature=+crt-static"); - return; -} - -// Android doesn't use a container as it's controlled by the installation of the -// SDK/NDK. -if (process.env.INPUT_NAME && process.env.INPUT_NAME.indexOf("android") >= 0) { - return; -} - -// ... and on Linux we do fancy things with containers. We'll spawn an old -// CentOS container in the background with a super old glibc, and then we'll run -// commands in there with the `$CENTOS` env var. - -if (process.env.CENTOS !== undefined) { - const args = ['exec', '--workdir', process.cwd(), '--interactive']; - // Forward any rust-looking env vars from the environment into the container - // itself. - for (let key in process.env) { - if (key.startsWith('CARGO') || key.startsWith('RUST')) { - args.push('--env'); - args.push(key); - } - } - args.push('build-container') - - // Start the container by appending to `$PATH` with the `/rust/bin` path that - // is mounted below. - args.push('bash'); - args.push('-c'); - args.push('export PATH=$PATH:/rust/bin; export RUSTFLAGS="$RUSTFLAGS $EXTRA_RUSTFLAGS"; exec "$@"'); - args.push('bash'); - - // Add in whatever we're running which will get executed in the sub-shell with - // an augmented PATH. - for (const arg of process.argv.slice(2)) { - args.push(arg); - } - child_process.execFileSync('docker', args, stdio); - return; -} - -const name = process.env.INPUT_NAME.replace(/-min$/, ''); - -child_process.execFileSync('docker', [ - 'build', - '--tag', 'build-image', - `${process.cwd()}/ci/docker/${name}` -], stdio); - -child_process.execFileSync('docker', [ - 'run', - '--detach', - '--interactive', - '--name', 'build-container', - '-v', `${process.cwd()}:${process.cwd()}`, - '-v', `${child_process.execSync('rustc --print sysroot').toString().trim()}:/rust:ro`, - 'build-image', -], stdio); - -// Use ourselves to run future commands -set_env("CENTOS", __filename); diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2397a9f322ae..b5512665d685 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1072,6 +1072,7 @@ jobs: strategy: fail-fast: ${{ github.event_name != 'pull_request' }} matrix: ${{ fromJson(needs.determine.outputs.build-matrix) }} + env: ${{ matrix.env || fromJSON('{}') }} steps: - uses: actions/checkout@v4 with: @@ -1089,16 +1090,13 @@ jobs: # it everywhere - run: ./ci/build-src-tarball.sh if: matrix.build == 'x86_64-linux' - - uses: ./.github/actions/binary-compatible-builds - with: - name: ${{ matrix.build }} - uses: ./.github/actions/android-ndk if: contains(matrix.target, 'android') with: target: ${{ matrix.target }} - - run: $CENTOS ./ci/build-release-artifacts.sh "${{ matrix.build }}" "${{ matrix.target }}" + - run: ./ci/build-release-artifacts.sh "${{ matrix.build }}" "${{ matrix.target }}" # Assemble release artifacts appropriate for this platform, then upload them # unconditionally to this workflow's files so we have a copy of them. diff --git a/ci/build-build-matrix.js b/ci/build-build-matrix.js index 135e78f6952f..2a27c6e98fea 100644 --- a/ci/build-build-matrix.js +++ b/ci/build-build-matrix.js @@ -17,41 +17,52 @@ const array = [ "os": ubuntu, // The Rust target that will be used for the build. "target": "x86_64-unknown-linux-gnu", + "env": { "DOCKER_IMAGE": "./ci/docker/x86_64-linux/Dockerfile" }, }, { "build": "aarch64-linux", "os": ubuntu, "target": "aarch64-unknown-linux-gnu", + "env": { "DOCKER_IMAGE": "./ci/docker/aarch64-linux/Dockerfile" }, }, { "build": "s390x-linux", "os": ubuntu, "target": "s390x-unknown-linux-gnu", + "env": { "DOCKER_IMAGE": "./ci/docker/s390x-linux/Dockerfile" }, }, { "build": "riscv64gc-linux", "os": ubuntu, "target": "riscv64gc-unknown-linux-gnu", + "env": { "DOCKER_IMAGE": "./ci/docker/riscv64gc-linux/Dockerfile" }, }, { "build": "x86_64-macos", "os": macos, "target": "x86_64-apple-darwin", + // On OSX all we need to do is configure our deployment target as old as + // possible. For now 10.9 is the limit. + "env": { "MACOSX_DEPLOYMENT_TARGET": "10.9" }, }, { "build": "aarch64-macos", "os": macos, "target": "aarch64-apple-darwin", + "env": { "MACOSX_DEPLOYMENT_TARGET": "10.9" }, }, { "build": "x86_64-windows", "os": windows, "target": "x86_64-pc-windows-msvc", + // On Windows we build against the static CRT to reduce dll dependencies + "env": { "RUSTFLAGS": "-Ctarget-feature=+crt-static" }, }, { "build": "x86_64-mingw", "os": windows, "target": "x86_64-pc-windows-gnu", + "env": { "RUSTFLAGS": "-Ctarget-feature=+crt-static" }, }, { "build": "aarch64-android", @@ -67,11 +78,19 @@ const array = [ "build": "x86_64-musl", "os": ubuntu, "target": "x86_64-unknown-linux-musl", + "env": { "DOCKER_IMAGE": "./ci/docker/x86_64-musl/Dockerfile" }, + }, + { + "build": "aarch64-musl", + "os": ubuntu, + "target": "aarch64-unknown-linux-musl", + "env": { "DOCKER_IMAGE": "./ci/docker/aarch64-musl/Dockerfile" }, }, { "build": "aarch64-windows", "os": windows, "target": "aarch64-pc-windows-msvc", + "env": { "RUSTFLAGS": "-Ctarget-feature=+crt-static" }, }, ]; diff --git a/ci/build-release-artifacts.sh b/ci/build-release-artifacts.sh index 606cf61c9b87..37f3bb463cdd 100755 --- a/ci/build-release-artifacts.sh +++ b/ci/build-release-artifacts.sh @@ -13,6 +13,29 @@ set -ex build=$1 target=$2 +wrapper="" + +# If `$DOCKER_IMAGE` is set then run the build inside of that docker container +# instead of on the host machine. In CI this uses `./ci/docker/*/Dockerfile` to +# have precise glibc requirements for Linux platforms for example. +if [ "$DOCKER_IMAGE" != "" ]; then + if [ -f "$DOCKER_IMAGE" ]; then + docker build --tag build-image --file $DOCKER_IMAGE ci/docker + DOCKER_IMAGE=build-image + fi + + # Inherit the environment's rustc and env vars related to cargo/rust, and then + # otherwise re-execute ourselves and we'll be missing `$DOCKER_IMAGE` in the + # container so we'll continue below. + exec docker run --interactive \ + --volume `pwd`:`pwd` \ + --volume `rustc --print sysroot`:/rust:ro \ + --workdir `pwd` \ + --interactive \ + --env-file <(env | grep 'CARGO\|RUST') \ + $DOCKER_IMAGE \ + bash -c "PATH=\$PATH:/rust/bin RUSTFLAGS=\"\$RUSTFLAGS \$EXTRA_RUSTFLAGS\" `pwd`/$0 $*" +fi # Default build flags for release artifacts. Leave debugging for # builds-from-source which have richer information anyway, and additionally the diff --git a/ci/docker/aarch64-musl/Dockerfile b/ci/docker/aarch64-musl/Dockerfile new file mode 100644 index 000000000000..38eaeacc120d --- /dev/null +++ b/ci/docker/aarch64-musl/Dockerfile @@ -0,0 +1,5 @@ +FROM ghcr.io/cross-rs/aarch64-unknown-linux-musl + +RUN apt-get update -y && apt-get install -y ninja-build +RUN git config --global --add safe.directory '*' +ENV EXTRA_RUSTFLAGS=-Ctarget-feature=-crt-static