Skip to content

Commit ee98fac

Browse files
Add loongarch64-linux support
Signed-off-by: 吴小白 <296015668@qq.com>
1 parent 684cb94 commit ee98fac

17 files changed

+238
-5
lines changed

ci-matrix.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
{"name": "build", "arch": "x86_64"},
2626
{"name": "build.cross", "arch": "x86_64"},
2727
{"name": "build.cross-riscv64", "arch": "x86_64"},
28+
{"name": "build.cross-loongarch64", "arch": "x86_64"},
2829
{"name": "build.debian9", "arch": "aarch64"},
2930
{"name": "gcc", "arch": "x86_64"},
3031
{"name": "gcc.debian9", "arch": "aarch64"},

ci-targets.yaml

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

102+
loongarch64-unknown-linux-gnu:
103+
arch: loongarch64
104+
libc: gnu
105+
python_versions:
106+
- "3.9"
107+
- "3.10"
108+
- "3.11"
109+
- "3.12"
110+
- "3.13"
111+
- "3.14"
112+
build_options:
113+
- debug
114+
- noopt
115+
- lto
116+
build_options_conditional:
117+
- options:
118+
- freethreaded+debug
119+
- freethreaded+noopt
120+
- freethreaded+lto
121+
minimum-python-version: "3.13"
122+
102123
s390x-unknown-linux-gnu:
103124
arch: s390x
104125
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
@@ -1094,6 +1103,9 @@ armv7-unknown-linux-gnueabi)
10941103
armv7-unknown-linux-gnueabihf)
10951104
PYTHON_ARCH="arm-linux-gnueabihf"
10961105
;;
1106+
loongarch64-unknown-linux-gnu)
1107+
PYTHON_ARCH="loongarch64-linux-gnu"
1108+
;;
10971109
mips-unknown-linux-gnu)
10981110
PYTHON_ARCH="mips-linux-gnu"
10991111
;;
@@ -1251,7 +1263,8 @@ if [ -d "${TOOLS_PATH}/deps/lib/tcl8" ]; then
12511263
cp -av $source ${ROOT}/out/python/install/lib/
12521264
done
12531265

1254-
if [[ "${PYBUILD_PLATFORM}" != macos* ]]; then
1266+
# Tix doesn't support macOS and loongarch64, so we don't copy it there.
1267+
if [[ "${PYBUILD_PLATFORM}" != macos* ]] && [[ "${TARGET_TRIPLE}" != loongarch64* ]]; then
12551268
cp -av ${TOOLS_PATH}/deps/lib/Tix8.4.3 ${ROOT}/out/python/install/lib/
12561269
fi
12571270
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

100755100644
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,9 @@ 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-build.debian9",
99100
"toolchain-image-gcc",
100-
"toolchain-image-xcb",
101-
"toolchain-image-xcb.cross",
102-
"toolchain-image-xcb.cross-riscv64",
103101
},
104102
default="default",
105103
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 <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_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)