Skip to content

Commit f8cd0b1

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 2faddf7 commit f8cd0b1

17 files changed

+200
-62
lines changed

.github/workflows/linux.yml

Lines changed: 9 additions & 9 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:
@@ -58,7 +58,7 @@ jobs:
5858
strategy:
5959
fail-fast: false
6060
matrix: ${{ fromJson(needs.generate-matrix.outputs.docker-build-matrix) }}
61-
name: image / ${{ matrix.name }}
61+
name: image / ${{ matrix.arch }} / ${{ matrix.name }}
6262
runs-on: ${{ matrix.runner }}
6363
permissions:
6464
packages: write
@@ -100,23 +100,23 @@ jobs:
100100
# Cache from the default branch of the canonical repo so forks can have cache hits.
101101
# Ignore errors on cache writes so CI of forks works without a valid GHCR config.
102102
cache-from: |
103-
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.name }}-${{ env.GIT_REF_NAME }}
104-
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.name }}-main
105-
type=registry,ref=ghcr.io/astral-sh/python-build-standalone:${{ matrix.name }}-main
103+
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.name }}-linux_${{ matrix.arch }}-${{ env.GIT_REF_NAME }}
104+
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.name }}-linux_${{ matrix.arch }}-main
105+
type=registry,ref=ghcr.io/astral-sh/python-build-standalone:${{ matrix.name }}-linux_${{ matrix.arch }}-main
106106
cache-to: |
107-
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.name }}-${{ env.GIT_REF_NAME }},ignore-error=true
107+
type=registry,ref=ghcr.io/${{ env.REPO_NAME }}:${{ matrix.name }}-linux_${{ matrix.arch }}-${{ env.GIT_REF_NAME }},ignore-error=true
108108
outputs: |
109-
type=docker,dest=build/image-${{ matrix.name }}.tar
109+
type=docker,dest=build/image-${{ matrix.name }}.linux_${{ matrix.arch }}.tar
110110
111111
- name: Compress Image
112112
run: |
113-
echo ${{ steps.build-image.outputs.imageid }} > build/image-${{ matrix.name }}
113+
echo ${{ steps.build-image.outputs.imageid }} > build/image-${{ matrix.name }}.linux_${{ matrix.arch }}
114114
zstd -v -T0 -6 --rm build/image-*.tar
115115
116116
- name: Upload Docker Image
117117
uses: actions/upload-artifact@v4
118118
with:
119-
name: image-${{ matrix.name }}
119+
name: image-${{ matrix.name }}-linux_${{ matrix.arch }}
120120
path: build/image-*
121121

122122
generate-matrix:

ci-matrix.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
{"name": "build", "arch": "x86_64"},
2626
{"name": "build.cross", "arch": "x86_64"},
2727
{"name": "build.cross-riscv64", "arch": "x86_64"},
28+
{"name": "build.debian9", "arch": "aarch64"},
2829
{"name": "gcc", "arch": "x86_64"},
30+
{"name": "gcc.debian9", "arch": "aarch64"},
31+
{"name": "xcb.debian9", "arch": "aarch64"},
2932
]
3033

3134

@@ -159,7 +162,11 @@ def generate_crate_build_matrix_entries(
159162
{
160163
"platform": platform,
161164
"arch": arch,
162-
"runner": find_runner(runners, platform, arch, True),
165+
# Use the GitHub runner for Windows, because the Depot one is
166+
# missing a Rust toolchain.
167+
"runner": find_runner(
168+
runners, platform, arch, True if platform == "windows" else False
169+
),
163170
"crate_artifact_name": crate_artifact_name(
164171
platform,
165172
arch,

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 <[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)