name: Determinism Check

env:
  CONVEX_VS_MESH_HASH: '0x4e5ff3fefc2a35fb'
  RAGDOLL_HASH: '0x5c61578b3cfa4cd0'
  PYRAMID_HASH: '0xafd93b295e75e3f6'
  CHARACTER_VIRTUAL_HASH: '0x19c55223035a8f1a'
  EMSCRIPTEN_VERSION: 4.0.2
  NODE_VERSION: 23.x
  UBUNTU_CLANG_VERSION: clang++-18
  UBUNTU_GCC_VERSION: g++-14
  UBUNTU_GCC_AARCH64_VERSION: aarch64-linux-gnu-g++-14
  UBUNTU_GCC_RISCV_VERSION: riscv64-linux-gnu-g++-14
  UBUNTU_GCC_POWERPC_VERSION: powerpc64le-linux-gnu-g++-14
  UBUNTU_GCC_LOONGARCH_VERSION: loongarch64-linux-gnu-g++-14

on:
  push:
    branches: [ master ]
    paths-ignore:
      - 'Docs/**'
      - '**.md'
  pull_request:
    branches: [ master ]
    paths-ignore:
      - 'Docs/**'
      - '**.md'

jobs:
  linux_clang:
    runs-on: ubuntu-latest
    name: Linux Clang Determinism Check

    steps:
    - name: Checkout Code
      uses: actions/checkout@v5
    - name: Configure CMake
      working-directory: ${{github.workspace}}/Build
      run: ./cmake_linux_clang_gcc.sh Distribution ${{env.UBUNTU_CLANG_VERSION}} -DCROSS_PLATFORM_DETERMINISTIC=ON -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=ON -DTARGET_PERFORMANCE_TEST=ON
    - name: Build
      run: cmake --build ${{github.workspace}}/Build/Linux_Distribution -j $(nproc)
    - name: Unit Tests
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ctest --output-on-failure --verbose
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ./PerformanceTest -q=LinearCast -t=max -s=ConvexVsMesh -validate_hash=${CONVEX_VS_MESH_HASH}
    - name: Test Ragdoll
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ./PerformanceTest -q=LinearCast -t=max -s=Ragdoll -validate_hash=${RAGDOLL_HASH}
    - name: Test Pyramid
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ./PerformanceTest -q=LinearCast -t=max -s=Pyramid -validate_hash=${PYRAMID_HASH}
    - name: Test CharacterVirtual
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ./PerformanceTest -q=Discrete -t=max -s=CharacterVirtual -validate_hash=${CHARACTER_VIRTUAL_HASH}

  linux_gcc:
    runs-on: ubuntu-latest
    name: Linux GCC Determinism Check

    steps:
    - name: Checkout Code
      uses: actions/checkout@v5
    - name: Configure CMake
      working-directory: ${{github.workspace}}/Build
      run: ./cmake_linux_clang_gcc.sh Distribution ${{env.UBUNTU_GCC_VERSION}} -DCROSS_PLATFORM_DETERMINISTIC=ON -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=ON -DTARGET_PERFORMANCE_TEST=ON
    - name: Build
      run: cmake --build ${{github.workspace}}/Build/Linux_Distribution -j $(nproc)
    - name: Unit Tests
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ctest --output-on-failure --verbose
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ./PerformanceTest -q=LinearCast -t=max -s=ConvexVsMesh -validate_hash=${CONVEX_VS_MESH_HASH}
    - name: Test Ragdoll
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ./PerformanceTest -q=LinearCast -t=max -s=Ragdoll -validate_hash=${RAGDOLL_HASH}
    - name: Test Pyramid
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ./PerformanceTest -q=LinearCast -t=max -s=Pyramid -validate_hash=${PYRAMID_HASH}
    - name: Test CharacterVirtual
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ./PerformanceTest -q=Discrete -t=max -s=CharacterVirtual -validate_hash=${CHARACTER_VIRTUAL_HASH}

  msvc_cl:
    runs-on: windows-latest
    name: Visual Studio CL Determinism Check

    steps:
    - name: Checkout Code
      uses: actions/checkout@v5
    - name: Add msbuild to PATH
      uses: microsoft/setup-msbuild@v2
    - name: Configure CMake
      working-directory: ${{github.workspace}}/Build
      run: ./cmake_vs2022_cl.bat -DCROSS_PLATFORM_DETERMINISTIC=ON -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=ON -DTARGET_PERFORMANCE_TEST=ON
    - name: Build
      run: msbuild Build\VS2022_CL\JoltPhysics.sln /property:Configuration=Distribution
    - name: Unit Tests
      working-directory: ${{github.workspace}}/Build/VS2022_CL/Distribution
      run: ./UnitTests.exe
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/VS2022_CL/Distribution
      run: ./PerformanceTest -q=LinearCast -t=max -s=ConvexVsMesh "-validate_hash=$env:CONVEX_VS_MESH_HASH"
    - name: Test Ragdoll
      working-directory: ${{github.workspace}}/Build/VS2022_CL/Distribution
      run: ./PerformanceTest -q=LinearCast -t=max -s=Ragdoll "-validate_hash=$env:RAGDOLL_HASH"
    - name: Test Pyramid
      working-directory: ${{github.workspace}}/Build/VS2022_CL/Distribution
      run: ./PerformanceTest -q=LinearCast -t=max -s=Pyramid "-validate_hash=$env:PYRAMID_HASH"
    - name: Test CharacterVirtual
      working-directory: ${{github.workspace}}/Build/VS2022_CL/Distribution
      run: ./PerformanceTest -q=Discrete -t=max -s=CharacterVirtual "-validate_hash=$env:CHARACTER_VIRTUAL_HASH"

  msvc_cl_32:
    runs-on: windows-latest
    name: Visual Studio CL 32-bit Determinism Check

    steps:
    - name: Checkout Code
      uses: actions/checkout@v5
    - name: Add msbuild to PATH
      uses: microsoft/setup-msbuild@v2
    - name: Configure CMake
      working-directory: ${{github.workspace}}/Build
      run: ./cmake_vs2022_cl_32bit.bat -DCROSS_PLATFORM_DETERMINISTIC=ON -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=ON -DTARGET_PERFORMANCE_TEST=ON
    - name: Build
      run: msbuild Build\VS2022_CL_32BIT\JoltPhysics.sln /property:Configuration=Distribution
    - name: Unit Tests
      working-directory: ${{github.workspace}}/Build/VS2022_CL_32BIT/Distribution
      run: ./UnitTests.exe
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/VS2022_CL_32BIT/Distribution
      run: ./PerformanceTest -q=LinearCast -t=max -s=ConvexVsMesh "-validate_hash=$env:CONVEX_VS_MESH_HASH"
    - name: Test Ragdoll
      working-directory: ${{github.workspace}}/Build/VS2022_CL_32BIT/Distribution
      run: ./PerformanceTest -q=LinearCast -t=max -s=Ragdoll "-validate_hash=$env:RAGDOLL_HASH"
    - name: Test Pyramid
      working-directory: ${{github.workspace}}/Build/VS2022_CL_32BIT/Distribution
      run: ./PerformanceTest -q=LinearCast -t=max -s=Pyramid "-validate_hash=$env:PYRAMID_HASH"
    - name: Test CharacterVirtual
      working-directory: ${{github.workspace}}/Build/VS2022_CL_32BIT/Distribution
      run: ./PerformanceTest -q=Discrete -t=max -s=CharacterVirtual "-validate_hash=$env:CHARACTER_VIRTUAL_HASH"

  macos:
    runs-on: macos-latest
    name: macOS Determinism Check

    steps:
    - name: Checkout Code
      uses: actions/checkout@v5
    - name: Configure CMake
      working-directory: ${{github.workspace}}/Build
      run: ./cmake_linux_clang_gcc.sh Distribution clang++ -DCROSS_PLATFORM_DETERMINISTIC=ON -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=ON -DTARGET_PERFORMANCE_TEST=ON
    - name: Build
      run: cmake --build ${{github.workspace}}/Build/Linux_Distribution -j $(nproc)
    - name: Unit Tests
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ctest --output-on-failure --verbose
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ./PerformanceTest -q=LinearCast -t=max -s=ConvexVsMesh -validate_hash=${CONVEX_VS_MESH_HASH}
    - name: Test Ragdoll
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ./PerformanceTest -q=LinearCast -t=max -s=Ragdoll -validate_hash=${RAGDOLL_HASH}
    - name: Test Pyramid
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ./PerformanceTest -q=LinearCast -t=max -s=Pyramid -validate_hash=${PYRAMID_HASH}
    - name: Test CharacterVirtual
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: ./PerformanceTest -q=Discrete -t=max -s=CharacterVirtual -validate_hash=${CHARACTER_VIRTUAL_HASH}

  arm_clang:
    runs-on: ubuntu-latest
    name: ARM Clang Determinism Check
    steps:
    - name: Checkout Code
      uses: actions/checkout@v5
    - name: Update index
      run: sudo apt-get update
    - name: Install Cross Compiler
      run: sudo apt-get install gcc-14-aarch64-linux-gnu gcc-14-multilib g++-14-multilib libstdc++-14-dev-arm64-cross qemu-user -y
    - name: Configure CMake
      working-directory: ${{github.workspace}}/Build
      run: ./cmake_linux_clang_gcc.sh Distribution ${{env.UBUNTU_CLANG_VERSION}} -DCROSS_COMPILE_ARM=ON -DCROSS_PLATFORM_DETERMINISTIC=ON -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=ON -DTARGET_PERFORMANCE_TEST=ON
    - name: Build
      run: cmake --build ${{github.workspace}}/Build/Linux_Distribution -j $(nproc)
    - name: Unit Tests
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./UnitTests
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./PerformanceTest -q=LinearCast -t=max -s=ConvexVsMesh -validate_hash=${CONVEX_VS_MESH_HASH}
    - name: Test Ragdoll
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./PerformanceTest -q=LinearCast -t=max -s=Ragdoll -validate_hash=${RAGDOLL_HASH}
    - name: Test Pyramid
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./PerformanceTest -q=LinearCast -t=max -s=Pyramid -validate_hash=${PYRAMID_HASH}
    - name: Test CharacterVirtual
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./PerformanceTest -q=Discrete -t=max -s=CharacterVirtual -validate_hash=${CHARACTER_VIRTUAL_HASH}

  arm_clang_32:
    runs-on: ubuntu-latest
    name: ARM Clang 32-bit Determinism Check
    steps:
    - name: Checkout Code
      uses: actions/checkout@v5
    - name: Update index
      run: sudo apt-get update
    - name: Install Cross Compiler
      run: sudo apt-get install g++-14-arm-linux-gnueabihf qemu-user -y
    - name: Configure CMake
      working-directory: ${{github.workspace}}/Build
      run: ./cmake_linux_clang_gcc.sh Distribution ${{env.UBUNTU_CLANG_VERSION}} -DCROSS_COMPILE_ARM=ON -DCROSS_COMPILE_ARM_TARGET="arm-linux-gnueabihf" -DCROSS_PLATFORM_DETERMINISTIC=ON -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=ON -DTARGET_PERFORMANCE_TEST=ON
    - name: Build
      run: cmake --build ${{github.workspace}}/Build/Linux_Distribution -j $(nproc)
    - name: Unit Tests
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-arm -L /usr/arm-linux-gnueabihf/ ./UnitTests
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-arm -L /usr/arm-linux-gnueabihf/ ./PerformanceTest -q=LinearCast -t=max -s=ConvexVsMesh -validate_hash=${CONVEX_VS_MESH_HASH}
    - name: Test Ragdoll
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-arm -L /usr/arm-linux-gnueabihf/ ./PerformanceTest -q=LinearCast -t=max -s=Ragdoll -validate_hash=${RAGDOLL_HASH}
    - name: Test Pyramid
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-arm -L /usr/arm-linux-gnueabihf/ ./PerformanceTest -q=LinearCast -t=max -s=Pyramid -validate_hash=${PYRAMID_HASH}
    - name: Test CharacterVirtual
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-arm -L /usr/arm-linux-gnueabihf/ ./PerformanceTest -q=Discrete -t=max -s=CharacterVirtual -validate_hash=${CHARACTER_VIRTUAL_HASH}

  arm_gcc:
    runs-on: ubuntu-latest
    name: ARM GCC Determinism Check
    steps:
    - name: Checkout Code
      uses: actions/checkout@v5
    - name: Update index
      run: sudo apt-get update
    - name: Install Cross Compiler
      run: sudo apt-get install g++-14-aarch64-linux-gnu gcc-14-multilib g++-14-multilib libstdc++-14-dev-arm64-cross qemu-user -y
    - name: Configure CMake
      working-directory: ${{github.workspace}}/Build
      run: ./cmake_linux_clang_gcc.sh Distribution ${{env.UBUNTU_GCC_AARCH64_VERSION}} -DCROSS_COMPILE_ARM=ON -DCROSS_PLATFORM_DETERMINISTIC=ON -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=ON -DTARGET_PERFORMANCE_TEST=ON
    - name: Build
      run: cmake --build ${{github.workspace}}/Build/Linux_Distribution -j $(nproc)
    - name: Unit Tests
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./UnitTests
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./PerformanceTest -q=LinearCast -t=max -s=ConvexVsMesh -validate_hash=${CONVEX_VS_MESH_HASH}
    - name: Test Ragdoll
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./PerformanceTest -q=LinearCast -t=max -s=Ragdoll -validate_hash=${RAGDOLL_HASH}
    - name: Test Pyramid
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./PerformanceTest -q=LinearCast -t=max -s=Pyramid -validate_hash=${PYRAMID_HASH}
    - name: Test CharacterVirtual
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./PerformanceTest -q=Discrete -t=max -s=CharacterVirtual -validate_hash=${CHARACTER_VIRTUAL_HASH}

  riscv_gcc:
    runs-on: ubuntu-latest
    name: RISC-V GCC Determinism Check
    steps:
    - name: Checkout Code
      uses: actions/checkout@v5
    - name: Update index
      run: sudo apt-get update
    - name: Install Cross Compiler
      run: sudo apt-get install g++-14-riscv64-linux-gnu gcc-14-multilib g++-14-multilib qemu-user -y
    - name: Configure CMake
      working-directory: ${{github.workspace}}/Build
      run: ./cmake_linux_clang_gcc.sh Distribution ${{env.UBUNTU_GCC_RISCV_VERSION}} -DCROSS_COMPILE_ARM=ON -DCROSS_PLATFORM_DETERMINISTIC=ON -DCROSS_COMPILE_ARM_TARGET="" -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=ON -DTARGET_PERFORMANCE_TEST=ON
    - name: Build
      run: cmake --build ${{github.workspace}}/Build/Linux_Distribution -j $(nproc)
    - name: Unit Tests
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-riscv64 -L /usr/riscv64-linux-gnu/ ./UnitTests
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-riscv64 -L /usr/riscv64-linux-gnu/ ./PerformanceTest -q=LinearCast -t=max -s=ConvexVsMesh -validate_hash=${CONVEX_VS_MESH_HASH}
    - name: Test Ragdoll
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-riscv64 -L /usr/riscv64-linux-gnu/ ./PerformanceTest -q=LinearCast -t=max -s=Ragdoll -validate_hash=${RAGDOLL_HASH}
    - name: Test Pyramid
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-riscv64 -L /usr/riscv64-linux-gnu/ ./PerformanceTest -q=LinearCast -t=max -s=Pyramid -validate_hash=${PYRAMID_HASH}
    - name: Test CharacterVirtual
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-riscv64 -L /usr/riscv64-linux-gnu/ ./PerformanceTest -q=Discrete -t=max -s=CharacterVirtual -validate_hash=${CHARACTER_VIRTUAL_HASH}

  powerpcle_gcc:
    runs-on: ubuntu-latest
    name: PowerPC Little Endian GCC Determinism Check
    steps:
    - name: Checkout Code
      uses: actions/checkout@v5
    - name: Update index
      run: sudo apt-get update
    - name: Install Cross Compiler
      run: sudo apt-get install g++-14-powerpc64le-linux-gnu gcc-14-multilib g++-14-multilib qemu-user -y
    - name: Configure CMake
      working-directory: ${{github.workspace}}/Build
      run: ./cmake_linux_clang_gcc.sh Distribution ${{env.UBUNTU_GCC_POWERPC_VERSION}} -DCROSS_COMPILE_ARM=ON -DCROSS_PLATFORM_DETERMINISTIC=ON -DCROSS_COMPILE_ARM_TARGET="" -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=ON -DTARGET_PERFORMANCE_TEST=ON
    - name: Build
      run: cmake --build ${{github.workspace}}/Build/Linux_Distribution -j $(nproc)
    - name: Unit Tests
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-ppc64le -L /usr/powerpc64le-linux-gnu/ ./UnitTests
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-ppc64le -L /usr/powerpc64le-linux-gnu/ ./PerformanceTest -q=LinearCast -t=max -s=ConvexVsMesh -validate_hash=${CONVEX_VS_MESH_HASH}
# This is really slow so disabled for the moment
#    - name: Test Ragdoll
#      working-directory: ${{github.workspace}}/Build/Linux_Distribution
#      run: qemu-ppc64le -L /usr/powerpc64le-linux-gnu/ ./PerformanceTest -q=LinearCast -t=max -s=Ragdoll -validate_hash=${RAGDOLL_HASH}
#    - name: Test Pyramid
#      working-directory: ${{github.workspace}}/Build/Linux_Distribution
#      run: qemu-ppc64le -L /usr/powerpc64le-linux-gnu/ ./PerformanceTest -q=LinearCast -t=max -s=Pyramid -validate_hash=${PYRAMID_HASH}

  loongarch_gcc:
    runs-on: ubuntu-latest
    name: LoongArch GCC Determinism Check
    steps:
    - name: Checkout Code
      uses: actions/checkout@v5
    - name: Update index
      run: sudo apt-get update
    - name: Install Cross Compiler
      run: sudo apt-get install g++-14-loongarch64-linux-gnu gcc-14-multilib g++-14-multilib qemu-user -y
    - name: Configure CMake
      working-directory: ${{github.workspace}}/Build
      run: ./cmake_linux_clang_gcc.sh Distribution ${{env.UBUNTU_GCC_LOONGARCH_VERSION}} -DCROSS_COMPILE_ARM=ON -DCROSS_PLATFORM_DETERMINISTIC=ON -DCROSS_COMPILE_ARM_TARGET="" -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=ON -DTARGET_PERFORMANCE_TEST=ON
    - name: Build
      run: cmake --build ${{github.workspace}}/Build/Linux_Distribution -j $(nproc)
    - name: Unit Tests
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-loongarch64 -L /usr/loongarch64-linux-gnu/ ./UnitTests
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-loongarch64 -L /usr/loongarch64-linux-gnu/ ./PerformanceTest -q=LinearCast -t=max -s=ConvexVsMesh -validate_hash=${CONVEX_VS_MESH_HASH}
    - name: Test Ragdoll
      working-directory: ${{github.workspace}}/Build/Linux_Distribution
      run: qemu-loongarch64 -L /usr/loongarch64-linux-gnu/ ./PerformanceTest -q=LinearCast -t=max -s=Ragdoll -validate_hash=${RAGDOLL_HASH}
# This is slow so disabled for the moment
#    - name: Test Pyramid
#      working-directory: ${{github.workspace}}/Build/Linux_Distribution
#      run: qemu-loongarch64 -L /usr/loongarch64-linux-gnu/ ./PerformanceTest -q=LinearCast -t=max -s=Pyramid -validate_hash=${PYRAMID_HASH}

  emscripten:
    runs-on: ubuntu-latest
    name: Emscripten WASM32 Determinism Check

    steps:
    - name: Checkout Code
      uses: actions/checkout@v5
    - name: Setup emsdk
      uses: mymindstorm/setup-emsdk@v14
      with:
        version: ${{env.EMSCRIPTEN_VERSION}}
    - name: Verify emsdk
      run: emcc -v
    - name: Setup Node.js ${{env.NODE_VERSION}}
      uses: actions/setup-node@v4
      with:
        node-version: ${{env.NODE_VERSION}}
    - name: Configure CMake
      working-directory: ${{github.workspace}}/Build
      run: ./cmake_linux_emscripten.sh Distribution -DCROSS_PLATFORM_DETERMINISTIC=ON -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=ON -DTARGET_PERFORMANCE_TEST=ON
    - name: Build
      run: cmake --build ${{github.workspace}}/Build/WASM_Distribution -j $(nproc)      
    - name: Unit Tests
      working-directory: ${{github.workspace}}/Build/WASM_Distribution
      run: node UnitTests.js
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/WASM_Distribution
      run: node PerformanceTest.js -q=LinearCast -t=max -s=ConvexVsMesh -validate_hash=${CONVEX_VS_MESH_HASH}
    - name: Test Ragdoll
      working-directory: ${{github.workspace}}/Build/WASM_Distribution
      run: node PerformanceTest.js -q=LinearCast -t=max -s=Ragdoll -validate_hash=${RAGDOLL_HASH}
    - name: Test Pyramid
      working-directory: ${{github.workspace}}/Build/WASM_Distribution
      run: node PerformanceTest.js -q=LinearCast -t=max -s=Pyramid -validate_hash=${PYRAMID_HASH}
    - name: Test CharacterVirtual
      working-directory: ${{github.workspace}}/Build/WASM_Distribution
      run: node PerformanceTest.js -q=Discrete -t=max -s=CharacterVirtual -validate_hash=${CHARACTER_VIRTUAL_HASH}

  emscripten64:
    runs-on: ubuntu-latest
    name: Emscripten WASM64 Determinism Check

    steps:
    - name: Checkout Code
      uses: actions/checkout@v5
    - name: Setup emsdk
      uses: mymindstorm/setup-emsdk@v14
      with:
        version: ${{env.EMSCRIPTEN_VERSION}}
    - name: Verify emsdk
      run: emcc -v
    - name: Setup Node.js ${{env.NODE_VERSION}}
      uses: actions/setup-node@v4
      with:
        node-version: ${{env.NODE_VERSION}}
    - name: Configure CMake
      working-directory: ${{github.workspace}}/Build
      run: ./cmake_linux_emscripten.sh Distribution -DCROSS_PLATFORM_DETERMINISTIC=ON -DTARGET_VIEWER=OFF -DTARGET_SAMPLES=OFF -DTARGET_HELLO_WORLD=OFF -DTARGET_UNIT_TESTS=ON -DTARGET_PERFORMANCE_TEST=ON -DJPH_USE_WASM64=ON
    - name: Build
      run: cmake --build ${{github.workspace}}/Build/WASM_Distribution -j $(nproc)      
    - name: Unit Tests
      working-directory: ${{github.workspace}}/Build/WASM_Distribution
      run: node --experimental-wasm-memory64 UnitTests.js
    - name: Test ConvexVsMesh
      working-directory: ${{github.workspace}}/Build/WASM_Distribution
      run: node --experimental-wasm-memory64 PerformanceTest.js -q=LinearCast -t=max -s=ConvexVsMesh -validate_hash=${CONVEX_VS_MESH_HASH}
    - name: Test Ragdoll
      working-directory: ${{github.workspace}}/Build/WASM_Distribution
      run: node --experimental-wasm-memory64 PerformanceTest.js -q=LinearCast -t=max -s=Ragdoll -validate_hash=${RAGDOLL_HASH}
    - name: Test Pyramid
      working-directory: ${{github.workspace}}/Build/WASM_Distribution
      run: node --experimental-wasm-memory64 PerformanceTest.js -q=LinearCast -t=max -s=Pyramid -validate_hash=${PYRAMID_HASH}
    - name: Test CharacterVirtual
      working-directory: ${{github.workspace}}/Build/WASM_Distribution
      run: node --experimental-wasm-memory64 PerformanceTest.js -q=Discrete -t=max -s=CharacterVirtual -validate_hash=${CHARACTER_VIRTUAL_HASH}
