Skip to content

Commit

Permalink
feat: gyp add OS wasm alias (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed Apr 25, 2024
1 parent 82fad55 commit 1d4b624
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
19 changes: 10 additions & 9 deletions packages/emnapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,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 @@ -645,7 +646,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 @@ -701,7 +702,7 @@ declare var emnapi_manual_linking: 0 | 1
["OS == 'wasi'", {
# ...
}],
["OS == 'unknown' or OS == ''", {
["OS in ' wasm unknown'", {
# ...
}]
]
Expand Down Expand Up @@ -752,35 +753,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

0 comments on commit 1d4b624

Please sign in to comment.