From bafb4a9bf0edb2e7034e1a918e38a1317668bc7f Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Tue, 22 Oct 2024 14:34:09 +0900 Subject: [PATCH] [WIP] ci: Add LLVM toolchain build job --- .github/workflows/ci.yml | 171 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 170 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cafe37d3..6f51bfe0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -833,6 +833,175 @@ jobs: md5.sum sha256.sum + # Build LLVM toolchain + build-llvm-toolchain: + name: LLVM Toolchain (${{ matrix.host.name }}) + needs: setup + runs-on: + group: ${{ matrix.host.runner }} + container: ${{ matrix.host.container }} + + defaults: + run: + shell: bash + + strategy: + fail-fast: false + matrix: + host: ${{ fromJSON(needs.setup.outputs.hosts) }} + + steps: + - name: Set up build environment (Linux) + if: ${{ runner.os == 'Linux' }} + run: | + # Create workspace directory + WORKSPACE="${RUNNER_TEMP}/workspace" + sudo mkdir -p ${WORKSPACE} + + # Clean up working directories + shopt -s dotglob + sudo rm -rf ${GITHUB_WORKSPACE}/* + sudo rm -rf ${WORKSPACE}/* + shopt -u dotglob + + # Allow non-root access to the working directories + sudo chmod -R 777 ${GITHUB_WORKSPACE} + sudo chmod -R 777 ${RUNNER_TEMP} + + # Install common dependencies + sudo apt-get update + sudo apt-get install -y qemu-system + + # Install dependencies for cross compilation + if [ "${{ matrix.host.name }}" == "windows-x86_64" ]; then + # Install MinGW-w64 cross toolchain + sudo apt-get install -y binutils-mingw-w64 gcc-mingw-w64 \ + g++-mingw-w64 + fi + + # Set environment variables + echo "TAR=tar" >> $GITHUB_ENV + echo "WORKSPACE=${WORKSPACE}" >> $GITHUB_ENV + + - name: Set up build environment (macOS) + if: ${{ runner.os == 'macOS' }} + run: | + # Delete workspace from the previous run + WORKSPACE="/Volumes/Workspace" + if [ -d ${WORKSPACE} ]; then + # Get disk device name + OLDDISK=$(diskutil info -plist "${WORKSPACE}" | + plutil -extract ParentWholeDisk xml1 - -o - | + sed -n "s/.*\(.*\)<\/string>.*/\1/p") + + # Force unmount and eject to deallocate disk blocks + if [ ! -z "${OLDDISK}" ]; then + diskutil unmountDisk force ${OLDDISK} + diskutil eject ${OLDDISK} + fi + fi + + # Clean up working directories + shopt -s dotglob + rm -rf ${GITHUB_WORKSPACE}/* + rm -f ${RUNNER_TEMP}/Workspace.sparseimage + shopt -u dotglob + + # Create case-sensitive workspace volume for macOS + hdiutil create ${RUNNER_TEMP}/Workspace.sparseimage \ + -volname Workspace -type SPARSE -size 150g -fs HFSX + hdiutil mount ${RUNNER_TEMP}/Workspace.sparseimage -mountpoint ${WORKSPACE} + + # Install dependencies + brew install qemu + + # Set environment variables + echo "TAR=gtar" >> $GITHUB_ENV + echo "WORKSPACE=${WORKSPACE}" >> $GITHUB_ENV + + - name: Check out source code + if: ${{ github.event_name != 'pull_request_target' }} + uses: actions/checkout@v4 + with: + submodules: recursive + persist-credentials: false + + - name: Check out source code (pull request) + if: ${{ github.event_name == 'pull_request_target' }} + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + submodules: recursive + persist-credentials: false + + - name: Setup debug session (pre) + if: always() && needs.setup.outputs.debug == 'toolchain-pre' + uses: mxschmitt/action-tmate@v3 + with: + limit-access-to-actor: true + + - name: Build LLVM toolchain + run: | + # Create build directory + pushd ${WORKSPACE} + mkdir -p llvm-build + cd llvm-build + + # Configure and generate LLVM build scripts + if [ "${{ matrix.host.name }}" == "windows-x86_64" ]; then + LLVM_CMAKE_ARGS+="-DLLVM_TOOLCHAIN_CROSS_BUILD_MINGW=ON " + elif [ "${{ matrix.host.name }}" == "macos-x86_64" ]; then + LLVM_CMAKE_ARGS+="-DCMAKE_OSX_ARCHITECTURES=x86_64 " + elif [ "${{ matrix.host.name }}" == "macos-x86_64" ]; then + LLVM_CMAKE_ARGS+="-DCMAKE_OSX_ARCHITECTURES=arm64 " + fi + + cmake \ + -GNinja \ + ${LLVM_CMAKE_ARGS} \ + ${GITHUB_WORKSPACE}/scripts/llvm \ + |& tee ${GITHUB_WORKSPACE}/llvm-cmake.log + + # Build LLVM toolchain + ninja llvm-toolchain |& tee ${GITHUB_WORKSPACE}/llvm-build.log + + # Run LLVM tests + ninja check-llvm-toolchain |& tee ${GITHUB_WORKSPACE}/llvm-test.log + + # Package + ninja package-llvm-toolchain |& tee ${GITHUB_WORKSPACE}/llvm-package.log + popd + + # Prepare archive + ARCHIVE_NAME=toolchain_gnu_${{ matrix.host.name }} + ARCHIVE_FILE=${ARCHIVE_NAME}.${{ matrix.host.archive }} + + # Compute checksum + md5sum ${ARCHIVE_FILE} > md5.sum + sha256sum ${ARCHIVE_FILE} > sha256.sum + + - name: Setup debug session (post) + if: always() && needs.setup.outputs.debug == 'toolchain-post' + uses: mxschmitt/action-tmate@v3 + with: + limit-access-to-actor: true + + - name: Upload toolchain build log + if: always() + uses: actions/upload-artifact@v4 + with: + name: log_toolchain_llvm_${{ matrix.host.name }} + path: '*.log' + + - name: Upload toolchain build artifact + uses: actions/upload-artifact@v4 + with: + name: toolchain_llvm_${{ matrix.host.name }} + path: | + toolchain_llvm_${{ matrix.host.name }}.${{ matrix.host.archive }} + md5.sum + sha256.sum + # Build host tools build-hosttools: name: Host Tools (${{ matrix.host.name }}) @@ -1075,7 +1244,7 @@ jobs: # Build distribution bundle build-dist-bundle: name: Distribution Bundle (${{ matrix.host.name }}) - needs: [ setup, build-gnu-toolchain, build-hosttools, build-cmake-pkg ] + needs: [ setup, build-gnu-toolchain, build-llvm-toolchain, build-hosttools, build-cmake-pkg ] runs-on: group: ${{ matrix.host.runner }} container: ${{ matrix.host.container }}