From dedfe179e6a72ef636f6dc98f8b14cc7baa7f70f Mon Sep 17 00:00:00 2001 From: Zephyr Lykos Date: Fri, 12 Apr 2024 18:04:05 +0800 Subject: [PATCH] Refactor CI workflow --- .github/workflows/build.yml | 105 ++++++++++++++++------------------ .github/workflows/node.js.yml | 30 ---------- Makefile | 16 ++++++ 3 files changed, 65 insertions(+), 86 deletions(-) delete mode 100644 .github/workflows/node.js.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3231523..338960a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,79 +2,72 @@ name: Test on: push: - branches: main pull_request: branches: main -env: - WASI_VERSION: 12 - WASI_VERSION_FULL: "12.0" - WABT_VERSION: "1.0.24" - EMCC_VERSION: "1.40.1-fastcomp" - jobs: build: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest + env: + WASI_SDK_VERSION: "21" + WASI_SDK_PATH: /opt/wasi-sdk + WABT_VERSION: "1.0.34" + WABT_PATH: /opt/wabt + BINARYEN_VERSION: "117" + BINARYEN_PATH: /opt/binaryen steps: - name: Checkout - uses: actions/checkout@v2 - - - name: Prepare - id: preparation - run: | - export PWD=$(pwd); - echo "::set-output name=PROJ_ROOT::$PWD"; + uses: actions/checkout@v4 + - name: Setup Node + uses: actions/setup-node@v4 + with: + cache: 'npm' - name: Install - run: npm install + run: npm ci - - name: Install wasi-sdk - env: - PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} + - name: "Restore WASI SDK" + id: cache-wasi-sdk + uses: actions/cache@v4 + with: + path: ${{ env.WASI_SDK_PATH }} + key: ${{ runner.os }}-wasi-sdk-${{ env.WASI_SDK_VERSION }} + - name: "Install WASI SDK" + if: steps.cache-wasi-sdk.outputs.cache-hit != 'true' + run: | + mkdir ${{ env.WASI_SDK_PATH }} && \ + curl -s -S --location https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${{ env.WASI_SDK_VERSION }}/wasi-sdk-${{ env.WASI_SDK_VERSION }}.0-linux.tar.gz | \ + tar --strip-components 1 --directory ${{ env.WASI_SDK_PATH }} --extract --gunzip + - name: "Restore WABT" + id: cache-wabt + uses: actions/cache@v4 + with: + path: ${{ env.WABT_PATH }} + key: ${{ runner.os }}-wabt-${{ env.WABT_VERSION }} + - name: "Install WABT" + if: steps.cache-wabt.outputs.cache-hit != 'true' run: | - cd $PROJ_ROOT; - cd ../; - export WASI_OS="linux" - curl -sL https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VERSION}/wasi-sdk-${WASI_VERSION_FULL}-${WASI_OS}.tar.gz -O - # check if package downloaded - ls -la - tar xvf wasi-sdk-${WASI_VERSION_FULL}-${WASI_OS}.tar.gz - # print clang version - ./wasi-sdk-${WASI_VERSION_FULL}/bin/clang --version - - name: Install wabt - env: - PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} + mkdir ${{ env.WABT_PATH }} && \ + curl -s -S --location https://github.com/WebAssembly/wabt/releases/download/${{ env.WABT_VERSION }}/wabt-${{ env.WABT_VERSION }}-ubuntu.tar.gz | \ + tar --strip-components 1 --directory ${{ env.WABT_PATH }} --extract --gunzip + - name: "Restore Binaryen" + id: cache-binaryen + uses: actions/cache@v4 + with: + path: ${{ env.BINARYEN_PATH }} + key: ${{ runner.os }}-binaryen-${{ env.BINARYEN_VERSION }} + - name: "Install Binaryen" + if: steps.cache-binaryen.outputs.cache-hit != 'true' run: | - cd $PROJ_ROOT; - cd ../; - if [[ "$RUNNER_OS" == "Linux" ]]; then - export WABT_OS="ubuntu"; - fi - if [[ "$RUNNER_OS" == "macOS" ]]; then - export WABT_OS="macos"; - fi - if [[ "$RUNNER_OS" == "Windows" ]]; then - export WABT_OS="windows"; - fi - curl -sL https://github.com/WebAssembly/wabt/releases/download/${WABT_VERSION}/wabt-${WABT_VERSION}-${WABT_OS}.tar.gz -O - # check if package downloaded - ls -la - tar xvf wabt-${WABT_VERSION}-${WABT_OS}.tar.gz - # check if wabt binaries installed - ls -la ./wabt-${WABT_VERSION}/bin/ + mkdir ${{ env.BINARYEN_PATH }} && \ + curl -s -S --location https://github.com/WebAssembly/binaryen/releases/download/version_${{ env.BINARYEN_VERSION }}/binaryen-version_${{ env.BINARYEN_VERSION }}-x86_64-linux.tar.gz | \ + tar --strip-components 1 --directory ${{ env.WABT_PATH }} --extract --gunzip - name: Compile to Wasm & Test Wasm - env: - PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} run: | - cd $PROJ_ROOT; rm lib/lexer.wasm; npm run build-wasm; npm run build; # test npm run test; - name: Benchmark Wasm - env: - PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} - run: | - cd $PROJ_ROOT; - npm run bench; + run: npm run bench; diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml deleted file mode 100644 index c993415..0000000 --- a/.github/workflows/node.js.yml +++ /dev/null @@ -1,30 +0,0 @@ -# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - -name: Node.js CI - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [14.x] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ - - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - run: npm ci - - run: npm run build --if-present - - run: npm test diff --git a/Makefile b/Makefile index 961b336..76b9f32 100755 --- a/Makefile +++ b/Makefile @@ -1,10 +1,26 @@ # These flags depend on the system and may be overridden + +ifeq ($(WASI_SDK_PATH),) WASM_CC := ../wasi-sdk-12.0/bin/clang WASM_CFLAGS := --sysroot=../wasi-sdk-12.0/share/wasi-sysroot +else +WASM_CC := $(WASI_SDK_PATH)/bin/clang +WASM_CFLAGS := $(WASI_SDK_PATH)/share/wasi-sysroot +endif + WASM_LDFLAGS := -nostartfiles +ifeq ($(WABT_PATH),) WASM2WAT := ../wabt/bin/wasm2wat +else +WASM2WAT := $(WABT_PATH)/bin/wasm2wat +endif + +ifeq ($(BINARYEN_PATH),) WASM_OPT := ../binaryen/bin/wasm-opt +else +WASM_OPT := $(BINARYEN_PATH)/bin/wasm-opt +endif # These are project-specific and are expected to be kept intact WASM_EXTRA_CFLAGS := -I include-wasm/ -Wno-logical-op-parentheses -Wno-parentheses -Oz