Skip to content
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

Add riscv64-linux support #491

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ jobs:
image:
- build
- build.cross
- build.cross-riscv64
- gcc
- xcb
- xcb.cross
- xcb.cross-riscv64
name: ${{ matrix.image }}
runs-on: depot-ubuntu-22.04
permissions:
Expand Down
21 changes: 21 additions & 0 deletions ci-targets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,27 @@ linux:
- freethreaded+lto
minimum-python-version: "3.13"

riscv64-unknown-linux-gnu:
arch: riscv64
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"

x86_64-unknown-linux-gnu:
arch: x86_64
libc: gnu
Expand Down
3 changes: 3 additions & 0 deletions cpython-unix/build-cpython.sh
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,9 @@ mips64el-unknown-linux-gnuabi64)
ppc64le-unknown-linux-gnu)
PYTHON_ARCH="powerpc64le-linux-gnu"
;;
riscv64-unknown-linux-gnu)
PYTHON_ARCH="riscv64-linux-gnu"
;;
s390x-unknown-linux-gnu)
PYTHON_ARCH="s390x-linux-gnu"
;;
Expand Down
3 changes: 3 additions & 0 deletions cpython-unix/build-libX11.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ if [ -n "${CROSS_COMPILING}" ]; then
ppc64le-unknown-linux-gnu)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
riscv64-unknown-linux-gnu)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
s390x-unknown-linux-gnu)
EXTRA_FLAGS="${EXTRA_FLAGS} --enable-malloc0returnsnull"
;;
Expand Down
2 changes: 2 additions & 0 deletions cpython-unix/build-main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ def main():
"toolchain",
"toolchain-image-build",
"toolchain-image-build.cross",
"toolchain-image-build.cross-riscv64",
"toolchain-image-gcc",
"toolchain-image-xcb",
"toolchain-image-xcb.cross",
"toolchain-image-xcb.cross-riscv64",
},
default="default",
help="The make target to evaluate",
Expand Down
68 changes: 68 additions & 0 deletions cpython-unix/build.cross-riscv64.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Debian Buster.
FROM debian@sha256:2a0c1b9175adf759420fe0fbd7f5b449038319171eb76554bb76cbe172b62b42
MAINTAINER 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_buster debian_buster-updates debian-security_buster/updates; do \
echo "deb http://snapshot.debian.org/archive/${s%_*}/20250109T084424Z/ ${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

RUN apt-get update

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

# Cross-building.
RUN apt-get install \
gcc-aarch64-linux-gnu \
gcc-arm-linux-gnueabi \
gcc-arm-linux-gnueabihf \
gcc-mips-linux-gnu \
gcc-mips64el-linux-gnuabi64 \
gcc-mipsel-linux-gnu \
gcc-powerpc64le-linux-gnu \
gcc-riscv64-linux-gnu \
gcc-s390x-linux-gnu \
libc6-dev-arm64-cross \
libc6-dev-armel-cross \
libc6-dev-armhf-cross \
libc6-dev-mips-cross \
libc6-dev-mips64el-cross \
libc6-dev-mipsel-cross \
libc6-dev-ppc64el-cross \
libc6-dev-riscv64-cross \
libc6-dev-s390x-cross
7 changes: 7 additions & 0 deletions cpython-unix/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,13 @@ def python_build_info(
if mips and version == "3.13":
# See https://github.com/indygreg/python-build-standalone/issues/410
linux_allowed_system_libraries.add("atomic")
riscv = target_triple.split("-")[0] in {"riscv64"}
if riscv:
# RISC-V binary often comes with libatomic on old GCC versions
# See https://github.com/riscvarchive/riscv-gcc/issues/12
# https://github.com/riscvarchive/riscv-gcc/issues/337
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86005
linux_allowed_system_libraries.add("atomic")

# Add in core linking annotations.
libs = extra_metadata["python_config_vars"].get("LIBS", "").split()
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 @@ -259,6 +259,7 @@ _decimal:
targets:
- aarch64-.*
- ppc64le-unknown-linux.*
- riscv64-unknown-linux.*
- s390x-unknown-linux-.*
- x86_64.*
links:
Expand Down
40 changes: 40 additions & 0 deletions cpython-unix/targets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,46 @@ ppc64le-unknown-linux-gnu:
- zlib
openssl_target: linux-ppc64le

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

s390x-unknown-linux-gnu:
host_platforms:
- linux64
Expand Down
3 changes: 3 additions & 0 deletions cpython-unix/xcb.cross-riscv64.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% include 'build.cross-riscv64.Dockerfile' %}
RUN apt-get install \
python
1 change: 1 addition & 0 deletions docs/building.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ As are various other targets::
$ ./build-linux.py --target mips-unknown-linux-gnu
$ ./build-linux.py --target mipsel-unknown-linux-gnu
$ ./build-linux.py --target ppc64le-unknown-linux-gnu
$ ./build-linux.py --target riscv64-unknown-linux-gnu
$ ./build-linux.py --target s390x-unknown-linux-gnu

macOS
Expand Down
13 changes: 13 additions & 0 deletions src/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@ pub static RELEASE_TRIPLES: Lazy<BTreeMap<&'static str, TripleRelease>> = Lazy::
},
);

h.insert(
"riscv64-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(
"s390x-unknown-linux-gnu",
TripleRelease {
Expand Down
8 changes: 8 additions & 0 deletions src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const RECOGNIZED_TRIPLES: &[&str] = &[
"mipsel-unknown-linux-gnu",
"mips64el-unknown-linux-gnuabi64",
"ppc64le-unknown-linux-gnu",
"riscv64-unknown-linux-gnu",
"s390x-unknown-linux-gnu",
"thumbv7k-apple-watchos",
"x86_64-apple-darwin",
Expand Down Expand Up @@ -172,6 +173,10 @@ static GLIBC_MAX_VERSION_BY_TRIPLE: Lazy<HashMap<&'static str, version_compare::
"ppc64le-unknown-linux-gnu",
version_compare::Version::from("2.17").unwrap(),
);
versions.insert(
"riscv64-unknown-linux-gnu",
version_compare::Version::from("2.28").unwrap(),
);
versions.insert(
"s390x-unknown-linux-gnu",
version_compare::Version::from("2.17").unwrap(),
Expand Down Expand Up @@ -233,6 +238,7 @@ static ELF_ALLOWED_LIBRARIES_BY_TRIPLE: Lazy<HashMap<&'static str, Vec<&'static
),
("mips64el-unknown-linux-gnuabi64", vec![]),
("ppc64le-unknown-linux-gnu", vec!["ld64.so.1", "ld64.so.2"]),
("riscv64-unknown-linux-gnu", vec!["ld-linux-riscv64-lp64d.so.1", "libatomic.so.1"]),
("s390x-unknown-linux-gnu", vec!["ld64.so.1"]),
("x86_64-unknown-linux-gnu", vec!["ld-linux-x86-64.so.2"]),
("x86_64_v2-unknown-linux-gnu", vec!["ld-linux-x86-64.so.2"]),
Expand Down Expand Up @@ -488,6 +494,7 @@ static PLATFORM_TAG_BY_TRIPLE: Lazy<HashMap<&'static str, &'static str>> = Lazy:
("mipsel-unknown-linux-gnu", "linux-mipsel"),
("mips64el-unknown-linux-gnuabi64", "todo"),
("ppc64le-unknown-linux-gnu", "linux-powerpc64le"),
("riscv64-unknown-linux-gnu", "linux-riscv64"),
("s390x-unknown-linux-gnu", "linux-s390x"),
("x86_64-apple-darwin", "macosx-10.15-x86_64"),
("x86_64-apple-ios", "iOS-x86_64"),
Expand Down Expand Up @@ -866,6 +873,7 @@ fn validate_elf<Elf: FileHeader<Endian = Endianness>>(
"mipsel-unknown-linux-gnu" => object::elf::EM_MIPS,
"mips64el-unknown-linux-gnuabi64" => 0,
"ppc64le-unknown-linux-gnu" => object::elf::EM_PPC64,
"riscv64-unknown-linux-gnu" => object::elf::EM_RISCV,
"s390x-unknown-linux-gnu" => object::elf::EM_S390,
"x86_64-unknown-linux-gnu" => object::elf::EM_X86_64,
"x86_64_v2-unknown-linux-gnu" => object::elf::EM_X86_64,
Expand Down
Loading