From 87c478f86c3b1363029ded2675963707fa75f986 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 6 Feb 2025 16:20:10 -0800 Subject: [PATCH] GHA: build sanitizers for distribution The unified build was split, separating the runtimes from the compilers build to be more effective about cross-compilation. Wire up the new sanitizers build in the GHA build to allow packaging into the toolchain. --- .github/workflows/swift-toolchain.yml | 90 ++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 1 deletion(-) diff --git a/.github/workflows/swift-toolchain.yml b/.github/workflows/swift-toolchain.yml index f76db118..e377f669 100644 --- a/.github/workflows/swift-toolchain.yml +++ b/.github/workflows/swift-toolchain.yml @@ -1226,6 +1226,93 @@ jobs: symbolsFolder: ${{ github.workspace }}/BinaryCache/1 searchPattern: '**/*.exe' + sanitizers: + # TODO: Build this on macOS or make an equivalent Mac-only job + if: inputs.build_os == 'Windows' + runs-on: ${{ inputs.default_build_runner }} + needs: [compilers] + + strategy: + fail-fast: false + matrix: ${{ fromJSON(inputs.target_matrix) }} + + name: ${{ matrix.os }} ${{ matrix.arch }} Sanitizers + + steps: + - name: Download Compilers + uses: thebrowsercompany/gha-download-tar-artifact@59992d91335d4ecba543c8535f7d07238e42125d # main + with: + name: compilers-Windows-${{ inputs.build_arch }} + path: ${{ github.workspace }}/BinaryCache/Library + + - uses: actions/checkout@v4 + with: + repository: swiftlang/llvm-project + ref: ${{ inputs.llvm_project_revision }} + path: ${{ github.workspace }}/SourceCache/llvm-project + show-progress: false + + - uses: nttld/setup-ndk@v1 + if: matrix.os == 'Android' && inputs.build_android + id: setup-ndk + with: + ndk-version: ${{ inputs.ANDROID_NDK_VERSION }} + + - name: Compute workspace hash + id: workspace_hash + shell: pwsh + run: | + $stringAsStream = [System.IO.MemoryStream]::new() + $writer = [System.IO.StreamWriter]::new($stringAsStream) + $writer.write("${{ github.workspace }}") + $writer.Flush() + $stringAsStream.Position = 0 + $hash = (Get-FileHash -Algorithm SHA256 -InputStream $stringAsStream).Hash + echo "hash=$hash" >> $env:GITHUB_OUTPUT + + - name: Setup sccache + uses: hendrikmuhs/ccache-action@2e0e89e8d74340a03f75d58d02aae4c5ee1b15c6 + with: + max-size: 500M + key: ${{ steps.workspace_hash.outputs.hash }}-${{ matrix.os }}-${{ matrix.arch }}-sanitizers + variant: sccache + + - uses: seanmiddleditch/gha-setup-ninja@96bed6edff20d1dd61ecff9b75cc519d516e6401 # master + + - name: Configure Sanitizers + run: | + cmake -B "${{ github.workspace }}/BinaryCache/${{ matrix.os }}-${{ matrix.arch }}-sanitzers" ` + -D CMAKE_BUILD_TYPE=Release ` + -D CMAKE_ASM_COMPILER="${{ github.workspace }}/BinaryCache/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr/bin/clang${{ matrix.exe_suffix }}" ` + -D CMAKE_ASM_COMPILER_LAUNCHER=sccache ` + -D CMAKE_C_COMPILER="${{ matrix.cc }}" ` + -D CMAKE_C_COMPILER_LAUNCHER=sccache ` + -D CMAKE_C_FLAGS="${{ matrix.cflags }}" ` + -D CMAKE_CXX_COMPILER="${{ matrix.cxx }}" ` + -D CMAKE_CXX_COMPILER_LAUNCHER=sccache ` + -D CMAKE_CXX_FLAGS="${{ matrix.cxxflags }}" ` + -D CMAKE_INSTALL_PREFIX=${{ github.workspace }}/BuildRoot/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain/usr ` + -D CMAKE_SYSTEM_NAME=${{ matrix.os }} ` + -G Ninja ` + -S ${{ github.workspace }}/SourceCache/llvm-project/compiler-rt ` + -D COMPILER_RT_DEFAULT_TARGET_ONLY=YES ` + -D COMPILER_RT_BUILD_BUILTINS=NO ` + -D COMPILER_RT_BUILD_CRT=NO ` + -D COMPILER_RT_BUILD_LIBFUZZER=NO ` + -D COMPILER_RT_BUILD_ORC=NO ` + -D COMPILER_RT_BUILD_PROFILE=YES ` + -D COMPILER_RT_BUILD_SANITIZERS=YES ` + -D COMPILER_RT_BUILD_XRAY=NO + - name: Build Sanitizers + run: cmake --build ${{ github.workspace }}/BinaryCache/${{ matrix.os }}-${{ matrix.arch }}-sanitzers + - name: Install Sanitizers + run: cmake --build ${{ github.workspace }}/BinaryCache/${{ matrix.os }}-${{ matrix.arch }}-sanitzers --target install-compiler-rt-stripped + + - uses: thebrowsercompany/gha-upload-tar-artifact@e18c33b1cd416d0d96a91dc6dce06219f98e4e27 # main + with: + name: sanitizers-${{ matrix.os }}-${{ matrix.arch }} + path: ${{ github.workspace }}/BuildRoot/Library + zlib: runs-on: ${{ inputs.default_build_runner }} @@ -1630,7 +1717,7 @@ jobs: os: Windows llvm_flags: linker_flags: '-D CMAKE_EXE_LINKER_FLAGS="${{ inputs.WINDOWS_CMAKE_EXE_LINKER_FLAGS }}" -D CMAKE_SHARED_LINKER_FLAGS="${{ inputs.WINDOWS_CMAKE_SHARED_LINKER_FLAGS }}"' - extra_flags: + extra_flags: - arch: arm64 cpu: 'aarch64' @@ -1696,6 +1783,7 @@ jobs: with: name: compilers-Windows-${{ inputs.build_arch }} path: ${{ github.workspace }}/BinaryCache/Library + - uses: actions/checkout@v4 with: repository: swiftlang/llvm-project