Skip to content

Commit

Permalink
universe/rust: backport patch and add loongarch64 support
Browse files Browse the repository at this point in the history
[ commit eb17ca5372b7bdaa233edc72d81c5a707a8c2323 ]

* Patch(0001 to 0005) backported from:
rust-lang/rust#121832
rust-lang/rust#122269
rust-lang/rust#122323

* Patch(0008 to 0010) backported from:
rust-lang/libc#3605

*Patch(0011) vendor/compiler_builtins backported from:
rust-lang/compiler-builtins#579
  • Loading branch information
huajingyun01 authored and kholmanskikh committed Apr 12, 2024
1 parent bffea2f commit 27468a2
Show file tree
Hide file tree
Showing 12 changed files with 2,682 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
From 9499baeeabc8f4494460770714a9805ff8aeaaa8 Mon Sep 17 00:00:00 2001
From: WANG Rui <[email protected]>
Date: Mon, 5 Jun 2023 19:51:24 +0800
Subject: [PATCH 01/12] Add new Tier-3 target: `loongarch64-unknown-linux-musl`

MCP: https://github.com/rust-lang/compiler-team/issues/518
---
compiler/rustc_target/src/spec/mod.rs | 1 +
.../targets/loongarch64_unknown_linux_musl.rs | 18 ++++++++++++++++++
src/doc/rustc/src/platform-support.md | 1 +
3 files changed, 20 insertions(+)
create mode 100644 compiler/rustc_target/src/spec/targets/loongarch64_unknown_linux_musl.rs

diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
index 6c698c5b0..b3ee709c2 100644
--- a/compiler/rustc_target/src/spec/mod.rs
+++ b/compiler/rustc_target/src/spec/mod.rs
@@ -1402,6 +1402,7 @@ supported_targets! {
("i686-unknown-linux-gnu", i686_unknown_linux_gnu),
("i586-unknown-linux-gnu", i586_unknown_linux_gnu),
("loongarch64-unknown-linux-gnu", loongarch64_unknown_linux_gnu),
+ ("loongarch64-unknown-linux-musl", loongarch64_unknown_linux_musl),
("m68k-unknown-linux-gnu", m68k_unknown_linux_gnu),
("csky-unknown-linux-gnuabiv2", csky_unknown_linux_gnuabiv2),
("csky-unknown-linux-gnuabiv2hf", csky_unknown_linux_gnuabiv2hf),
diff --git a/compiler/rustc_target/src/spec/targets/loongarch64_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/targets/loongarch64_unknown_linux_musl.rs
new file mode 100644
index 000000000..01a003ce8
--- /dev/null
+++ b/compiler/rustc_target/src/spec/targets/loongarch64_unknown_linux_musl.rs
@@ -0,0 +1,18 @@
+use crate::spec::{base, Target, TargetOptions};
+
+pub fn target() -> Target {
+ Target {
+ llvm_target: "loongarch64-unknown-linux-musl".into(),
+ pointer_width: 64,
+ data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".into(),
+ arch: "loongarch64".into(),
+ options: TargetOptions {
+ cpu: "generic".into(),
+ features: "+f,+d".into(),
+ llvm_abiname: "lp64d".into(),
+ max_atomic_width: Some(64),
+ crt_static_default: false,
+ ..base::linux_musl::opts()
+ },
+ }
+}
diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md
index f648a60b6..bc2427d6a 100644
--- a/src/doc/rustc/src/platform-support.md
+++ b/src/doc/rustc/src/platform-support.md
@@ -167,6 +167,7 @@ target | std | notes
`i686-unknown-freebsd` | ✓ | 32-bit FreeBSD [^x86_32-floats-return-ABI]
`i686-unknown-linux-musl` | ✓ | 32-bit Linux with MUSL [^x86_32-floats-return-ABI]
[`i686-unknown-uefi`](platform-support/unknown-uefi.md) | * | 32-bit UEFI
+[`loongarch64-unknown-linux-musl`](platform-support/loongarch-linux.md) | ? | | LoongArch64 Linux (LP64D ABI)
[`loongarch64-unknown-none`](platform-support/loongarch-none.md) | * | | LoongArch64 Bare-metal (LP64D ABI)
[`loongarch64-unknown-none-softfloat`](platform-support/loongarch-none.md) | * | | LoongArch64 Bare-metal (LP64S ABI)
[`nvptx64-nvidia-cuda`](platform-support/nvptx64-nvidia-cuda.md) | * | --emit=asm generates PTX code that [runs on NVIDIA GPUs]
--
2.44.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From 440278d4971c82b366077d61f682105e197f9680 Mon Sep 17 00:00:00 2001
From: WANG Rui <[email protected]>
Date: Fri, 1 Mar 2024 11:43:27 +0800
Subject: [PATCH 02/12] tests: Add loongarch64-unknown-linux-musl target

---
tests/assembly/targets/targets-elf.rs | 3 +++
1 file changed, 3 insertions(+)

diff --git a/tests/assembly/targets/targets-elf.rs b/tests/assembly/targets/targets-elf.rs
index 41f5df0fb..bf89790a5 100644
--- a/tests/assembly/targets/targets-elf.rs
+++ b/tests/assembly/targets/targets-elf.rs
@@ -231,6 +231,9 @@
// revisions: loongarch64_unknown_linux_gnu
// [loongarch64_unknown_linux_gnu] compile-flags: --target loongarch64-unknown-linux-gnu
// [loongarch64_unknown_linux_gnu] needs-llvm-components: loongarch
+// revisions: loongarch64_unknown_linux_musl
+// [loongarch64_unknown_linux_musl] compile-flags: --target loongarch64-unknown-linux-musl
+// [loongarch64_unknown_linux_musl] needs-llvm-components: loongarch
// revisions: loongarch64_unknown_none
// [loongarch64_unknown_none] compile-flags: --target loongarch64-unknown-none
// [loongarch64_unknown_none] needs-llvm-components: loongarch
--
2.44.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From ac3ab633b1d4ca35e49c7dfe8dbe5a6be7cbc303 Mon Sep 17 00:00:00 2001
From: WANG Rui <[email protected]>
Date: Mon, 11 Mar 2024 11:28:34 +0800
Subject: [PATCH 05/12] configure.py: add flag for loongarch64 musl-root

---
src/bootstrap/configure.py | 2 ++
1 file changed, 2 insertions(+)

diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py
index d34c19a47..cba7f98e8 100755
--- a/src/bootstrap/configure.py
+++ b/src/bootstrap/configure.py
@@ -130,6 +130,8 @@ v("musl-root-riscv32gc", "target.riscv32gc-unknown-linux-musl.musl-root",
"riscv32gc-unknown-linux-musl install directory")
v("musl-root-riscv64gc", "target.riscv64gc-unknown-linux-musl.musl-root",
"riscv64gc-unknown-linux-musl install directory")
+v("musl-root-loongarch64", "target.loongarch64-unknown-linux-musl.musl-root",
+ "loongarch64-unknown-linux-musl install directory")
v("qemu-armhf-rootfs", "target.arm-unknown-linux-gnueabihf.qemu-rootfs",
"rootfs in qemu testing, you probably don't want to use this")
v("qemu-aarch64-rootfs", "target.aarch64-unknown-linux-gnu.qemu-rootfs",
--
2.44.0

121 changes: 121 additions & 0 deletions universe/rust/0006-ci-Add-support-for-dist-loongarch64-musl.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
From fb5f17d6958e86af31e719482001b13bec3b29ce Mon Sep 17 00:00:00 2001
From: WANG Rui <[email protected]>
Date: Tue, 5 Mar 2024 16:04:02 +0800
Subject: [PATCH 06/12] ci: Add support for dist-loongarch64-musl

---
src/ci/docker/README.md | 16 +++++++++
.../dist-loongarch64-musl/Dockerfile | 36 +++++++++++++++++++
.../loongarch64-unknown-linux-musl.defconfig | 15 ++++++++
src/ci/github-actions/ci.yml | 3 ++
4 files changed, 70 insertions(+)
create mode 100644 src/ci/docker/host-x86_64/dist-loongarch64-musl/Dockerfile
create mode 100644 src/ci/docker/host-x86_64/dist-loongarch64-musl/loongarch64-unknown-linux-musl.defconfig

diff --git a/src/ci/docker/README.md b/src/ci/docker/README.md
index 2e6456837..c53cf28c0 100644
--- a/src/ci/docker/README.md
+++ b/src/ci/docker/README.md
@@ -274,6 +274,22 @@ For targets: `loongarch64-unknown-linux-gnu`
- C compiler > gcc version = 13.2.0
- C compiler > C++ = ENABLE -- to cross compile LLVM

+### `loongarch64-linux-musl.defconfig`
+
+For targets: `loongarch64-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 = loongarch
+- Target options > Bitness = 64-bit
+- Operating System > Target OS = linux
+- Operating System > Linux kernel version = 5.19.16
+- Binary utilities > Version of binutils = 2.41
+- C-library > musl version = 1.2.5
+- C compiler > gcc version = 13.2.0
+- C compiler > C++ = ENABLE -- to cross compile LLVM
+
### `mips-linux-gnu.defconfig`

For targets: `mips-unknown-linux-gnu`
diff --git a/src/ci/docker/host-x86_64/dist-loongarch64-musl/Dockerfile b/src/ci/docker/host-x86_64/dist-loongarch64-musl/Dockerfile
new file mode 100644
index 000000000..201e83b2c
--- /dev/null
+++ b/src/ci/docker/host-x86_64/dist-loongarch64-musl/Dockerfile
@@ -0,0 +1,36 @@
+FROM ubuntu:22.04
+
+COPY scripts/cross-apt-packages.sh /scripts/
+RUN sh /scripts/cross-apt-packages.sh
+
+COPY scripts/crosstool-ng.sh /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-loongarch64-linux/loongarch64-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/loongarch64-unknown-linux-musl/bin
+
+ENV CC_loongarch64_unknown_linux_musl=loongarch64-unknown-linux-musl-gcc \
+ AR_loongarch64_unknown_linux_musl=loongarch64-unknown-linux-musl-ar \
+ CXX_loongarch64_unknown_linux_musl=loongarch64-unknown-linux-musl-g++
+
+ENV HOSTS=loongarch64-unknown-linux-musl
+
+ENV RUST_CONFIGURE_ARGS \
+ --enable-extended \
+ --enable-lld \
+ --disable-docs \
+ --set target.loongarch64-unknown-linux-musl.crt-static=false \
+ --set target.loongarch64-unknown-linux-musl.musl-root=/x-tools/loongarch64-unknown-linux-musl/loongarch64-unknown-linux-musl/sysroot/usr \
+ --build $HOSTS
+
+ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS
diff --git a/src/ci/docker/host-x86_64/dist-loongarch64-musl/loongarch64-unknown-linux-musl.defconfig b/src/ci/docker/host-x86_64/dist-loongarch64-musl/loongarch64-unknown-linux-musl.defconfig
new file mode 100644
index 000000000..3ab676ed9
--- /dev/null
+++ b/src/ci/docker/host-x86_64/dist-loongarch64-musl/loongarch64-unknown-linux-musl.defconfig
@@ -0,0 +1,15 @@
+CT_CONFIG_VERSION="4"
+CT_EXPERIMENTAL=y
+CT_PREFIX_DIR="/x-tools/${CT_TARGET}"
+CT_USE_MIRROR=y
+CT_MIRROR_BASE_URL="https://ci-mirrors.rust-lang.org/rustc"
+CT_ARCH_LOONGARCH=y
+# CT_DEMULTILIB is not set
+CT_ARCH_USE_MMU=y
+CT_ARCH_ARCH="loongarch64"
+CT_KERNEL_LINUX=y
+CT_LINUX_V_5_19=y
+CT_LIBC_MUSL=y
+CT_CC_GCC_ENABLE_DEFAULT_PIE=y
+CT_CC_LANG_CXX=y
+CT_GETTEXT_NEEDED=y
diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml
index f2effcbd8..81fc89ab8 100644
--- a/src/ci/github-actions/ci.yml
+++ b/src/ci/github-actions/ci.yml
@@ -392,6 +392,9 @@ jobs:
- name: dist-loongarch64-linux
<<: *job-linux-8c

+ - name: dist-loongarch64-musl
+ <<: *job-linux-8c
+
- name: dist-powerpc-linux
<<: *job-linux-8c

--
2.44.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
From 713ed86a10cc2a95937d7165c05603ab12984f87 Mon Sep 17 00:00:00 2001
From: WANG Rui <[email protected]>
Date: Mon, 13 Nov 2023 19:45:27 +0800
Subject: [PATCH 07/12] Promote loongarch64-unknown-linux-musl to Tier 2 with
host tools

MCP: https://github.com/rust-lang/compiler-team/issues/518
---
src/bootstrap/src/core/build_steps/llvm.rs | 1 +
src/tools/build-manifest/src/main.rs | 2 ++
2 files changed, 3 insertions(+), 0 deletion(-)

diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs
index 4b2d3e9ab..1409acc3b 100644
--- a/src/bootstrap/src/core/build_steps/llvm.rs
+++ b/src/bootstrap/src/core/build_steps/llvm.rs
@@ -201,6 +201,7 @@ pub(crate) fn is_ci_llvm_available(config: &Config, asserts: bool) -> bool {
("arm-unknown-linux-gnueabihf", false),
("armv7-unknown-linux-gnueabihf", false),
("loongarch64-unknown-linux-gnu", false),
+ ("loongarch64-unknown-linux-musl", false),
("mips-unknown-linux-gnu", false),
("mips64-unknown-linux-gnuabi64", false),
("mips64el-unknown-linux-gnuabi64", false),
diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs
index 1ef8cf7de..8fb36c3c7 100644
--- a/src/tools/build-manifest/src/main.rs
+++ b/src/tools/build-manifest/src/main.rs
@@ -25,6 +25,7 @@ static HOSTS: &[&str] = &[
"i686-pc-windows-msvc",
"i686-unknown-linux-gnu",
"loongarch64-unknown-linux-gnu",
+ "loongarch64-unknown-linux-musl",
"mips-unknown-linux-gnu",
"mips64-unknown-linux-gnuabi64",
"mips64el-unknown-linux-gnuabi64",
@@ -99,6 +100,7 @@ static TARGETS: &[&str] = &[
"i686-unknown-linux-musl",
"i686-unknown-uefi",
"loongarch64-unknown-linux-gnu",
+ "loongarch64-unknown-linux-musl",
"loongarch64-unknown-none",
"loongarch64-unknown-none-softfloat",
"m68k-unknown-linux-gnu",
--
2.44.0

Loading

0 comments on commit 27468a2

Please sign in to comment.