diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c320b031..acb47cd22 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,10 @@ jobs: node: 16 host: arm64 target: arm64 + - os: ubuntu-20.04 + node: 16 + host: x64 + target: wasm32 name: ${{ matrix.os }} (node=${{ matrix.node }}, host=${{ matrix.host }}, target=${{ matrix.target }}) steps: - uses: actions/checkout@v3 @@ -52,6 +56,13 @@ jobs: with: node-version: ${{ matrix.node }} architecture: ${{ matrix.host }} + + - name: Setup Emscripten (WebAssembly) + if: matrix.target == 'wasm32' + uses: mymindstorm/setup-emsdk@v11 + with: + version: '3.1.29' + actions-cache-folder: 'emsdk-cache' - name: Add yarn (self-hosted) if: matrix.os == 'macos-m1' @@ -84,21 +95,43 @@ jobs: echo "CXXFLAGS=${CXXFLAGS:-} -include ../src/gcc-preinclude.h" >> $GITHUB_ENV - name: Configure build + if: matrix.target != 'wasm32' run: yarn node-pre-gyp configure --target_arch=${{ env.TARGET }} + + - name: Configure build (WebAssembly) + if: matrix.target == 'wasm32' + run: yarn node-pre-gyp configure --nodedir=./wasm --target_arch=${{ env.TARGET }} - name: Build binaries + if: matrix.target != 'wasm32' run: yarn node-pre-gyp build --target_arch=${{ env.TARGET }} + + - name: Build binaries (WebAssembly) + if: matrix.target == 'wasm32' + run: emmake yarn node-pre-gyp build --nodedir=./wasm --target_arch=${{ env.TARGET }} - name: Print binary info - if: contains(matrix.os, 'ubuntu') + if: contains(matrix.os, 'ubuntu') && matrix.target != 'wasm32' run: | ldd lib/binding/*/node_sqlite3.node echo "---" nm lib/binding/*/node_sqlite3.node | grep "GLIBC_" | c++filt || true echo "---" file lib/binding/napi-v*/* + + - name: Print binary info (WebAssembly) + if: contains(matrix.os, 'ubuntu') && matrix.target == 'wasm32' + run: | + file lib/binding/napi-v*/* - name: Run tests + if: matrix.target != 'wasm32' + run: yarn test + + - name: Run tests (WebAssembly) + if: matrix.target == 'wasm32' + env: + npm_config_target_arch: 'wasm32' run: yarn test - name: Package prebuilt binaries diff --git a/binding.gyp b/binding.gyp index 20d418b3c..a73a13176 100644 --- a/binding.gyp +++ b/binding.gyp @@ -16,34 +16,54 @@ "msvs_settings": { "VCCLCompilerTool": { "ExceptionHandling": 1 }, }, - "include_dirs": [ - " JSON.stringify(path.relative(process.cwd(), x))).join(\' \')")' + ], + + 'default_configuration': 'Release', + 'configurations': { + 'Debug': { + 'defines': [ 'DEBUG', '_DEBUG' ], + 'cflags': [ '-g', '-O0' ], + 'ldflags': [ '-g', '-O0', '-sSAFE_HEAP=1' ], + }, + 'Release': { + 'cflags': [ '-O3' ], + 'ldflags': [ '-O3' ], + } + }, + + 'conditions': [ + ['target_arch == "wasm64"', { + 'cflags': [ + '-sMEMORY64=1', + ], + 'ldflags': [ + '-sMEMORY64=1' + ] + }], + ['wasm_threads == 1', { + 'cflags': [ '-sUSE_PTHREADS=1' ], + 'ldflags': [ '-sUSE_PTHREADS=1' ], + }], + ], + } +}