Skip to content

Commit f1ccfb0

Browse files
Add loongarch64-linux support
Signed-off-by: 吴小白 <[email protected]>
1 parent 4c3dfd8 commit f1ccfb0

17 files changed

+237
-5
lines changed

.github/workflows/linux.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ jobs:
5959
- build
6060
- build.cross
6161
- build.cross-riscv64
62+
- build.cross-loongarch64
6263
- gcc
6364
name: ${{ matrix.image }}
6465
runs-on: depot-ubuntu-22.04

ci-targets.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,27 @@ linux:
101101
- freethreaded+lto
102102
minimum-python-version: "3.13"
103103

104+
loongarch64-unknown-linux-gnu:
105+
arch: loongarch64
106+
libc: gnu
107+
python_versions:
108+
- "3.9"
109+
- "3.10"
110+
- "3.11"
111+
- "3.12"
112+
- "3.13"
113+
- "3.14"
114+
build_options:
115+
- debug
116+
- noopt
117+
- lto
118+
build_options_conditional:
119+
- options:
120+
- freethreaded+debug
121+
- freethreaded+noopt
122+
- freethreaded+lto
123+
minimum-python-version: "3.13"
124+
104125
s390x-unknown-linux-gnu:
105126
arch: s390x
106127
libc: gnu

cpython-unix/build-cpython.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
6969
fi
7070
fi
7171

72+
# configure doesn't support cross-compiling on LoongArch. Teach it.
73+
if [ "${PYBUILD_PLATFORM}" != "macos" ]; then
74+
case "${PYTHON_MAJMIN_VERSION}" in
75+
3.9|3.10|3.11)
76+
patch -p1 -i ${ROOT}/patch-configure-add-loongarch-triplet.patch
77+
;;
78+
esac
79+
fi
80+
7281
# disable readelf check when cross-compiling on older Python versions
7382
if [ -n "${CROSS_COMPILING}" ]; then
7483
if [ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_11}" ]; then
@@ -1097,6 +1106,9 @@ armv7-unknown-linux-gnueabi)
10971106
armv7-unknown-linux-gnueabihf)
10981107
PYTHON_ARCH="arm-linux-gnueabihf"
10991108
;;
1109+
loongarch64-unknown-linux-gnu)
1110+
PYTHON_ARCH="loongarch64-linux-gnu"
1111+
;;
11001112
mips-unknown-linux-gnu)
11011113
PYTHON_ARCH="mips-linux-gnu"
11021114
;;
@@ -1254,7 +1266,8 @@ if [ -d "${TOOLS_PATH}/deps/lib/tcl8" ]; then
12541266
cp -av $source ${ROOT}/out/python/install/lib/
12551267
done
12561268

1257-
if [[ "${PYBUILD_PLATFORM}" != macos* ]]; then
1269+
# Tix doesn't support macOS and loongarch64, so we don't copy it there.
1270+
if [[ "${PYBUILD_PLATFORM}" != macos* ]] && [[ "${TARGET_TRIPLE}" != loongarch64* ]]; then
12581271
cp -av ${TOOLS_PATH}/deps/lib/Tix8.4.3 ${ROOT}/out/python/install/lib/
12591272
fi
12601273
fi

cpython-unix/build-libX11.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ if [ -n "${CROSS_COMPILING}" ]; then
5454
armv7-unknown-linux-gnueabihf)
5555
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
5656
;;
57+
loongarch64-unknown-linux-gnu)
58+
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
59+
;;
5760
mips-unknown-linux-gnu)
5861
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
5962
;;
@@ -78,6 +81,9 @@ if [ -n "${CROSS_COMPILING}" ]; then
7881
aarch64-unknown-linux-musl)
7982
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
8083
;;
84+
loongarch64-unknown-linux-musl)
85+
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
86+
;;
8187
mips-unknown-linux-musl)
8288
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
8389
;;

cpython-unix/build-libxcb.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ export PKG_CONFIG_PATH=/tools/deps/share/pkgconfig:/tools/deps/lib/pkgconfig
1313
tar -xf libxcb-${LIBXCB_VERSION}.tar.gz
1414
pushd libxcb-${LIBXCB_VERSION}
1515

16+
if [[ "${TARGET_TRIPLE}" = loongarch64* ]]; then
17+
rm -f build-aux/config.guess build-aux/config.sub
18+
curl -sSL -o build-aux/config.guess https://github.com/cgitmirror/config/raw/refs/heads/master/config.guess
19+
curl -sSL -o build-aux/config.sub https://github.com/cgitmirror/config/raw/refs/heads/master/config.sub
20+
fi
21+
1622
if [ "${CC}" = "musl-clang" ]; then
1723
EXTRA_FLAGS="--disable-shared"
1824
fi

cpython-unix/build-main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ def main():
9595
"toolchain-image-build",
9696
"toolchain-image-build.cross",
9797
"toolchain-image-build.cross-riscv64",
98+
"toolchain-image-build.cross-loongarch64",
9899
"toolchain-image-gcc",
99-
"toolchain-image-xcb",
100-
"toolchain-image-xcb.cross",
101-
"toolchain-image-xcb.cross-riscv64",
102100
},
103101
default="default",
104102
help="The make target to evaluate",

cpython-unix/build-ncurses.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ else
109109
"
110110
fi
111111

112+
mkdir -p ${ROOT}/out/usr/lib
113+
112114
CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" LDFLAGS="${EXTRA_TARGET_LDFLAGS}" ./configure ${CONFIGURE_FLAGS}
113115
make -j ${NUM_CPUS}
114116
make -j ${NUM_CPUS} install DESTDIR=${ROOT}/out

cpython-unix/build-xorgproto.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ export PKG_CONFIG_PATH=/tools/deps/share/pkgconfig
1515
tar -xf xorgproto-${XORGPROTO_VERSION}.tar.gz
1616
pushd xorgproto-${XORGPROTO_VERSION}
1717

18+
if [[ "${TARGET_TRIPLE}" = loongarch64* ]]; then
19+
rm -f config.guess.sub config.sub
20+
curl -sSL -o config.guess https://github.com/cgitmirror/config/raw/refs/heads/master/config.guess
21+
curl -sSL -o config.sub https://github.com/cgitmirror/config/raw/refs/heads/master/config.sub
22+
fi
23+
1824
CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" LDFLAGS="${EXTRA_TARGET_LDFLAGS}" ./configure \
1925
--build=${BUILD_TRIPLE} \
2026
--host=${TARGET_TRIPLE} \

cpython-unix/build.Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# Various other build tools are needed for various building.
1010
RUN ulimit -n 10000 && apt-get install \
1111
bzip2 \
12+
ca-certificates \
13+
curl \
1214
file \
1315
libc6-dev \
1416
libffi-dev \
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Debian Trixie.
2+
FROM debian@sha256:653dfb9f86c3782e8369d5f7d29bb8faba1f4bff9025db46e807fa4c22903671
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_trixie debian_trixie-updates; do \
21+
echo "deb http://snapshot.debian.org/archive/${s%_*}/20250515T202920Z/ ${s#*_} main"; \
22+
done > /etc/apt/sources.list && \
23+
for s in debian-security_trixie-security/updates; do \
24+
echo "deb http://snapshot.debian.org/archive/${s%_*}/20250515T175729Z/ ${s#*_} main"; \
25+
done >> /etc/apt/sources.list && \
26+
( echo 'quiet "true";'; \
27+
echo 'APT::Get::Assume-Yes "true";'; \
28+
echo 'APT::Install-Recommends "false";'; \
29+
echo 'Acquire::Check-Valid-Until "false";'; \
30+
echo 'Acquire::Retries "5";'; \
31+
) > /etc/apt/apt.conf.d/99cpython-portable && \
32+
rm -f /etc/apt/sources.list.d/*
33+
34+
RUN apt-get update
35+
36+
# Host building.
37+
RUN apt-get install \
38+
bzip2 \
39+
ca-certificates \
40+
curl \
41+
gcc \
42+
g++ \
43+
libc6-dev \
44+
libffi-dev \
45+
make \
46+
patch \
47+
perl \
48+
pkg-config \
49+
tar \
50+
xz-utils \
51+
unzip \
52+
zip \
53+
zlib1g-dev
54+
55+
RUN apt-get install \
56+
gcc-loongarch64-linux-gnu \
57+
libc6-dev-loong64-cross
58+
59+
RUN cd /tmp && \
60+
curl -LO https://snapshot.debian.org/archive/debian-ports/20250515T194251Z/pool-loong64/main/libx/libxcrypt/libcrypt-dev_4.4.38-1_loong64.deb && \
61+
curl -LO https://snapshot.debian.org/archive/debian-ports/20250515T194251Z/pool-loong64/main/libx/libxcrypt/libcrypt1_4.4.38-1_loong64.deb && \
62+
dpkg -x libcrypt-dev_4.4.38-1_loong64.deb / && \
63+
dpkg -x libcrypt1_4.4.38-1_loong64.deb / && \
64+
rm -f /tmp/*.deb

0 commit comments

Comments
 (0)