Skip to content

Commit 96a589a

Browse files
authored
cross compile riscv64 with LLVM toolchain and sysroot (#1116)
Use the same LLVM toolchain that is used for native x86-64 builds to cross compile for riscv64 using a sysroot.
1 parent f0ae464 commit 96a589a

2 files changed

Lines changed: 19 additions & 34 deletions

File tree

cpython-unix/build.cross-riscv64.Dockerfile

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ RUN for s in debian_buster debian_buster-updates debian-security_buster/updates;
2929

3030
RUN apt-get update
3131

32-
# Host building.
32+
# Build tools, same as in build.Dockerfile
3333
RUN apt-get install \
3434
bzip2 \
35-
gcc \
36-
g++ \
35+
ca-certificates \
36+
curl \
37+
file \
3738
libc6-dev \
3839
libffi-dev \
3940
make \
@@ -46,32 +47,15 @@ RUN apt-get install \
4647
zip \
4748
zlib1g-dev
4849

49-
# Cross-building.
50+
# riscv64 sysroot and host binutils for the riscv64-linux-gnu target
5051
RUN apt-get install \
51-
g++-aarch64-linux-gnu \
52-
g++-arm-linux-gnueabi \
53-
g++-arm-linux-gnueabihf \
54-
g++-mips-linux-gnu \
55-
g++-mips64el-linux-gnuabi64 \
56-
g++-mipsel-linux-gnu \
57-
g++-powerpc64le-linux-gnu \
58-
g++-riscv64-linux-gnu \
59-
g++-s390x-linux-gnu \
60-
gcc-aarch64-linux-gnu \
61-
gcc-arm-linux-gnueabi \
62-
gcc-arm-linux-gnueabihf \
63-
gcc-mips-linux-gnu \
64-
gcc-mips64el-linux-gnuabi64 \
65-
gcc-mipsel-linux-gnu \
66-
gcc-powerpc64le-linux-gnu \
67-
gcc-riscv64-linux-gnu \
68-
gcc-s390x-linux-gnu \
69-
libc6-dev-arm64-cross \
70-
libc6-dev-armel-cross \
71-
libc6-dev-armhf-cross \
72-
libc6-dev-mips-cross \
73-
libc6-dev-mips64el-cross \
74-
libc6-dev-mipsel-cross \
75-
libc6-dev-ppc64el-cross \
52+
binutils-riscv64-linux-gnu \
53+
libc6-riscv64-cross \
7654
libc6-dev-riscv64-cross \
77-
libc6-dev-s390x-cross
55+
linux-libc-dev-riscv64-cross \
56+
libgcc1-riscv64-cross \
57+
libgcc-8-dev-riscv64-cross
58+
59+
# target specific symlinks to cross-compile using external LLVM toolchain
60+
RUN ln -s /tools/llvm/bin/clang /usr/bin/riscv64-linux-gnu-clang && \
61+
ln -s /tools/llvm/bin/clang++ /usr/bin/riscv64-linux-gnu-clang++

cpython-unix/targets.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,12 @@ riscv64-unknown-linux-gnu:
445445
- '3.13'
446446
- '3.14'
447447
- '3.15'
448+
needs_toolchain: true
448449
docker_image_suffix: .cross-riscv64
449-
host_cc: /usr/bin/x86_64-linux-gnu-gcc
450-
host_cxx: /usr/bin/x86_64-linux-gnu-g++
451-
target_cc: /usr/bin/riscv64-linux-gnu-gcc
452-
target_cxx: /usr/bin/riscv64-linux-gnu-g++
450+
host_cc: clang
451+
host_cxx: clang++
452+
target_cc: /usr/bin/riscv64-linux-gnu-clang
453+
target_cxx: /usr/bin/riscv64-linux-gnu-clang++
453454
target_ldflags:
454455
# Hardening
455456
- '-Wl,-z,noexecstack'

0 commit comments

Comments
 (0)