From 5e8d91619279828e615c272c2cf214a0d7636425 Mon Sep 17 00:00:00 2001 From: Ruoyu Zhong Date: Sun, 27 Oct 2024 03:56:53 +0800 Subject: [PATCH] Add Docker image for aarch64 --- .github/workflows/build.yml | 23 ++++++++++++++--------- Dockerfile.aarch64 | 17 +++++++++++++++++ debian7/Dockerfile => Dockerfile.x86_64 | 0 README.md | 18 +++++++++--------- utils.sh | 3 ++- 5 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 Dockerfile.aarch64 rename debian7/Dockerfile => Dockerfile.x86_64 (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 717fa10..e44b289 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,12 +5,11 @@ on: paths: - .github/workflows/build.yml - "build-*.sh" - - debian7/Dockerfile + - Dockerfile* workflow_call: jobs: build: - runs-on: ubuntu-latest strategy: fail-fast: false matrix: @@ -23,25 +22,31 @@ jobs: - python3 - sed include: - - container: debian7 + - arch: x86_64 + runs-on: ubuntu-latest + # TODO: add aarch64 when available + runs-on: ${{matrix.runs-on}} + name: ${{matrix.binary}} (${{matrix.arch}}) + env: + ARCH: ${{matrix.arch}} + BINARY: ${{matrix.binary}} steps: - uses: actions/checkout@v4 - name: Build Docker image - run: docker build --tag ${{matrix.container}} . - working-directory: debian7 + run: docker build --tag glibc-bootstrap --file "Dockerfile.$ARCH" . - name: Run Docker container - run: docker run --rm --detach --user linuxbrew --name ${{github.sha}} --workdir /home/linuxbrew --volume $(pwd):/home/linuxbrew/glibc-bootstrap ${{matrix.container}} sleep inf + run: docker run --rm --detach --user linuxbrew --name "$GITHUB_SHA" --workdir /home/linuxbrew --volume "$(pwd)":/home/linuxbrew/glibc-bootstrap glibc-bootstrap sleep inf - name: Build ${{matrix.binary}} - run: docker exec ${{github.sha}} /bin/bash -c "/home/linuxbrew/glibc-bootstrap/build-${{matrix.binary}}.sh" + run: docker exec "$GITHUB_SHA" /bin/bash -c "/home/linuxbrew/glibc-bootstrap/build-$BINARY.sh" - name: Copy binaries from container - run: docker cp ${{github.sha}}:/home/linuxbrew/bootstrap-binaries . + run: docker cp "$GITHUB_SHA":/home/linuxbrew/bootstrap-binaries . - name: Upload binaries to GitHub Actions uses: actions/upload-artifact@v4 with: - name: bootstrap-${{matrix.binary}} + name: bootstrap-${{matrix.arch}}-${{matrix.binary}} path: bootstrap-binaries diff --git a/Dockerfile.aarch64 b/Dockerfile.aarch64 new file mode 100644 index 0000000..ab374f1 --- /dev/null +++ b/Dockerfile.aarch64 @@ -0,0 +1,17 @@ +FROM centos:7 + +RUN sed -e 's/mirror\.centos\.org/vault\.centos\.org/g' \ + -e 's/^mirrorlist=/#mirrorlist=/g' \ + -e 's/^#\s*baseurl=/baseurl=/g' \ + -i /etc/yum.repos.d/CentOS-*.repo \ + && yum install -y @development bzip2 ca-certificates texinfo wget zlib-devel \ + && yum clean all + +RUN useradd --create-home --shell /bin/bash linuxbrew + +ENV CFLAGS="-march=armv8-a -O2" +ENV CXXFLAGS="-march=armv8-a -O2" +ENV PREFIX=/tmp/homebrew +RUN su - linuxbrew --command 'mkdir --parents /tmp/homebrew' +ENV PKGDIR=/home/linuxbrew/bootstrap-binaries +RUN su - linuxbrew --command 'mkdir --parents /home/linuxbrew/bootstrap-binaries' diff --git a/debian7/Dockerfile b/Dockerfile.x86_64 similarity index 100% rename from debian7/Dockerfile rename to Dockerfile.x86_64 diff --git a/README.md b/README.md index f6952e9..0693873 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,13 @@ Bootstrap binaries for compiling `glibc` from source. To run the binaries built by this workflow: -Linux with `glibc` 2.13 or newer. +For x86-64 Linux: `glibc` 2.13 or newer, and x86-64 CPU architecture with support for `-march=core2` (defined [here](https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html)). -x86-64 CPU architecture with support for `-march=core2` (defined [here](https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html)). +For AArch64 (ARM64) Linux: `glibc` 2.17 or newer. To build the binaries: -A host machine capable of running building and running Linux x86-64 Docker images. +A host machine capable of building and running Linux x86-64 or AArch64 Docker images. ## Installation @@ -27,23 +27,23 @@ git clone https://github.com/Homebrew/glibc-bootstrap cd glibc-bootstrap # Build the Docker image. -docker build --tag debian7 debian7 +docker build --tag glibc-bootstrap --file "Dockerfile.$(uname -m)" . # Start the Docker image and leave it running the background so the binaries # can easily be copied out after they are built. -docker run --rm --detach --user linuxbrew --name debian7 \ - --workdir /home/linuxbrew --volume $(pwd):/home/linuxbrew/glibc-bootstrap debian7 sleep inf +docker run --rm --detach --user linuxbrew --name glibc-bootstrap \ + --workdir /home/linuxbrew --volume $(pwd):/home/linuxbrew/glibc-bootstrap glibc-bootstrap sleep inf # Call a build-*.sh script to build a specific binary. We use build-make.sh as an example. -docker exec debian7 /bin/bash -c "/home/linuxbrew/glibc-bootstrap/build-make.sh" +docker exec glibc-bootstrap /bin/bash -c "/home/linuxbrew/glibc-bootstrap/build-make.sh" # Copy the binaries out of the container after they have been compiled. -docker cp debian7:/home/linuxbrew/bootstrap-binaries . +docker cp glibc-bootstrap:/home/linuxbrew/bootstrap-binaries . ``` ## Motivation -The `glibc` bottle is not relocatable and must be built from source if the user is in a non-default prefix. While `glibc` has no runtime dependencies, it does have build dependencies which may be too new or unavailable to users without root access. Rather than requiring the user to build these dependencies from source, we build them with GitHub Actions in this repository using a Linux image with an older version of `glibc` and a prefix of `/tmp/homebrew`. Assuming the user has write access to `/tmp`, this approach guarantees that all users on actively maintained versions of `glibc` (2.17 or newer) can install and run these binaries. The build dependency binaries are installed as resources to `/tmp/homebrew` and used to build `glibc` instead of the host toolchain. +The `glibc` bottle is not relocatable and must be built from source if the user is in a non-default prefix. While `glibc` has no runtime dependencies, it does have build dependencies which may be too new or unavailable to users without root access. Rather than requiring the user to build these dependencies from source, we build them with GitHub Actions in this repository using a Linux image with an older version of `glibc` and a prefix of `/tmp/homebrew`. Assuming the user has write access to `/tmp`, this approach guarantees that all users on actively maintained versions of `glibc` can install and run these binaries. The build dependency binaries are installed as resources to `/tmp/homebrew` and used to build `glibc` instead of the host toolchain. ## Copyright Copyright (c) Homebrew maintainers. See LICENSE.txt for details. diff --git a/utils.sh b/utils.sh index 2a1c450..3f245a5 100755 --- a/utils.sh +++ b/utils.sh @@ -16,9 +16,10 @@ verify_checksum() { package() { PKGNAME="$1" VERSION="$2" + ARCH="$(uname -m)" tar --directory "$PREFIX" \ --create --gzip --verbose \ - --file "$PKGDIR/bootstrap-$PKGNAME-$VERSION.tar.gz" . + --file "$PKGDIR/bootstrap-$ARCH-$PKGNAME-$VERSION.tar.gz" . find "$PREFIX" -mindepth 1 -delete }