Skip to content

Add loongarch64-linux support #653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci-matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
{"name": "build", "arch": "x86_64"},
{"name": "build.cross", "arch": "x86_64"},
{"name": "build.cross-riscv64", "arch": "x86_64"},
{"name": "build.cross-loongarch64", "arch": "x86_64"},
{"name": "build.debian9", "arch": "aarch64"},
{"name": "gcc", "arch": "x86_64"},
{"name": "gcc.debian9", "arch": "aarch64"},
Expand Down
21 changes: 21 additions & 0 deletions ci-targets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ linux:
- freethreaded+lto
minimum-python-version: "3.13"

loongarch64-unknown-linux-gnu:
arch: loongarch64
libc: gnu
python_versions:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"
build_options:
- debug
- noopt
- lto
build_options_conditional:
- options:
- freethreaded+debug
- freethreaded+noopt
- freethreaded+lto
minimum-python-version: "3.13"

s390x-unknown-linux-gnu:
arch: s390x
libc: gnu
Expand Down
2 changes: 1 addition & 1 deletion cpython-unix/base.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Debian Jessie.
FROM debian@sha256:32ad5050caffb2c7e969dac873bce2c370015c2256ff984b70c1c08b3a2816a0
MAINTAINER Gregory Szorc <[email protected]>
LABEL org.opencontainers.image.authors="Gregory Szorc <[email protected]>"

RUN groupadd -g 1000 build && \
useradd -u 1000 -g 1000 -d /build -s /bin/bash -m build && \
Expand Down
2 changes: 1 addition & 1 deletion cpython-unix/base.debian9.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Debian Stretch.
FROM debian@sha256:c5c5200ff1e9c73ffbf188b4a67eb1c91531b644856b4aefe86a58d2f0cb05be
MAINTAINER Gregory Szorc <[email protected]>
LABEL org.opencontainers.image.authors="Gregory Szorc <[email protected]>"

RUN groupadd -g 1000 build && \
useradd -u 1000 -g 1000 -d /build -s /bin/bash -m build && \
Expand Down
12 changes: 12 additions & 0 deletions cpython-unix/build-cpython.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then
fi
fi

# configure doesn't support cross-compiling on LoongArch. Teach it.
if [ "${PYBUILD_PLATFORM}" != "macos" ]; then
case "${PYTHON_MAJMIN_VERSION}" in
3.9|3.10|3.11)
patch -p1 -i ${ROOT}/patch-configure-add-loongarch-triplet.patch
;;
esac
fi

# disable readelf check when cross-compiling on older Python versions
if [ -n "${CROSS_COMPILING}" ]; then
if [ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_11}" ]; then
Expand Down Expand Up @@ -1091,6 +1100,9 @@ armv7-unknown-linux-gnueabi)
armv7-unknown-linux-gnueabihf)
PYTHON_ARCH="arm-linux-gnueabihf"
;;
loongarch64-unknown-linux-gnu)
PYTHON_ARCH="loongarch64-linux-gnu"
;;
mips-unknown-linux-gnu)
PYTHON_ARCH="mips-linux-gnu"
;;
Expand Down
6 changes: 6 additions & 0 deletions cpython-unix/build-libX11.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ if [ -n "${CROSS_COMPILING}" ]; then
armv7-unknown-linux-gnueabihf)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
loongarch64-unknown-linux-gnu)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
mips-unknown-linux-gnu)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
Expand All @@ -78,6 +81,9 @@ if [ -n "${CROSS_COMPILING}" ]; then
aarch64-unknown-linux-musl)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
loongarch64-unknown-linux-musl)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
mips-unknown-linux-musl)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
Expand Down
6 changes: 6 additions & 0 deletions cpython-unix/build-libxcb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export PKG_CONFIG_PATH=/tools/deps/share/pkgconfig:/tools/deps/lib/pkgconfig
tar -xf libxcb-${LIBXCB_VERSION}.tar.gz
pushd libxcb-${LIBXCB_VERSION}

if [[ "${TARGET_TRIPLE}" = loongarch64* ]]; then
rm -f build-aux/config.guess build-aux/config.sub
curl -sSL -o build-aux/config.guess 'https://git.savannah.gnu.org/cgit/config.git/plain/config.guess'
curl -sSL -o build-aux/config.sub 'https://git.savannah.gnu.org/cgit/config.git/plain/config.sub'
fi

if [ "${CC}" = "musl-clang" ]; then
EXTRA_FLAGS="--disable-shared"
fi
Expand Down
1 change: 1 addition & 0 deletions cpython-unix/build-main.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def main():
"toolchain-image-build",
"toolchain-image-build.cross",
"toolchain-image-build.cross-riscv64",
"toolchain-image-build.cross-loongarch64",
"toolchain-image-build.debian9",
"toolchain-image-gcc",
"toolchain-image-xcb",
Expand Down
2 changes: 2 additions & 0 deletions cpython-unix/build-ncurses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ else
"
fi

mkdir -p ${ROOT}/out/usr/lib

CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" LDFLAGS="${EXTRA_TARGET_LDFLAGS}" ./configure ${CONFIGURE_FLAGS}
make -j ${NUM_CPUS}
make -j ${NUM_CPUS} install DESTDIR=${ROOT}/out
Expand Down
6 changes: 6 additions & 0 deletions cpython-unix/build-xorgproto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export PKG_CONFIG_PATH=/tools/deps/share/pkgconfig
tar -xf xorgproto-${XORGPROTO_VERSION}.tar.gz
pushd xorgproto-${XORGPROTO_VERSION}

if [[ "${TARGET_TRIPLE}" = loongarch64* ]]; then
rm -f config.guess.sub config.sub
curl -sSL -o config.guess 'https://git.savannah.gnu.org/cgit/config.git/plain/config.guess'
curl -sSL -o config.sub 'https://git.savannah.gnu.org/cgit/config.git/plain/config.sub'
fi

CFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" CPPFLAGS="${EXTRA_TARGET_CFLAGS} -fPIC" LDFLAGS="${EXTRA_TARGET_LDFLAGS}" ./configure \
--build=${BUILD_TRIPLE} \
--host=${TARGET_TRIPLE} \
Expand Down
2 changes: 2 additions & 0 deletions cpython-unix/build.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# Various other build tools are needed for various building.
RUN ulimit -n 10000 && apt-get install \
bzip2 \
ca-certificates \
curl \
file \
libc6-dev \
libffi-dev \
Expand Down
64 changes: 64 additions & 0 deletions cpython-unix/build.cross-loongarch64.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Debian Trixie.
FROM debian@sha256:5e64db7e29879fbb479ab2c6324656c9c0e489423e4885ed7e2f22c5b58a7a9b
LABEL org.opencontainers.image.authors="Gregory Szorc <[email protected]>"

RUN groupadd -g 1000 build && \
useradd -u 1000 -g 1000 -d /build -s /bin/bash -m build && \
mkdir /tools && \
chown -R build:build /build /tools

ENV HOME=/build \
SHELL=/bin/bash \
USER=build \
LOGNAME=build \
HOSTNAME=builder \
DEBIAN_FRONTEND=noninteractive

CMD ["/bin/bash", "--login"]
WORKDIR '/build'

RUN for s in debian_trixie debian_trixie-updates; do \
echo "deb http://snapshot.debian.org/archive/${s%_*}/20240812T212427Z/ ${s#*_} main"; \
done > /etc/apt/sources.list && \
for s in debian-security_trixie-security/updates; do \
echo "deb http://snapshot.debian.org/archive/${s%_*}/20240813T064849Z/ ${s#*_} main"; \
done >> /etc/apt/sources.list && \
( echo 'quiet "true";'; \
echo 'APT::Get::Assume-Yes "true";'; \
echo 'APT::Install-Recommends "false";'; \
echo 'Acquire::Check-Valid-Until "false";'; \
echo 'Acquire::Retries "5";'; \
) > /etc/apt/apt.conf.d/99cpython-portable && \
rm -f /etc/apt/sources.list.d/*

RUN apt-get update

# Host building.
RUN apt-get install \
bzip2 \
ca-certificates \
curl \
gcc \
g++ \
libc6-dev \
libffi-dev \
make \
patch \
perl \
pkg-config \
tar \
xz-utils \
unzip \
zip \
zlib1g-dev

RUN apt-get install \
gcc-loongarch64-linux-gnu \
libc6-dev-loong64-cross

RUN cd /tmp && \
curl -LO https://snapshot.debian.org/archive/debian-ports/20240812T192057Z/pool-loong64/main/libx/libxcrypt/libcrypt-dev_4.4.36-4_loong64.deb && \
curl -LO https://snapshot.debian.org/archive/debian-ports/20240812T192057Z/pool-loong64/main/libx/libxcrypt/libcrypt1_4.4.36-4_loong64.deb && \
dpkg -x libcrypt-dev_4.4.36-4_loong64.deb / && \
dpkg -x libcrypt1_4.4.36-4_loong64.deb / && \
rm -f /tmp/*.deb
2 changes: 1 addition & 1 deletion cpython-unix/build.cross-riscv64.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Debian Buster.
FROM debian@sha256:2a0c1b9175adf759420fe0fbd7f5b449038319171eb76554bb76cbe172b62b42
MAINTAINER Gregory Szorc <[email protected]>
LABEL org.opencontainers.image.authors="Gregory Szorc <[email protected]>"

RUN groupadd -g 1000 build && \
useradd -u 1000 -g 1000 -d /build -s /bin/bash -m build && \
Expand Down
2 changes: 1 addition & 1 deletion cpython-unix/build.cross.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Debian Stretch.
FROM debian@sha256:cebe6e1c30384958d471467e231f740e8f0fd92cbfd2a435a186e9bada3aee1c
MAINTAINER Gregory Szorc <[email protected]>
LABEL org.opencontainers.image.authors="Gregory Szorc <[email protected]>"

RUN groupadd -g 1000 build && \
useradd -u 1000 -g 1000 -d /build -s /bin/bash -m build && \
Expand Down
1 change: 1 addition & 0 deletions cpython-unix/extension-modules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ _decimal:
- define: CONFIG_64=1
targets:
- aarch64-.*
- loongarch64-unknown-linux.*
- ppc64le-unknown-linux.*
- riscv64-unknown-linux.*
- s390x-unknown-linux-.*
Expand Down
50 changes: 50 additions & 0 deletions cpython-unix/patch-configure-add-loongarch-triplet.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
diff --git a/configure b/configure
index b7be60e..d799415 100755
--- a/configure
+++ b/configure
@@ -5261,6 +5261,20 @@ cat >> conftest.c <<EOF
hppa-linux-gnu
# elif defined(__ia64__)
ia64-linux-gnu
+# elif defined(__loongarch__)
+# if defined(__loongarch_lp64)
+# if defined(__loongarch_soft_float)
+ loongarch64-linux-gnusf
+# elif defined(__loongarch_single_float)
+ loongarch64-linux-gnuf32
+# elif defined(__loongarch_double_float)
+ loongarch64-linux-gnu
+# else
+# error unknown platform triplet
+# endif
+# else
+# error unknown platform triplet
+# endif
# elif defined(__m68k__) && !defined(__mcoldfire__)
m68k-linux-gnu
# elif defined(__mips_hard_float) && defined(__mips_isa_rev) && (__mips_isa_rev >=6) && defined(_MIPSEL)
diff --git a/configure.ac b/configure.ac
index aa515da..b5bad6e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -779,6 +779,20 @@ cat >> conftest.c <<EOF
hppa-linux-gnu
# elif defined(__ia64__)
ia64-linux-gnu
+# elif defined(__loongarch__)
+# if defined(__loongarch_lp64)
+# if defined(__loongarch_soft_float)
+ loongarch64-linux-gnusf
+# elif defined(__loongarch_single_float)
+ loongarch64-linux-gnuf32
+# elif defined(__loongarch_double_float)
+ loongarch64-linux-gnu
+# else
+# error unknown platform triplet
+# endif
+# else
+# error unknown platform triplet
+# endif
# elif defined(__m68k__) && !defined(__mcoldfire__)
m68k-linux-gnu
# elif defined(__mips_hard_float) && defined(__mips_isa_rev) && (__mips_isa_rev >=6) && defined(_MIPSEL)
41 changes: 41 additions & 0 deletions cpython-unix/targets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,47 @@ armv7-unknown-linux-gnueabihf:
- zstd
openssl_target: linux-armv4

loongarch64-unknown-linux-gnu:
host_platforms:
- linux_x86_64
pythons_supported:
- '3.9'
- '3.10'
- '3.11'
- '3.12'
- '3.13'
- '3.14'
docker_image_suffix: .cross-loongarch64
host_cc: /usr/bin/x86_64-linux-gnu-gcc
host_cxx: /usr/bin/x86_64-linux-gnu-g++
target_cc: /usr/bin/loongarch64-linux-gnu-gcc
target_cxx: /usr/bin/loongarch64-linux-gnu-g++
needs:
- autoconf
- bdb
- binutils
- bzip2
- expat
- libedit
- libffi
- libX11
- libXau
- libxcb
- m4
- mpdecimal
- ncurses
- openssl-3.0
- patchelf
- sqlite
- tcl
- tk
- uuid
- xorgproto
- xz
- zlib
- zstd
openssl_target: linux64-loongarch64

mips-unknown-linux-gnu:
host_platforms:
- linux_x86_64
Expand Down
1 change: 1 addition & 0 deletions docs/building.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ As are various other targets::
$ ./build-linux.py --target aarch64-unknown-linux-gnu
$ ./build-linux.py --target armv7-unknown-linux-gnueabi
$ ./build-linux.py --target armv7-unknown-linux-gnueabihf
$ ./build-linux.py --target loongarch64-unknown-linux-gnu
$ ./build-linux.py --target mips-unknown-linux-gnu
$ ./build-linux.py --target mipsel-unknown-linux-gnu
$ ./build-linux.py --target ppc64le-unknown-linux-gnu
Expand Down
13 changes: 13 additions & 0 deletions src/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,19 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
},
);

h.insert(
"loongarch64-unknown-linux-gnu",
TripleRelease {
suffixes: linux_suffixes_nopgo.clone(),
install_only_suffix: "lto",
python_version_requirement: Some(VersionSpecifier::from_str(">=3.9").unwrap()),
conditional_suffixes: vec![ConditionalSuffixes {
python_version_requirement: VersionSpecifier::from_str(">=3.13").unwrap(),
suffixes: linux_suffixes_nopgo_freethreaded.clone(),
}],
},
);

h.insert(
"ppc64le-unknown-linux-gnu",
TripleRelease {
Expand Down
Loading
Loading