
# Copyright 2024-2026 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause

name: RK superbuild (release)

on:
  workflow_dispatch:
    inputs:
      version:
        description: 'ISPC release version (just number without v, e.g., 1.24.0)'
        required: true
        type: string

permissions: read-all

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build-cpu-ubuntu-2204:
    runs-on: ubuntu-latest
    # Disabling this workflow for non ispc/ispc repo as it needs to run on releases only.
    if: github.repository == 'ispc/ispc'
    container:
      image: ubuntu:22.04

    steps:
    - name: Install packages
      run: |
        echo "Installing build dependencies..."
        apt -y update && apt -y install git wget tar build-essential cmake ninja-build libglfw3-dev libgl1-mesa-dev libxinerama-dev libxcursor-dev libxi-dev python3-dev

    - name: Clone RK superbuild repo
      uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
      with:
        repository: RenderKit/superbuild

    - name: Download ISPC release archives
      env:
        LINK: https://github.com/ispc/ispc/releases/download/v${{ inputs.version }}/ispc-v${{ inputs.version }}-linux.tar.gz
        INPUTS_VERSION: ${{ inputs.version }}
      run: |
        echo "Download artifact ${LINK}" >> "$GITHUB_STEP_SUMMARY"
        wget "${LINK}"
        tar xf "ispc-v${INPUTS_VERSION}-linux.tar.gz"
      shell: bash

    - name: Build
      run: |
        mkdir build
        cd build
        cmake -DISPC_URL="${GITHUB_WORKSPACE}/ispc-v${INPUTS_VERSION}-linux.tar.gz" -DISPC_VERSION=${INPUTS_VERSION} ../
        cmake --build .
      env:
        INPUTS_VERSION: ${{ inputs.version }}

    - name: Upload RK install
      uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
      with:
        name: rk_install_linux
        path: build/install

  test-oidn-ubuntu-2204:
    needs: build-cpu-ubuntu-2204
    runs-on: ubuntu-latest
    if: github.repository == 'ispc/ispc'
    container:
      image: ubuntu:22.04
    strategy:
      fail-fast: false
      matrix:
        test:
          - name: oidnTest
            cmd: ./bin/oidnTest
          - name: oidnBenchmark
            cmd: ./bin/oidnBenchmark -v 1

    steps:
    - name: Install packages
      run: |
        apt -y update && apt -y install libtbb-dev libglfw3-dev

    - name: Download RK install
      uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
      with:
        name: rk_install_linux

    - name: Run ${{ matrix.test.name }}
      run: |
        chmod +x ./bin/*
        export LD_LIBRARY_PATH=$PWD/lib:$LD_LIBRARY_PATH
        ${{ matrix.test.cmd }}

  build-ospray-windows:
    runs-on: windows-2022
    # Disabling this workflow for non ispc/ispc repo as it needs to run on releases only.
    if: github.repository == 'ispc/ispc'
    steps:
    - name: Clone RK ospray repo
      uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
      with:
        repository: ospray/ospray

    - name: Download ISPC release archives
      env:
        LINK: https://github.com/ispc/ispc/releases/download/v${{ inputs.version }}/ispc-v${{ inputs.version }}-windows.zip
      run: |
        Install-ChocoPackage wget
        echo "Download artifact $env:LINK >> $env:GITHUB_STEP_SUMMARY"
        wget -q $env:LINK

    - name: Add ISPC to the PATH
      run: |
        Expand-Archive $pwd\ispc-v$env:INPUTS_VERSION-windows.zip -DestinationPath $pwd
        echo "$pwd\ispc-v$env:INPUTS_VERSION-windows\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
      env:
        INPUTS_VERSION: ${{ inputs.version }}

    - name: Build ospray superbuild
      run: |
        mkdir build
        cd build
        cmake -G "Visual Studio 17 2022" -A x64 ../scripts/superbuild -DDOWNLOAD_ISPC=OFF -DCMAKE_BUILD_TYPE=Release -DDEPENDENCIES_BUILD_TYPE=Release
        cmake --build . --config Release

  build-oidn-linux-aarch64:
    runs-on: ubuntu-24.04-arm
    if: github.repository == 'ispc/ispc'
    container:
      image: arm64v8/ubuntu:22.04

    steps:
    - name: Install packages
      run: |
        apt -y update && apt -y install build-essential cmake git git-lfs wget python3 libtbb2-dev

    - name: Clone OIDN repo
      uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
      with:
        repository: RenderKit/oidn
        submodules: true
        lfs: true

    - name: Download ISPC release archives
      env:
        LINK: https://github.com/ispc/ispc/releases/download/v${{ inputs.version }}/ispc-v${{ inputs.version }}-linux.aarch64.tar.gz
        INPUTS_VERSION: ${{ inputs.version }}
      run: |
        echo "Download artifact ${LINK}" >> "$GITHUB_STEP_SUMMARY"
        wget "${LINK}"
        tar xf "ispc-v${INPUTS_VERSION}-linux.aarch64.tar.gz"
      shell: bash

    - name: Build OIDN
      run: |
        export PATH="${GITHUB_WORKSPACE}/ispc-v${INPUTS_VERSION}-linux.aarch64/bin:$PATH"
        mkdir build
        cd build
        cmake -DCMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/install -DOIDN_INSTALL_DEPENDENCIES=ON -DOIDN_ZIP_MODE=ON ..
        make -j$(nproc) install
      env:
        INPUTS_VERSION: ${{ inputs.version }}

    - name: Upload OIDN install
      uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
      with:
        name: oidn_install_linux_aarch64
        path: install

  test-oidn-linux-aarch64:
    needs: build-oidn-linux-aarch64
    runs-on: ubuntu-24.04-arm
    if: github.repository == 'ispc/ispc'
    container:
      image: arm64v8/ubuntu:22.04
    strategy:
      fail-fast: false
      matrix:
        test:
          - name: oidnTest
            cmd: ./bin/oidnTest
          - name: oidnBenchmark
            cmd: ./bin/oidnBenchmark -v 1

    steps:
    - name: Install packages
      run: |
        apt -y update && apt -y install libtbb2-dev

    - name: Download OIDN install
      uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
      with:
        name: oidn_install_linux_aarch64

    - name: Run ${{ matrix.test.name }}
      run: |
        chmod +x ./bin/*
        export LD_LIBRARY_PATH=$PWD/lib:$LD_LIBRARY_PATH
        ${{ matrix.test.cmd }}
