Skip to content

Commit 27468a2

Browse files
huajingyun01kholmanskikh
authored andcommitted
universe/rust: backport patch and add loongarch64 support
[ 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
1 parent bffea2f commit 27468a2

12 files changed

+2682
-2
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
From 9499baeeabc8f4494460770714a9805ff8aeaaa8 Mon Sep 17 00:00:00 2001
2+
From: WANG Rui <wangrui@loongson.cn>
3+
Date: Mon, 5 Jun 2023 19:51:24 +0800
4+
Subject: [PATCH 01/12] Add new Tier-3 target: `loongarch64-unknown-linux-musl`
5+
6+
MCP: https://github.com/rust-lang/compiler-team/issues/518
7+
---
8+
compiler/rustc_target/src/spec/mod.rs | 1 +
9+
.../targets/loongarch64_unknown_linux_musl.rs | 18 ++++++++++++++++++
10+
src/doc/rustc/src/platform-support.md | 1 +
11+
3 files changed, 20 insertions(+)
12+
create mode 100644 compiler/rustc_target/src/spec/targets/loongarch64_unknown_linux_musl.rs
13+
14+
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
15+
index 6c698c5b0..b3ee709c2 100644
16+
--- a/compiler/rustc_target/src/spec/mod.rs
17+
+++ b/compiler/rustc_target/src/spec/mod.rs
18+
@@ -1402,6 +1402,7 @@ supported_targets! {
19+
("i686-unknown-linux-gnu", i686_unknown_linux_gnu),
20+
("i586-unknown-linux-gnu", i586_unknown_linux_gnu),
21+
("loongarch64-unknown-linux-gnu", loongarch64_unknown_linux_gnu),
22+
+ ("loongarch64-unknown-linux-musl", loongarch64_unknown_linux_musl),
23+
("m68k-unknown-linux-gnu", m68k_unknown_linux_gnu),
24+
("csky-unknown-linux-gnuabiv2", csky_unknown_linux_gnuabiv2),
25+
("csky-unknown-linux-gnuabiv2hf", csky_unknown_linux_gnuabiv2hf),
26+
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
27+
new file mode 100644
28+
index 000000000..01a003ce8
29+
--- /dev/null
30+
+++ b/compiler/rustc_target/src/spec/targets/loongarch64_unknown_linux_musl.rs
31+
@@ -0,0 +1,18 @@
32+
+use crate::spec::{base, Target, TargetOptions};
33+
+
34+
+pub fn target() -> Target {
35+
+ Target {
36+
+ llvm_target: "loongarch64-unknown-linux-musl".into(),
37+
+ pointer_width: 64,
38+
+ data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".into(),
39+
+ arch: "loongarch64".into(),
40+
+ options: TargetOptions {
41+
+ cpu: "generic".into(),
42+
+ features: "+f,+d".into(),
43+
+ llvm_abiname: "lp64d".into(),
44+
+ max_atomic_width: Some(64),
45+
+ crt_static_default: false,
46+
+ ..base::linux_musl::opts()
47+
+ },
48+
+ }
49+
+}
50+
diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md
51+
index f648a60b6..bc2427d6a 100644
52+
--- a/src/doc/rustc/src/platform-support.md
53+
+++ b/src/doc/rustc/src/platform-support.md
54+
@@ -167,6 +167,7 @@ target | std | notes
55+
`i686-unknown-freebsd` | ✓ | 32-bit FreeBSD [^x86_32-floats-return-ABI]
56+
`i686-unknown-linux-musl` | ✓ | 32-bit Linux with MUSL [^x86_32-floats-return-ABI]
57+
[`i686-unknown-uefi`](platform-support/unknown-uefi.md) | * | 32-bit UEFI
58+
+[`loongarch64-unknown-linux-musl`](platform-support/loongarch-linux.md) | ? | | LoongArch64 Linux (LP64D ABI)
59+
[`loongarch64-unknown-none`](platform-support/loongarch-none.md) | * | | LoongArch64 Bare-metal (LP64D ABI)
60+
[`loongarch64-unknown-none-softfloat`](platform-support/loongarch-none.md) | * | | LoongArch64 Bare-metal (LP64S ABI)
61+
[`nvptx64-nvidia-cuda`](platform-support/nvptx64-nvidia-cuda.md) | * | --emit=asm generates PTX code that [runs on NVIDIA GPUs]
62+
--
63+
2.44.0
64+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
From 440278d4971c82b366077d61f682105e197f9680 Mon Sep 17 00:00:00 2001
2+
From: WANG Rui <wangrui@loongson.cn>
3+
Date: Fri, 1 Mar 2024 11:43:27 +0800
4+
Subject: [PATCH 02/12] tests: Add loongarch64-unknown-linux-musl target
5+
6+
---
7+
tests/assembly/targets/targets-elf.rs | 3 +++
8+
1 file changed, 3 insertions(+)
9+
10+
diff --git a/tests/assembly/targets/targets-elf.rs b/tests/assembly/targets/targets-elf.rs
11+
index 41f5df0fb..bf89790a5 100644
12+
--- a/tests/assembly/targets/targets-elf.rs
13+
+++ b/tests/assembly/targets/targets-elf.rs
14+
@@ -231,6 +231,9 @@
15+
// revisions: loongarch64_unknown_linux_gnu
16+
// [loongarch64_unknown_linux_gnu] compile-flags: --target loongarch64-unknown-linux-gnu
17+
// [loongarch64_unknown_linux_gnu] needs-llvm-components: loongarch
18+
+// revisions: loongarch64_unknown_linux_musl
19+
+// [loongarch64_unknown_linux_musl] compile-flags: --target loongarch64-unknown-linux-musl
20+
+// [loongarch64_unknown_linux_musl] needs-llvm-components: loongarch
21+
// revisions: loongarch64_unknown_none
22+
// [loongarch64_unknown_none] compile-flags: --target loongarch64-unknown-none
23+
// [loongarch64_unknown_none] needs-llvm-components: loongarch
24+
--
25+
2.44.0
26+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
From ac3ab633b1d4ca35e49c7dfe8dbe5a6be7cbc303 Mon Sep 17 00:00:00 2001
2+
From: WANG Rui <wangrui@loongson.cn>
3+
Date: Mon, 11 Mar 2024 11:28:34 +0800
4+
Subject: [PATCH 05/12] configure.py: add flag for loongarch64 musl-root
5+
6+
---
7+
src/bootstrap/configure.py | 2 ++
8+
1 file changed, 2 insertions(+)
9+
10+
diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py
11+
index d34c19a47..cba7f98e8 100755
12+
--- a/src/bootstrap/configure.py
13+
+++ b/src/bootstrap/configure.py
14+
@@ -130,6 +130,8 @@ v("musl-root-riscv32gc", "target.riscv32gc-unknown-linux-musl.musl-root",
15+
"riscv32gc-unknown-linux-musl install directory")
16+
v("musl-root-riscv64gc", "target.riscv64gc-unknown-linux-musl.musl-root",
17+
"riscv64gc-unknown-linux-musl install directory")
18+
+v("musl-root-loongarch64", "target.loongarch64-unknown-linux-musl.musl-root",
19+
+ "loongarch64-unknown-linux-musl install directory")
20+
v("qemu-armhf-rootfs", "target.arm-unknown-linux-gnueabihf.qemu-rootfs",
21+
"rootfs in qemu testing, you probably don't want to use this")
22+
v("qemu-aarch64-rootfs", "target.aarch64-unknown-linux-gnu.qemu-rootfs",
23+
--
24+
2.44.0
25+
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
From fb5f17d6958e86af31e719482001b13bec3b29ce Mon Sep 17 00:00:00 2001
2+
From: WANG Rui <wangrui@loongson.cn>
3+
Date: Tue, 5 Mar 2024 16:04:02 +0800
4+
Subject: [PATCH 06/12] ci: Add support for dist-loongarch64-musl
5+
6+
---
7+
src/ci/docker/README.md | 16 +++++++++
8+
.../dist-loongarch64-musl/Dockerfile | 36 +++++++++++++++++++
9+
.../loongarch64-unknown-linux-musl.defconfig | 15 ++++++++
10+
src/ci/github-actions/ci.yml | 3 ++
11+
4 files changed, 70 insertions(+)
12+
create mode 100644 src/ci/docker/host-x86_64/dist-loongarch64-musl/Dockerfile
13+
create mode 100644 src/ci/docker/host-x86_64/dist-loongarch64-musl/loongarch64-unknown-linux-musl.defconfig
14+
15+
diff --git a/src/ci/docker/README.md b/src/ci/docker/README.md
16+
index 2e6456837..c53cf28c0 100644
17+
--- a/src/ci/docker/README.md
18+
+++ b/src/ci/docker/README.md
19+
@@ -274,6 +274,22 @@ For targets: `loongarch64-unknown-linux-gnu`
20+
- C compiler > gcc version = 13.2.0
21+
- C compiler > C++ = ENABLE -- to cross compile LLVM
22+
23+
+### `loongarch64-linux-musl.defconfig`
24+
+
25+
+For targets: `loongarch64-unknown-linux-musl`
26+
+
27+
+- Path and misc options > Prefix directory = /x-tools/${CT\_TARGET}
28+
+- Path and misc options > Use a mirror = ENABLE
29+
+- Path and misc options > Base URL = https://ci-mirrors.rust-lang.org/rustc
30+
+- Target options > Target Architecture = loongarch
31+
+- Target options > Bitness = 64-bit
32+
+- Operating System > Target OS = linux
33+
+- Operating System > Linux kernel version = 5.19.16
34+
+- Binary utilities > Version of binutils = 2.41
35+
+- C-library > musl version = 1.2.5
36+
+- C compiler > gcc version = 13.2.0
37+
+- C compiler > C++ = ENABLE -- to cross compile LLVM
38+
+
39+
### `mips-linux-gnu.defconfig`
40+
41+
For targets: `mips-unknown-linux-gnu`
42+
diff --git a/src/ci/docker/host-x86_64/dist-loongarch64-musl/Dockerfile b/src/ci/docker/host-x86_64/dist-loongarch64-musl/Dockerfile
43+
new file mode 100644
44+
index 000000000..201e83b2c
45+
--- /dev/null
46+
+++ b/src/ci/docker/host-x86_64/dist-loongarch64-musl/Dockerfile
47+
@@ -0,0 +1,36 @@
48+
+FROM ubuntu:22.04
49+
+
50+
+COPY scripts/cross-apt-packages.sh /scripts/
51+
+RUN sh /scripts/cross-apt-packages.sh
52+
+
53+
+COPY scripts/crosstool-ng.sh /scripts/
54+
+RUN sh /scripts/crosstool-ng.sh
55+
+
56+
+COPY scripts/rustbuild-setup.sh /scripts/
57+
+RUN sh /scripts/rustbuild-setup.sh
58+
+WORKDIR /tmp
59+
+
60+
+COPY scripts/crosstool-ng-build.sh /scripts/
61+
+COPY host-x86_64/dist-loongarch64-linux/loongarch64-unknown-linux-musl.defconfig /tmp/crosstool.defconfig
62+
+RUN /scripts/crosstool-ng-build.sh
63+
+
64+
+COPY scripts/sccache.sh /scripts/
65+
+RUN sh /scripts/sccache.sh
66+
+
67+
+ENV PATH=$PATH:/x-tools/loongarch64-unknown-linux-musl/bin
68+
+
69+
+ENV CC_loongarch64_unknown_linux_musl=loongarch64-unknown-linux-musl-gcc \
70+
+ AR_loongarch64_unknown_linux_musl=loongarch64-unknown-linux-musl-ar \
71+
+ CXX_loongarch64_unknown_linux_musl=loongarch64-unknown-linux-musl-g++
72+
+
73+
+ENV HOSTS=loongarch64-unknown-linux-musl
74+
+
75+
+ENV RUST_CONFIGURE_ARGS \
76+
+ --enable-extended \
77+
+ --enable-lld \
78+
+ --disable-docs \
79+
+ --set target.loongarch64-unknown-linux-musl.crt-static=false \
80+
+ --set target.loongarch64-unknown-linux-musl.musl-root=/x-tools/loongarch64-unknown-linux-musl/loongarch64-unknown-linux-musl/sysroot/usr \
81+
+ --build $HOSTS
82+
+
83+
+ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS
84+
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
85+
new file mode 100644
86+
index 000000000..3ab676ed9
87+
--- /dev/null
88+
+++ b/src/ci/docker/host-x86_64/dist-loongarch64-musl/loongarch64-unknown-linux-musl.defconfig
89+
@@ -0,0 +1,15 @@
90+
+CT_CONFIG_VERSION="4"
91+
+CT_EXPERIMENTAL=y
92+
+CT_PREFIX_DIR="/x-tools/${CT_TARGET}"
93+
+CT_USE_MIRROR=y
94+
+CT_MIRROR_BASE_URL="https://ci-mirrors.rust-lang.org/rustc"
95+
+CT_ARCH_LOONGARCH=y
96+
+# CT_DEMULTILIB is not set
97+
+CT_ARCH_USE_MMU=y
98+
+CT_ARCH_ARCH="loongarch64"
99+
+CT_KERNEL_LINUX=y
100+
+CT_LINUX_V_5_19=y
101+
+CT_LIBC_MUSL=y
102+
+CT_CC_GCC_ENABLE_DEFAULT_PIE=y
103+
+CT_CC_LANG_CXX=y
104+
+CT_GETTEXT_NEEDED=y
105+
diff --git a/src/ci/github-actions/ci.yml b/src/ci/github-actions/ci.yml
106+
index f2effcbd8..81fc89ab8 100644
107+
--- a/src/ci/github-actions/ci.yml
108+
+++ b/src/ci/github-actions/ci.yml
109+
@@ -392,6 +392,9 @@ jobs:
110+
- name: dist-loongarch64-linux
111+
<<: *job-linux-8c
112+
113+
+ - name: dist-loongarch64-musl
114+
+ <<: *job-linux-8c
115+
+
116+
- name: dist-powerpc-linux
117+
<<: *job-linux-8c
118+
119+
--
120+
2.44.0
121+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
From 713ed86a10cc2a95937d7165c05603ab12984f87 Mon Sep 17 00:00:00 2001
2+
From: WANG Rui <wangrui@loongson.cn>
3+
Date: Mon, 13 Nov 2023 19:45:27 +0800
4+
Subject: [PATCH 07/12] Promote loongarch64-unknown-linux-musl to Tier 2 with
5+
host tools
6+
7+
MCP: https://github.com/rust-lang/compiler-team/issues/518
8+
---
9+
src/bootstrap/src/core/build_steps/llvm.rs | 1 +
10+
src/tools/build-manifest/src/main.rs | 2 ++
11+
2 files changed, 3 insertions(+), 0 deletion(-)
12+
13+
diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs
14+
index 4b2d3e9ab..1409acc3b 100644
15+
--- a/src/bootstrap/src/core/build_steps/llvm.rs
16+
+++ b/src/bootstrap/src/core/build_steps/llvm.rs
17+
@@ -201,6 +201,7 @@ pub(crate) fn is_ci_llvm_available(config: &Config, asserts: bool) -> bool {
18+
("arm-unknown-linux-gnueabihf", false),
19+
("armv7-unknown-linux-gnueabihf", false),
20+
("loongarch64-unknown-linux-gnu", false),
21+
+ ("loongarch64-unknown-linux-musl", false),
22+
("mips-unknown-linux-gnu", false),
23+
("mips64-unknown-linux-gnuabi64", false),
24+
("mips64el-unknown-linux-gnuabi64", false),
25+
diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs
26+
index 1ef8cf7de..8fb36c3c7 100644
27+
--- a/src/tools/build-manifest/src/main.rs
28+
+++ b/src/tools/build-manifest/src/main.rs
29+
@@ -25,6 +25,7 @@ static HOSTS: &[&str] = &[
30+
"i686-pc-windows-msvc",
31+
"i686-unknown-linux-gnu",
32+
"loongarch64-unknown-linux-gnu",
33+
+ "loongarch64-unknown-linux-musl",
34+
"mips-unknown-linux-gnu",
35+
"mips64-unknown-linux-gnuabi64",
36+
"mips64el-unknown-linux-gnuabi64",
37+
@@ -99,6 +100,7 @@ static TARGETS: &[&str] = &[
38+
"i686-unknown-linux-musl",
39+
"i686-unknown-uefi",
40+
"loongarch64-unknown-linux-gnu",
41+
+ "loongarch64-unknown-linux-musl",
42+
"loongarch64-unknown-none",
43+
"loongarch64-unknown-none-softfloat",
44+
"m68k-unknown-linux-gnu",
45+
--
46+
2.44.0
47+

0 commit comments

Comments
 (0)