diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index 9e06fec550d64db9b75e26cc6ea13df38bc46fa7..979ff7880af16f5a65362fa0186aec277e27c0c0 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -297,6 +297,18 @@ const BPF_ALLOWED_FEATURES: &[(&str, Option)] = &[("alu32", Some(sym::bpf_target_feature))]; +const LOONGARCH_ALLOWED_FEATURES: &[(&str, Option)] = &[ + // tidy-alphabetical-start + ("d", Some(sym::loongarch_target_feature)), + ("f", Some(sym::loongarch_target_feature)), + ("lasx", Some(sym::loongarch_target_feature)), + ("lbt", Some(sym::loongarch_target_feature)), + ("lsx", Some(sym::loongarch_target_feature)), + ("lvz", Some(sym::loongarch_target_feature)), + ("ual", Some(sym::loongarch_target_feature)), + // tidy-alphabetical-end +]; + /// When rustdoc is running, provide a list of all known features so that all their respective /// primitives may be documented. /// @@ -312,6 +324,7 @@ pub fn all_known_features() -> impl Iterator &'static [(&'static str, Opt "riscv32" | "riscv64" => RISCV_ALLOWED_FEATURES, "wasm32" | "wasm64" => WASM_ALLOWED_FEATURES, "bpf" => BPF_ALLOWED_FEATURES, + "loongarch64" => LOONGARCH_ALLOWED_FEATURES, _ => &[], } } @@ -401,6 +415,7 @@ pub fn from_target_feature( Some(sym::ermsb_target_feature) => rust_features.ermsb_target_feature, Some(sym::bpf_target_feature) => rust_features.bpf_target_feature, Some(sym::aarch64_ver_target_feature) => rust_features.aarch64_ver_target_feature, + Some(sym::loongarch_target_feature) => rust_features.loongarch_target_feature, Some(name) => bug!("unknown target feature gate {}", name), None => true, }; diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 56a2c5eff3d07098b038c31268953f8dd4938e46..5d6b81d44296e0835d6183aef78601bdfa8fdb37 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -260,6 +260,7 @@ pub fn set(&self, features: &mut Features, span: Span) { (active, bpf_target_feature, "1.54.0", Some(44839), None), (active, ermsb_target_feature, "1.49.0", Some(44839), None), (active, hexagon_target_feature, "1.27.0", Some(44839), None), + (active, loongarch_target_feature, "1.72.0", Some(44839), None), (active, mips_target_feature, "1.27.0", Some(44839), None), (active, powerpc_target_feature, "1.27.0", Some(44839), None), (active, riscv_target_feature, "1.45.0", Some(44839), None), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 5c6d43e50ea28d7628d9a5c718119692f4f8ae92..2eba8603b3612eb53337455a480f4e3e8b4cbf9c 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -906,6 +906,7 @@ log_syntax, logf32, logf64, + loongarch_target_feature, loop_break_value, lt, macro_at_most_once_rep, diff --git a/compiler/rustc_target/src/spec/loongarch64_unknown_linux_musl.rs b/compiler/rustc_target/src/spec/loongarch64_unknown_linux_musl.rs new file mode 100644 index 0000000000000000000000000000000000000000..12817b2294182385baceb4a4006a4a41664911de --- /dev/null +++ b/compiler/rustc_target/src/spec/loongarch64_unknown_linux_musl.rs @@ -0,0 +1,18 @@ +use crate::spec::{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, + ..super::linux_musl_base::opts() + }, + } +} diff --git a/compiler/rustc_target/src/spec/loongarch64_unknown_linux_ohos.rs b/compiler/rustc_target/src/spec/loongarch64_unknown_linux_ohos.rs new file mode 100644 index 0000000000000000000000000000000000000000..a238f69be8a311f94ad21e750b6cbd47e5960c37 --- /dev/null +++ b/compiler/rustc_target/src/spec/loongarch64_unknown_linux_ohos.rs @@ -0,0 +1,31 @@ +use crate::spec::{Target, TargetOptions}; + +use super::SanitizerSet; + +pub fn target() -> Target { + // LLVM 15 doesn't support OpenHarmony yet, use a linux target instead. + let mut base = super::linux_musl_base::opts(); + base.env = "ohos".into(); + base.crt_static_default = false; + base.max_atomic_width = Some(64); + + 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(), + force_emulated_tls: true, + has_thread_local: false, + supported_sanitizers: SanitizerSet::ADDRESS + | SanitizerSet::CFI + | SanitizerSet::LEAK + | SanitizerSet::MEMORY + | SanitizerSet::THREAD, + ..base + }, + } +} diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 689150b89f4cf46a93ec72b347c39eb7c63dc1b6..c9f9c692480a6c9265e379e4626ed62169e16b3f 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1242,6 +1242,7 @@ fn $module() { ("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), ("mips-unknown-linux-gnu", mips_unknown_linux_gnu), ("mips64-unknown-linux-gnuabi64", mips64_unknown_linux_gnuabi64), @@ -1435,6 +1436,7 @@ fn $module() { ("loongarch64-unknown-none", loongarch64_unknown_none), ("loongarch64-unknown-none-softfloat", loongarch64_unknown_none_softfloat), + ("loongarch64-unknown-linux-ohos", loongarch64_unknown_linux_ohos), ("aarch64-unknown-none", aarch64_unknown_none), ("aarch64-unknown-none-softfloat", aarch64_unknown_none_softfloat), diff --git a/rust-build/README.md b/rust-build/README.md index 1029977f47484e8536d5e660728433d456b155f9..8370c2f358fb350a04566dc9a74a54bdb8937c74 100644 --- a/rust-build/README.md +++ b/rust-build/README.md @@ -69,6 +69,7 @@ rust-std-nightly-x86_64-pc-windows-gnullvm.tar.gz rust-std-nightly-aarch64-unknown-linux-ohos.tar.gz rust-std-nightly-armv7-unknown-linux-ohos.tar.gz rust-std-nightly-x86_64-unknown-linux-ohos.tar.gz +rust-std-nightly-loongarch64-unknown-linux-ohos.tar.gz ``` - Mac arm64 system diff --git a/rust-build/config.toml b/rust-build/config.toml index d0f386596d4de6d7b311a1e5f284d48fff346861..bd2e4c2159249ffe8b874805c6d2c646edb6135e 100644 --- a/rust-build/config.toml +++ b/rust-build/config.toml @@ -8,7 +8,7 @@ cflags = "-fstack-protector-all" cxxflags = "-fstack-protector-all" [build] -target = ["x86_64-unknown-linux-gnu", "x86_64-pc-windows-gnullvm", "armv7-unknown-linux-ohos", "x86_64-unknown-linux-ohos", "aarch64-unknown-linux-ohos"] +target = ["x86_64-unknown-linux-gnu", "x86_64-pc-windows-gnullvm", "armv7-unknown-linux-ohos", "x86_64-unknown-linux-ohos", "aarch64-unknown-linux-ohos", "loongarch64-unknown-linux-ohos"] submodules = false compiler-docs = false extended = true @@ -66,5 +66,11 @@ cxx = "x86_64-w64-mingw32-clang++" linker = "x86_64-w64-mingw32-clang" ar = "x86_64-w64-mingw32-ar" +[target.loongarch64-unknown-linux-ohos] +cc = "loongarch64-unknown-linux-ohos-clang" +cxx = "loongarch64-unknown-linux-ohos-clang++" +linker = "loongarch64-unknown-linux-ohos-clang" +ar = "llvm-ar" + [dist] -compression-formats = ["gz"] \ No newline at end of file +compression-formats = ["gz"] diff --git a/rust-build/function.sh b/rust-build/function.sh index 321395607a28eff3b49f41293242b1be7cd0f590..a3ce50ca321415a22851c5b893498ca67a95f217 100644 --- a/rust-build/function.sh +++ b/rust-build/function.sh @@ -67,10 +67,12 @@ update_config_clang() { update_config_clang_path ${1} aarch64-unknown-linux-ohos-clang llvm-ar update_config_clang_path ${1} armv7-unknown-linux-ohos-clang llvm-ar update_config_clang_path ${1} x86_64-unknown-linux-ohos-clang llvm-ar + update_config_clang_path ${1} loongarch64-unknown-linux-ohos-clang llvm-ar update_config_clang_path ${2} x86_64-w64-mingw32-clang x86_64-w64-mingw32-ar update_musl_head_file_path ${3} aarch64-unknown-linux-ohos-clang update_musl_head_file_path ${3} armv7-unknown-linux-ohos-clang update_musl_head_file_path ${3} x86_64-unknown-linux-ohos-clang + update_musl_head_file_path ${3} loongarch64-unknown-linux-ohos-clang fi } diff --git a/rust-build/ohos_ci_build.sh b/rust-build/ohos_ci_build.sh index 364bbf75e42fa12db2371d6dd2f0c04406d91903..a877de1f16b4fb8718612b08a84eb3941f515404 100755 --- a/rust-build/ohos_ci_build.sh +++ b/rust-build/ohos_ci_build.sh @@ -33,6 +33,7 @@ collect_build_result() { cp ${install_path}/rust-std-nightly-aarch64-unknown-linux-ohos.tar.gz ${output_install}/ cp ${install_path}/rust-std-nightly-armv7-unknown-linux-ohos.tar.gz ${output_install}/ cp ${install_path}/rust-std-nightly-x86_64-unknown-linux-ohos.tar.gz ${output_install}/ + cp ${install_path}/rust-std-nightly-loongarch64-unknown-linux-ohos.tar.gz ${output_install}/ elif [ "${host_platform}" = "darwin" ] && [ ${host_cpu} = "x86_64" ]; then cp ${install_path}/rust-nightly-x86_64-apple-darwin.tar.gz ${output_install}/ elif [ "${host_platform}" = "darwin" ] && [ ${host_cpu} = "arm64" ]; then diff --git a/rust-build/tools/loongarch64-unknown-linux-ohos-clang b/rust-build/tools/loongarch64-unknown-linux-ohos-clang new file mode 100644 index 0000000000000000000000000000000000000000..a628b38ac9914f724896b597ee1f011aca938b3d --- /dev/null +++ b/rust-build/tools/loongarch64-unknown-linux-ohos-clang @@ -0,0 +1,3 @@ +#!/bin/bash + +exec loongarch64-unknown-linux-ohos-clang -fstack-protector-all "$@" diff --git a/rust-build/tools/loongarch64-unknown-linux-ohos-clang++ b/rust-build/tools/loongarch64-unknown-linux-ohos-clang++ new file mode 100644 index 0000000000000000000000000000000000000000..8151ff10d70091801a6f2ecb7664c4475118e28a --- /dev/null +++ b/rust-build/tools/loongarch64-unknown-linux-ohos-clang++ @@ -0,0 +1,3 @@ +#!/bin/bash + +exec loongarch64-unknown-linux-ohos-clang++ -fstack-protector-all "$@" diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index e8eebdfb5a581399a5bd97de7d5eff9356b2d869..b5628e378f1bc4e4f2d00e3ffe353d637ff982f4 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -142,6 +142,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", diff --git a/src/bootstrap/llvm.rs b/src/bootstrap/llvm.rs index 2dea078ba2ee3b2690f95643a5d39fbfd8f6fc15..a5de77e46e04b21afa9c0d1e99dcc60b67587bba 100644 --- a/src/bootstrap/llvm.rs +++ b/src/bootstrap/llvm.rs @@ -186,6 +186,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/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 682186a159eda47cdb85e92ff698356d56f6af23..9a053e5cd982facc7bd1045bc39c3a4c081a20cd 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -89,6 +89,7 @@ target | notes `arm-unknown-linux-gnueabihf` | ARMv6 Linux, hardfloat (kernel 3.2, glibc 2.17) `armv7-unknown-linux-gnueabihf` | ARMv7-A Linux, hardfloat (kernel 3.2, glibc 2.17) [`loongarch64-unknown-linux-gnu`](platform-support/loongarch-linux.md) | LoongArch64 Linux, LP64D ABI (kernel 5.19, glibc 2.36) +[`loongarch64-unknown-linux-musl`](platform-support/loongarch-linux.md) | LoongArch64 Linux, LP64D ABI (kernel 5.19, musl 1.2.5) `mips-unknown-linux-gnu` | MIPS Linux (kernel 4.4, glibc 2.23) `mips64-unknown-linux-gnuabi64` | MIPS64 Linux, n64 ABI (kernel 4.4, glibc 2.23) `mips64el-unknown-linux-gnuabi64` | MIPS64 (LE) Linux, n64 ABI (kernel 4.4, glibc 2.23) diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index 8b28c68e04fe9ad92f3ed68dadd549910e6e2003..443ed23411f564f87d7fdad7d808d4db655993a2 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -25,6 +25,7 @@ "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,8 @@ "i686-unknown-linux-musl", "i686-unknown-uefi", "loongarch64-unknown-linux-gnu", + "loongarch64-unknown-linux-musl", + "loongarch64-unknown-linux-ohos", "m68k-unknown-linux-gnu", "mips-unknown-linux-gnu", "mips-unknown-linux-musl",