current commit
260612.3 · Fix sed commands in create_release.yml (#8837)
name: Create Release

# Trigger whenever a tag is created/updated

on:
  push:
    tags:
      - "*"

permissions:
  contents: write

jobs:
  build:
    name: build
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [macos-14, windows-latest, windows-11-arm]
    defaults:
      run:
        shell: bash
    steps:
    - uses: actions/checkout@v4
      with:
        submodules: true

    - name: install ninja (macos)
      run: brew install ninja
      if: startsWith(matrix.os, 'macos')

    - name: install ninja (win)
      run: choco install ninja
      if: startsWith(matrix.os, 'windows')

    - name: mkdir
      run: mkdir -p out

    - name: cmake (macos)
      run: |
        cmake -S . -B out -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=out/install -DCMAKE_OSX_ARCHITECTURES=x86_64
        cmake -S . -B out-arm64 -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=out-arm64/install -DCMAKE_OSX_ARCHITECTURES=arm64
      if: startsWith(matrix.os, 'macos')

    - name: cmake (win)
      # -G "Visual Studio 15 2017"
      run: cmake -S . -B out -DCMAKE_INSTALL_PREFIX=out/install
      if: matrix.os == 'windows-latest'

    - name: cmake (win arm64)
      # -G "Visual Studio 15 2017"
      run: cmake -S . -B out -DCMAKE_INSTALL_PREFIX=out-arm64/install 
      if: matrix.os == 'windows-11-arm'

    - name: build
      run: cmake --build out -v --config Release --target install

    - name: build-arm64
      run: cmake --build out-arm64 -v --config Release --target install
      if: startsWith(matrix.os, 'macos')

    - name: strip
      run: find out*/install/ -type f -perm -u=x -exec strip -x {} +
      if: ${{ !startsWith(matrix.os, 'windows') }}

    - name: archive
      id: archive
      run: |
        # Ignore all but the first component of the os name
        OSNAME=$(echo ${{ matrix.os }} | sed 's/-.*//')
        VERSION=$GITHUB_REF_NAME
        PKGNAME="binaryen-$VERSION-x86_64-$OSNAME"
        TARBALL=$PKGNAME.tar.gz
        SHASUM=$PKGNAME.tar.gz.sha256
        rm -rf binaryen-$VERSION
        mv out/install binaryen-$VERSION
        tar -czf $TARBALL binaryen-$VERSION
        # on Windows, MSYS2 will strip the carriage return from CMake output
        cmake -E sha256sum $TARBALL > $SHASUM
        echo "TARBALL=$TARBALL" >> $GITHUB_OUTPUT
        echo "SHASUM=$SHASUM" >> $GITHUB_OUTPUT
      if: matrix.os != 'windows-11-arm'

    - name: archive-arm64
      id: archive-arm64
      run: |
        # Ignore all but the first component of the os name
        OSNAME=$(echo ${{ matrix.os }} | sed 's/-.*//')
        VERSION=$GITHUB_REF_NAME
        PKGNAME="binaryen-$VERSION-arm64-$OSNAME"
        TARBALL=$PKGNAME.tar.gz
        SHASUM=$PKGNAME.tar.gz.sha256
        rm -rf binaryen-$VERSION
        mv out-arm64/install binaryen-$VERSION
        tar -czf $TARBALL binaryen-$VERSION
        # on Windows, MSYS2 will strip the carriage return from CMake output
        cmake -E sha256sum $TARBALL > $SHASUM
        echo "TARBALL=$TARBALL" >> $GITHUB_OUTPUT
        echo "SHASUM=$SHASUM" >> $GITHUB_OUTPUT
      if: ${{ matrix.os == 'macos-14' || matrix.os == 'windows-11-arm' }}

    - name: upload tarball
      uses: softprops/action-gh-release@v1
      with:
        draft: true
        files: |
          ${{ steps.archive.outputs.TARBALL }}
          ${{ steps.archive.outputs.SHASUM }}
          ${{ steps.archive-arm64.outputs.TARBALL }}
          ${{ steps.archive-arm64.outputs.SHASUM }}

  # Build with gcc 6.3 and run tests on Alpine Linux (inside chroot).
  # Keep in sync with ci.yml.
  # Note: Alpine uses musl libc.
  build-alpine:
    name: alpine
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, ubuntu-24.04-arm]
    steps:
    - uses: actions/setup-python@v5
      with:
        python-version: '3.x'
    - uses: actions/checkout@v4
      with:
        submodules: true

    - name: start docker
      run: |
        if [[ "${{ matrix.docker_platform }}" == "ubuntu-24.04-arm" ]]; then
          platform="--platform=linux/arm64"
        fi
        docker run -w /src -dit $platform --name alpine -v $PWD:/src node:lts-alpine
        echo 'docker exec alpine "$@";' > ./alpine.sh
        chmod +x ./alpine.sh

    - name: install packages
      run: |
        ./alpine.sh apk update
        ./alpine.sh apk add build-base cmake git python3 py3-pip clang ninja util-linux

    - name: avoid d8 tests (jsvu is not compatible with alpine)
      run: |
        ./alpine.sh rm -Rf test/lit/d8

    - name: install python dev dependencies
      run: ./alpine.sh pip3 install --break-system-packages -r requirements-dev.txt

    - name: cmake
      # Build with an 8MB stack size, as otherwise Alpine/musl's default stack
      # size for pthreads is tiny,
      # https://github.com/WebAssembly/binaryen/issues/8594
      run: |
        ./alpine.sh cmake . -G Ninja -DCMAKE_CXX_FLAGS="-static" -DCMAKE_C_FLAGS="-static" -DCMAKE_EXE_LINKER_FLAGS="-Wl,-z,stack-size=8388608" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DBUILD_MIMALLOC=ON -DCMAKE_INSTALL_PREFIX=install

    - name: build
      run: |
        ./alpine.sh ninja install

    - name: test
      run: ./alpine.sh python3 ./check.py

    - name: archive
      id: archive
      run: |
        VERSION=$GITHUB_REF_NAME
        ARCH=$(./alpine.sh uname -m)
        PKGNAME="binaryen-$VERSION-$ARCH-linux"
        TARBALL=$PKGNAME.tar.gz
        SHASUM=$PKGNAME.tar.gz.sha256
        ./alpine.sh find install/ -type f -perm -u=x -exec strip {} +
        mv install binaryen-$VERSION
        tar -czf $TARBALL binaryen-$VERSION
        cmake -E sha256sum $TARBALL > $SHASUM
        echo "TARBALL=$TARBALL" >> $GITHUB_OUTPUT
        echo "SHASUM=$SHASUM" >> $GITHUB_OUTPUT

    - name: upload tarball
      uses: softprops/action-gh-release@v1
      with:
        draft: true
        files: |
          ${{ steps.archive.outputs.TARBALL }}
          ${{ steps.archive.outputs.SHASUM }}

  # Build using Emscripten to JavaScript+WebAssembly.
  build-node:
    name: node
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash
    steps:
    - uses: actions/setup-python@v5
      with:
        python-version: '3.x'
    - uses: actions/checkout@v1
      with:
        submodules: true
    - name: install ninja
      run: sudo apt-get install ninja-build
    - name: emsdk install
      run: |
        mkdir $HOME/emsdk
        git clone --depth 1 https://github.com/emscripten-core/emsdk.git $HOME/emsdk
        $HOME/emsdk/emsdk update-tags
        $HOME/emsdk/emsdk install tot
        $HOME/emsdk/emsdk activate tot
    - name: update path
      run:  echo "PATH=$PATH:$HOME/emsdk" >> $GITHUB_ENV

    # Configure with wasm EH and pthreads for maximal performance.
    - name: cmake
      run: |
        source $HOME/emsdk/emsdk_env.sh
        emcmake cmake -S . -B out -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=out/install -DEMSCRIPTEN_ENABLE_WASM_EH=ON -DEMSCRIPTEN_ENABLE_PTHREADS=ON

    # Build wasm-opt for now TODO add other tools as desired
    - name: build
      run: ninja -C out wasm-opt

    # Minimal smoke test: roundtrip a file.
    # TODO: Add more testing here, but the full test suite is overkill as there
    #       is a 0.5 second cost to each run of wasm-opt.js
    - name: test
      run: |
        node out/bin/wasm-opt.js test/hello_world.wat --print > out/t.wat
        diff test/hello_world.wat out/t.wat

    - name: archive
      id: archive
      run: |
        VERSION=$GITHUB_REF_NAME
        PKGNAME="binaryen-$VERSION-node"
        TARBALL=$PKGNAME.tar.gz
        SHASUM=$PKGNAME.tar.gz.sha256
        mkdir binaryen-$VERSION
        cp out/bin/wasm-opt* binaryen-$VERSION/
        tar -czf $TARBALL binaryen-$VERSION
        cmake -E sha256sum $TARBALL > $SHASUM
        echo "TARBALL=$TARBALL" >> $GITHUB_OUTPUT
        echo "SHASUM=$SHASUM" >> $GITHUB_OUTPUT

    - name: upload tarball
      uses: softprops/action-gh-release@v1
      with:
        draft: true
        files: |
          ${{ steps.archive.outputs.TARBALL }}
          ${{ steps.archive.outputs.SHASUM }}