|
| 1 | +name: 'Builds LLVM for WebAssembly' |
| 2 | +description: 'This action builds LLVM for WebAssembly targets via emscripten' |
| 3 | +inputs: |
| 4 | + cache-hit: |
| 5 | + required: true |
| 6 | + |
| 7 | +runs: |
| 8 | + using: composite |
| 9 | + steps: |
| 10 | + - name: Build LLVM/Cling on Unix systems if the cache is invalid (emscripten) |
| 11 | + if: ${{ inputs.cache-hit != 'true' && runner.os != 'Windows' }} |
| 12 | + shell: bash |
| 13 | + run: | |
| 14 | + ./emsdk/emsdk activate ${{ env.EMSDK_VER }} |
| 15 | + source ./emsdk/emsdk_env.sh |
| 16 | + cling_on=$(echo "${{ matrix.cling }}" | tr '[:lower:]' '[:upper:]') |
| 17 | + if [[ "${cling_on}" == "ON" ]]; then |
| 18 | + git clone https://github.com/root-project/cling.git |
| 19 | + cd ./cling |
| 20 | + git checkout tags/v${{ matrix.cling-version }} |
| 21 | + git apply -v ../patches/llvm/cling1.2-LookupHelper.patch |
| 22 | + cd .. |
| 23 | + git clone --depth=1 -b cling-llvm${{ matrix.clang-runtime }} https://github.com/root-project/llvm-project.git |
| 24 | + else # repl |
| 25 | + git clone --depth=1 -b release/${{ matrix.clang-runtime }}.x https://github.com/llvm/llvm-project.git |
| 26 | + fi |
| 27 | + cd llvm-project |
| 28 | + # Build |
| 29 | + mkdir native_build |
| 30 | + cd native_build |
| 31 | + cmake -DLLVM_ENABLE_PROJECTS=clang -DLLVM_TARGETS_TO_BUILD=host -DCMAKE_BUILD_TYPE=Release ../llvm/ |
| 32 | + cmake --build . --target llvm-tblgen clang-tblgen --parallel $(nproc --all) |
| 33 | + export NATIVE_DIR=$PWD/bin/ |
| 34 | + cd .. |
| 35 | + mkdir build |
| 36 | + if [[ "${cling_on}" == "ON" ]]; then |
| 37 | + cd build |
| 38 | + emcmake cmake -DLLVM_EXTERNAL_PROJECTS=cling \ |
| 39 | + -DLLVM_EXTERNAL_CLING_SOURCE_DIR=../../cling \ |
| 40 | + -DCMAKE_BUILD_TYPE=Release \ |
| 41 | + -DLLVM_HOST_TRIPLE=wasm32-unknown-emscripten \ |
| 42 | + -DLLVM_TARGETS_TO_BUILD="${{ env.LLVM_TARGETS_TO_BUILD }}" \ |
| 43 | + -DLLVM_ENABLE_LIBEDIT=OFF \ |
| 44 | + -DLLVM_ENABLE_PROJECTS="${{ env.LLVM_ENABLE_PROJECTS }}" \ |
| 45 | + -DLLVM_ENABLE_ZSTD=OFF \ |
| 46 | + -DLLVM_ENABLE_LIBXML2=OFF \ |
| 47 | + -DCLANG_ENABLE_STATIC_ANALYZER=OFF \ |
| 48 | + -DCLANG_ENABLE_ARCMT=OFF \ |
| 49 | + -DCLANG_ENABLE_BOOTSTRAP=OFF \ |
| 50 | + -DCMAKE_CXX_FLAGS="-Dwait4=__syscall_wait4" \ |
| 51 | + -DLLVM_INCLUDE_BENCHMARKS=OFF \ |
| 52 | + -DLLVM_INCLUDE_EXAMPLES=OFF \ |
| 53 | + -DLLVM_INCLUDE_TESTS=OFF \ |
| 54 | + -DLLVM_ENABLE_THREADS=OFF \ |
| 55 | + -G Ninja \ |
| 56 | + -DLLVM_BUILD_TOOLS=OFF \ |
| 57 | + -DLLVM_ENABLE_LIBPFM=OFF \ |
| 58 | + -DCLANG_BUILD_TOOLS=OFF \ |
| 59 | + -DLLVM_NATIVE_TOOL_DIR=$NATIVE_DIR \ |
| 60 | + -DCMAKE_C_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" \ |
| 61 | + -DCMAKE_CXX_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" \ |
| 62 | + -DLLVM_ENABLE_LTO=Full \ |
| 63 | + ../llvm |
| 64 | + EMCC_CFLAGS="-fwasm-exceptions" emmake ninja clang cling lld gtest_main |
| 65 | + else |
| 66 | + # Apply patches |
| 67 | + llvm_vers=$(echo "${{ matrix.clang-runtime }}" | tr '[:lower:]' '[:upper:]') |
| 68 | + if [[ "${llvm_vers}" == "19" || "${llvm_vers}" == "20" || "${llvm_vers}" == "21" ]]; then |
| 69 | + git apply -v ../patches/llvm/emscripten-clang${{ matrix.clang-runtime }}-*.patch |
| 70 | + echo "Apply emscripten-clang${{ matrix.clang-runtime }}-*.patch patches:" |
| 71 | + fi |
| 72 | + cd build |
| 73 | + emcmake cmake -DCMAKE_BUILD_TYPE=Release \ |
| 74 | + -DLLVM_HOST_TRIPLE=wasm32-unknown-emscripten \ |
| 75 | + -DLLVM_TARGETS_TO_BUILD="${{ env.LLVM_TARGETS_TO_BUILD }}" \ |
| 76 | + -DLLVM_ENABLE_LIBEDIT=OFF \ |
| 77 | + -DLLVM_ENABLE_PROJECTS="${{ env.LLVM_ENABLE_PROJECTS }}" \ |
| 78 | + -DLLVM_ENABLE_ZSTD=OFF \ |
| 79 | + -DLLVM_ENABLE_LIBXML2=OFF \ |
| 80 | + -DCLANG_ENABLE_STATIC_ANALYZER=OFF \ |
| 81 | + -DCLANG_ENABLE_ARCMT=OFF \ |
| 82 | + -DCLANG_ENABLE_BOOTSTRAP=OFF \ |
| 83 | + -DCMAKE_CXX_FLAGS="-Dwait4=__syscall_wait4" \ |
| 84 | + -DLLVM_INCLUDE_BENCHMARKS=OFF \ |
| 85 | + -DLLVM_INCLUDE_EXAMPLES=OFF \ |
| 86 | + -DLLVM_INCLUDE_TESTS=OFF \ |
| 87 | + -DLLVM_ENABLE_THREADS=OFF \ |
| 88 | + -DLLVM_BUILD_TOOLS=OFF \ |
| 89 | + -DLLVM_ENABLE_LIBPFM=OFF \ |
| 90 | + -DCLANG_BUILD_TOOLS=OFF \ |
| 91 | + -G Ninja \ |
| 92 | + -DLLVM_NATIVE_TOOL_DIR=$NATIVE_DIR \ |
| 93 | + -DCMAKE_C_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" \ |
| 94 | + -DCMAKE_CXX_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" \ |
| 95 | + -DLLVM_ENABLE_LTO=Full \ |
| 96 | + ../llvm |
| 97 | + EMCC_CFLAGS="-fwasm-exceptions" emmake ninja libclang clangInterpreter clangStaticAnalyzerCore |
| 98 | + fi |
| 99 | + cd ../ |
| 100 | + rm -rf $(find . -maxdepth 1 ! -name "build" ! -name "llvm" ! -name "clang" ! -name ".") |
| 101 | + if [[ "${cling_on}" == "ON" ]]; then |
| 102 | + cd ./llvm/ |
| 103 | + rm -rf $(find . -maxdepth 1 ! -name "include" ! -name "lib" ! -name "cmake" ! -name "utils" ! -name ".") |
| 104 | + cd ../clang/ |
| 105 | + rm -rf $(find . -maxdepth 1 ! -name "include" ! -name "lib" ! -name "cmake" ! -name "utils" ! -name ".") |
| 106 | + cd ../.. |
| 107 | + else # repl |
| 108 | + cd ./llvm/ |
| 109 | + rm -rf $(find . -maxdepth 1 ! -name "include" ! -name "lib" ! -name "cmake" ! -name ".") |
| 110 | + cd ../clang/ |
| 111 | + rm -rf $(find . -maxdepth 1 ! -name "include" ! -name "lib" ! -name "cmake" ! -name ".") |
| 112 | + cd ../.. |
| 113 | + fi |
| 114 | +
|
| 115 | +
|
| 116 | + - name: Build LLVM/Cling on Windows systems if the cache is invalid (emscripten) |
| 117 | + if: ${{ inputs.cache-hit != 'true' && runner.os == 'Windows' }} |
| 118 | + shell: powershell |
| 119 | + run: | |
| 120 | + .\emsdk\emsdk activate ${{ env.EMSDK_VER }} |
| 121 | + .\emsdk\emsdk_env.ps1 |
| 122 | + if ( "${{ matrix.cling }}" -imatch "On" ) |
| 123 | + { |
| 124 | + git clone https://github.com/root-project/cling.git |
| 125 | + cd ./cling |
| 126 | + git checkout tags/v${{ matrix.cling-version }} |
| 127 | + git apply -v ../patches/llvm/cling1.2-LookupHelper.patch |
| 128 | + cd .. |
| 129 | + git clone --depth=1 -b cling-llvm${{ matrix.clang-runtime }} https://github.com/root-project/llvm-project.git |
| 130 | + $env:PWD_DIR= $PWD.Path |
| 131 | + $env:CLING_DIR="$env:PWD_DIR\cling" |
| 132 | + echo "CLING_DIR=$env:CLING_DIR" |
| 133 | + } |
| 134 | + else |
| 135 | + { |
| 136 | + git clone --depth=1 -b release/${{ matrix.clang-runtime }}.x https://github.com/llvm/llvm-project.git |
| 137 | + } |
| 138 | +
|
| 139 | + cd llvm-project |
| 140 | + # Build |
| 141 | + mkdir native_build |
| 142 | + cd native_build |
| 143 | + cmake -DLLVM_ENABLE_PROJECTS=clang -DLLVM_TARGETS_TO_BUILD=host -DCMAKE_BUILD_TYPE=Release -G Ninja ../llvm/ |
| 144 | + cmake --build . --target llvm-tblgen clang-tblgen --parallel $(nproc --all) |
| 145 | + $env:PWD_DIR= $PWD.Path |
| 146 | + $env:NATIVE_DIR="$env:PWD_DIR/bin/" |
| 147 | + cd .. |
| 148 | + mkdir build |
| 149 | + if ( "${{ matrix.cling }}" -imatch "On" ) |
| 150 | + { |
| 151 | + cd build |
| 152 | + emcmake cmake -DLLVM_EXTERNAL_PROJECTS=cling ` |
| 153 | + -DLLVM_EXTERNAL_CLING_SOURCE_DIR=../../cling ` |
| 154 | + -DCMAKE_BUILD_TYPE=Release ` |
| 155 | + -DLLVM_HOST_TRIPLE=wasm32-unknown-emscripten ` |
| 156 | + -DLLVM_TARGETS_TO_BUILD="${{ env.LLVM_TARGETS_TO_BUILD }}" ` |
| 157 | + -DLLVM_ENABLE_LIBEDIT=OFF ` |
| 158 | + -DLLVM_ENABLE_PROJECTS="${{ env.LLVM_ENABLE_PROJECTS }}" ` |
| 159 | + -DLLVM_ENABLE_ZSTD=OFF ` |
| 160 | + -DLLVM_ENABLE_LIBXML2=OFF ` |
| 161 | + -DCLANG_ENABLE_STATIC_ANALYZER=OFF ` |
| 162 | + -DCLANG_ENABLE_ARCMT=OFF ` |
| 163 | + -DCLANG_ENABLE_BOOTSTRAP=OFF ` |
| 164 | + -DCMAKE_CXX_FLAGS="-Dwait4=__syscall_wait4" ` |
| 165 | + -DLLVM_INCLUDE_BENCHMARKS=OFF ` |
| 166 | + -DLLVM_INCLUDE_EXAMPLES=OFF ` |
| 167 | + -DLLVM_INCLUDE_TESTS=OFF ` |
| 168 | + -DLLVM_ENABLE_THREADS=OFF ` |
| 169 | + -G Ninja ` |
| 170 | + -DLLVM_BUILD_TOOLS=OFF ` |
| 171 | + -DLLVM_ENABLE_LIBPFM=OFF ` |
| 172 | + -DCLANG_BUILD_TOOLS=OFF ` |
| 173 | + -DCMAKE_C_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" ` |
| 174 | + -DCMAKE_CXX_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" ` |
| 175 | + -DLLVM_ENABLE_LTO=Full ` |
| 176 | + -DLLVM_NATIVE_TOOL_DIR="$env:NATIVE_DIR" ` |
| 177 | + ..\llvm |
| 178 | + $env:EMCC_CFLAGS="-fwasm-exceptions" |
| 179 | + emmake make clang cling lld gtest_main |
| 180 | + $env:EMCC_CFLAGS="" |
| 181 | + } |
| 182 | + else |
| 183 | + { |
| 184 | + cp -r ..\patches\llvm\emscripten-clang${{ matrix.clang-runtime }}* |
| 185 | + #FIXME: Apply patches without hardcoding |
| 186 | + if ( "${{ matrix.clang-runtime }}" -imatch "19" ) |
| 187 | + { |
| 188 | + git apply -v emscripten-clang19-2-shift-temporary-files-to-tmp-dir.patch |
| 189 | + git apply -v emscripten-clang19-3-remove-zdefs.patch |
| 190 | + git apply -v emscripten-clang19-4-enable_exception_handling.patch |
| 191 | + } |
| 192 | + elseif ( "${{ matrix.clang-runtime }}" -imatch "20" ) |
| 193 | + { |
| 194 | + git apply -v emscripten-clang20-2-shift-temporary-files-to-tmp-dir.patch |
| 195 | + git apply -v emscripten-clang20-3-enable_exception_handling.patch |
| 196 | + } |
| 197 | + elseif ( "${{ matrix.clang-runtime }}" -imatch "21" ) |
| 198 | + { |
| 199 | + git apply -v emscripten-clang21-1-shift-temporary-files-to-tmp-dir.patch |
| 200 | + git apply -v emscripten-clang21-2-enable_exception_handling.patch |
| 201 | + git apply -v emscripten-clang21-3-webassembly_target_machine_reordering.patch |
| 202 | + } |
| 203 | + cd build |
| 204 | + echo "Apply clang${{ matrix.clang-runtime }}-*.patch patches:" |
| 205 | + emcmake cmake -DCMAKE_BUILD_TYPE=Release ` |
| 206 | + -DLLVM_HOST_TRIPLE=wasm32-unknown-emscripten ` |
| 207 | + -DLLVM_TARGETS_TO_BUILD="${{ env.LLVM_TARGETS_TO_BUILD }}" ` |
| 208 | + -DLLVM_ENABLE_LIBEDIT=OFF ` |
| 209 | + -DLLVM_ENABLE_PROJECTS="${{ env.LLVM_ENABLE_PROJECTS }}" ` |
| 210 | + -DLLVM_ENABLE_ZSTD=OFF ` |
| 211 | + -DLLVM_ENABLE_LIBXML2=OFF ` |
| 212 | + -DCLANG_ENABLE_STATIC_ANALYZER=OFF ` |
| 213 | + -DCLANG_ENABLE_ARCMT=OFF ` |
| 214 | + -DCLANG_ENABLE_BOOTSTRAP=OFF ` |
| 215 | + -DCMAKE_CXX_FLAGS="-Dwait4=__syscall_wait4" ` |
| 216 | + -DLLVM_INCLUDE_BENCHMARKS=OFF ` |
| 217 | + -DLLVM_INCLUDE_EXAMPLES=OFF ` |
| 218 | + -DLLVM_INCLUDE_TESTS=OFF ` |
| 219 | + -DLLVM_ENABLE_THREADS=OFF ` |
| 220 | + -DLLVM_BUILD_TOOLS=OFF ` |
| 221 | + -DLLVM_ENABLE_LIBPFM=OFF ` |
| 222 | + -DCLANG_BUILD_TOOLS=OFF ` |
| 223 | + -DCMAKE_C_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" ` |
| 224 | + -DCMAKE_CXX_FLAGS_RELEASE="-Oz -g0 -DNDEBUG" ` |
| 225 | + -DLLVM_ENABLE_LTO=Full ` |
| 226 | + -G Ninja ` |
| 227 | + -DLLVM_NATIVE_TOOL_DIR="$env:NATIVE_DIR" ` |
| 228 | + ..\llvm |
| 229 | + $env:EMCC_CFLAGS="-fwasm-exceptions" |
| 230 | + emmake ninja libclang clangInterpreter clangStaticAnalyzerCore |
| 231 | + $env:EMCC_CFLAGS="" |
| 232 | + } |
| 233 | + cd ..\ |
| 234 | + rm -r -force $(find.exe . -maxdepth 1 ! -name "build" ! -name "llvm" ! -name "clang" ! -name ".") |
| 235 | + if ( "${{ matrix.cling }}" -imatch "On" ) |
| 236 | + { |
| 237 | + cd .\llvm\ |
| 238 | + rm -r -force $(find.exe . -maxdepth 1 ! -name "include" ! -name "lib" ! -name "cmake" ! -name "utils" ! -name ".") |
| 239 | + cd ..\clang\ |
| 240 | + rm -r -force $(find.exe . -maxdepth 1 ! -name "include" ! -name "lib" ! -name "cmake" ! -name "utils" ! -name ".") |
| 241 | + cd ..\.. |
| 242 | + } |
| 243 | + else |
| 244 | + { |
| 245 | + cd .\llvm\ |
| 246 | + rm -r -force $(find.exe . -maxdepth 1 ! -name "include" ! -name "lib" ! -name "cmake" ! -name ".") |
| 247 | + cd ..\clang\ |
| 248 | + rm -r -force $(find.exe . -maxdepth 1 ! -name "include" ! -name "lib" ! -name "cmake" ! -name ".") |
| 249 | + cd ..\.. |
| 250 | + } |
0 commit comments