emnapi 0.33.0 → 0.33.1
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 +1 -1
- package/README.md +10 -14
- package/package.json +1 -1
package/CMakeLists.txt
CHANGED
|
@@ -44,7 +44,7 @@ set(EMNAPI_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
|
|
44
44
|
set(EMNAPI_JS_LIB "${CMAKE_CURRENT_SOURCE_DIR}/dist/library_napi.js")
|
|
45
45
|
|
|
46
46
|
if(IS_EMSCRIPTEN)
|
|
47
|
-
set(EMNAPI_MT_CFLAGS "-
|
|
47
|
+
set(EMNAPI_MT_CFLAGS "-pthread" "-sWASM_WORKERS=1")
|
|
48
48
|
else()
|
|
49
49
|
set(EMNAPI_MT_CFLAGS "-pthread")
|
|
50
50
|
endif()
|
package/README.md
CHANGED
|
@@ -551,12 +551,14 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
|
|
|
551
551
|
"-sEXPORTED_FUNCTIONS=['_malloc','_free']"
|
|
552
552
|
)
|
|
553
553
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "WASI")
|
|
554
|
+
set_target_properties(hello PROPERTIES SUFFIX ".wasm")
|
|
554
555
|
target_link_options(hello PRIVATE
|
|
555
556
|
"-mexec-model=reactor"
|
|
556
557
|
"-Wl,--export=napi_register_wasm_v1"
|
|
557
558
|
"-Wl,--initial-memory=16777216,--export-dynamic,--export=malloc,--export=free,--import-undefined,--export-table"
|
|
558
559
|
)
|
|
559
560
|
elseif((CMAKE_C_COMPILER_TARGET STREQUAL "wasm32") OR (CMAKE_C_COMPILER_TARGET STREQUAL "wasm32-unknown-unknown"))
|
|
561
|
+
set_target_properties(hello PROPERTIES SUFFIX ".wasm")
|
|
560
562
|
target_link_options(hello PRIVATE
|
|
561
563
|
"-nostdlib"
|
|
562
564
|
"-Wl,--export=napi_register_wasm_v1"
|
|
@@ -744,11 +746,11 @@ add_executable(hello hello.c)
|
|
|
744
746
|
target_link_libraries(hello emnapi-mt)
|
|
745
747
|
|
|
746
748
|
if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
|
|
747
|
-
target_compile_options(hello PRIVATE "-
|
|
749
|
+
target_compile_options(hello PRIVATE "-pthread")
|
|
748
750
|
target_link_options(hello PRIVATE
|
|
749
751
|
"-sALLOW_MEMORY_GROWTH=1"
|
|
750
752
|
"-sEXPORTED_FUNCTIONS=['_malloc','_free']"
|
|
751
|
-
"-
|
|
753
|
+
"-pthread"
|
|
752
754
|
"-sPTHREAD_POOL_SIZE=4"
|
|
753
755
|
# try to specify stack size if you experience pthread errors
|
|
754
756
|
"-sSTACK_SIZE=2MB"
|
|
@@ -756,6 +758,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
|
|
|
756
758
|
)
|
|
757
759
|
elseif(CMAKE_C_COMPILER_TARGET STREQUAL "wasm32-wasi-threads")
|
|
758
760
|
# Experimental
|
|
761
|
+
set_target_properties(hello PROPERTIES SUFFIX ".wasm")
|
|
759
762
|
target_compile_options(hello PRIVATE "-fno-exceptions" "-pthread")
|
|
760
763
|
target_link_options(hello PRIVATE
|
|
761
764
|
"-pthread"
|
|
@@ -795,6 +798,7 @@ instantiateNapiModule(input, {
|
|
|
795
798
|
onCreateWorker () {
|
|
796
799
|
return new Worker('./worker.js')
|
|
797
800
|
// Node.js
|
|
801
|
+
// const { Worker } = require('worker_threads')
|
|
798
802
|
// return new Worker(join(__dirname, './worker.js'), {
|
|
799
803
|
// env: process.env,
|
|
800
804
|
// execArgv: ['--experimental-wasi-unstable-preview1']
|
|
@@ -863,15 +867,7 @@ instantiateNapiModule(input, {
|
|
|
863
867
|
|
|
864
868
|
const handler = new MessageHandler({
|
|
865
869
|
onLoad ({ wasmModule, wasmMemory }) {
|
|
866
|
-
const wasi = new WASI({
|
|
867
|
-
fs,
|
|
868
|
-
print: ENVIRONMENT_IS_NODE
|
|
869
|
-
? (...args) => {
|
|
870
|
-
const str = require('util').format(...args)
|
|
871
|
-
fs.writeSync(1, str + '\n')
|
|
872
|
-
}
|
|
873
|
-
: function () { console.log.apply(console, arguments) }
|
|
874
|
-
})
|
|
870
|
+
const wasi = new WASI({ fs })
|
|
875
871
|
|
|
876
872
|
return instantiateNapiModuleSync(wasmModule, {
|
|
877
873
|
childThread: true,
|
|
@@ -918,7 +914,7 @@ You can set both `PTHREAD_POOL_SIZE` and `EMNAPI_WORKER_POOL_SIZE` to `number of
|
|
|
918
914
|
If you use another library function which may create `N` child threads in async work,
|
|
919
915
|
then you need to set `PTHREAD_POOL_SIZE` to `EMNAPI_WORKER_POOL_SIZE * (N + 1)`.
|
|
920
916
|
|
|
921
|
-
This option only has effect if you use `-
|
|
917
|
+
This option only has effect if you use `-pthread`.
|
|
922
918
|
Emnapi will create `EMNAPI_WORKER_POOL_SIZE` threads when initializing,
|
|
923
919
|
it will throw error if `PTHREAD_POOL_SIZE < EMNAPI_WORKER_POOL_SIZE && PTHREAD_POOL_SIZE_STRICT == 2`.
|
|
924
920
|
|
|
@@ -926,7 +922,7 @@ See [Issue #8](https://github.com/toyobayashi/emnapi/issues/8) for more detail.
|
|
|
926
922
|
|
|
927
923
|
### `-DEMNAPI_NEXTTICK_TYPE=0`
|
|
928
924
|
|
|
929
|
-
This option only has effect if you use `-
|
|
925
|
+
This option only has effect if you use `-pthread`, Default is `0`.
|
|
930
926
|
Tell emnapi how to delay async work in `uv_async_send` / `uv__async_close`.
|
|
931
927
|
|
|
932
928
|
- `0`: Use `setImmediate()` (Node.js native `setImmediate` or browser `MessageChannel` and `port.postMessage`)
|
|
@@ -934,7 +930,7 @@ Tell emnapi how to delay async work in `uv_async_send` / `uv__async_close`.
|
|
|
934
930
|
|
|
935
931
|
### `-DEMNAPI_USE_PROXYING=1`
|
|
936
932
|
|
|
937
|
-
This option only has effect if you use emscripten `-
|
|
933
|
+
This option only has effect if you use emscripten `-pthread`. Default is `1` if emscripten version `>= 3.1.9`, else `0`.
|
|
938
934
|
|
|
939
935
|
- `0`
|
|
940
936
|
|