yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Gangzheng TongUse self-hosted runner for Windows release build (#8470)570277137

master
6.2 KiB171 linesraw
1name: Common setup
2
3description: Performs setup common to all our actions
4
5inputs:
6  os:
7    required: true
8  compiler:
9    required: true
10  platform:
11    required: true
12  config:
13    required: true
14  build-llvm:
15    required: true
16runs:
17  using: composite
18  steps:
19    - name: Add bash to PATH
20      shell: pwsh
21      if: ${{inputs.os == 'windows'}}
22      run: |
23        Add-Content -Path $env:GITHUB_PATH -Value "C:\\Program Files\\Git\\bin"
24        Add-Content -Path $env:GITHUB_PATH -Value "C:\\Program Files\\Git\\usr\\bin"
25
26    - name: Set up MSVC dev tools on Windows
27      uses: ilammy/msvc-dev-cmd@v1
28
29    - name: Install dependencies (Linux only)
30      if: inputs.os == 'linux'
31      shell: bash
32      run: |
33        sudo apt-get update
34        sudo apt-get install -y libx11-dev
35
36    - name: Setup Node.js (Linux only)
37      if: inputs.os == 'linux'
38      uses: actions/setup-node@v4
39      with:
40        node-version: "20.x"
41
42    - shell: bash
43      run: |
44        # Set up system dependencies
45
46        # Install Ninja
47        if ! command -v ninja; then
48          case "${{inputs.os}}" in
49            linux*) sudo apt-get install -y ninja-build;;
50            windows*) choco install ninja;;
51            macos*) brew install ninja;;
52          esac
53        fi
54
55        # Install cross tools on Ubuntu
56        if [[ "${{inputs.os}}" == linux* && "${{inputs.platform}}" == "aarch64" && "$(uname -m)" != "aarch64" ]]; then
57          sudo apt-get install -y crossbuild-essential-arm64
58        fi
59
60        # Set compiler
61        CC=${{inputs.compiler}}
62        CXX=${{inputs.compiler}}
63        # infer C++ compiler
64        CXX=${CXX/gcc/g++}
65        CXX=${CXX/clang/clang++}
66        # Correct gcc version on older ubuntu
67        if [[ "${{inputs.os}}" == linux* ]]; then
68          gcc_version=$(gcc -dumpversion | cut -d'.' -f1)
69          if [ "$gcc_version" -lt 10 ]; then
70            CC=${CC/gcc/gcc-10}
71            CXX=${CXX/g++/g++-10}
72          fi
73        fi
74        # Export
75        echo "CC=$CC" >> "$GITHUB_ENV"
76        echo "CXX=$CXX" >> "$GITHUB_ENV"
77
78        # Some useful variables
79        config=${{inputs.config}}
80        cmake_config=$(echo "${{inputs.config}}" | sed '
81            s/^debug$/Debug/
82            s/^release$/Release/
83            s/^releaseWithDebugInfo$/RelWithDebInfo/
84            s/^minSizeRelease$/MinSizeRel/
85        ')
86        bin_dir=$(pwd)/build/$cmake_config/bin
87        lib_dir=$(pwd)/build/$cmake_config/lib
88        echo "config=$config" >> "$GITHUB_ENV"
89        echo "cmake_config=$cmake_config" >> "$GITHUB_ENV"
90        echo "bin_dir=$bin_dir" >> "$GITHUB_ENV"
91        echo "lib_dir=$lib_dir" >> "$GITHUB_ENV"
92
93    # Try to restore an LLVM install, and build it otherwise
94    - uses: actions/cache/restore@v4
95      id: cache-llvm
96      if: inputs.build-llvm == 'true'
97      with:
98        path: build/llvm-project-install
99        # Use os*compiler*platform in lieu of an ABI key here, which is what we really want
100        key: llvm-${{ inputs.os }}-${{ inputs.compiler }}-${{ inputs.platform }}-${{ hashFiles('external/build-llvm.sh') }}
101    - name: Build LLVM
102      if: inputs.build-llvm == 'true' && steps.cache-llvm.outputs.cache-hit != 'true'
103      shell: bash
104      run: |
105        ./external/build-llvm.sh \
106          --install-prefix "${{github.workspace}}/build/llvm-project-install" \
107          --repo "https://${{github.token}}@github.com/llvm/llvm-project"
108    - uses: actions/cache/save@v4
109      if: inputs.build-llvm == 'true' && steps.cache-llvm.outputs.cache-hit != 'true'
110      with:
111        path: build/llvm-project-install
112        key: ${{ steps.cache-llvm.outputs.cache-primary-key }}
113
114    - name: Set environment variable for CMake
115      shell: bash
116      run: |
117        if [ "${{inputs.build-llvm}}" == "true" ]; then
118          echo "LLVM_DIR=${{ github.workspace }}/build/llvm-project-install" >> "$GITHUB_ENV"
119          echo "Clang_DIR=${{ github.workspace }}/build/llvm-project-install" >> "$GITHUB_ENV"
120        fi
121
122    # Put spirv-tools in path
123    - shell: bash
124      run: |
125        win_platform="${{ inputs.platform }}"
126        win_platform="${win_platform//x86_64/x64}"
127        case "${{inputs.os}}" in
128          windows*) echo "${{github.workspace}}/external/slang-binaries/spirv-tools/windows-$win_platform/bin" >> "$GITHUB_PATH";;
129          linux*) echo "${{github.workspace}}/external/slang-binaries/spirv-tools/$(uname -m)-linux/bin" >> "$GITHUB_PATH";;
130        esac
131
132      # Setup ccache for local compilation speedup (Windows self-hosted only)
133      # Only use ccache if already installed - don't attempt installation
134    - name: Setup ccache (if available, local only, no GitHub uploads)
135      if: ${{ inputs.os == 'windows' && runner.environment == 'self-hosted' }}
136      shell: bash
137      run: |
138        # Check if ccache is available
139        if ! command -v ccache &> /dev/null; then
140          echo "⚠️  ccache not found on this self-hosted runner"
141          echo "   Skipping ccache setup to avoid permission issues"
142          echo "   Build will proceed without ccache acceleration"
143          echo "   To enable ccache: manually install it on the runner with admin rights"
144          exit 0
145        fi
146
147        echo "✅ ccache found on self-hosted runner - setting up persistent caching"
148
149        # Set ccache directory to a persistent location outside workspace
150        if [[ "${{ inputs.os }}" == "windows" ]]; then
151          ccache_base_dir="C:/ccache-slang"
152        else
153          # Linux/macOS: Use home directory for persistence
154          ccache_base_dir="$HOME/.ccache-slang"
155        fi
156        ccache_dir="$ccache_base_dir/${{ inputs.os }}-${{ inputs.compiler }}-${{ inputs.platform }}"
157        mkdir -p "$ccache_dir"
158        echo "CCACHE_DIR=$ccache_dir" >> $GITHUB_ENV
159        echo "🔧 Using persistent ccache directory: $ccache_dir"
160
161        # Configure ccache settings for local use only
162        ccache --set-config=max_size=20G
163        ccache --set-config=compression=true
164        ccache --set-config=compression_level=6
165        ccache --set-config=sloppiness=pch_defines,time_macros
166        ccache --set-config=cache_dir="$ccache_dir"
167
168        # Enable ccache for CMake (set environment variables)
169        # Get the full path to ccache executable
170        ccache_path=$(which ccache)
171        echo "ccache_symlinks_path=$ccache_path" >> $GITHUB_ENV