From eccf588b24dc80026916c33d21b57dadf28479d0 Mon Sep 17 00:00:00 2001 From: Dominik Hassler Date: Thu, 19 Dec 2024 16:22:35 +0000 Subject: [PATCH] aarch64: build rust --- build/rust/build-arch-aarch64.sh | 105 +++++++++++ build/rust/build.sh | 1 + ...ch64-cpu-feature-support-for-illumos.patch | 167 ++++++++++++++++++ build/rust/patches/aarch64-cpu-features.patch | 35 ---- build/rust/patches/aarch64-eh_frame-ro.patch | 2 +- build/rust/patches/series | 2 +- doc/baseline.aarch64 | 1 + doc/pkglist.aarch64 | 1 + 8 files changed, 277 insertions(+), 37 deletions(-) create mode 100755 build/rust/build-arch-aarch64.sh create mode 100644 build/rust/patches/0001-aarch64-cpu-feature-support-for-illumos.patch delete mode 100644 build/rust/patches/aarch64-cpu-features.patch diff --git a/build/rust/build-arch-aarch64.sh b/build/rust/build-arch-aarch64.sh new file mode 100755 index 000000000..59cbde0da --- /dev/null +++ b/build/rust/build-arch-aarch64.sh @@ -0,0 +1,105 @@ +#!/usr/bin/bash +# +# {{{ CDDL HEADER +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# }}} + +# Copyright 2024 OmniOS Community Edition (OmniOSce) Association. + +. ../../lib/build.sh + +PROG=rust +PKG=ooce/developer/rust +VER=1.83.0 +SUMMARY="Rust systems programming language" +DESC="Rust is a systems programming language that runs blazingly fast, " +DESC+="prevents segfaults, and guarantees thread safety." + +set_builddir ${PROG}c-${VER}-src + +OPREFIX=$PREFIX +PREFIX+=/$PROG + +BUILD_DEPENDS_IPS="developer/gnu-binutils" +# TODO: globbing only works reliably as long as we just have +# one cross compiler version per arch. +crossgccver=`pkg_ver aarch64/gcc*` +crossgccver=${crossgccver%%.*} +# `rustc` uses `gcc` as its linker. Other dependencies such as the C runtime +# and linker are themselves pulled in as dependencies of the gcc package. +RUN_DEPENDS_IPS="developer/gcc$crossgccver" + +# rust build requires the final install directory to be present +[ -d "$PREFIX" ] || logcmd $PFEXEC mkdir -p $PREFIX + +XFORM_ARGS=" + -DPREFIX=${PREFIX#/} + -DOPREFIX=${OPREFIX#/} + -DPROG=$PROG +" + +SKIP_RTIME_CHECK=1 +SKIP_SSP_CHECK=1 +NO_SONAME_EXPECTED=1 + +aarch64prefix=$CROSSTOOLS/aarch64/bin/${TRIPLETS[aarch64]} +CONFIGURE_OPTS[aarch64]=" + --prefix=$PREFIX + --sysconfdir=/etc$PREFIX + --localstatedir=/var$PREFIX + --set target.${RUSTTRIPLETS[aarch64]}.cc=$aarch64prefix-gcc + --set target.${RUSTTRIPLETS[aarch64]}.cxx=$aarch64prefix-g++ + --set target.${RUSTTRIPLETS[aarch64]}.ar=$aarch64prefix-ar +" +CONFIGURE_OPTS+=" + --release-description=OmniOS/$RELVER + --enable-vendor + --enable-local-rust + --enable-extended + --build=${RUSTTRIPLETS[$BUILD_ARCH]} + --host=${RUSTTRIPLETS[aarch64]} + --target=${RUSTTRIPLETS[aarch64]} + --enable-rpath + --enable-ninja + --disable-codegen-tests + --disable-dist-src + --disable-llvm-static-stdcpp + --disable-docs + --release-channel=stable + --python=$PYTHON +" + +pre_configure() { :; + # rust needs to find the native gcc for bootstrapping + set_gccver $DEFAULT_GCC_VER + + tripus=${RUSTTRIPLETS[aarch64]//-/_} + tripuc=${tripus^^} + export CARGO_TARGET_${tripuc}_RUSTFLAGS=" + -C link-arg=--sysroot=${SYSROOT[aarch64]} + " + export CXXFLAGS_${tripus}="-mno-outline-atomics -mtls-dialect=trad" +} + +pre_install() { + logcmd $MKDIR -p $DESTDIR/$PREFIX || logerr "failed to create directory" +} + +init +download_source $PROG ${PROG}c $VER-src +patch_source +prep_build autoconf-like +build -noctf +make_package +clean_up + +# Vim hints +# vim:ts=4:sw=4:et:fdm=marker diff --git a/build/rust/build.sh b/build/rust/build.sh index f0f2359c0..429a290ed 100755 --- a/build/rust/build.sh +++ b/build/rust/build.sh @@ -14,6 +14,7 @@ # Copyright 2024 OmniOS Community Edition (OmniOSce) Association. +. ../../lib/arch.sh . ../../lib/build.sh PROG=rust diff --git a/build/rust/patches/0001-aarch64-cpu-feature-support-for-illumos.patch b/build/rust/patches/0001-aarch64-cpu-feature-support-for-illumos.patch new file mode 100644 index 000000000..febdef682 --- /dev/null +++ b/build/rust/patches/0001-aarch64-cpu-feature-support-for-illumos.patch @@ -0,0 +1,167 @@ +From 3e39942698fdc876135000d3fa12f5bad0eecfcc Mon Sep 17 00:00:00 2001 +From: Dominik Hassler +Date: Fri, 20 Dec 2024 15:17:18 +0000 +Subject: [PATCH] aarch64 cpu feature support for illumos + +--- + compiler-rt/lib/builtins/cpu_model/aarch64.c | 7 ++ + .../cpu_model/aarch64/fmv/illumos.inc | 109 ++++++++++++++++++ + .../cpu_model/aarch64/lse_atomics/illumos.inc | 5 + + 3 files changed, 121 insertions(+) + create mode 100644 compiler-rt/lib/builtins/cpu_model/aarch64/fmv/illumos.inc + create mode 100644 compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/illumos.inc + +diff --git a/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c b/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c +index b868caa991b2..a789a9c47745 100644 +--- a/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c ++++ b/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c +@@ -45,6 +45,11 @@ _Bool __aarch64_have_lse_atomics + #elif defined(__ANDROID__) + #include "aarch64/hwcap.inc" + #include "aarch64/lse_atomics/android.inc" ++#elif defined(__illumos__) ++// clang-format off: should not reorder sys/auxv.h alphabetically ++#include ++// clang-format on ++#include "aarch64/lse_atomics/illumos.inc" + #elif __has_include() + #include "aarch64/hwcap.inc" + #include "aarch64/lse_atomics/sysauxv.inc" +@@ -73,6 +78,8 @@ struct { + #elif defined(__ANDROID__) + #include "aarch64/fmv/mrs.inc" + #include "aarch64/fmv/android.inc" ++#elif defined(__illumos__) ++#include "aarch64/fmv/illumos.inc" + #elif __has_include() + #include "aarch64/fmv/mrs.inc" + #include "aarch64/fmv/sysauxv.inc" +diff --git a/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/illumos.inc b/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/illumos.inc +new file mode 100644 +index 000000000000..2a968e1a1d1f +--- /dev/null ++++ b/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/fmv/illumos.inc +@@ -0,0 +1,109 @@ ++#include ++#define HAVE_SYS_AUXV_H ++ ++static void __init_cpu_features_constructor(unsigned long hwcap, ++ const __ifunc_arg_t *arg) { ++ ++ uint64_t features = 0; ++ uint64_t hwcaps[] = { hwcap, arg->_hwcap2 }; ++ ++ static const struct hwcap_map_t { ++ uint32_t hw_cap; ++ uint32_t hw_index; ++ enum CPUFeatures hw_feature; ++ } hwcap_map[] = { ++ { AV_AARCH64_FP, 1, FEAT_FP }, ++ { AV_AARCH64_ADVSIMD, 1, FEAT_SIMD }, ++ { AV_AARCH64_SVE, 1, FEAT_SVE }, ++ { AV_AARCH64_CRC32, 1, FEAT_CRC }, ++ { AV_AARCH64_SB, 1, FEAT_SB }, ++// { AV_AARCH64_SSBS, 1, RESERVED_FEAT_SSBS}, ++// { AV_AARCH64_DGH, 1, RESERVED_FEAT_DGH}, ++// { AV_AARCH64_AES, 1, RESERVED_FEAT_AES}, ++ { AV_AARCH64_PMULL, 1, FEAT_PMULL}, ++// { AV_AARCH64_SHA1, 1, RESERVED_FEAT_SHA1}, ++ { AV_AARCH64_SHA256, 1, FEAT_SHA2}, ++ { AV_AARCH64_SHA512, 1, FEAT_SHA2}, ++ { AV_AARCH64_SHA3, 1, FEAT_SHA3}, ++// { AV_AARCH64_SM3, 1, ++// { AV_AARCH64_SM4, 1, ++ { AV_AARCH64_LSE, 1, FEAT_LSE}, ++ { AV_AARCH64_RDM, 1, FEAT_RDM}, ++ { AV_AARCH64_FP16, 1, FEAT_FP16}, ++ { AV_AARCH64_DOTPROD, 1, FEAT_DOTPROD}, ++// { AV_AARCH64_FHM, 1, ++// { AV_AARCH64_DCPOP, 1, ++ { AV_AARCH64_F32MM, 1, FEAT_SVE_F32MM}, ++ { AV_AARCH64_F64MM, 1, FEAT_SVE_F64MM}, ++// { AV_AARCH64_DCPODP, 1, ++ { AV_AARCH64_BF16, 1, FEAT_BF16}, ++ { AV_AARCH64_I8MM, 1, FEAT_I8MM}, ++ { AV_AARCH64_FCMA, 1, FEAT_FCMA}, ++ { AV_AARCH64_JSCVT, 1, FEAT_JSCVT}, ++ { AV_AARCH64_LRCPC, 1, FEAT_RCPC}, ++// { AV_AARCH64_PACA, 1, ++// { AV_AARCH64_PACG, 1, ++ { AV_AARCH64_DIT, 1, FEAT_DIT}, ++ { AV_AARCH64_2_FLAGM, 2, FEAT_FLAGM}, ++ { AV_AARCH64_2_ILRCPC, 2, FEAT_RCPC}, ++// { AV_AARCH64_2_LSE2, 2, ++ { AV_AARCH64_2_FLAGM2, 2, FEAT_FLAGM2}, ++ { AV_AARCH64_2_FRINTTS, 2, FEAT_FRINTTS}, ++ { AV_AARCH64_2_BTI, 2, FEAT_BTI}, ++ { AV_AARCH64_2_RNG, 2, FEAT_RNG}, ++ { AV_AARCH64_2_MTE, 2, FEAT_MEMTAG2}, ++// { AV_AARCH64_2_MTE3, 2, RESERVED_FEAT_MEMTAG3}, ++// { AV_AARCH64_2_ECV, 2, ++// { AV_AARCH64_2_AFP, 2, ++// { AV_AARCH64_2_RPRES, 2, RESERVED_FEAT_RPRES}, ++// { AV_AARCH64_2_LD64B, 2, ++// { AV_AARCH64_2_ST64BV, 2, ++// { AV_AARCH64_2_ST64BV0, ,2 ++ { AV_AARCH64_2_WFXT, 2, FEAT_WFXT}, ++ { AV_AARCH64_2_MOPS, 2, FEAT_MOPS}, ++// { AV_AARCH64_2_HBC, 2, ++// { AV_AARCH64_2_CMOW, 2, ++ { AV_AARCH64_2_SVE2, 2, FEAT_SVE2}, ++// { AV_AARCH64_2_SVE2_AES, 2, RESERVED_FEAT_SVE_AES}, ++ { AV_AARCH64_2_SVE2_BITPERM, 2, FEAT_SVE_BITPERM}, ++ { AV_AARCH64_2_SVE2_PMULL128, 2, FEAT_SVE_PMULL128}, ++ { AV_AARCH64_2_SVE2_SHA3, 2, FEAT_SVE_SHA3}, ++ { AV_AARCH64_2_SVE2_SM4, 2, FEAT_SVE_SM4}, ++// { AV_AARCH64_2_TME, 2, ++ { AV_AARCH64_2_SME, 2, FEAT_SME}, ++// { AV_AARCH64_2_SME_FA64, 2, ++// { AV_AARCH64_2_EBF16, 2, RESERVED_FEAT_EBF16}, ++ { AV_AARCH64_2_SME_F64F64, 2, FEAT_SME_F64}, ++ { AV_AARCH64_2_SME_I16I64, 2, FEAT_SME_I64} ++ }; ++ ++ for (size_t i = 0; i < sizeof (hwcap_map) / sizeof (hwcap_map[0]); i++) ++ if (hwcaps[hwcap_map[i].hw_index - 1] & hwcap_map[i].hw_cap) ++ features |= (1ULL << hwcap_map[i].hw_feature); ++ ++ __atomic_store_n(&__aarch64_cpu_features.features, features, __ATOMIC_RELAXED); ++} ++ ++void __init_cpu_features_resolver(unsigned long hwcap, ++ const __ifunc_arg_t *arg) { ++ if (__atomic_load_n(&__aarch64_cpu_features.features, __ATOMIC_RELAXED)) ++ return; ++ __init_cpu_features_constructor(hwcap, arg); ++} ++ ++void CONSTRUCTOR_ATTRIBUTE __init_cpu_features(void) { ++ uint32_t hwcap[2] = {0}; ++ // CPU features already initialized. ++ if (__atomic_load_n(&__aarch64_cpu_features.features, __ATOMIC_RELAXED)) ++ return; ++ ++ uint_t res = getisax(hwcap, 2); ++ if (res == 0) ++ return; ++ ++ __ifunc_arg_t arg; ++ arg._size = sizeof(__ifunc_arg_t); ++ arg._hwcap = hwcap[0], ++ arg._hwcap2 = hwcap[1]; ++ __init_cpu_features_constructor(hwcap[0], &arg); ++} +diff --git a/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/illumos.inc b/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/illumos.inc +new file mode 100644 +index 000000000000..78af1a19f48d +--- /dev/null ++++ b/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/illumos.inc +@@ -0,0 +1,5 @@ ++static void CONSTRUCTOR_ATTRIBUTE init_have_lse_atomics(void) { ++ uint32_t hwcap = 0; ++ uint_t res = getisax(&hwcap, 1); ++ __aarch64_have_lse_atomics = res != 0 && (hwcap & AV_AARCH64_LSE) != 0; ++} +-- +2.47.1 + diff --git a/build/rust/patches/aarch64-cpu-features.patch b/build/rust/patches/aarch64-cpu-features.patch deleted file mode 100644 index 367182005..000000000 --- a/build/rust/patches/aarch64-cpu-features.patch +++ /dev/null @@ -1,35 +0,0 @@ -diff -wpruN --no-dereference '--exclude=*.orig' a~/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/illumos.inc a/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/illumos.inc ---- a~/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/illumos.inc 1970-01-01 00:00:00 -+++ a/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64/lse_atomics/illumos.inc 1970-01-01 00:00:00 -@@ -0,0 +1,9 @@ -+#include -+ -+static void CONSTRUCTOR_ATTRIBUTE init_have_lse_atomics(void) { -+ uint32_t hwc[2] = {0}; -+ -+ (void) getisax(&hwc, 2); -+ -+ __aarch64_have_lse_atomics = (hwc[0] & AV_AARCH64_LSE) != 0; -+} -diff -wpruN --no-dereference '--exclude=*.orig' a~/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c a/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c ---- a~/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c 1970-01-01 00:00:00 -+++ a/src/llvm-project/compiler-rt/lib/builtins/cpu_model/aarch64.c 1970-01-01 00:00:00 -@@ -45,6 +45,9 @@ _Bool __aarch64_have_lse_atomics - #elif defined(__ANDROID__) - #include "aarch64/hwcap.inc" - #include "aarch64/lse_atomics/android.inc" -+#elif defined(__illumos__) -+#include "aarch64/hwcap.inc" -+#include "aarch64/lse_atomics/illumos.inc" - #elif __has_include() - #include "aarch64/hwcap.inc" - #include "aarch64/lse_atomics/sysauxv.inc" -@@ -141,7 +144,7 @@ struct { - #elif defined(__ANDROID__) - #include "aarch64/fmv/mrs.inc" - #include "aarch64/fmv/android.inc" --#elif __has_include() -+#elif __has_include() && !defined(__illumos__) - #include "aarch64/fmv/mrs.inc" - #include "aarch64/fmv/sysauxv.inc" - #else diff --git a/build/rust/patches/aarch64-eh_frame-ro.patch b/build/rust/patches/aarch64-eh_frame-ro.patch index e5afe505e..7422b606a 100644 --- a/build/rust/patches/aarch64-eh_frame-ro.patch +++ b/build/rust/patches/aarch64-eh_frame-ro.patch @@ -3,7 +3,7 @@ Ensure .eh_frame is consistently read-only for aarch64 diff -wpruN --no-dereference '--exclude=*.orig' a~/src/llvm-project/llvm/lib/MC/MCObjectFileInfo.cpp a/src/llvm-project/llvm/lib/MC/MCObjectFileInfo.cpp --- a~/src/llvm-project/llvm/lib/MC/MCObjectFileInfo.cpp 1970-01-01 00:00:00 +++ a/src/llvm-project/llvm/lib/MC/MCObjectFileInfo.cpp 1970-01-01 00:00:00 -@@ -381,8 +381,10 @@ void MCObjectFileInfo::initELFMCObjectFi +@@ -383,8 +383,10 @@ void MCObjectFileInfo::initELFMCObjectFi // Solaris requires different flags for .eh_frame to seemingly every other // platform. unsigned EHSectionFlags = ELF::SHF_ALLOC; diff --git a/build/rust/patches/series b/build/rust/patches/series index 7c53c7705..9dd199a9d 100644 --- a/build/rust/patches/series +++ b/build/rust/patches/series @@ -1,2 +1,2 @@ aarch64-eh_frame-ro.patch -aarch64-cpu-features.patch +0001-aarch64-cpu-feature-support-for-illumos.patch diff --git a/doc/baseline.aarch64 b/doc/baseline.aarch64 index 359400044..efb67109f 100644 --- a/doc/baseline.aarch64 +++ b/doc/baseline.aarch64 @@ -17,6 +17,7 @@ extra.omnios ooce/developer/cunit extra.omnios ooce/developer/git-absorb extra.omnios ooce/developer/ninja extra.omnios ooce/developer/protobuf +extra.omnios ooce/developer/rust extra.omnios ooce/editor/joe extra.omnios ooce/file/tree extra.omnios ooce/fonts/liberation diff --git a/doc/pkglist.aarch64 b/doc/pkglist.aarch64 index 9db96299a..454824512 100644 --- a/doc/pkglist.aarch64 +++ b/doc/pkglist.aarch64 @@ -9,6 +9,7 @@ # .SYSROOT Wait, rebuild the repo, `pkg install *` to the # arch-specific sysroot. +ooce/developer/rust ooce/system/htop ooce/library/libogg ooce/library/nettle