Skip to content

Commit

Permalink
Merge pull request #29 from toyobayashi/feat-wasi-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi authored Feb 7, 2023
2 parents 740aad5 + d64d61b commit cb997e5
Show file tree
Hide file tree
Showing 124 changed files with 10,708 additions and 1,155 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ node_modules
/test/CMakeFiles
/packages/runtime/lib
/packages/emnapi/lib
/packages/emnapi/transformer/out
/packages/core/src/index.js
52 changes: 48 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ jobs:
build:
name: Build
runs-on: ${{ matrix.os }}
env:
WASI_VERSION: '19'
WASI_VERSION_FULL: '19.0'
WASI_SDK_PATH: './wasi-sdk-19.0'
LLVM_VERSION: '15.0.7'
LLVM_PATH: './wasi-sdk-19.0'
strategy:
fail-fast: false
matrix:
Expand All @@ -36,6 +42,32 @@ jobs:
version: '3.1.29'
# no-cache: true
actions-cache-folder: 'emsdk-cache'
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
default: true
target: wasm32-unknown-unknown
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
default: true
target: wasm32-wasi

- name: Cache wasi-sdk
id: cache-wasi-sdk
uses: actions/cache@v3
with:
path: ${{ env.WASI_SDK_PATH }}
key: ${{ runner.os }}-${{ env.WASI_VERSION_FULL }}

- name: Install wasi-sdk
if: ${{ steps.cache-wasi-sdk.outputs.cache-hit != 'true' }}
shell: bash
run: |
wget -q https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VERSION}/wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz
mkdir -p $WASI_SDK_PATH
tar zxvf wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz -C $WASI_SDK_PATH --strip 1
- uses: actions/setup-node@v3
with:
node-version: '16.15.0'
Expand All @@ -50,27 +82,39 @@ jobs:
npm install -g node-gyp
npm install --legacy-peer-deps
npm run build --workspaces --if-present
- name: Lint
run: npm run lint

- name: Test
- name: Test wasm32-unknown-emscripten
run: |
npm run rebuild -w packages/test
npm run test -w packages/test
- name: Test MEMORY64
- name: Test wasm64-unknown-emscripten
env:
MEMORY64: '1'
run: |
npm run rebuild -w packages/test
npm run test -w packages/test
- name: Test wasm32-wasi
run: |
npm run rebuild:w -w packages/test
cd ./packages/test/rust && cargo build --release --target=wasm32-wasi && cd ../../..
npm run test:w -w packages/test
- name: Test wasm32-unknown-unknown
run: |
npm run rebuild:wasm32 -w packages/test
cd ./packages/test/rust && cargo build --release --target=wasm32-unknown-unknown && cd ../../..
npm run test:wasm32 -w packages/test
- name: Publish
if: ${{ startsWith(github.event.ref, 'refs/tags') && matrix.os == 'ubuntu-latest' }}
run: |
node ./script/release.js
npm publish --ignore-scripts -w packages/runtime -w packages/node -w packages/emnapi
npm publish --ignore-scripts -w packages/runtime -w packages/node -w packages/emnapi -w packages/core
- name: Create release
if: ${{ startsWith(github.event.ref, 'refs/tags') }}
Expand Down
23 changes: 21 additions & 2 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
{
"name": "Emscripten",
"defines": ["${defines}", "__wasm32__", "__EMSCRIPTEN_PTHREADS__", "NAPI_VERSION=8"],
"defines": ["${defines}", "__wasm__", "__EMSCRIPTEN_PTHREADS__", "NAPI_VERSION=8"],
"compilerPath": "${env:EMSDK}/upstream/emscripten/emcc",
"intelliSenseMode": "linux-clang-x86",
"cStandard": "c11",
Expand All @@ -58,12 +58,31 @@
},
{
"name": "Win32 Emscripten",
"defines": ["${defines}", "__wasm32__", "__EMSCRIPTEN_PTHREADS__", "NAPI_VERSION=8"],
"defines": ["${defines}", "__wasm__", "__EMSCRIPTEN_PTHREADS__", "NAPI_VERSION=8"],
"compilerPath": "${env:EMSDK}\\upstream\\emscripten\\emcc.bat",
"intelliSenseMode": "linux-clang-x86",
"cStandard": "c11",
"cppStandard": "c++17",
"includePath": ["${includePath}"]
},
{
"name": "WASI",
"defines": ["${defines}"],
"compilerPath": "${env:WASI_SDK_PATH}/bin/clang",
"intelliSenseMode": "clang-x86",
"cStandard": "c11",
"cppStandard": "c++14",
"includePath": ["${includePath}"]
},
{
"name": "WASM32",
"defines": ["${defines}", "PAGESIZE=65536"],
"compilerPath": "${env:WASI_SDK_PATH}/bin/clang",
"intelliSenseMode": "clang-x86",
"cStandard": "c11",
"cppStandard": "c++14",
"includePath": ["${includePath}"],
"compilerArgs": ["--target=wasm32"]
}
],
"version": 4
Expand Down
15 changes: 13 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Build",
"runtimeArgs": [],
"program": "${workspaceFolder}/packages/emnapi/script/build.js",
"args": []
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"runtimeArgs": ["--expose-gc"],
"program": "${workspaceFolder}/packages/test/make_callback/make_callback.test.js",
"env": {
"EMNAPI_TEST_WASI": "1"
},
"runtimeArgs": ["--experimental-wasi-unstable-preview1", "--expose-gc"],
"program": "${workspaceFolder}/packages/test/arg/arg.test.js",
"args": []
},
{
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"packages/runtime",
"packages/node",
"packages/emnapi",
"packages/core",
"packages/test",
"packages/bench"
]
Expand Down
2 changes: 1 addition & 1 deletion packages/bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"rebuild": "cgen rebuild -e"
},
"devDependencies": {
"@tybys/cgen": "^0.14.0",
"@tybys/cgen": "^0.14.1",
"node-addon-api": "5.1.0",
"benchmark": "^2.1.4"
}
Expand Down
4 changes: 4 additions & 0 deletions packages/core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/lib
node_modules
/dist
/src/index.js
9 changes: 9 additions & 0 deletions packages/core/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.vscode
node_modules
/script
/lib
/src
.gitignore
.npmignore
api-extractor.json
tsconfig.json
21 changes: 21 additions & 0 deletions packages/core/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021-present Toyobayashi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See [https://github.com/toyobayashi/emnapi](https://github.com/toyobayashi/emnapi)
46 changes: 46 additions & 0 deletions packages/core/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export declare interface CreateOptions {
context: import('@tybys/emnapi-runtime').Context
filename?: string
nodeBinding?: {
node: {
emitAsyncInit: Function
emitAsyncDestroy: Function
makeCallback: Function
}
napi: {
asyncInit: Function
asyncDestroy: Function
makeCallback: Function
}
}
}

export declare interface PointerInfo {
address: number
ownership: 0 | 1
runtimeAllocated: 0 | 1
}

export declare interface NapiModule {
imports: {
env: any
napi: any
emnapi: any
}
exports: any
loaded: boolean
filename: string
emnapi: {
syncMemory<T extends ArrayBuffer | ArrayBufferView> (
js_to_wasm: boolean,
arrayBufferOrView: T,
offset?: number,
len?: int
): T
getMemoryAddress (arrayBufferOrView: ArrayBuffer | ArrayBufferView): PointerInfo
}

init (instance: WebAssembly.Instance, memory?: WebAssembly.Memory, table?: WebAssembly.Table): any
}

export function createNapiModule (options: CreateOptions): NapiModule
5 changes: 5 additions & 0 deletions packages/core/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/emnapi-core.cjs.min.js')
} else {
module.exports = require('./dist/emnapi-core.cjs.js')
}
51 changes: 51 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@tybys/emnapi-core",
"version": "0.29.0",
"description": "emnapi core",
"main": "index.js",
"module": "./src/index.js",
"types": "./index.d.ts",
"sideEffects": false,
"exports": {
".": {
"module": "./src/index.js",
"import": "./dist/emnapi-core.mjs",
"require": "./index.js",
"types": "./index.d.ts"
},
"./dist/emnapi-core.cjs.min": {
"default": "./dist/emnapi-core.cjs.min.js",
"types": "./index.d.ts"
},
"./dist/emnapi-core.min.mjs": {
"import": "./dist/emnapi-core.min.mjs",
"require": null,
"types": "./index.d.ts"
}
},
"dependencies": {
"tslib": "^2.4.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-replace": "^5.0.2",
"rollup": "^2.77.2",
"rollup-plugin-terser": "^7.0.2"
},
"scripts": {
"build": "node ./script/build.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/toyobayashi/emnapi.git"
},
"author": "toyobayashi",
"license": "MIT",
"bugs": {
"url": "https://github.com/toyobayashi/emnapi/issues"
},
"homepage": "https://github.com/toyobayashi/emnapi#readme",
"publishConfig": {
"access": "public"
}
}
Loading

0 comments on commit cb997e5

Please sign in to comment.