From 5c012f598c320ebfde4a280d93216541466ab0b9 Mon Sep 17 00:00:00 2001 From: E Shattow Date: Thu, 28 May 2026 14:23:28 -0700 Subject: [PATCH 1/3] Promote riscv64-unknown-linux-musl to tier 2 with host tools Implements MCP 982 via issue 156191 --- .../targets/riscv64gc_unknown_linux_musl.rs | 2 +- src/bootstrap/src/core/build_steps/llvm.rs | 1 + src/bootstrap/src/core/download.rs | 1 + src/ci/docker/README.md | 16 +++++++ .../Dockerfile | 2 +- .../riscv64-unknown-linux-gnu.defconfig | 0 .../dist-riscv64-linux-musl/Dockerfile | 39 ++++++++++++++++ .../riscv64-unknown-linux-musl.defconfig | 16 +++++++ src/ci/github-actions/jobs.yml | 5 +- src/doc/rustc/src/platform-support.md | 2 +- .../riscv64gc-unknown-linux-gnu.md | 15 +++--- .../riscv64gc-unknown-linux-musl.md | 46 +++++++++++-------- 12 files changed, 116 insertions(+), 29 deletions(-) rename src/ci/docker/host-x86_64/{dist-riscv64-linux => dist-riscv64-linux-gnu}/Dockerfile (92%) rename src/ci/docker/host-x86_64/{dist-riscv64-linux => dist-riscv64-linux-gnu}/riscv64-unknown-linux-gnu.defconfig (100%) create mode 100644 src/ci/docker/host-x86_64/dist-riscv64-linux-musl/Dockerfile create mode 100644 src/ci/docker/host-x86_64/dist-riscv64-linux-musl/riscv64-unknown-linux-musl.defconfig diff --git a/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_linux_musl.rs index 8ed4e09adbbfe..088d4821042d8 100644 --- a/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_linux_musl.rs +++ b/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_linux_musl.rs @@ -10,7 +10,7 @@ pub(crate) fn target() -> Target { metadata: TargetMetadata { description: Some("RISC-V Linux (kernel 4.20, musl 1.2.5)".into()), tier: Some(2), - host_tools: Some(false), + host_tools: Some(true), std: Some(true), }, pointer_width: 64, diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 572df47d3a62c..b13759cfdaa25 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -248,6 +248,7 @@ pub(crate) fn is_ci_llvm_available_for_target( ("powerpc64le-unknown-linux-gnu", false), ("powerpc64le-unknown-linux-musl", false), ("riscv64gc-unknown-linux-gnu", false), + ("riscv64gc-unknown-linux-musl", false), ("s390x-unknown-linux-gnu", false), ("x86_64-pc-windows-gnullvm", false), ("x86_64-unknown-freebsd", false), diff --git a/src/bootstrap/src/core/download.rs b/src/bootstrap/src/core/download.rs index 76fd2cb0bc14b..4058f1482a951 100644 --- a/src/bootstrap/src/core/download.rs +++ b/src/bootstrap/src/core/download.rs @@ -481,6 +481,7 @@ pub(crate) fn is_download_ci_available(target_triple: &str, llvm_assertions: boo "powerpc64le-unknown-linux-gnu", "powerpc64le-unknown-linux-musl", "riscv64gc-unknown-linux-gnu", + "riscv64gc-unknown-linux-musl", "s390x-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-gnu", diff --git a/src/ci/docker/README.md b/src/ci/docker/README.md index 6e5a38a3c515a..b113adc2008cd 100644 --- a/src/ci/docker/README.md +++ b/src/ci/docker/README.md @@ -462,6 +462,22 @@ For targets: `riscv64-unknown-linux-gnu` - C compiler > gcc version = 8.5.0 - C compiler > C++ = ENABLE -- to cross compile LLVM +### `riscv64-unknown-linux-musl.defconfig` + +For targets: `riscv64-unknown-linux-musl` + +- Path and misc options > Prefix directory = /x-tools/${CT\_TARGET} +- Path and misc options > Use a mirror = ENABLE +- Path and misc options > Base URL = https://ci-mirrors.rust-lang.org/rustc +- Target options > Target Architecture = riscv +- Target options > Bitness = 64-bit +- Operating System > Target OS = linux +- Operating System > Linux kernel version = 4.20.17 +- Binary utilities > Version of binutils = 2.40 +- C-library > musl version = 1.2.5 +- C compiler > gcc version = 8.5.0 +- C compiler > C++ = ENABLE -- to cross compile LLVM + ### `s390x-linux-gnu.defconfig` For targets: `s390x-unknown-linux-gnu` diff --git a/src/ci/docker/host-x86_64/dist-riscv64-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-riscv64-linux-gnu/Dockerfile similarity index 92% rename from src/ci/docker/host-x86_64/dist-riscv64-linux/Dockerfile rename to src/ci/docker/host-x86_64/dist-riscv64-linux-gnu/Dockerfile index 5186c99c4f430..57f3b68a96e3f 100644 --- a/src/ci/docker/host-x86_64/dist-riscv64-linux/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-riscv64-linux-gnu/Dockerfile @@ -12,7 +12,7 @@ RUN sh /scripts/rustbuild-setup.sh WORKDIR /tmp COPY scripts/crosstool-ng-build.sh /scripts/ -COPY host-x86_64/dist-riscv64-linux/riscv64-unknown-linux-gnu.defconfig /tmp/crosstool.defconfig +COPY host-x86_64/dist-riscv64-linux-gnu/riscv64-unknown-linux-gnu.defconfig /tmp/crosstool.defconfig RUN /scripts/crosstool-ng-build.sh COPY scripts/sccache.sh /scripts/ diff --git a/src/ci/docker/host-x86_64/dist-riscv64-linux/riscv64-unknown-linux-gnu.defconfig b/src/ci/docker/host-x86_64/dist-riscv64-linux-gnu/riscv64-unknown-linux-gnu.defconfig similarity index 100% rename from src/ci/docker/host-x86_64/dist-riscv64-linux/riscv64-unknown-linux-gnu.defconfig rename to src/ci/docker/host-x86_64/dist-riscv64-linux-gnu/riscv64-unknown-linux-gnu.defconfig diff --git a/src/ci/docker/host-x86_64/dist-riscv64-linux-musl/Dockerfile b/src/ci/docker/host-x86_64/dist-riscv64-linux-musl/Dockerfile new file mode 100644 index 0000000000000..bb7537fc7d279 --- /dev/null +++ b/src/ci/docker/host-x86_64/dist-riscv64-linux-musl/Dockerfile @@ -0,0 +1,39 @@ +FROM ubuntu:22.04 + +COPY scripts/cross-apt-packages.sh /scripts/ +RUN sh /scripts/cross-apt-packages.sh + +COPY scripts/crosstool-ng.sh /scripts/ +COPY scripts/crosstool-ng-sha256-20260705.diff /scripts/ +RUN sh /scripts/crosstool-ng.sh + +COPY scripts/rustbuild-setup.sh /scripts/ +RUN sh /scripts/rustbuild-setup.sh + +WORKDIR /tmp + +COPY scripts/crosstool-ng-build.sh /scripts/ +COPY host-x86_64/dist-riscv64-linux-musl/riscv64-unknown-linux-musl.defconfig /tmp/crosstool.defconfig +RUN /scripts/crosstool-ng-build.sh + +COPY scripts/sccache.sh /scripts/ +RUN sh /scripts/sccache.sh + +ENV PATH=$PATH:/x-tools/riscv64-unknown-linux-musl/bin + +ENV CC_riscv64gc_unknown_linux_musl=riscv64-unknown-linux-musl-gcc \ + AR_riscv64gc_unknown_linux_musl=riscv64-unknown-linux-musl-ar \ + CXX_riscv64gc_unknown_linux_musl=riscv64-unknown-linux-musl-g++ + +ENV HOSTS=riscv64gc-unknown-linux-musl +ENV TARGETS=riscv64gc-unknown-linux-musl + +ENV RUST_CONFIGURE_ARGS="--enable-extended \ + --enable-full-tools \ + --enable-profiler \ + --enable-sanitizers \ + --disable-docs \ + --set target.riscv64gc-unknown-linux-musl.crt-static=false \ + --musl-root-riscv64gc=/x-tools/riscv64-unknown-linux-musl/riscv64-unknown-linux-musl/sysroot/usr" + +ENV SCRIPT="python3 ../x.py dist --target $TARGETS --host $HOSTS" diff --git a/src/ci/docker/host-x86_64/dist-riscv64-linux-musl/riscv64-unknown-linux-musl.defconfig b/src/ci/docker/host-x86_64/dist-riscv64-linux-musl/riscv64-unknown-linux-musl.defconfig new file mode 100644 index 0000000000000..435a2bea80d36 --- /dev/null +++ b/src/ci/docker/host-x86_64/dist-riscv64-linux-musl/riscv64-unknown-linux-musl.defconfig @@ -0,0 +1,16 @@ +CT_CONFIG_VERSION="4" +CT_PREFIX_DIR="/x-tools/${CT_TARGET}" +CT_USE_MIRROR=y +CT_MIRROR_BASE_URL="https://ci-mirrors.rust-lang.org/rustc" +CT_VERIFY_DOWNLOAD_DIGEST_SHA256=y +CT_ARCH_RISCV=y +CT_ARCH_USE_MMU=y +CT_ARCH_64=y +CT_ARCH_ARCH="rv64gc" +CT_KERNEL_LINUX=y +CT_LINUX_V_4_20=y +CT_LIBC_MUSL=y +CT_BINUTILS_V_2_40=y +CT_MUSL_V_1_2_5=y +CT_GCC_V_8=y +CT_CC_LANG_CXX=y diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index a236effaa9b40..c374888ac8909 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -270,7 +270,10 @@ auto: - name: dist-powerpc64le-linux-musl <<: *job-linux-4c - - name: dist-riscv64-linux + - name: dist-riscv64-linux-gnu + <<: *job-linux-4c + + - name: dist-riscv64-linux-musl <<: *job-linux-4c - name: dist-s390x-linux diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index ce4d55c2d2b00..c527911bc96a2 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -105,6 +105,7 @@ target | notes [`powerpc64le-unknown-linux-gnu`](platform-support/powerpc64le-unknown-linux-gnu.md) | PPC64LE Linux (kernel 3.10+, glibc 2.17) [`powerpc64le-unknown-linux-musl`](platform-support/powerpc64le-unknown-linux-musl.md) | PPC64LE Linux (kernel 4.19+, musl 1.2.5) [`riscv64gc-unknown-linux-gnu`](platform-support/riscv64gc-unknown-linux-gnu.md) | RISC-V Linux (kernel 4.20+, glibc 2.29) +[`riscv64gc-unknown-linux-musl`](platform-support/riscv64gc-unknown-linux-musl.md) | RISC-V Linux (kernel 4.20+, musl 1.2.5) [`s390x-unknown-linux-gnu`](platform-support/s390x-unknown-linux-gnu.md) | S390x Linux (kernel 3.2+, glibc 2.17) [`x86_64-apple-darwin`](platform-support/apple-darwin.md) | 64-bit macOS (10.12+, Sierra+) [`x86_64-pc-windows-gnullvm`](platform-support/windows-gnullvm.md) | 64-bit x86 MinGW (Windows 10+), LLVM ABI @@ -196,7 +197,6 @@ target | std | notes [`riscv32imafc-unknown-none-elf`](platform-support/riscv32-unknown-none-elf.md) | * | Bare RISC-V (RV32IMAFC ISA) [`riscv32imc-unknown-none-elf`](platform-support/riscv32-unknown-none-elf.md) | * | Bare RISC-V (RV32IMC ISA) [`riscv64a23-unknown-linux-gnu`](platform-support/riscv64a23-unknown-linux-gnu.md) | ✓ | RISC-V Linux (kernel 6.8.0+, glibc 2.39) -[`riscv64gc-unknown-linux-musl`](platform-support/riscv64gc-unknown-linux-musl.md) | ✓ |RISC-V Linux (kernel 4.20+, musl 1.2.5) `riscv64gc-unknown-none-elf` | * | Bare RISC-V (RV64IMAFDC ISA) [`riscv64im-unknown-none-elf`](platform-support/riscv64im-unknown-none-elf.md) | * | Bare RISC-V (RV64IM ISA) `riscv64imac-unknown-none-elf` | * | Bare RISC-V (RV64IMAC ISA) diff --git a/src/doc/rustc/src/platform-support/riscv64gc-unknown-linux-gnu.md b/src/doc/rustc/src/platform-support/riscv64gc-unknown-linux-gnu.md index d62a65b21904f..119c3053cda7e 100644 --- a/src/doc/rustc/src/platform-support/riscv64gc-unknown-linux-gnu.md +++ b/src/doc/rustc/src/platform-support/riscv64gc-unknown-linux-gnu.md @@ -2,7 +2,8 @@ **Tier: 2 (with Host Tools)** -RISC-V targets using the *RV64I* base instruction set with the *G* collection of extensions, as well as the *C* extension. +Linux GNU libc RISC-V target using the *RV64I* base instruction set with the +*G* collection of extensions, as well as the *C* extension. ## Target maintainers @@ -22,10 +23,10 @@ This target requires: ## Building the target -These targets are distributed through `rustup`, and otherwise require no +This target is distributed through `rustup`, and otherwise requires no special configuration. -If you need to build your own Rust for some reason though, the targets can be +If you need to build your own Rust for some reason though, the target can be enabled in `bootstrap.toml`. For example: ```toml @@ -37,10 +38,10 @@ target = ["riscv64gc-unknown-linux-gnu"] ## Building Rust programs -On a RISC-V host, the `riscv64gc-unknown-linux-gnu` target should be automatically -installed and used by default. +On a riscv64gc-unknown-linux-gnu host, the `riscv64gc-unknown-linux-gnu` +target should be automatically installed and used by default. -On a non-RISC-V host, add the target: +On all other hosts, add the target: ```bash rustup target add riscv64gc-unknown-linux-gnu @@ -55,7 +56,7 @@ cargo build --target riscv64gc-unknown-linux-gnu ## Testing -There are no special requirements for testing and running the targets. +There are no special requirements for testing and running the target. For testing cross builds on the host, please refer to the "Cross-compilation toolchains and C code" section below. diff --git a/src/doc/rustc/src/platform-support/riscv64gc-unknown-linux-musl.md b/src/doc/rustc/src/platform-support/riscv64gc-unknown-linux-musl.md index 2e88b5aa813ff..4ac2a894117c1 100644 --- a/src/doc/rustc/src/platform-support/riscv64gc-unknown-linux-musl.md +++ b/src/doc/rustc/src/platform-support/riscv64gc-unknown-linux-musl.md @@ -1,8 +1,10 @@ # riscv64gc-unknown-linux-musl -**Tier: 2** +**Tier: 2 (with Host Tools)** + +Linux musl libc RISC-V target using the *RV64I* base instruction set with the +*G* collection of extensions, as well as the *C* extension. -Target for RISC-V Linux programs using musl libc. ## Target maintainers @@ -11,37 +13,45 @@ Target for RISC-V Linux programs using musl libc. ## Requirements -Building the target itself requires a RISC-V compiler that is supported by `cc-rs`. +This target requires: + +* Linux Kernel version 4.20 or later +* musl libc 1.2.5 or later + ## Building the target -The target can be built by enabling it for a `rustc` build. +This target is distributed through `rustup`, and otherwise requires no +special configuration. + +If you need to build your own Rust then the targets can be enabled in +`bootstrap.toml`. For example: ```toml [build] target = ["riscv64gc-unknown-linux-musl"] ``` -Make sure your C compiler is included in `$PATH`, then add it to the `bootstrap.toml`: - -```toml -[target.riscv64gc-unknown-linux-musl] -cc = "riscv64-linux-gnu-gcc" -cxx = "riscv64-linux-gnu-g++" -ar = "riscv64-linux-gnu-ar" -linker = "riscv64-linux-gnu-gcc" -``` ## Building Rust programs -This target are distributed through `rustup`, and otherwise require no -special configuration. -## Cross-compilation +On a riscv64gc-unknown-linux-musl host, the `riscv64gc-unknown-linux-musl` +target should be automatically installed and used by default. -This target can be cross-compiled from any host. +On all other hosts, add the target: + +```bash +rustup target add riscv64gc-unknown-linux-musl +``` + +Then cross compile crates with: + +```bash +cargo build --target riscv64gc-unknown-linux-musl +``` ## Testing -This target can be tested as normal with `x.py` on a RISC-V host or via QEMU +The target can be tested as normal with `x.py` on a RISC-V host or via QEMU emulation. From 3086aff340346d1ef047dd556298e66532eb4983 Mon Sep 17 00:00:00 2001 From: MarcoIeni <11428655+MarcoIeni@users.noreply.github.com> Date: Tue, 21 Jul 2026 23:50:26 +0200 Subject: [PATCH 2/3] don't build riscv64gc-unknown-linux-musl twice --- .../docker/host-x86_64/dist-various-2/Dockerfile | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile index f07fb91edaf0b..12705809e4290 100644 --- a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile @@ -24,8 +24,7 @@ RUN apt-get update && apt-get build-dep -y clang llvm && apt-get install -y --no # Needed for apt-key to work: dirmngr \ gpg-agent \ - g++-9-arm-linux-gnueabi \ - g++-11-riscv64-linux-gnu + g++-9-arm-linux-gnueabi ENV \ AR_x86_64_unknown_fuchsia=x86_64-unknown-fuchsia-ar \ @@ -71,10 +70,6 @@ RUN env \ CC=arm-linux-gnueabi-gcc-9 CFLAGS="-march=armv7-a" \ CXX=arm-linux-gnueabi-g++-9 CXXFLAGS="-march=armv7-a" \ bash musl.sh armv7 && \ - env \ - CC=riscv64-linux-gnu-gcc-11 \ - CXX=riscv64-linux-gnu-g++-11 \ - bash musl.sh riscv64gc && \ rm -rf /build/* WORKDIR /tmp @@ -120,7 +115,6 @@ ENV TARGETS=$TARGETS,x86_64-unknown-none ENV TARGETS=$TARGETS,aarch64-unknown-uefi ENV TARGETS=$TARGETS,i686-unknown-uefi ENV TARGETS=$TARGETS,x86_64-unknown-uefi -ENV TARGETS=$TARGETS,riscv64gc-unknown-linux-musl ENV TARGETS_SANITIZERS=x86_64-unknown-linux-gnuasan ENV TARGETS_SANITIZERS=$TARGETS_SANITIZERS,x86_64-unknown-linux-gnumsan @@ -132,11 +126,7 @@ ENV TARGETS_SANITIZERS=$TARGETS_SANITIZERS,x86_64-unknown-linux-gnutsan # Luckily one of the folders is /usr/local/include so symlink /usr/include/x86_64-linux-gnu/asm there RUN ln -s /usr/include/x86_64-linux-gnu/asm /usr/local/include/asm -# musl-gcc can't find libgcc_s.so.1 since it doesn't use the standard search paths. -RUN ln -s /usr/riscv64-linux-gnu/lib/libgcc_s.so.1 /usr/lib/gcc-cross/riscv64-linux-gnu/11/ - ENV RUST_CONFIGURE_ARGS="--enable-extended --enable-lld --enable-llvm-bitcode-linker --disable-docs \ - --musl-root-armv7=/musl-armv7 \ - --musl-root-riscv64gc=/musl-riscv64gc" + --musl-root-armv7=/musl-armv7" ENV SCRIPT="python3 ../x.py dist --host= --target $TARGETS && python3 ../x.py dist --host= --set build.sanitizers=true --target $TARGETS_SANITIZERS" From 2af4af2fb1abcdd12eb116c3f5c451e20b8b82f1 Mon Sep 17 00:00:00 2001 From: MarcoIeni <11428655+MarcoIeni@users.noreply.github.com> Date: Thu, 23 Jul 2026 09:13:59 +0200 Subject: [PATCH 3/3] update download-ci-llvm-stamp --- src/bootstrap/download-ci-llvm-stamp | 2 +- .../rustc/src/platform-support/riscv64gc-unknown-linux-musl.md | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bootstrap/download-ci-llvm-stamp b/src/bootstrap/download-ci-llvm-stamp index b61c7b18bad01..ba6dcfc761c5a 100644 --- a/src/bootstrap/download-ci-llvm-stamp +++ b/src/bootstrap/download-ci-llvm-stamp @@ -1,4 +1,4 @@ Change this file to make users of the `download-ci-llvm` configuration download a new version of LLVM from CI, even if the LLVM submodule hasn’t changed. -Last change is for: https://github.com/rust-lang/rust/pull/157385 +Last change is for: https://github.com/rust-lang/rust/pull/158766 diff --git a/src/doc/rustc/src/platform-support/riscv64gc-unknown-linux-musl.md b/src/doc/rustc/src/platform-support/riscv64gc-unknown-linux-musl.md index 4ac2a894117c1..12872b74b6820 100644 --- a/src/doc/rustc/src/platform-support/riscv64gc-unknown-linux-musl.md +++ b/src/doc/rustc/src/platform-support/riscv64gc-unknown-linux-musl.md @@ -35,7 +35,6 @@ target = ["riscv64gc-unknown-linux-musl"] ## Building Rust programs - On a riscv64gc-unknown-linux-musl host, the `riscv64gc-unknown-linux-musl` target should be automatically installed and used by default.