diff --git a/.github/workflows/loongarch.yml b/.github/workflows/loongarch.yml new file mode 100644 index 0000000..939fbbf --- /dev/null +++ b/.github/workflows/loongarch.yml @@ -0,0 +1,64 @@ +name: Rust + +on: [pull_request, workflow_dispatch] + +env: + TOOLCHAIN_HOME: /opt/cross-tools + TARGET: loongarch64-unknown-linux-gnu + DEBIAN_FRONTEND: noninteractive + +jobs: + loongarch: + name: LoongArch64 + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.rust == 'nightly' }} + strategy: + matrix: + rust: + - stable + - nightly + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Linux Install Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust }} + targets: "${TARGET}" + + - name: Install Cross Toolchain + run: | + # NOTE: Update this periodically + release="2025.08.08" + filename="loongarch64.tar.xz" + url="https://github.com/loongson/build-tools/releases/download/${release}/x86_64-cross-tools-loongarch64-binutils_2.45-gcc_15.1.0-glibc_2.42.tar.xz" + + wget "${url}" -O "${filename}" + tar -xf "${filename}" + sudo mv "cross-tools" "${TOOLCHAIN_HOME}" + rm "${filename}" + + "${TOOLCHAIN_HOME}/bin/loongarch64-unknown-linux-gnu-gcc" --version + + - name: Install Qemu Runner + run: | + sudo apt update && sudo apt install qemu-user -y --no-install-recommends + qemu-loongarch64 --version + + - name: Build and Test Library + run: | + export CC_loongarch64_unknown_linux_gnu="${TOOLCHAIN_HOME}/bin/loongarch64-unknown-linux-gnu-gcc" + export CXX_loongarch64_unknown_linux_gnu="${TOOLCHAIN_HOME}/bin/loongarch64-unknown-linux-gnu-g++" + export AR_loongarch64_unknown_linux_gnu="${TOOLCHAIN_HOME}/bin/loongarch64-unknown-linux-gnu-gcc-ar" + export CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_LINKER="${TOOLCHAIN_HOME}/bin/loongarch64-unknown-linux-gnu-gcc" + export CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_GNU_RUNNER="qemu-loongarch64 -L ${TOOLCHAIN_HOME}/target" + + # NOTE: The qemu runner does not seem to work for this architecture. + cargo build --target "${TARGET}" + cargo test --target "${TARGET}" + + cd devel + cargo build --target "${TARGET}" + cargo test --target "${TARGET}" diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index fe27e64..499170b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -122,9 +122,7 @@ jobs: uses: actions/checkout@v4 - name: Linux Install Rust toolchain - uses: dtolnay/rust-toolchain@master - with: - toolchain: 1.75.0 + uses: dtolnay/rust-toolchain@stable - name: Build, Check, and Test run: | diff --git a/build.rs b/build.rs index 0b4af93..f47fe05 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,7 @@ fn main() { let version = rustc_version::version().unwrap(); + let version_meta = rustc_version::version_meta().unwrap(); + let support_unstable = version_meta.channel == rustc_version::Channel::Nightly; if version >= rustc_version::Version::parse("1.63.0").unwrap() { println!("cargo:rustc-cfg=has_aarch64_intrinsics"); @@ -8,4 +10,8 @@ fn main() { if version >= rustc_version::Version::parse("1.70.0").unwrap() { println!("cargo:rustc-cfg=has_x86_intrinsics"); } + + if support_unstable && version >= rustc_version::Version::parse("1.89.0").unwrap() { + println!("cargo:rustc-cfg=has_loongarch_intrinsics"); + } } diff --git a/src/binary16/arch.rs b/src/binary16/arch.rs index a96aced..9a41ca5 100644 --- a/src/binary16/arch.rs +++ b/src/binary16/arch.rs @@ -33,6 +33,7 @@ macro_rules! convert_fn { $aarch64 } else if #[cfg(all( + has_loongarch_intrinsics, target_arch = "loongarch64", target_feature = "lsx" ))] { @@ -65,6 +66,7 @@ macro_rules! convert_fn { } } else if #[cfg(all( + has_loongarch_intrinsics, feature = "std", target_arch = "loongarch64", ))] { diff --git a/src/binary16/arch/loongarch64.rs b/src/binary16/arch/loongarch64.rs index 5e075cc..937306d 100644 --- a/src/binary16/arch/loongarch64.rs +++ b/src/binary16/arch/loongarch64.rs @@ -1,3 +1,6 @@ +#![cfg(has_loongarch_intrinsics)] +#![allow(unknown_lints)] + #[cfg(target_arch = "loongarch64")] use core::arch::loongarch64::{lsx_vfcvt_h_s, lsx_vfcvtl_s_h, m128, m128i}; use core::{mem::MaybeUninit, ptr}; diff --git a/src/lib.rs b/src/lib.rs index 0120a18..5171f60 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,8 +60,10 @@ //! [`std`]: https://doc.rust-lang.org/std/ //! [`binary16`]: https://en.wikipedia.org/wiki/Half-precision_floating-point_format //! [`bfloat16`]: https://en.wikipedia.org/wiki/Bfloat16_floating-point_format + #![allow(clippy::verbose_bit_mask, clippy::cast_lossless, unexpected_cfgs)] #![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(all(target_arch = "loongarch64", has_loongarch_intrinsics), feature(stdarch_loongarch))] #![doc(html_root_url = "https://docs.rs/float16/0.1.6")] #![doc(test(attr(deny(warnings), allow(unused))))] // Until updated to use newly stabilized `from_bits`, disable new lint warning about the transmutes