Skip to content

Commit 2aff89e

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 2aff89e

16 files changed

+213
-67
lines changed

.github/workflows/linux.yml

Lines changed: 31 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,28 @@ 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
72+
platform: linux64
73+
- name: xcb.cross
74+
platform: linux64
75+
- name: xcb.cross-riscv64
76+
platform: linux64
77+
- name: xcb.debian9
78+
platform: linux_aarch64
79+
name: ${{ matrix.image.name }}
80+
runs-on: ${{ matrix.image.platform == 'linux_aarch64' && 'depot-ubuntu-22.04-arm' || 'depot-ubuntu-22.04' }}
6581
permissions:
6682
packages: write
6783
steps:
@@ -95,30 +111,30 @@ jobs:
95111
uses: docker/build-push-action@v5
96112
with:
97113
context: .
98-
file: build/${{ matrix.image }}.Dockerfile
114+
file: build/${{ matrix.image.name }}.Dockerfile
99115
labels: org.opencontainers.image.source=https://github.com/${{ env.REPO_NAME }}
100116
# Cache from/to the current branch of the current repo as the primary cache key.
101117
# Cache from the default branch of the current repo so branches can have cache hits.
102118
# Cache from the default branch of the canonical repo so forks can have cache hits.
103119
# Ignore errors on cache writes so CI of forks works without a valid GHCR config.
104120
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
121+
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.image.name }}-${{ matrix.image.platform }}-${{ env.GIT_REF_NAME }}
122+
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.image.name }}-${{ matrix.image.platform }}-main
123+
type=registry,ref=ghcr.io/astral-sh/python-build-standalone:${{ matrix.image.name }}-${{ matrix.image.platform }}-main
108124
cache-to: |
109-
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.image }}-${{ env.GIT_REF_NAME }},ignore-error=true
125+
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.image.name }}-${{ matrix.image.platform }}-${{ env.GIT_REF_NAME }},ignore-error=true
110126
outputs: |
111-
type=docker,dest=build/image-${{ matrix.image }}.tar
127+
type=docker,dest=build/image-${{ matrix.image.name }}.${{ matrix.image.platform }}.tar
112128
113129
- name: Compress Image
114130
run: |
115-
echo ${{ steps.build-image.outputs.imageid }} > build/image-${{ matrix.image }}
131+
echo ${{ steps.build-image.outputs.imageid }} > build/image-${{ matrix.image.name }}.${{ matrix.image.platform }}
116132
zstd -v -T0 -6 --rm build/image-*.tar
117133
118134
- name: Upload Docker Image
119135
uses: actions/upload-artifact@v4
120136
with:
121-
name: image-${{ matrix.image }}
137+
name: image-${{ matrix.image.name }}-${{ matrix.image.platform }}
122138
path: build/image-*
123139

124140
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: 6 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 = \
@@ -153,6 +153,7 @@ LIBXCB_DEPENDS = \
153153
$(PYTHON_DEP_DEPENDS) \
154154
$(HOST_PYTHON_DEPENDS) \
155155
$(HERE)/build-libxcb.sh \
156+
$(OUTDIR)/image-$(DOCKER_IMAGE_XCB).$(HOST_PLATFORM).tar \
156157
$(OUTDIR)/xcb-proto-$(XCB_PROTO_VERSION)-$(PACKAGE_SUFFIX).tar \
157158
$(OUTDIR)/libXau-$(LIBXAU_VERSION)-$(PACKAGE_SUFFIX).tar \
158159
$(OUTDIR)/xorgproto-$(XORGPROTO_VERSION)-$(PACKAGE_SUFFIX).tar \

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 <[email protected]>
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)