toolchain (clang) #66
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: toolchain | |
| run-name: "${{ inputs.run_name != '' && format('{0} ({1})', inputs.run_name, inputs.compiler) || format('{0} ({1})', github.workflow, inputs.compiler) }}" | |
| on: | |
| # schedule: | |
| # - cron: '0 12 * * *' | |
| workflow_dispatch: | |
| inputs: | |
| build_target: | |
| description: "Build target" | |
| required: false | |
| default: "all" | |
| type: choice | |
| options: | |
| - 64bit-v4 | |
| - 64bit-nvl | |
| - aarch64-armv9.2-a | |
| - all | |
| compiler: | |
| required: false | |
| default: "clang" | |
| type: choice | |
| options: | |
| - clang | |
| no_save_cache: | |
| description: "Don't save caches after success build" | |
| required: false | |
| default: false | |
| type: boolean | |
| trigger_build: | |
| description: "Trigger mpv build action after success build" | |
| required: false | |
| default: true | |
| type: boolean | |
| release: | |
| description: "Publish a release" | |
| required: false | |
| default: true | |
| type: boolean | |
| run_name: | |
| description: 'The name displayed in the list of workflow runs' | |
| required: false | |
| jobs: | |
| params: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.script.outputs.matrix }} | |
| cache_suffix: ${{ steps.suffix.outputs.cache_suffix }} | |
| steps: | |
| - id: script | |
| uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| let matrix = {}; | |
| let build_target = "${{ inputs.build_target }}" | |
| switch ( build_target ) { | |
| case "64bit-v4": | |
| matrix.bit = ["64-v4"]; | |
| break; | |
| case "64bit-nvl": | |
| matrix.bit = ["64-nvl"]; | |
| break; | |
| case "aarch64-armv9.2-a": | |
| matrix.bit = ["aarch64-armv9.2-a"]; | |
| break; | |
| case "all-64bit": | |
| matrix.bit = ["64-v4","64-nvl","aarch64-armv9.2-a"]; | |
| break; | |
| case "all": | |
| matrix.bit = ["64-v4","64-nvl","aarch64-armv9.2-a"]; | |
| break; | |
| default: | |
| matrix.bit = ["64-v4","64-nvl","aarch64-armv9.2-a"]; | |
| break; | |
| } | |
| core.setOutput("matrix",JSON.stringify(matrix)); | |
| - id: suffix | |
| run: | | |
| cache_suffix="$(date "+%Y-%m-%d")-${{ github.run_id }}-${{ github.run_attempt }}" | |
| echo "cache_suffix=$cache_suffix" >> "$GITHUB_OUTPUT" | |
| build: | |
| name: Build Toolchain | |
| needs: [params] | |
| runs-on: ubuntu-latest | |
| container: | |
| image: ghcr.io/archlinux/archlinux:base-devel | |
| continue-on-error: true | |
| strategy: | |
| matrix: ${{ fromJson(needs.params.outputs.matrix) }} | |
| steps: | |
| - name: Install Dependencies | |
| run: | | |
| lscpu | |
| sudo pacman-key --init | |
| sudo pacman-key --populate archlinux | |
| sudo pacman -Syu --noconfirm || true | |
| sudo pacman -Syu --noconfirm || true | |
| sudo pacman -Syu --noconfirm || true | |
| sudo pacman -S --noconfirm --needed git ninja cmake meson wget mimalloc go 7zip || true | |
| sudo pacman -S --noconfirm --needed git ninja cmake meson wget mimalloc go 7zip || true | |
| sudo pacman -S --noconfirm --needed git ninja cmake meson wget mimalloc go 7zip || true | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git config --global pull.rebase true | |
| git config --global rebase.autoStash true | |
| git config --global fetch.prune true | |
| sudo GOBIN=/usr/bin go install go.chromium.org/luci/cipd/client/cmd/...@latest | |
| sudo cipd install fuchsia/third_party/clang/linux-amd64 nightly -root /usr/local/fuchsia-clang | |
| echo "PATH=/usr/local/fuchsia-clang/bin:$PATH" >> $GITHUB_ENV | |
| echo "SOURCE_DATE_EPOCH=$(date -ud "" +%s)" >> $GITHUB_ENV | |
| - uses: actions/checkout@v6 | |
| - name: Checkout toolchain | |
| uses: actions/checkout@v6 | |
| with: | |
| repository: Andarwinux/mpv-winbuild-cmake | |
| path: mpv-winbuild-cmake | |
| fetch-depth: 0 | |
| - name: Restore llvm cache | |
| if: ${{ inputs.compiler =='clang' }} | |
| uses: actions/cache/restore@v5.0.5 | |
| with: | |
| fail-on-cache-miss: true | |
| path: | | |
| mpv-winbuild-cmake/clang_root | |
| key: llvm-${{ needs.params.outputs.cache_suffix }} | |
| restore-keys: | | |
| llvm- | |
| - name: Build GCC Toolchain | |
| uses: ./action/build_toolchain | |
| if: ${{ inputs.compiler =='gcc' }} | |
| with: | |
| bit: "${{ matrix.bit }}" | |
| compiler: "gcc" | |
| command: "ninja -C $buildroot/build$bit gcc" | |
| - name: Build Clang Toolchain | |
| uses: ./action/build_toolchain | |
| if: ${{ inputs.compiler =='clang' }} | |
| with: | |
| bit: "${{ matrix.bit }}" | |
| compiler: "clang" | |
| command: "ninja -C $buildroot/build$bit rebuild_cache && ninja -C $buildroot/build$bit toolchains-download || true ; ninja -C $buildroot/build$bit toolchains-download && ninja -C $buildroot/build$bit llvm-clang" | |
| extra_option: "-DLLVM_ENABLE_LTO=Thin -DCUSTOM_LIBCXX=ON -DCUSTOM_COMPILER_RT=OFF" | |
| - name: Save Toolchain Cache | |
| if: ${{ inputs.no_save_cache != true }} | |
| uses: actions/cache/save@v5.0.5 | |
| with: | |
| path: ${{ github.workspace }}/mpv-winbuild-cmake/build${{ matrix.bit }} | |
| key: toolchain-${{ inputs.compiler }}-build${{ matrix.bit }}-${{ needs.params.outputs.cache_suffix }} | |
| - name: Save clang_root cache | |
| if: ${{ inputs.compiler =='clang' && inputs.no_save_cache != true }} | |
| uses: actions/cache/save@v5.0.5 | |
| with: | |
| path: ${{ github.workspace }}/mpv-winbuild-cmake/clang_root | |
| key: ${{ matrix.bit }}-clang_root-${{ needs.params.outputs.cache_suffix }} | |
| - name: Collect logs | |
| if: ${{ always() }} | |
| run: | | |
| sudo 7z a logs.7z $(find mpv-winbuild-cmake -type f -iname "*-*.log") | |
| - name: upload logs | |
| uses: actions/upload-artifact@v7 | |
| if: ${{ always() }} | |
| with: | |
| name: ${{ matrix.bit }}_logs | |
| path: logs.7z | |
| trigger: | |
| needs: [build,params] | |
| if: ${{ always() && inputs.trigger_build != false && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| actions: write | |
| steps: | |
| - name: Trigger mpv build workflow | |
| uses: actions/github-script@v9 | |
| with: | |
| retries: 3 | |
| script: | | |
| let build_target=new Set(); | |
| const release = ${{ inputs.release }}; | |
| const targets = {"build64-v4":"64bit-v4","build64-nvl":"64bit-nvl","buildaarch64-armv9.2-a":"aarch64-armv9.2-a"} | |
| const repo="${{github.repository}}".split('/')[1]; | |
| const cache_suffix="${{ needs.params.outputs.cache_suffix }}"; | |
| const cache = await github.rest.actions.getActionsCacheList({ | |
| owner: '${{github.repository_owner}}', | |
| repo, | |
| ref: '${{github.ref}}', | |
| key: 'toolchain-${{ inputs.compiler }}-', | |
| sort: 'created_at', | |
| per_page: 20, | |
| }) | |
| if(cache?.data?.actions_caches){ | |
| let success=cache.data.actions_caches.filter((i) => i.key.endsWith(cache_suffix)); | |
| for(const i of success){ | |
| for(const [key, value] of Object.entries(targets)){ | |
| if (i.key.includes(key)) { | |
| build_target.add(value); | |
| core.info(`Found success ${value} build cache: ${i.key}.`) | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| if(build_target.size>0){ | |
| if(build_target.has("64bit-v4") && build_target.has("64bit-nvl") && build_target.has("aarch64-armv9.2-a")) { | |
| build_target.delete("64bit-v4"); | |
| uild_target.delete("64bit-nvl"); | |
| build_target.delete("aarch64-armv9.2-a"); | |
| build_target.add("all"); | |
| } | |
| for (const t of build_target){ | |
| await github.rest.actions.createWorkflowDispatch({ | |
| owner: '${{github.repository_owner}}', | |
| repo, | |
| ref: '${{github.ref}}', | |
| workflow_id: 'mpv.yml', | |
| inputs: { | |
| build_target: t, | |
| compiler: "${{ inputs.compiler }}", | |
| needclean: true, | |
| release: release, | |
| run_name: `CI Build: ${t} toolchain cache update` | |
| } | |
| }) | |
| } | |
| } else { | |
| core.setFailed("Don't find any success build cache"); | |
| } |