From 0545cbe4b353dddc12089c7f4d86e9b7d3254b0a Mon Sep 17 00:00:00 2001 From: Madhav Madhusoodanan Date: Sat, 18 Oct 2025 11:27:36 +0530 Subject: [PATCH 1/4] feat: separate `intrinsic-test` from the other CI pipelines --- .github/workflows/main.yml | 69 ++++++++++++++++++++++ ci/intrinsic-test-docker.sh | 58 ++++++++++++++++++ ci/intrinsic-test.sh | 114 ++++++++++++++++++++++++++++++++++++ ci/run.sh | 51 ---------------- 4 files changed, 241 insertions(+), 51 deletions(-) create mode 100755 ci/intrinsic-test-docker.sh create mode 100755 ci/intrinsic-test.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b0d476f0e2..f80855b08b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -248,6 +248,74 @@ jobs: if: matrix.target.os == 'ubuntu-latest' && !startsWith(matrix.target.tuple, 'thumb') env: TARGET: ${{ matrix.target.tuple }} + + intrinsic-test: + needs: [style] + name: Intrinsic Test + runs-on: ${{ matrix.target.os }} + strategy: + matrix: + profile: + - dev + - release + target: + # Dockers that are run through docker on linux + - tuple: arm-unknown-linux-gnueabihf + os: ubuntu-latest + - tuple: armv7-unknown-linux-gnueabihf + os: ubuntu-latest + - tuple: aarch64-unknown-linux-gnu + os: ubuntu-latest + - tuple: aarch64_be-unknown-linux-gnu + os: ubuntu-latest + + # Add additional variables to the matrix variations generated above using `include`: + include: + # `TEST_EVERYTHING` setups - there should be at least 1 for each architecture + - target: + tuple: aarch64-unknown-linux-gnu + os: ubuntu-latest + test_everything: true + - target: + tuple: aarch64_be-unknown-linux-gnu + os: ubuntu-latest + test_everything: true + build_std: true + - target: + tuple: armv7-unknown-linux-gnueabihf + os: ubuntu-latest + test_everything: true + + steps: + - uses: actions/checkout@v4 + - name: Install Rust + run: | + rustup update nightly --no-self-update + rustup default nightly + shell: bash + - run: rustup target add ${{ matrix.target.tuple }} + shell: bash + if: matrix.build_std == '' + - run: | + rustup component add rust-src + echo "CARGO_UNSTABLE_BUILD_STD=std" >> $GITHUB_ENV + shell: bash + if: matrix.build_std != '' + + # Configure some env vars based on matrix configuration + - run: echo "PROFILE=--profile=${{matrix.profile}}" >> $GITHUB_ENV + shell: bash + - run: echo "STDARCH_TEST_EVERYTHING=1" >> $GITHUB_ENV + shell: bash + if: matrix.test_everything != '' + - run: echo "STDARCH_DISABLE_ASSERT_INSTR=1" >> $GITHUB_ENV + shell: bash + if: matrix.disable_assert_instr != '' + - run: ./ci/intrinsic-test-docker.sh ${{ matrix.target.tuple }} + shell: bash + if: matrix.target.os == 'ubuntu-latest' && !startsWith(matrix.target.tuple, 'thumb') + env: + TARGET: ${{ matrix.target.tuple }} # Check that the generated files agree with the checked-in versions. check-stdarch-gen: @@ -276,6 +344,7 @@ jobs: - docs - verify - test + - intrinsic-test - check-stdarch-gen runs-on: ubuntu-latest # We need to ensure this job does *not* get skipped if its dependencies fail, diff --git a/ci/intrinsic-test-docker.sh b/ci/intrinsic-test-docker.sh new file mode 100755 index 0000000000..f9c6edc349 --- /dev/null +++ b/ci/intrinsic-test-docker.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env sh + +# Small script to run tests for a target (or all targets) inside all the +# respective docker images. + +set -ex + +if [ $# -lt 1 ]; then + >&2 echo "Usage: $0 " + exit 1 +fi + +run() { + # Set the linker that is used for the host (e.g. when compiling a build.rs) + # This overrides any configuration in e.g. `.cargo/config.toml`, which will + # probably not work within the docker container. + HOST_LINKER="CARGO_TARGET_$(rustc --print host-tuple | tr '[:lower:]-' '[:upper:]_')_LINKER" + + # Prevent `Read-only file system (os error 30)`. + cargo generate-lockfile + + echo "Building docker container for TARGET=${1}" + docker build -t stdarch -f "ci/docker/${1}/Dockerfile" ci/ + mkdir -p target c_programs rust_programs + echo "Running docker" + # shellcheck disable=SC2016 + docker run \ + --rm \ + --user "$(id -u)":"$(id -g)" \ + --env CARGO_HOME=/cargo \ + --env CARGO_TARGET_DIR=/checkout/target \ + --env TARGET="${1}" \ + --env "${HOST_LINKER}"="cc" \ + --env STDARCH_TEST_EVERYTHING \ + --env STDARCH_DISABLE_ASSERT_INSTR \ + --env NOSTD \ + --env NORUN \ + --env RUSTFLAGS \ + --env CARGO_UNSTABLE_BUILD_STD \ + --volume "${HOME}/.cargo":/cargo \ + --volume "$(rustc --print sysroot)":/rust:ro \ + --volume "$(pwd)":/checkout:ro \ + --volume "$(pwd)"/target:/checkout/target \ + --volume "$(pwd)"/c_programs:/checkout/c_programs \ + --volume "$(pwd)"/rust_programs:/checkout/rust_programs \ + --init \ + --workdir /checkout \ + --privileged \ + stdarch \ + sh -c "HOME=/tmp PATH=\$PATH:/rust/bin exec ci/intrinsic-test.sh ${1}" +} + +if [ -z "$1" ]; then + >&2 echo "No target specified!" + exit 1 +else + run "${1}" +fi diff --git a/ci/intrinsic-test.sh b/ci/intrinsic-test.sh new file mode 100755 index 0000000000..fe47f235be --- /dev/null +++ b/ci/intrinsic-test.sh @@ -0,0 +1,114 @@ +#!/usr/bin/env sh + +set -ex + +: "${TARGET?The TARGET environment variable must be set.}" + +# Tests are all super fast anyway, and they fault often enough on travis that +# having only one thread increases debuggability to be worth it. +#export RUST_BACKTRACE=full +#export RUST_TEST_NOCAPTURE=1 +#export RUST_TEST_THREADS=1 + +export RUSTFLAGS="${RUSTFLAGS} -D warnings -Z merge-functions=disabled -Z verify-llvm-ir" +export HOST_RUSTFLAGS="${RUSTFLAGS}" +export PROFILE="${PROFILE:="--profile=release"}" + +case ${TARGET} in + # On 32-bit use a static relocation model which avoids some extra + # instructions when dealing with static data, notably allowing some + # instruction assertion checks to pass below the 20 instruction limit. If + # this is the default, dynamic, then too many instructions are generated + # when we assert the instruction for a function and it causes tests to fail. + i686-* | i586-*) + export RUSTFLAGS="${RUSTFLAGS} -C relocation-model=static" + ;; + # Some x86_64 targets enable by default more features beyond SSE2, + # which cause some instruction assertion checks to fail. + x86_64-*) + export RUSTFLAGS="${RUSTFLAGS} -C target-feature=-sse3" + ;; + #Unoptimized build uses fast-isel which breaks with msa + mips-* | mipsel-*) + export RUSTFLAGS="${RUSTFLAGS} -C llvm-args=-fast-isel=false" + ;; + armv7-*eabihf | thumbv7-*eabihf) + export RUSTFLAGS="${RUSTFLAGS} -Ctarget-feature=+neon" + ;; + # Some of our test dependencies use the deprecated `gcc` crates which + # doesn't detect RISC-V compilers automatically, so do it manually here. + riscv*) + export RUSTFLAGS="${RUSTFLAGS} -Ctarget-feature=+zk,+zks,+zbb,+zbc" + ;; +esac + +echo "RUSTFLAGS=${RUSTFLAGS}" +echo "OBJDUMP=${OBJDUMP}" +echo "STDARCH_DISABLE_ASSERT_INSTR=${STDARCH_DISABLE_ASSERT_INSTR}" +echo "STDARCH_TEST_EVERYTHING=${STDARCH_TEST_EVERYTHING}" +echo "STDARCH_TEST_SKIP_FEATURE=${STDARCH_TEST_SKIP_FEATURE}" +echo "STDARCH_TEST_SKIP_FUNCTION=${STDARCH_TEST_SKIP_FUNCTION}" +echo "PROFILE=${PROFILE}" + +INTRINSIC_TEST="--manifest-path=crates/intrinsic-test/Cargo.toml" + +# Test targets compiled with extra features. +case ${TARGET} in + + x86_64* | i686*) + export STDARCH_DISABLE_ASSERT_INSTR=1 + ;; + + # Setup aarch64 & armv7 specific variables, the runner, along with some + # tests to skip + aarch64-unknown-linux-gnu*) + TEST_CPPFLAGS="-fuse-ld=lld -I/usr/aarch64-linux-gnu/include/ -I/usr/aarch64-linux-gnu/include/c++/9/aarch64-linux-gnu/" + TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_aarch64.txt + TEST_CXX_COMPILER="clang++" + TEST_RUNNER="${CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER}" + ;; + + aarch64_be-unknown-linux-gnu*) + TEST_CPPFLAGS="-fuse-ld=lld" + TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_aarch64.txt + TEST_CXX_COMPILER="clang++" + TEST_RUNNER="${CARGO_TARGET_AARCH64_BE_UNKNOWN_LINUX_GNU_RUNNER}" + ;; + + armv7-unknown-linux-gnueabihf*) + TEST_CPPFLAGS="-fuse-ld=lld -I/usr/arm-linux-gnueabihf/include/ -I/usr/arm-linux-gnueabihf/include/c++/9/arm-linux-gnueabihf/" + TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_arm.txt + TEST_CXX_COMPILER="clang++" + TEST_RUNNER="${CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER}" + ;; + *) + ;; + +esac + +# Arm specific +case "${TARGET}" in + aarch64-unknown-linux-gnu*|armv7-unknown-linux-gnueabihf*) + CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" RUST_LOG=warn \ + cargo run "${INTRINSIC_TEST}" "${PROFILE}" \ + --bin intrinsic-test -- intrinsics_data/arm_intrinsics.json \ + --runner "${TEST_RUNNER}" \ + --cppcompiler "${TEST_CXX_COMPILER}" \ + --skip "${TEST_SKIP_INTRINSICS}" \ + --target "${TARGET}" + ;; + + aarch64_be-unknown-linux-gnu*) + CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" RUST_LOG=warn \ + cargo run "${INTRINSIC_TEST}" "${PROFILE}" \ + --bin intrinsic-test -- intrinsics_data/arm_intrinsics.json \ + --runner "${TEST_RUNNER}" \ + --cppcompiler "${TEST_CXX_COMPILER}" \ + --skip "${TEST_SKIP_INTRINSICS}" \ + --target "${TARGET}" \ + --linker "${CARGO_TARGET_AARCH64_BE_UNKNOWN_LINUX_GNU_LINKER}" \ + --cxx-toolchain-dir "${AARCH64_BE_TOOLCHAIN}" + ;; + *) + ;; +esac diff --git a/ci/run.sh b/ci/run.sh index aa4479395d..2bb77bae25 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -79,7 +79,6 @@ cargo_test() { CORE_ARCH="--manifest-path=crates/core_arch/Cargo.toml" STDARCH_EXAMPLES="--manifest-path=examples/Cargo.toml" -INTRINSIC_TEST="--manifest-path=crates/intrinsic-test/Cargo.toml" cargo_test "${CORE_ARCH} ${PROFILE}" @@ -130,61 +129,11 @@ case ${TARGET} in export RUSTFLAGS="${RUSTFLAGS} -C target-feature=+altivec" cargo_test "${PROFILE}" ;; - - # Setup aarch64 & armv7 specific variables, the runner, along with some - # tests to skip - aarch64-unknown-linux-gnu*) - TEST_CPPFLAGS="-fuse-ld=lld -I/usr/aarch64-linux-gnu/include/ -I/usr/aarch64-linux-gnu/include/c++/9/aarch64-linux-gnu/" - TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_aarch64.txt - TEST_CXX_COMPILER="clang++" - TEST_RUNNER="${CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER}" - ;; - - aarch64_be-unknown-linux-gnu*) - TEST_CPPFLAGS="-fuse-ld=lld" - TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_aarch64.txt - TEST_CXX_COMPILER="clang++" - TEST_RUNNER="${CARGO_TARGET_AARCH64_BE_UNKNOWN_LINUX_GNU_RUNNER}" - ;; - - armv7-unknown-linux-gnueabihf*) - TEST_CPPFLAGS="-fuse-ld=lld -I/usr/arm-linux-gnueabihf/include/ -I/usr/arm-linux-gnueabihf/include/c++/9/arm-linux-gnueabihf/" - TEST_SKIP_INTRINSICS=crates/intrinsic-test/missing_arm.txt - TEST_CXX_COMPILER="clang++" - TEST_RUNNER="${CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER}" - ;; *) ;; esac -# Arm specific -case "${TARGET}" in - aarch64-unknown-linux-gnu*|armv7-unknown-linux-gnueabihf*) - CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" RUST_LOG=warn \ - cargo run "${INTRINSIC_TEST}" "${PROFILE}" \ - --bin intrinsic-test -- intrinsics_data/arm_intrinsics.json \ - --runner "${TEST_RUNNER}" \ - --cppcompiler "${TEST_CXX_COMPILER}" \ - --skip "${TEST_SKIP_INTRINSICS}" \ - --target "${TARGET}" - ;; - - aarch64_be-unknown-linux-gnu*) - CPPFLAGS="${TEST_CPPFLAGS}" RUSTFLAGS="${HOST_RUSTFLAGS}" RUST_LOG=warn \ - cargo run "${INTRINSIC_TEST}" "${PROFILE}" \ - --bin intrinsic-test -- intrinsics_data/arm_intrinsics.json \ - --runner "${TEST_RUNNER}" \ - --cppcompiler "${TEST_CXX_COMPILER}" \ - --skip "${TEST_SKIP_INTRINSICS}" \ - --target "${TARGET}" \ - --linker "${CARGO_TARGET_AARCH64_BE_UNKNOWN_LINUX_GNU_LINKER}" \ - --cxx-toolchain-dir "${AARCH64_BE_TOOLCHAIN}" - ;; - *) - ;; -esac - if [ "$NORUN" != "1" ] && [ "$NOSTD" != 1 ]; then # Test examples ( From 9d6f82439fd64d1c500a8cb0646c3ce6f5cd67e3 Mon Sep 17 00:00:00 2001 From: Madhav Madhusoodanan Date: Wed, 22 Oct 2025 11:48:08 +0530 Subject: [PATCH 2/4] chore: removing unused definitions or commented functionality in `ci/intrinsic-test.sh` --- ci/intrinsic-test.sh | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/ci/intrinsic-test.sh b/ci/intrinsic-test.sh index fe47f235be..469e9e21c7 100755 --- a/ci/intrinsic-test.sh +++ b/ci/intrinsic-test.sh @@ -4,12 +4,6 @@ set -ex : "${TARGET?The TARGET environment variable must be set.}" -# Tests are all super fast anyway, and they fault often enough on travis that -# having only one thread increases debuggability to be worth it. -#export RUST_BACKTRACE=full -#export RUST_TEST_NOCAPTURE=1 -#export RUST_TEST_THREADS=1 - export RUSTFLAGS="${RUSTFLAGS} -D warnings -Z merge-functions=disabled -Z verify-llvm-ir" export HOST_RUSTFLAGS="${RUSTFLAGS}" export PROFILE="${PROFILE:="--profile=release"}" @@ -44,21 +38,12 @@ esac echo "RUSTFLAGS=${RUSTFLAGS}" echo "OBJDUMP=${OBJDUMP}" -echo "STDARCH_DISABLE_ASSERT_INSTR=${STDARCH_DISABLE_ASSERT_INSTR}" -echo "STDARCH_TEST_EVERYTHING=${STDARCH_TEST_EVERYTHING}" -echo "STDARCH_TEST_SKIP_FEATURE=${STDARCH_TEST_SKIP_FEATURE}" -echo "STDARCH_TEST_SKIP_FUNCTION=${STDARCH_TEST_SKIP_FUNCTION}" echo "PROFILE=${PROFILE}" INTRINSIC_TEST="--manifest-path=crates/intrinsic-test/Cargo.toml" # Test targets compiled with extra features. case ${TARGET} in - - x86_64* | i686*) - export STDARCH_DISABLE_ASSERT_INSTR=1 - ;; - # Setup aarch64 & armv7 specific variables, the runner, along with some # tests to skip aarch64-unknown-linux-gnu*) From 24dd9a9ed22641f4cbd0aebc2b6398d592331d09 Mon Sep 17 00:00:00 2001 From: Madhav Madhusoodanan Date: Thu, 23 Oct 2025 19:28:32 +0530 Subject: [PATCH 3/4] feat: melding targets and include for `intrinsic-test` CI step --- .github/workflows/main.yml | 25 ++++++++----------------- ci/intrinsic-test-docker.sh | 1 - 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f80855b08b..9d7cd78084 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -258,33 +258,24 @@ jobs: profile: - dev - release - target: - # Dockers that are run through docker on linux - - tuple: arm-unknown-linux-gnueabihf - os: ubuntu-latest - - tuple: armv7-unknown-linux-gnueabihf - os: ubuntu-latest - - tuple: aarch64-unknown-linux-gnu - os: ubuntu-latest - - tuple: aarch64_be-unknown-linux-gnu - os: ubuntu-latest - # Add additional variables to the matrix variations generated above using `include`: include: - # `TEST_EVERYTHING` setups - there should be at least 1 for each architecture - target: tuple: aarch64-unknown-linux-gnu os: ubuntu-latest - test_everything: true + - target: tuple: aarch64_be-unknown-linux-gnu os: ubuntu-latest - test_everything: true build_std: true + - target: tuple: armv7-unknown-linux-gnueabihf os: ubuntu-latest - test_everything: true + + - target: + tuple: arm-unknown-linux-gnueabihf + os: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -295,12 +286,12 @@ jobs: shell: bash - run: rustup target add ${{ matrix.target.tuple }} shell: bash - if: matrix.build_std == '' + if: ${{ (matrix.build_std || false) == false }} - run: | rustup component add rust-src echo "CARGO_UNSTABLE_BUILD_STD=std" >> $GITHUB_ENV shell: bash - if: matrix.build_std != '' + if: ${{ (matrix.build_std || false) == true }} # Configure some env vars based on matrix configuration - run: echo "PROFILE=--profile=${{matrix.profile}}" >> $GITHUB_ENV diff --git a/ci/intrinsic-test-docker.sh b/ci/intrinsic-test-docker.sh index f9c6edc349..038fc4678e 100755 --- a/ci/intrinsic-test-docker.sh +++ b/ci/intrinsic-test-docker.sh @@ -31,7 +31,6 @@ run() { --env CARGO_TARGET_DIR=/checkout/target \ --env TARGET="${1}" \ --env "${HOST_LINKER}"="cc" \ - --env STDARCH_TEST_EVERYTHING \ --env STDARCH_DISABLE_ASSERT_INSTR \ --env NOSTD \ --env NORUN \ From 9d7cb2af081f20511029b787e61c4292299a85a3 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Thu, 23 Oct 2025 19:09:58 +0200 Subject: [PATCH 4/4] simplify intrinsic test matrix --- .github/workflows/main.yml | 55 +++++++++++--------------------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9d7cd78084..b852110a32 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -248,34 +248,22 @@ jobs: if: matrix.target.os == 'ubuntu-latest' && !startsWith(matrix.target.tuple, 'thumb') env: TARGET: ${{ matrix.target.tuple }} - + intrinsic-test: needs: [style] name: Intrinsic Test - runs-on: ${{ matrix.target.os }} + runs-on: ubuntu-latest strategy: matrix: - profile: - - dev - - release - + target: + - aarch64-unknown-linux-gnu + - aarch64_be-unknown-linux-gnu + - armv7-unknown-linux-gnueabihf + - arm-unknown-linux-gnueabihf + profile: [dev, release] include: - - target: - tuple: aarch64-unknown-linux-gnu - os: ubuntu-latest - - - target: - tuple: aarch64_be-unknown-linux-gnu - os: ubuntu-latest - build_std: true - - - target: - tuple: armv7-unknown-linux-gnueabihf - os: ubuntu-latest - - - target: - tuple: arm-unknown-linux-gnueabihf - os: ubuntu-latest + - target: aarch64_be-unknown-linux-gnu + build_std: true steps: - uses: actions/checkout@v4 @@ -283,30 +271,19 @@ jobs: run: | rustup update nightly --no-self-update rustup default nightly - shell: bash - - run: rustup target add ${{ matrix.target.tuple }} - shell: bash + - run: rustup target add ${{ matrix.target }} if: ${{ (matrix.build_std || false) == false }} - run: | rustup component add rust-src echo "CARGO_UNSTABLE_BUILD_STD=std" >> $GITHUB_ENV - shell: bash - if: ${{ (matrix.build_std || false) == true }} + if: ${{ matrix.build_std }} # Configure some env vars based on matrix configuration - - run: echo "PROFILE=--profile=${{matrix.profile}}" >> $GITHUB_ENV - shell: bash - - run: echo "STDARCH_TEST_EVERYTHING=1" >> $GITHUB_ENV - shell: bash - if: matrix.test_everything != '' - - run: echo "STDARCH_DISABLE_ASSERT_INSTR=1" >> $GITHUB_ENV - shell: bash - if: matrix.disable_assert_instr != '' - - run: ./ci/intrinsic-test-docker.sh ${{ matrix.target.tuple }} - shell: bash - if: matrix.target.os == 'ubuntu-latest' && !startsWith(matrix.target.tuple, 'thumb') + - run: echo "PROFILE=--profile=${{ matrix.profile }}" >> $GITHUB_ENV + - run: ./ci/intrinsic-test-docker.sh ${{ matrix.target }} + if: ${{ !startsWith(matrix.target, 'thumb') }} env: - TARGET: ${{ matrix.target.tuple }} + TARGET: ${{ matrix.target }} # Check that the generated files agree with the checked-in versions. check-stdarch-gen: