Skip to content

Commit

Permalink
Add Docker image for aarch64
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhongRuoyu committed Nov 18, 2024
1 parent ca52b20 commit 5e8d916
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
23 changes: 14 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
17 changes: 17 additions & 0 deletions Dockerfile.aarch64
Original file line number Diff line number Diff line change
@@ -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'
File renamed without changes.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
3 changes: 2 additions & 1 deletion utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 5e8d916

Please sign in to comment.