emnapi 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CMakeLists.txt +14 -2
- package/README.md +39 -11
- package/common.gypi +4 -4
- package/dist/library_napi.js +2 -2
- package/emnapi.gyp +1 -1
- package/include/node/emnapi.h +2 -2
- package/lib/wasm32/libdlmalloc-mt.a +0 -0
- package/lib/wasm32/libdlmalloc.a +0 -0
- package/lib/wasm32/libemmalloc-mt.a +0 -0
- package/lib/wasm32/libemmalloc.a +0 -0
- package/lib/wasm32/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32/libemnapi-basic.a +0 -0
- package/lib/wasm32/libemnapi.a +0 -0
- package/lib/wasm32-emscripten/libemnapi-basic.a +0 -0
- package/lib/wasm32-emscripten/libemnapi-mt.a +0 -0
- package/lib/wasm32-emscripten/libemnapi.a +0 -0
- package/lib/wasm32-wasi/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasi/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasi/libemnapi.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi.a +0 -0
- package/lib/wasm32-wasip1/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasip1/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasip1/libemnapi.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi.a +0 -0
- package/lib/wasm64-emscripten/libemnapi-basic.a +0 -0
- package/lib/wasm64-emscripten/libemnapi-mt.a +0 -0
- package/lib/wasm64-emscripten/libemnapi.a +0 -0
- package/package.json +1 -1
package/CMakeLists.txt
CHANGED
|
@@ -17,6 +17,18 @@ else()
|
|
|
17
17
|
set(IS_WASM32 OFF)
|
|
18
18
|
endif()
|
|
19
19
|
|
|
20
|
+
if((CMAKE_C_COMPILER_TARGET STREQUAL "wasm32-wasi") OR (CMAKE_C_COMPILER_TARGET STREQUAL "wasm32-wasip1"))
|
|
21
|
+
set(IS_WASM32_WASIP1 ON)
|
|
22
|
+
else()
|
|
23
|
+
set(IS_WASM32_WASIP1 OFF)
|
|
24
|
+
endif()
|
|
25
|
+
|
|
26
|
+
if((CMAKE_C_COMPILER_TARGET STREQUAL "wasm32-wasi-threads") OR (CMAKE_C_COMPILER_TARGET STREQUAL "wasm32-wasip1-threads"))
|
|
27
|
+
set(IS_WASM32_WASIP1_THREADS ON)
|
|
28
|
+
else()
|
|
29
|
+
set(IS_WASM32_WASIP1_THREADS OFF)
|
|
30
|
+
endif()
|
|
31
|
+
|
|
20
32
|
set(UV_SRC
|
|
21
33
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/uv/uv-common.c"
|
|
22
34
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/uv/threadpool.c"
|
|
@@ -133,7 +145,7 @@ if(IS_EMSCRIPTEN)
|
|
|
133
145
|
target_link_options(${EMNAPI_BASIC_TARGET_NAME} INTERFACE "--js-library=${EMNAPI_JS_LIB}")
|
|
134
146
|
endif()
|
|
135
147
|
|
|
136
|
-
if(IS_WASM32 OR
|
|
148
|
+
if(IS_WASM32 OR IS_WASM32_WASIP1 OR IS_WASM32_WASIP1_THREADS)
|
|
137
149
|
set(EMNAPI_BUILD_BASIC_MT ON)
|
|
138
150
|
else()
|
|
139
151
|
set(EMNAPI_BUILD_BASIC_MT OFF)
|
|
@@ -155,7 +167,7 @@ if(EMNAPI_BUILD_BASIC_MT)
|
|
|
155
167
|
endif()
|
|
156
168
|
endif()
|
|
157
169
|
|
|
158
|
-
if(IS_EMSCRIPTEN OR
|
|
170
|
+
if(IS_EMSCRIPTEN OR IS_WASM32_WASIP1_THREADS)
|
|
159
171
|
set(EMNAPI_BUILD_MT ON)
|
|
160
172
|
else()
|
|
161
173
|
set(EMNAPI_BUILD_MT OFF)
|
package/README.md
CHANGED
|
@@ -23,6 +23,8 @@ This project aims to
|
|
|
23
23
|
|
|
24
24
|
This project also powers the WebAssembly feature for [napi-rs](https://github.com/napi-rs/napi-rs), and enables many Node.js native addons to run on [StackBlitz](https://stackblitz.com)'s WebContainer.
|
|
25
25
|
|
|
26
|
+
[Node-API changes](https://github.com/nodejs/node/pulls?q=is%3Apr+label%3Anode-api+) will be synchronized into this repo.
|
|
27
|
+
|
|
26
28
|
See documentation for more details:
|
|
27
29
|
- [https://toyobayashi.github.io/emnapi-docs/guide/](https://toyobayashi.github.io/emnapi-docs/guide/)
|
|
28
30
|
- [https://emnapi-docs.vercel.app/guide/](https://emnapi-docs.vercel.app/guide/)
|
|
@@ -628,9 +630,10 @@ Output code can run in recent version modern browsers and Node.js latest LTS. IE
|
|
|
628
630
|
### Using node-gyp (Experimental)
|
|
629
631
|
|
|
630
632
|
Currently node-gyp works on Linux only and don't support static library linking in cross-compiling.
|
|
631
|
-
There are
|
|
633
|
+
There are related PRs to try to make node-gyp work fine.
|
|
632
634
|
|
|
633
635
|
- https://github.com/nodejs/gyp-next/pull/222
|
|
636
|
+
- https://github.com/nodejs/gyp-next/pull/240
|
|
634
637
|
- https://github.com/nodejs/node-gyp/pull/2974
|
|
635
638
|
|
|
636
639
|
If you experienced issues on Windows or macOS, please check the PRs for upstream changes detail and see
|
|
@@ -643,7 +646,7 @@ Arch: `node-gyp configure --arch=<wasm32 | wasm64>`
|
|
|
643
646
|
```ts
|
|
644
647
|
// node-gyp configure -- -Dvariable_name=value
|
|
645
648
|
|
|
646
|
-
declare var OS: 'emscripten' | 'wasi' | 'unknown' | ''
|
|
649
|
+
declare var OS: 'emscripten' | 'wasi' | 'unknown' | 'wasm' | ''
|
|
647
650
|
|
|
648
651
|
/**
|
|
649
652
|
* Enable async work and threadsafe-functions
|
|
@@ -699,7 +702,7 @@ declare var emnapi_manual_linking: 0 | 1
|
|
|
699
702
|
["OS == 'wasi'", {
|
|
700
703
|
# ...
|
|
701
704
|
}],
|
|
702
|
-
["OS
|
|
705
|
+
["OS in ' wasm unknown'", {
|
|
703
706
|
# ...
|
|
704
707
|
}]
|
|
705
708
|
]
|
|
@@ -750,19 +753,19 @@ call set CXX_target=%%WASI_SDK_PATH:\=/%%/bin/clang++.exe
|
|
|
750
753
|
emmake node-gyp rebuild \
|
|
751
754
|
--arch=wasm32 \
|
|
752
755
|
--nodedir=./node_modules/emnapi \
|
|
753
|
-
-- -f make-
|
|
756
|
+
-- -f make-emscripten # -Dwasm_threads=1
|
|
754
757
|
|
|
755
758
|
# wasi
|
|
756
759
|
node-gyp rebuild \
|
|
757
760
|
--arch=wasm32 \
|
|
758
761
|
--nodedir=./node_modules/emnapi \
|
|
759
|
-
-- -f make-
|
|
762
|
+
-- -f make-wasi # -Dwasm_threads=1
|
|
760
763
|
|
|
761
764
|
# bare wasm32
|
|
762
765
|
node-gyp rebuild \
|
|
763
766
|
--arch=wasm32 \
|
|
764
767
|
--nodedir=./node_modules/emnapi \
|
|
765
|
-
-- -f make-
|
|
768
|
+
-- -f make-wasm # -Dwasm_threads=1
|
|
766
769
|
```
|
|
767
770
|
|
|
768
771
|
```bat
|
|
@@ -770,15 +773,15 @@ node-gyp rebuild \
|
|
|
770
773
|
@REM Run the bat file in POSIX-like environment (e.g. Cygwin)
|
|
771
774
|
|
|
772
775
|
@REM emscripten
|
|
773
|
-
call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-
|
|
776
|
+
call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-emscripten
|
|
774
777
|
call emmake.bat make -C %~dp0build
|
|
775
778
|
|
|
776
779
|
@REM wasi
|
|
777
|
-
call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-
|
|
780
|
+
call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-wasi
|
|
778
781
|
make -C %~dp0build
|
|
779
782
|
|
|
780
783
|
@REM bare wasm32
|
|
781
|
-
call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-
|
|
784
|
+
call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-wasm
|
|
782
785
|
make -C %~dp0build
|
|
783
786
|
```
|
|
784
787
|
|
|
@@ -935,7 +938,32 @@ instantiateNapiModule(input, {
|
|
|
935
938
|
*/
|
|
936
939
|
asyncWorkPoolSize: 4, // 0: single thread mock, > 0: schedule async work in web worker
|
|
937
940
|
wasi: new WASI(/* ... */),
|
|
938
|
-
|
|
941
|
+
|
|
942
|
+
/**
|
|
943
|
+
* Setting this to `true` or a delay (ms) makes
|
|
944
|
+
* pthread_create() do not return until worker actually start.
|
|
945
|
+
* It will throw error if emnapi runs in browser main thread
|
|
946
|
+
* since browser disallow blocking the main thread (Atomics.wait).
|
|
947
|
+
* @defaultValue false
|
|
948
|
+
*/
|
|
949
|
+
waitThreadStart: isNode || (isBrowser && !isBrowserMainThread),
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* Reuse the thread worker after thread exit to avoid re-creatation
|
|
953
|
+
* @defaultValue false
|
|
954
|
+
*/
|
|
955
|
+
reuseWorker: {
|
|
956
|
+
/**
|
|
957
|
+
* @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size | PTHREAD_POOL_SIZE}
|
|
958
|
+
*/
|
|
959
|
+
size: 0,
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* @see {@link https://emscripten.org/docs/tools_reference/settings_reference.html#pthread-pool-size-strict | PTHREAD_POOL_SIZE_STRICT}
|
|
963
|
+
*/
|
|
964
|
+
strict: false
|
|
965
|
+
},
|
|
966
|
+
|
|
939
967
|
onCreateWorker () {
|
|
940
968
|
return new Worker('./worker.js')
|
|
941
969
|
// Node.js
|
|
@@ -988,7 +1016,7 @@ instantiateNapiModule(input, {
|
|
|
988
1016
|
}
|
|
989
1017
|
})
|
|
990
1018
|
|
|
991
|
-
WASI = require('
|
|
1019
|
+
WASI = require('wasi').WASI
|
|
992
1020
|
emnapiCore = require('@emnapi/core')
|
|
993
1021
|
} else {
|
|
994
1022
|
importScripts('./node_modules/memfs-browser/dist/memfs.js')
|
package/common.gypi
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# in https://github.com/lovell/sharp/pull/3522
|
|
3
3
|
{
|
|
4
4
|
'variables': {
|
|
5
|
-
# OS: 'emscripten' | 'wasi' | 'unknown'
|
|
5
|
+
# OS: 'emscripten' | 'wasi' | 'unknown' | 'wasm'
|
|
6
6
|
'clang': 1,
|
|
7
7
|
'target_arch%': 'wasm32',
|
|
8
8
|
'wasm_threads%': 0,
|
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
}],
|
|
140
140
|
],
|
|
141
141
|
}],
|
|
142
|
-
['OS in "wasi unknown "', {
|
|
142
|
+
['OS in "wasi wasm unknown "', {
|
|
143
143
|
'configurations': {
|
|
144
144
|
'Release': {
|
|
145
145
|
'ldflags': [ '-Wl,--strip-debug' ],
|
|
@@ -239,7 +239,7 @@
|
|
|
239
239
|
'target_conditions': [
|
|
240
240
|
['_type=="executable"', {
|
|
241
241
|
'conditions': [
|
|
242
|
-
['OS in "wasi unknown "', {
|
|
242
|
+
['OS in "wasi wasm unknown "', {
|
|
243
243
|
'product_extension': 'wasm',
|
|
244
244
|
|
|
245
245
|
'ldflags': [
|
|
@@ -326,7 +326,7 @@
|
|
|
326
326
|
}]
|
|
327
327
|
],
|
|
328
328
|
}],
|
|
329
|
-
['OS in "wasi unknown "', {
|
|
329
|
+
['OS in "wasi wasm unknown "', {
|
|
330
330
|
'product_extension': 'wasm',
|
|
331
331
|
|
|
332
332
|
'ldflags': [
|
package/dist/library_napi.js
CHANGED
|
@@ -1235,7 +1235,7 @@ function _napi_get_buffer_info(env, buffer, data, length) {
|
|
|
1235
1235
|
if (!buffer)
|
|
1236
1236
|
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
1237
1237
|
var handle = emnapiCtx.handleStore.get(buffer);
|
|
1238
|
-
if (!handle.isBuffer())
|
|
1238
|
+
if (!handle.isBuffer(emnapiCtx.feature.Buffer))
|
|
1239
1239
|
return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
|
|
1240
1240
|
return _napi_get_typedarray_info(env, buffer, 0, length, data, 0, 0);
|
|
1241
1241
|
}
|
|
@@ -6393,7 +6393,7 @@ function _napi_is_buffer(env, value, result) {
|
|
|
6393
6393
|
var h = emnapiCtx.handleStore.get(value);
|
|
6394
6394
|
{{{ from64('result') }}};
|
|
6395
6395
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6396
|
-
var r = h.isBuffer() ? 1 : 0;
|
|
6396
|
+
var r = h.isBuffer(emnapiCtx.feature.Buffer) ? 1 : 0;
|
|
6397
6397
|
{{{ makeSetValue('result', 0, 'r', 'i8') }}};
|
|
6398
6398
|
return envObject.clearLastError();
|
|
6399
6399
|
}
|
package/emnapi.gyp
CHANGED
package/include/node/emnapi.h
CHANGED
|
Binary file
|
package/lib/wasm32/libdlmalloc.a
CHANGED
|
Binary file
|
|
Binary file
|
package/lib/wasm32/libemmalloc.a
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/lib/wasm32/libemnapi.a
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|