Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gyp add OS wasm alias #113

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions packages/emnapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,10 @@ Output code can run in recent version modern browsers and Node.js latest LTS. IE
### Using node-gyp (Experimental)

Currently node-gyp works on Linux only and don't support static library linking in cross-compiling.
There are opened PRs to try to make node-gyp work fine.
There are related PRs to try to make node-gyp work fine.

- https://github.com/nodejs/gyp-next/pull/222
- https://github.com/nodejs/gyp-next/pull/240
- https://github.com/nodejs/node-gyp/pull/2974

If you experienced issues on Windows or macOS, please check the PRs for upstream changes detail and see
Expand All @@ -643,7 +644,7 @@ Arch: `node-gyp configure --arch=<wasm32 | wasm64>`
```ts
// node-gyp configure -- -Dvariable_name=value

declare var OS: 'emscripten' | 'wasi' | 'unknown' | ''
declare var OS: 'emscripten' | 'wasi' | 'unknown' | 'wasm' | ''

/**
* Enable async work and threadsafe-functions
Expand Down Expand Up @@ -699,7 +700,7 @@ declare var emnapi_manual_linking: 0 | 1
["OS == 'wasi'", {
# ...
}],
["OS == 'unknown' or OS == ''", {
["OS in ' wasm unknown'", {
# ...
}]
]
Expand Down Expand Up @@ -750,35 +751,35 @@ call set CXX_target=%%WASI_SDK_PATH:\=/%%/bin/clang++.exe
emmake node-gyp rebuild \
--arch=wasm32 \
--nodedir=./node_modules/emnapi \
-- -f make-linux -DOS=emscripten # -Dwasm_threads=1
-- -f make-emscripten # -Dwasm_threads=1

# wasi
node-gyp rebuild \
--arch=wasm32 \
--nodedir=./node_modules/emnapi \
-- -f make-linux -DOS=wasi # -Dwasm_threads=1
-- -f make-wasi # -Dwasm_threads=1

# bare wasm32
node-gyp rebuild \
--arch=wasm32 \
--nodedir=./node_modules/emnapi \
-- -f make-linux -DOS=unknown # -Dwasm_threads=1
-- -f make-wasm # -Dwasm_threads=1
```

```bat
@REM Use make generator on Windows
@REM Run the bat file in POSIX-like environment (e.g. Cygwin)

@REM emscripten
call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-linux -DOS=emscripten
call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-emscripten
call emmake.bat make -C %~dp0build

@REM wasi
call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-linux -DOS=wasi
call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-wasi
make -C %~dp0build

@REM bare wasm32
call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-linux -DOS=unknown
call npx.cmd node-gyp configure --arch=wasm32 --nodedir=./node_modules/emnapi -- -f make-wasm
make -C %~dp0build
```

Expand Down
8 changes: 4 additions & 4 deletions packages/emnapi/common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# in https://github.com/lovell/sharp/pull/3522
{
'variables': {
# OS: 'emscripten' | 'wasi' | 'unknown'
# OS: 'emscripten' | 'wasi' | 'unknown' | 'wasm'
'clang': 1,
'target_arch%': 'wasm32',
'wasm_threads%': 0,
Expand Down Expand Up @@ -139,7 +139,7 @@
}],
],
}],
['OS in "wasi unknown "', {
['OS in "wasi wasm unknown "', {
'configurations': {
'Release': {
'ldflags': [ '-Wl,--strip-debug' ],
Expand Down Expand Up @@ -239,7 +239,7 @@
'target_conditions': [
['_type=="executable"', {
'conditions': [
['OS in "wasi unknown "', {
['OS in "wasi wasm unknown "', {
'product_extension': 'wasm',

'ldflags': [
Expand Down Expand Up @@ -326,7 +326,7 @@
}]
],
}],
['OS in "wasi unknown "', {
['OS in "wasi wasm unknown "', {
'product_extension': 'wasm',

'ldflags': [
Expand Down
2 changes: 1 addition & 1 deletion packages/emnapi/emnapi.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
]
},
'conditions': [
['wasm_threads != 0 and OS in " unknown wasi"', {
['wasm_threads != 0 and OS in " unknown wasm wasi"', {
'sources': [
'src/thread/async_worker_create.c',
'src/thread/async_worker_init.S',
Expand Down