Skip to content

Commit

Permalink
Merge branch 'main' into bench
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed May 31, 2024
2 parents 7f4031f + 414439f commit b69d99a
Show file tree
Hide file tree
Showing 53 changed files with 2,627 additions and 469 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module.exports = {
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/member-delimiter-style': ['error', {
multiline: {
delimiter: 'none',
Expand Down
52 changes: 45 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ on:
- test-*
tags:
- v*
- wasi-threads-v*
pull_request:
paths-ignore:
- '**/*.md'
- '**/docs/**'
workflow_dispatch:

env:
WASI_VERSION: '21'
WASI_VERSION_FULL: '21.0'
WASI_SDK_PATH: './wasi-sdk-21.0'
EM_VERSION: '3.1.44'
WASI_VERSION: '22'
WASI_VERSION_FULL: '22.0'
WASI_SDK_PATH: './wasi-sdk-22.0'
EM_VERSION: '3.1.52'
EM_CACHE_FOLDER: 'emsdk-cache'

jobs:
build:
timeout-minutes: 15
name: Build
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -83,7 +85,7 @@ jobs:
shell: bash
run: |
npm install -g node-gyp
npm install
npm install --ignore-scripts
- name: NPM Build
shell: bash
Expand All @@ -93,6 +95,14 @@ jobs:
shell: bash
run: npm run test -w packages/ts-transform-emscripten-esm-library

- name: Test @emnapi/wasi-threads
if: ${{ matrix.target == 'wasm32-wasi-threads' }}
shell: bash
run: |
node ./packages/wasi-threads/test/build.js
npm run test -w packages/wasi-threads
timeout-minutes: 1

# - name: Lint
# run: npm run lint

Expand Down Expand Up @@ -133,7 +143,7 @@ jobs:
release:
name: Release
if: ${{ startsWith(github.event.ref, 'refs/tags') }}
if: ${{ startsWith(github.event.ref, 'refs/tags/v') }}
needs: build
runs-on: ubuntu-latest

Expand Down Expand Up @@ -165,7 +175,7 @@ jobs:
shell: bash
run: |
npm install -g node-gyp
npm install
npm install --ignore-scripts
- name: NPM Build
shell: bash
Expand All @@ -187,3 +197,31 @@ jobs:
prerelease: false
generate_release_notes: true
files: ./script/emnapi.zip

release-wasi-threads:
name: Release
if: ${{ startsWith(github.event.ref, 'refs/tags/wasi-threads-v') }}
needs: build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '20.9.0'
registry-url: 'https://registry.npmjs.org'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: NPM Install
shell: bash
run: |
npm install -g node-gyp
npm install --ignore-scripts
- name: NPM Build
shell: bash
run: npm run build -w packages/wasi-threads

- name: Publish
run: npm publish --ignore-scripts -w packages/wasi-threads
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package-lock.json
/example/build
out
/script/emnapi.zip
/script/*.cmake
*.tgz
/packages/bench/bench.txt
/packages/bench/build
10 changes: 9 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@
"program": "${file}",
"args": [],
"preLaunchTask": "CMake: build ${input:target}"
}
},
{
"type": "node",
"request": "launch",
"name": "wasi-threads test",
"runtimeArgs": [],
"program": "${workspaceFolder}/packages/wasi-threads/test/index.js",
"args": []
},
],
"inputs": [
{
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"packages/rollup-plugin-emscripten-esm-library",
"packages/runtime",
"packages/node",
"packages/wasi-threads",
"packages/emnapi",
"packages/core",
"packages/test",
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@emnapi/core",
"version": "1.1.1",
"version": "1.2.0",
"description": "emnapi core",
"main": "index.js",
"module": "./dist/emnapi-core.esm-bundler.js",
Expand All @@ -23,11 +23,11 @@
},
"./dist/emnapi-core.min.mjs": {
"types": "./dist/emnapi-core.d.mts",
"import": "./dist/emnapi-core.min.mjs",
"require": null
"default": "./dist/emnapi-core.min.mjs"
}
},
"dependencies": {
"@emnapi/wasi-threads": "1.0.1",
"tslib": "^2.4.0"
},
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions packages/core/script/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const dist = path.join(__dirname, '../dist')
function build () {
compile(path.join(__dirname, '../tsconfig.json'), {
optionsToExtend: {
target: require('typescript').ScriptTarget.ES2019,
target: ts.ScriptTarget.ES2019,
emitDeclarationOnly: true,
declaration: true,
declarationDir: path.join(__dirname, '../lib/typings')
Expand Down Expand Up @@ -108,7 +108,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES2019, false, ['tslib']),
input: createInput(ts.ScriptTarget.ES2019, false, ['tslib', '@emnapi/wasi-threads']),
output: {
file: path.join(dist, 'emnapi-core.cjs.js'),
format: 'cjs',
Expand All @@ -118,7 +118,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES2019, true, ['tslib']),
input: createInput(ts.ScriptTarget.ES2019, true, ['tslib', '@emnapi/wasi-threads']),
output: {
file: path.join(dist, 'emnapi-core.cjs.min.js'),
format: 'cjs',
Expand All @@ -128,7 +128,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES2019, false, ['tslib']),
input: createInput(ts.ScriptTarget.ES2019, false, ['tslib', '@emnapi/wasi-threads']),
output: {
file: path.join(dist, 'emnapi-core.mjs'),
format: 'esm',
Expand All @@ -138,7 +138,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES2019, true, ['tslib']),
input: createInput(ts.ScriptTarget.ES2019, true, ['tslib', '@emnapi/wasi-threads']),
output: {
file: path.join(dist, 'emnapi-core.min.mjs'),
format: 'esm',
Expand All @@ -148,7 +148,7 @@ function build () {
}
},
{
input: createInput(ts.ScriptTarget.ES5, false, ['tslib']),
input: createInput(ts.ScriptTarget.ES5, false, ['tslib', '@emnapi/wasi-threads']),
output: {
file: path.join(dist, 'emnapi-core.esm-bundler.js'),
format: 'esm',
Expand Down
12 changes: 9 additions & 3 deletions packages/core/src/emnapi/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Context } from '@emnapi/runtime'
import type { ThreadManager, ThreadManagerOptionsMain, MainThreadBaseOptions } from '@emnapi/wasi-threads'

/** @public */
export declare interface PointerInfo {
Expand Down Expand Up @@ -34,14 +35,17 @@ export declare interface NapiModule {
len?: number
): T
getMemoryAddress (arrayBufferOrView: ArrayBuffer | ArrayBufferView): PointerInfo
addSendListener (worker: any): boolean
}

init (options: InitOptions): any
spawnThread (startArg: number, errorOrTid?: number): number
startThread (tid: number, startArg: number): void
initWorker (arg: number): void
executeAsyncWork (work: number): void
postMessage?: (msg: any) => any

waitThreadStart: boolean | number
/** @internal */
PThread: ThreadManager
}

/** @public */
Expand All @@ -61,14 +65,16 @@ export declare interface NodeBinding {
/** @public */
export declare interface CreateWorkerInfo {
type: 'thread' | 'async-work'
name: string
}

/** @public */
export declare type BaseCreateOptions = {
filename?: string
nodeBinding?: NodeBinding
reuseWorker?: boolean
reuseWorker?: ThreadManagerOptionsMain['reuseWorker']
asyncWorkPoolSize?: number
waitThreadStart?: MainThreadBaseOptions['waitThreadStart']
onCreateWorker?: (info: CreateWorkerInfo) => any
print?: (str: string) => void
printErr?: (str: string) => void
Expand Down
9 changes: 5 additions & 4 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ export type {
export type {
LoadOptions,
InstantiateOptions,
InstantiatedSource,
ReactorWASI
LoadedSource,
InstantiatedSource
} from './load'

export type {
OnLoadData,
HandleOptions
MessageHandlerOptions
} from './worker'

export type {
InputType
} from './util'

export * from '@emnapi/wasi-threads'
Loading

0 comments on commit b69d99a

Please sign in to comment.