From 8bab8d9a9429c515726c6e8c70f2f1c0c5f1891c Mon Sep 17 00:00:00 2001 From: Ray Chan Date: Fri, 8 Oct 2021 12:13:47 +0800 Subject: [PATCH 1/2] feat: support ci on actions. --- .github/workflows/build.yml | 158 ++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..096632f --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,158 @@ +name: Test es-module-lexer + +on: + push: + # Sequence of patterns matched against refs/heads + branches: + - 'feat/**' + - 'fix/**' + - '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: ${{ matrix.os }} + continue-on-error: true + strategy: + matrix: + os: [ubuntu-18.04, windows-2016, macos-10.15] + + steps: + - name: Check out Git repository + uses: actions/checkout@v2 + with: + submodules: 'recursive' + + - name: Prepare + id: preparation + shell: bash + run: | + export PWD=$(pwd); + echo "::set-output name=PROJ_ROOT::$PWD"; + npm install; + + - name: Install wasi-sdk + shell: bash + if: runner.os != 'Windows' + env: + PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} + run: | + cd $PROJ_ROOT; + cd ../; + if [[ "$RUNNER_OS" == "Linux" ]]; then + export WASI_OS="linux"; + fi + if [[ "$RUNNER_OS" == "macOS" ]]; then + export WASI_OS="macos"; + fi + + 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 + shell: bash + env: + PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} + 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/ + + - name: Add make.exe on Windows + if: runner.os == 'Windows' + shell: bash + env: + PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} + run: | + # install make.exe + cd "C:/Program Files/Git/mingw64/" + if [ ! -e make.zip ]; then + curl -sL -o "make.zip" https://netix.dl.sourceforge.net/project/ezwinports/make-4.3-without-guile-w32-bin.zip + fi + unzip -n "make.zip" + + cd $PROJ_ROOT; + # test if make valid + which make; + + - name: Compile to Wasm & Test Wasm + shell: bash + env: + PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} + run: | + cd $PROJ_ROOT; + make lib/lexer.wasm && npm run build:wasm; + # test + npm run test:wasm; + + - name: Install Emscripten + id: emcc_steup + shell: bash + env: + PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} + run: | + cd $PROJ_ROOT; + cd ../; + git clone https://github.com/emscripten-core/emsdk.git; + cd ./emsdk; + ./emsdk install $EMCC_VERSION; + ./emsdk activate $EMCC_VERSION; + EMCC_REPO=$(pwd); + echo "::set-output name=EMCC_REPO::$EMCC_REPO" + + cd $PROJ_ROOT; + source $EMCC_REPO/emsdk_env.sh; + # check if emcc valid + emcc -v + + - name: Benchmark + continue-on-error: false + shell: bash + env: + PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} + run: | + cd $PROJ_ROOT; + npm run bench; + + - name: Compile to Asm.js & Test Asm.js (Experimental) + continue-on-error: true + shell: bash + env: + PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} + EMCC_REPO: ${{ steps.emcc_steup.outputs.EMCC_REPO }} + + run: | + cd $PROJ_ROOT; + source $EMCC_REPO/emsdk_env.sh; + make lib/lexer.asm.js && npm run build:asm; + # test + npm run build:cjs && npm run test:js; \ No newline at end of file From 11176ded6cf57e86f258f5272979652a4e5c91ba Mon Sep 17 00:00:00 2001 From: richardo2016 Date: Fri, 8 Oct 2021 23:43:42 +0800 Subject: [PATCH 2/2] ci: don't make lib/lexer.asm.js --- .github/workflows/build.yml | 82 ++++++++++++++++++++----------------- bench/index.js | 40 ++++++++++-------- package.json | 2 + 3 files changed, 69 insertions(+), 55 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 096632f..2590ccb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -114,45 +114,53 @@ jobs: # test npm run test:wasm; - - name: Install Emscripten - id: emcc_steup + - name: Benchmark Wasm shell: bash env: PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} run: | cd $PROJ_ROOT; - cd ../; - git clone https://github.com/emscripten-core/emsdk.git; - cd ./emsdk; - ./emsdk install $EMCC_VERSION; - ./emsdk activate $EMCC_VERSION; - EMCC_REPO=$(pwd); - echo "::set-output name=EMCC_REPO::$EMCC_REPO" - - cd $PROJ_ROOT; - source $EMCC_REPO/emsdk_env.sh; - # check if emcc valid - emcc -v - - - name: Benchmark - continue-on-error: false - shell: bash - env: - PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} - run: | - cd $PROJ_ROOT; - npm run bench; - - - name: Compile to Asm.js & Test Asm.js (Experimental) - continue-on-error: true - shell: bash - env: - PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} - EMCC_REPO: ${{ steps.emcc_steup.outputs.EMCC_REPO }} - - run: | - cd $PROJ_ROOT; - source $EMCC_REPO/emsdk_env.sh; - make lib/lexer.asm.js && npm run build:asm; - # test - npm run build:cjs && npm run test:js; \ No newline at end of file + npm run bench:wasm; + + # - name: Install Emscripten + # id: emcc_steup + # shell: bash + # env: + # PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} + # run: | + # cd $PROJ_ROOT; + # cd ../; + # git clone https://github.com/emscripten-core/emsdk.git; + # cd ./emsdk; + # ./emsdk install $EMCC_VERSION; + # ./emsdk activate $EMCC_VERSION; + # EMCC_REPO=$(pwd); + # echo "::set-output name=EMCC_REPO::$EMCC_REPO" + + # cd $PROJ_ROOT; + # source $EMCC_REPO/emsdk_env.sh; + # # check if emcc valid + # emcc -v + + # - name: Compile to Asm.js & Test Asm.js (Experimental) + # continue-on-error: true + # shell: bash + # env: + # PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} + # EMCC_REPO: ${{ steps.emcc_steup.outputs.EMCC_REPO }} + + # run: | + # cd $PROJ_ROOT; + # source $EMCC_REPO/emsdk_env.sh; + # make lib/lexer.asm.js && npm run build:asm; + # # test + # npm run test:js; + + # - name: Benchmark Asm.js + # continue-on-error: true + # shell: bash + # env: + # PROJ_ROOT: ${{ steps.preparation.outputs.PROJ_ROOT }} + # run: | + # cd $PROJ_ROOT; + # npm run bench:js; \ No newline at end of file diff --git a/bench/index.js b/bench/index.js index 8670509..b6bedb7 100755 --- a/bench/index.js +++ b/bench/index.js @@ -27,27 +27,31 @@ Promise.resolve().then(async () => { return Math.round(Number(end - start) / 1e6); } - console.log('--- JS Build ---'); - console.log('Module load time'); - { - const start = process.hrtime.bigint(); - var { parse } = await import('../dist/lexer.asm.js'); - console.log(`> ${c.bold.green(Math.round(Number(process.hrtime.bigint() - start) / 1e6) + 'ms')}`); + if (!process.env.BENCH || process.env.BENCH === 'js') { + console.log('--- JS Build ---'); + console.log('Module load time'); + { + const start = process.hrtime.bigint(); + var { parse } = await import('../dist/lexer.asm.js'); + console.log(`> ${c.bold.green(Math.round(Number(process.hrtime.bigint() - start) / 1e6) + 'ms')}`); + } + + doRun(); } - - doRun(); - - console.log('--- Wasm Build ---'); - console.log('Module load time'); - { - const start = process.hrtime.bigint(); - var { parse, init } = await import('../dist/lexer.js'); - await init; - console.log(`> ${c.bold.green(Math.round(Number(process.hrtime.bigint() - start) / 1e6) + 'ms')}`); + + if (!process.env.BENCH || process.env.BENCH === 'wasm') { + console.log('--- Wasm Build ---'); + console.log('Module load time'); + { + const start = process.hrtime.bigint(); + var { parse, init } = await import('../dist/lexer.js'); + await init; + console.log(`> ${c.bold.green(Math.round(Number(process.hrtime.bigint() - start) / 1e6) + 'ms')}`); + } + + doRun(); } - doRun(); - function doRun () { console.log('Cold Run, All Samples'); let totalSize = 0; diff --git a/package.json b/package.json index 9674e70..0cd6aaf 100755 --- a/package.json +++ b/package.json @@ -22,6 +22,8 @@ "build:wasm": "node build.js", "build:asm": "cat src/lexer.asm.js lib/lexer.asm.js | terser --module -c -m -o dist/lexer.asm.js", "bench": "node --expose-gc bench/index.js", + "bench:wasm": "cross-env BENCH=wasm node --expose-gc bench/index.js", + "bench:js": "cross-env BENCH=js node --expose-gc bench/index.js", "prepublishOnly": "npm run build", "footprint": "npm run build && echo Wasm: && cat dist/lexer.js | brotli | wc -c && echo Asm.js: && cat dist/lexer.asm.js | brotli | wc -c" },