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

# These jobs build ISPC for every push to main pushing artifacts to Github
# pre-release.
name: Pre-release Artifacts

on:
  push:
    branches: [ main ]
  workflow_dispatch:

concurrency:
  group: pre-release
  cancel-in-progress: true

permissions: {}

env:
  ISPC_HOME: ${{ github.workspace }}
  LLVM_HOME: ${{ github.workspace }}
  LLVM_VERSION: "21.1"

jobs:
  ubuntu:
    runs-on: ubuntu-22.04
    # Disabling this rebuild for non ispc/ispc repo
    if: github.repository == 'ispc/ispc'
    permissions:
      contents: write  # Needed for release creation/update

    env:
      LLVM_TAR: llvm-21.1.8-ubuntu22.04-Release+Asserts-lto-x86.arm.wasm.tar.xz

    steps:
    - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
      with:
        submodules: false

    - name: Install Dependencies
      run: |
        .github/workflows/scripts/install-build-deps.sh

    - name: Configure
      run: |
        cmake superbuild \
            -B build \
            --preset os \
            -DLTO=ON \
            -DINSTALL_WITH_XE_DEPS=ON \
            -DCMAKE_INSTALL_PREFIX="${GITHUB_WORKSPACE}/install" \
            -DPREBUILT_STAGE2_PATH="${GITHUB_WORKSPACE}/bin-$LLVM_VERSION"

    - name: Build
      run: cmake --build build

    - name: Upload Artifacts
      uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
      with:
        name: ispc-linux
        path: build/build-ispc-stage2/src/ispc-stage2-build/ispc-trunk-linux.tar.gz
      
    - name: Release
      uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # 2.5.0
      with:
        name: trunk-artifacts
        tag_name: trunk-artifacts
        files: build/build-ispc-stage2/src/ispc-stage2-build/ispc-trunk-linux.tar.gz
        draft: false
        prerelease: true
        body: "Automatically updated trunk artifacts"
        fail_on_unmatched_files: true
        generate_release_notes: false
        append_body: false

  windows:
    runs-on: windows-2022
    # Disabling this rebuild for non ispc/ispc repo
    if: github.repository == 'ispc/ispc'
    permissions:
      contents: write  # Needed for release creation/update

    env:
      LLVM_TAR: llvm-21.1.8-win.vs2022-Release+Asserts-lto-x86.arm.wasm.tar.7z

    steps:
    - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
      with:
        submodules: false

    - name: Install dependencies
      run: |
        .github/workflows/scripts/install-build-deps.ps1

    - name: Build
      shell: cmd
      run: |
        call scripts\install_emscripten.bat
        set VSVARS="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
        call %VSVARS%
        cmake -B build superbuild --preset os -G "NMake Makefiles" -DLTO=ON -DPREBUILT_STAGE2_PATH=%LLVM_HOME%\bin-%LLVM_VERSION% -DCMAKE_INSTALL_PREFIX=%GITHUB_WORKSPACE%\ispc-xe -DEXPLICIT_ENV_PATH=OFF -DINSTALL_WITH_XE_DEPS=ON -DGNUWIN32=%CROSS_TOOLS_GNUWIN32%
        cmake --build build

    - name: Upload artifacts
      uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
      with:
        name: ispc-windows
        path: build/build-ispc-stage2/src/ispc-stage2-build/ispc-trunk-windows.zip

    - name: Release
      uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # 2.5.0
      with:
        name: trunk-artifacts
        tag_name: trunk-artifacts
        files: build/build-ispc-stage2/src/ispc-stage2-build/ispc-trunk-windows.zip
        draft: false
        prerelease: true
        body: "Automatically updated trunk artifacts"
        fail_on_unmatched_files: true
        generate_release_notes: false
        append_body: false
