Skip to content

Commit 1b9b6ce

Browse files
committed
Enable native builds on Linux aarch64
I just published an LLVM 20 toolchain for aarch64. The toolchain has support for PGO and BOLT. This commit switches the Linux aarch64 builds to be performed natively on aarch64 machines. PGO and BOLT are enabled on the builds, hopefully making them a bit faster.
1 parent f555f11 commit 1b9b6ce

16 files changed

+205
-67
lines changed

.github/workflows/linux.yml

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: linux
22

33
on:
44
push:
5-
branches: [main]
5+
branches: [ main ]
66
pull_request:
77

88
concurrency:
@@ -56,12 +56,22 @@ jobs:
5656
fail-fast: false
5757
matrix:
5858
image:
59-
- build
60-
- build.cross
61-
- build.cross-riscv64
62-
- gcc
63-
name: ${{ matrix.image }}
64-
runs-on: depot-ubuntu-22.04
59+
- name: build
60+
platform: linux64
61+
- name: build.cross
62+
platform: linux64
63+
- name: build.cross-riscv64
64+
platform: linux64
65+
- name: build.debian9
66+
platform: linux_aarch64
67+
- name: gcc
68+
platform: linux64
69+
- name: gcc.debian9
70+
platform: linux_aarch64
71+
- name: xcb.debian9
72+
platform: linux_aarch64
73+
name: ${{ matrix.image.name }}
74+
runs-on: ${{ matrix.image.platform == 'linux_aarch64' && 'depot-ubuntu-22.04-arm' || 'depot-ubuntu-22.04' }}
6575
permissions:
6676
packages: write
6777
steps:
@@ -95,30 +105,30 @@ jobs:
95105
uses: docker/build-push-action@v5
96106
with:
97107
context: .
98-
file: build/${{ matrix.image }}.Dockerfile
108+
file: build/${{ matrix.image.name }}.Dockerfile
99109
labels: org.opencontainers.image.source=https://github.com/${{ env.REPO_NAME }}
100110
# Cache from/to the current branch of the current repo as the primary cache key.
101111
# Cache from the default branch of the current repo so branches can have cache hits.
102112
# Cache from the default branch of the canonical repo so forks can have cache hits.
103113
# Ignore errors on cache writes so CI of forks works without a valid GHCR config.
104114
cache-from: |
105-
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.image }}-${{ env.GIT_REF_NAME }}
106-
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.image }}-main
107-
type=registry,ref=ghcr.io/astral-sh/python-build-standalone:${{ matrix.image }}-main
115+
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.image.name }}-${{ matrix.image.platform }}-${{ env.GIT_REF_NAME }}
116+
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.image.name }}-${{ matrix.image.platform }}-main
117+
type=registry,ref=ghcr.io/astral-sh/python-build-standalone:${{ matrix.image.name }}-${{ matrix.image.platform }}-main
108118
cache-to: |
109-
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.image }}-${{ env.GIT_REF_NAME }},ignore-error=true
119+
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.image.name }}-${{ matrix.image.platform }}-${{ env.GIT_REF_NAME }},ignore-error=true
110120
outputs: |
111-
type=docker,dest=build/image-${{ matrix.image }}.tar
121+
type=docker,dest=build/image-${{ matrix.image.name }}.${{ matrix.image.platform }}.tar
112122
113123
- name: Compress Image
114124
run: |
115-
echo ${{ steps.build-image.outputs.imageid }} > build/image-${{ matrix.image }}
125+
echo ${{ steps.build-image.outputs.imageid }} > build/image-${{ matrix.image.name }}.${{ matrix.image.platform }}
116126
zstd -v -T0 -6 --rm build/image-*.tar
117127
118128
- name: Upload Docker Image
119129
uses: actions/upload-artifact@v4
120130
with:
121-
name: image-${{ matrix.image }}
131+
name: image-${{ matrix.image.name }}-${{ matrix.image.platform }}
122132
path: build/image-*
123133

124134
generate-matrix:

ci-runners.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ depot-ubuntu-22.04:
55
platform: linux
66
free: false
77

8-
# TODO: Enable this runner to perform native builds for aarch64
9-
# depot-ubuntu-22.04-arm:
10-
# arch: aarch64
11-
# platform: linux
12-
# free: false
8+
depot-ubuntu-22.04-arm:
9+
arch: aarch64
10+
platform: linux
11+
free: false
1312

1413
depot-macos-latest:
1514
arch: x86_64

ci-targets.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,11 @@ linux:
5050
- "3.14"
5151
build_options:
5252
- debug
53-
- noopt
54-
- lto
53+
- pgo+lto
5554
build_options_conditional:
5655
- options:
5756
- freethreaded+debug
58-
- freethreaded+noopt
59-
- freethreaded+lto
57+
- freethreaded+pgo+lto
6058
minimum-python-version: "3.13"
6159

6260
armv7-unknown-linux-gnueabi:

cpython-unix/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ TOOLCHAIN_DEPENDS := \
6666

6767
PYTHON_DEP_DEPENDS := \
6868
$(OUTDIR)/targets/$(TARGET_TRIPLE) \
69-
$(if $(PYBUILD_NO_DOCKER),,$(OUTDIR)/image-$(DOCKER_IMAGE_BUILD).tar) \
69+
$(if $(PYBUILD_NO_DOCKER),,$(OUTDIR)/image-$(DOCKER_IMAGE_BUILD).$(HOST_PLATFORM).tar) \
7070
$(TOOLCHAIN_DEPENDS) \
7171
$(NULL)
7272

@@ -75,12 +75,12 @@ HOST_PYTHON_DEPENDS := $(OUTDIR)/cpython-$(PYTHON_MAJOR_VERSION)-$(CPYTHON_$(PYT
7575
default: $(OUTDIR)/cpython-$(CPYTHON_$(PYTHON_MAJOR_VERSION)_VERSION)-$(PACKAGE_SUFFIX).tar
7676

7777
ifndef PYBUILD_NO_DOCKER
78-
$(OUTDIR)/image-%.tar: $(OUTDIR)/%.Dockerfile
78+
$(OUTDIR)/image-%.$(HOST_PLATFORM).tar: $(OUTDIR)/%.Dockerfile
7979
$(RUN_BUILD) --toolchain image-$*
8080
endif
8181

82-
$(OUTDIR)/binutils-$(BINUTILS_VERSION)-$(HOST_PLATFORM).tar: $(OUTDIR)/image-gcc.tar $(HERE)/build-binutils.sh
83-
$(RUN_BUILD) --toolchain binutils
82+
$(OUTDIR)/binutils-$(BINUTILS_VERSION)-$(HOST_PLATFORM).tar: $(HERE)/build-binutils.sh
83+
$(RUN_BUILD) --toolchain --docker-image $(DOCKER_IMAGE_GCC) binutils
8484

8585
$(OUTDIR)/$(CLANG_FILENAME):
8686
$(RUN_BUILD) --toolchain clang --target-triple $(TARGET_TRIPLE)
@@ -125,7 +125,7 @@ $(OUTDIR)/libffi-3.3-$(LIBFFI_3.3_VERSION)-$(PACKAGE_SUFFIX).tar: $(PYTHON_DEP_D
125125
$(OUTDIR)/libffi-$(LIBFFI_VERSION)-$(PACKAGE_SUFFIX).tar: $(PYTHON_DEP_DEPENDS) $(HERE)/build-libffi.sh
126126
$(RUN_BUILD) --docker-image $(DOCKER_IMAGE_BUILD) libffi
127127

128-
$(OUTDIR)/libpthread-stubs-$(LIBPTHREAD_STUBS_VERSION)-$(PACKAGE_SUFFIX).tar: $(PYTHON_DEP_DEPENDS) $(HERE)/build-libpthread-stubs.sh $(OUTDIR)/image-$(DOCKER_IMAGE_BUILD).tar
128+
$(OUTDIR)/libpthread-stubs-$(LIBPTHREAD_STUBS_VERSION)-$(PACKAGE_SUFFIX).tar: $(PYTHON_DEP_DEPENDS) $(HERE)/build-libpthread-stubs.sh $(OUTDIR)/image-$(DOCKER_IMAGE_BUILD).$(HOST_PLATFORM).tar
129129
$(RUN_BUILD) --docker-image $(DOCKER_IMAGE_BUILD) libpthread-stubs
130130

131131
LIBX11_DEPENDS = \

cpython-unix/base.debian9.Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Debian Stretch.
2+
FROM debian@sha256:c5c5200ff1e9c73ffbf188b4a67eb1c91531b644856b4aefe86a58d2f0cb05be
3+
MAINTAINER Gregory Szorc <gregory.szorc@gmail.com>
4+
5+
RUN groupadd -g 1000 build && \
6+
useradd -u 1000 -g 1000 -d /build -s /bin/bash -m build && \
7+
mkdir /tools && \
8+
chown -R build:build /build /tools
9+
10+
ENV HOME=/build \
11+
SHELL=/bin/bash \
12+
USER=build \
13+
LOGNAME=build \
14+
HOSTNAME=builder \
15+
DEBIAN_FRONTEND=noninteractive
16+
17+
CMD ["/bin/bash", "--login"]
18+
WORKDIR '/build'
19+
20+
RUN for s in debian_stretch debian_stretch-updates debian-security_stretch/updates; do \
21+
echo "deb http://snapshot.debian.org/archive/${s%_*}/20230423T032736Z/ ${s#*_} main"; \
22+
done > /etc/apt/sources.list && \
23+
( echo 'quiet "true";'; \
24+
echo 'APT::Get::Assume-Yes "true";'; \
25+
echo 'APT::Install-Recommends "false";'; \
26+
echo 'Acquire::Check-Valid-Until "false";'; \
27+
echo 'Acquire::Retries "5";'; \
28+
) > /etc/apt/apt.conf.d/99cpython-portable
29+
30+
# apt iterates all available file descriptors up to rlim_max and calls
31+
# fcntl(fd, F_SETFD, FD_CLOEXEC). This can result in millions of system calls
32+
# (we've seen 1B in the wild) and cause operations to take seconds to minutes.
33+
# Setting a fd limit mitigates.
34+
#
35+
# Attempts at enforcing the limit globally via /etc/security/limits.conf and
36+
# /root/.bashrc were not successful. Possibly because container image builds
37+
# don't perform a login or use a shell the way we expect.
38+
RUN ulimit -n 10000 && apt-get update

cpython-unix/build-binutils.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ tar -xf binutils-${BINUTILS_VERSION}.tar.xz
1111
mkdir binutils-objdir
1212
pushd binutils-objdir
1313

14+
if [ "$(uname -m)" = "x86_64" ]; then
15+
triple="x86_64-unknown-linux-gnu"
16+
else
17+
triple="aarch64-unknown-linux-gnu"
18+
fi
19+
1420
# gprofng requires a bison newer than what we have. So just disable it.
1521
../binutils-${BINUTILS_VERSION}/configure \
16-
--build=x86_64-unknown-linux-gnu \
22+
--build=${triple} \
1723
--prefix=/tools/host \
1824
--enable-plugins \
1925
--enable-gprofng=no \

cpython-unix/build-main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ def main():
9595
"toolchain-image-build",
9696
"toolchain-image-build.cross",
9797
"toolchain-image-build.cross-riscv64",
98+
"toolchain-image-build.debian9",
9899
"toolchain-image-gcc",
99100
"toolchain-image-xcb",
100101
"toolchain-image-xcb.cross",
101102
"toolchain-image-xcb.cross-riscv64",
103+
"toolchain-image-xcb.debian9",
102104
},
103105
default="default",
104106
help="The make target to evaluate",

cpython-unix/build.debian9.Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% include 'base.debian9.Dockerfile' %}
2+
3+
RUN ulimit -n 10000 && apt-get install \
4+
bzip2 \
5+
file \
6+
libc6-dev \
7+
libffi-dev \
8+
make \
9+
patch \
10+
perl \
11+
pkg-config \
12+
tar \
13+
xz-utils \
14+
unzip \
15+
zip \
16+
zlib1g-dev

0 commit comments

Comments
 (0)