|
| 1 | +name: Install Binaryen |
| 2 | + |
| 3 | +inputs: |
| 4 | + repository: |
| 5 | + description: 'Repository name with owner. For example, actions/checkout' |
| 6 | + default: WebAssembly/binaryen |
| 7 | + ref: |
| 8 | + description: > |
| 9 | + The branch, tag or SHA to checkout. When checking out the repository that |
| 10 | + triggered a workflow, this defaults to the reference or SHA for that |
| 11 | + event. Otherwise, uses the default branch. |
| 12 | + default: latest |
| 13 | + build: |
| 14 | + description: Whether we should build from source |
| 15 | + default: false |
| 16 | +runs: |
| 17 | + using: composite |
| 18 | + steps: |
| 19 | + - name: Restore cached binaryen |
| 20 | + if: ${{ inputs.build && inputs.build != 'false' }} |
| 21 | + id: cache-binaryen |
| 22 | + uses: actions/cache/restore@v4 |
| 23 | + with: |
| 24 | + path: binaryen |
| 25 | + key: ${{ runner.os }}-binaryen-${{ inputs.ref }} |
| 26 | + |
| 27 | + - name: Checkout binaryen |
| 28 | + if: ${{ inputs.build && inputs.build != 'false' && steps.cache-binaryen.outputs.cache-hit != 'true' }} |
| 29 | + uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + repository: ${{ inputs.repository }} |
| 32 | + path: binaryen |
| 33 | + submodules: true |
| 34 | + ref: ${{ inputs.ref == 'latest' && 'main' || inputs.ref }} |
| 35 | + |
| 36 | + - name: Install ninja (Linux) |
| 37 | + if: ${{ inputs.build && inputs.build != 'false' && runner.os == 'Linux' && steps.cache-binaryen.outputs.cache-hit != 'true' }} |
| 38 | + shell: bash |
| 39 | + run: sudo apt-get install ninja-build |
| 40 | + |
| 41 | + - name: Install ninja (MacOS) |
| 42 | + if: ${{ inputs.build && inputs.build != 'false' && runner.os == 'macOS' && steps.cache-binaryen.outputs.cache-hit != 'true' }} |
| 43 | + shell: bash |
| 44 | + run: brew install ninja |
| 45 | + |
| 46 | + - name: Build binaryen |
| 47 | + if: ${{ inputs.build && inputs.build != 'false' && runner.os != 'Windows' && steps.cache-binaryen.outputs.cache-hit != 'true' }} |
| 48 | + working-directory: ./binaryen |
| 49 | + shell: bash |
| 50 | + run: | |
| 51 | + cmake -G Ninja . |
| 52 | + ninja |
| 53 | +
|
| 54 | + - name: Install binaryen build dependencies (Windows) |
| 55 | + if: ${{ inputs.build && inputs.build != 'false' && runner.os == 'Windows' && steps.cache-binaryen.outputs.cache-hit != 'true' }} |
| 56 | + working-directory: ./binaryen |
| 57 | + shell: bash |
| 58 | + run: opam install conf-cmake conf-c++ |
| 59 | + |
| 60 | + - name: Build binaryen (Windows) |
| 61 | + if: ${{ inputs.build && inputs.build != 'false' && runner.os == 'Windows' && steps.cache-binaryen.outputs.cache-hit != 'true' }} |
| 62 | + working-directory: ./binaryen |
| 63 | + shell: bash |
| 64 | + run: | |
| 65 | + opam exec -- cmake . -DBUILD_STATIC_LIB=ON -DBUILD_TESTS=off -DINSTALL_LIBS=off -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc |
| 66 | + make -j 4 |
| 67 | +
|
| 68 | + - name: Cache binaryen |
| 69 | + if: ${{ inputs.build && inputs.build != 'false' && steps.cache-binaryen.outputs.cache-hit != 'true' }} |
| 70 | + uses: actions/cache/save@v4 |
| 71 | + with: |
| 72 | + path: binaryen |
| 73 | + key: ${{ runner.os }}-binaryen-${{ inputs.ref }} |
| 74 | + |
| 75 | + - name: Set binaryen's path |
| 76 | + if: ${{ inputs.build && inputs.build != 'false' && runner.os != 'Windows' }} |
| 77 | + shell: bash |
| 78 | + run: echo "$GITHUB_WORKSPACE/binaryen/bin" >> $GITHUB_PATH |
| 79 | + |
| 80 | + - name: Copy binaryen's tools (Windows) |
| 81 | + if: ${{ inputs.build && inputs.build != 'false' && runner.os == 'Windows' }} |
| 82 | + shell: bash |
| 83 | + run: cp $GITHUB_WORKSPACE/binaryen/bin/wasm-{merge,opt}.exe _opam/bin |
| 84 | + |
| 85 | + - name: Download Binaryen |
| 86 | + if: ${{ ! inputs.build || inputs.build == 'false' }} |
| 87 | + |
| 88 | + with: |
| 89 | + token: ${{ github.token }} |
| 90 | + version: ${{ inputs.ref }} |
0 commit comments