Skip to content

Commit 022dceb

Browse files
devsnekcodebytere
authored andcommitted
napi: add __wasm32__ guards
PR-URL: #33597 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 2a29ced commit 022dceb

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/js_native_api.h

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#ifndef NAPI_EXTERN
2929
#ifdef _WIN32
3030
#define NAPI_EXTERN __declspec(dllexport)
31+
#elif defined(__wasm32__)
32+
#define NAPI_EXTERN __attribute__((visibility("default"))) \
33+
__attribute__((__import_module__("napi")))
3134
#else
3235
#define NAPI_EXTERN __attribute__((visibility("default")))
3336
#endif

src/node_api.h

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifdef _WIN32
66
// Building native module against node
77
#define NAPI_EXTERN __declspec(dllimport)
8+
#elif defined(__wasm32__)
9+
#define NAPI_EXTERN __attribute__((__import_module__("napi")))
810
#endif
911
#endif
1012
#include "js_native_api.h"
@@ -71,8 +73,18 @@ typedef struct {
7173
} \
7274
EXTERN_C_END
7375

76+
#ifdef __wasm32__
77+
#define NAPI_MODULE(modname, regfunc) \
78+
EXTERN_C_START \
79+
NAPI_MODULE_EXPORT napi_value _napi_register(napi_env env, \
80+
napi_value exports) { \
81+
return regfunc(env, exports); \
82+
} \
83+
EXTERN_C_END
84+
#else
7485
#define NAPI_MODULE(modname, regfunc) \
7586
NAPI_MODULE_X(modname, regfunc, NULL, 0) // NOLINT (readability/null_usage)
87+
#endif
7688

7789
#define NAPI_MODULE_INITIALIZER_BASE napi_register_module_v
7890

@@ -196,6 +208,7 @@ NAPI_EXTERN napi_status napi_close_callback_scope(napi_env env,
196208

197209
#if NAPI_VERSION >= 4
198210

211+
#ifndef __wasm32__
199212
// Calling into JS from other threads
200213
NAPI_EXTERN napi_status
201214
napi_create_threadsafe_function(napi_env env,
@@ -231,6 +244,7 @@ napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func);
231244

232245
NAPI_EXTERN napi_status
233246
napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func);
247+
#endif // __wasm32__
234248

235249
#endif // NAPI_VERSION >= 4
236250

0 commit comments

Comments
 (0)