emnapi 0.43.1 → 0.45.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 CHANGED
@@ -29,7 +29,6 @@ set(UV_SRC
29
29
  set(ENAPI_BASIC_SRC
30
30
  "${CMAKE_CURRENT_SOURCE_DIR}/src/js_native_api.c"
31
31
  "${CMAKE_CURRENT_SOURCE_DIR}/src/node_api.c"
32
- "${CMAKE_CURRENT_SOURCE_DIR}/src/emnapi.c"
33
32
  "${CMAKE_CURRENT_SOURCE_DIR}/src/async_cleanup_hook.c"
34
33
  "${CMAKE_CURRENT_SOURCE_DIR}/src/async_context.c"
35
34
  )
@@ -40,11 +39,16 @@ set(EMNAPI_THREADS_SRC
40
39
  set(EMNAPI_SRC ${ENAPI_BASIC_SRC} ${EMNAPI_THREADS_SRC})
41
40
 
42
41
  set(EMNAPI_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/include")
42
+ set(EMNAPI_DEFINES "BUILDING_NODE_EXTENSION")
43
43
 
44
44
  set(EMNAPI_JS_LIB "${CMAKE_CURRENT_SOURCE_DIR}/dist/library_napi.js")
45
45
 
46
46
  if(IS_EMSCRIPTEN)
47
47
  set(EMNAPI_MT_CFLAGS "-pthread" "-sWASM_WORKERS=1")
48
+
49
+ # https://github.com/emscripten-core/emscripten/issues/20035
50
+ # https://github.com/emscripten-core/emscripten/pull/20130
51
+ list(APPEND EMNAPI_DEFINES "NAPI_EXTERN=__attribute__((__import_module__(\"env\")))")
48
52
  else()
49
53
  set(EMNAPI_MT_CFLAGS "-pthread")
50
54
  endif()
@@ -115,13 +119,17 @@ endif()
115
119
 
116
120
  add_library(${EMNAPI_TARGET_NAME} STATIC ${EMNAPI_SRC} ${UV_SRC})
117
121
  target_include_directories(${EMNAPI_TARGET_NAME} PUBLIC ${EMNAPI_INCLUDE})
122
+ target_compile_definitions(${EMNAPI_TARGET_NAME} PUBLIC ${EMNAPI_DEFINES})
118
123
  if(IS_EMSCRIPTEN)
124
+ set_target_properties(${EMNAPI_TARGET_NAME} PROPERTIES INTERFACE_LINK_DEPENDS ${EMNAPI_JS_LIB})
119
125
  target_link_options(${EMNAPI_TARGET_NAME} INTERFACE "--js-library=${EMNAPI_JS_LIB}")
120
126
  endif()
121
127
 
122
128
  add_library(${EMNAPI_BASIC_TARGET_NAME} STATIC ${ENAPI_BASIC_SRC})
123
129
  target_include_directories(${EMNAPI_BASIC_TARGET_NAME} PUBLIC ${EMNAPI_INCLUDE})
130
+ target_compile_definitions(${EMNAPI_BASIC_TARGET_NAME} PUBLIC ${EMNAPI_DEFINES})
124
131
  if(IS_EMSCRIPTEN)
132
+ set_target_properties(${EMNAPI_BASIC_TARGET_NAME} PROPERTIES INTERFACE_LINK_DEPENDS ${EMNAPI_JS_LIB})
125
133
  target_link_options(${EMNAPI_BASIC_TARGET_NAME} INTERFACE "--js-library=${EMNAPI_JS_LIB}")
126
134
  endif()
127
135
 
@@ -139,6 +147,12 @@ if(EMNAPI_BUILD_BASIC_MT)
139
147
  )
140
148
  target_compile_options(${EMNAPI_BASIC_MT_TARGET_NAME} PUBLIC "-matomics" "-mbulk-memory")
141
149
  target_include_directories(${EMNAPI_BASIC_MT_TARGET_NAME} PUBLIC ${EMNAPI_INCLUDE})
150
+ target_compile_definitions(${EMNAPI_BASIC_MT_TARGET_NAME} PUBLIC ${EMNAPI_DEFINES})
151
+
152
+ if(IS_EMSCRIPTEN)
153
+ set_target_properties(${EMNAPI_BASIC_MT_TARGET_NAME} PROPERTIES INTERFACE_LINK_DEPENDS ${EMNAPI_JS_LIB})
154
+ target_link_options(${EMNAPI_BASIC_MT_TARGET_NAME} INTERFACE "--js-library=${EMNAPI_JS_LIB}")
155
+ endif()
142
156
  endif()
143
157
 
144
158
  if(IS_EMSCRIPTEN OR (CMAKE_C_COMPILER_TARGET STREQUAL "wasm32-wasi-threads"))
@@ -151,7 +165,9 @@ if(EMNAPI_BUILD_MT)
151
165
  add_library(${EMNAPI_MT_TARGET_NAME} STATIC ${EMNAPI_SRC} ${UV_SRC})
152
166
  target_compile_options(${EMNAPI_MT_TARGET_NAME} PRIVATE ${EMNAPI_MT_CFLAGS})
153
167
  target_include_directories(${EMNAPI_MT_TARGET_NAME} PUBLIC ${EMNAPI_INCLUDE})
168
+ target_compile_definitions(${EMNAPI_MT_TARGET_NAME} PUBLIC ${EMNAPI_DEFINES})
154
169
  if(IS_EMSCRIPTEN)
170
+ set_target_properties(${EMNAPI_MT_TARGET_NAME} PROPERTIES INTERFACE_LINK_DEPENDS ${EMNAPI_JS_LIB})
155
171
  target_link_options(${EMNAPI_MT_TARGET_NAME} INTERFACE "--js-library=${EMNAPI_JS_LIB}")
156
172
  endif()
157
173
  if(EMNAPI_WORKER_POOL_SIZE)
package/README.md CHANGED
@@ -109,7 +109,7 @@ Create `hello.c`.
109
109
  ```c
110
110
  #include <node_api.h>
111
111
 
112
- #define NODE_API_CALL(env, the_call) \
112
+ #define NODE_API_CALL(env, the_call) \
113
113
  do { \
114
114
  if ((the_call) != napi_ok) { \
115
115
  const napi_extended_error_info *error_info; \
@@ -165,6 +165,8 @@ module.exports = (function (exports) {
165
165
 
166
166
  ```bash
167
167
  emcc -O3 \
168
+ -DBUILDING_NODE_EXTENSION \
169
+ "-DNAPI_EXTERN=__attribute__((__import_module__(\"env\")))" \
168
170
  -I./node_modules/emnapi/include \
169
171
  -L./node_modules/emnapi/lib/wasm32-emscripten \
170
172
  --js-library=./node_modules/emnapi/dist/library_napi.js \
@@ -181,6 +183,7 @@ emcc -O3 \
181
183
 
182
184
  ```bash
183
185
  clang -O3 \
186
+ -DBUILDING_NODE_EXTENSION \
184
187
  -I./node_modules/emnapi/include \
185
188
  -L./node_modules/emnapi/lib/wasm32-wasi \
186
189
  --target=wasm32-wasi \
@@ -208,6 +211,7 @@ Choose `libdlmalloc.a` or `libemmalloc.a` for `malloc` and `free`.
208
211
 
209
212
  ```bash
210
213
  clang -O3 \
214
+ -DBUILDING_NODE_EXTENSION \
211
215
  -I./node_modules/emnapi/include \
212
216
  -L./node_modules/emnapi/lib/wasm32 \
213
217
  --target=wasm32 \
@@ -448,6 +452,8 @@ Compile `hello.cpp` using `em++`. C++ exception is disabled by Emscripten defaul
448
452
 
449
453
  ```bash
450
454
  em++ -O3 \
455
+ -DBUILDING_NODE_EXTENSION \
456
+ "-DNAPI_EXTERN=__attribute__((__import_module__(\"env\")))" \
451
457
  -DNAPI_DISABLE_CPP_EXCEPTIONS \
452
458
  -DNODE_ADDON_API_ENABLE_MAYBE \
453
459
  -I./node_modules/emnapi/include \
@@ -467,6 +473,7 @@ em++ -O3 \
467
473
 
468
474
  ```bash
469
475
  clang++ -O3 \
476
+ -DBUILDING_NODE_EXTENSION \
470
477
  -DNAPI_DISABLE_CPP_EXCEPTIONS \
471
478
  -DNODE_ADDON_API_ENABLE_MAYBE \
472
479
  -I./node_modules/emnapi/include \
@@ -500,6 +507,7 @@ You can still use `wasm32-unknown-unknown` target if you use Node-API C API only
500
507
 
501
508
  ```bash
502
509
  clang++ -O3 \
510
+ -DBUILDING_NODE_EXTENSION \
503
511
  -I./node_modules/emnapi/include \
504
512
  -L./node_modules/emnapi/lib/wasm32 \
505
513
  --target=wasm32 \