Skip to content

Commit

Permalink
feat(core): support compile to wasi target (#22870)
Browse files Browse the repository at this point in the history
This pull request is trying to add wasm32-wasi target support for the
nx/native

To test the build, you can run the following commands:

- `rustup target add wasm32-wasip1-threads`
- `pnpm exec napi build --release --platform --package-json-path
packages/nx/package.json --manifest-path packages/nx/Cargo.toml --js
./native-bindings.js -o packages/nx/src/native --target
wasm32-wasip1-threads`

And the wasm file will be built at
packages/nx/src/native/nx.wasm32-wasi.wasm

Blocked by:

- Support @napi-rs/cli 3.0  Cammisuli/monodon#48
- napi-rs/napi-rs#2009

The pseudo_terminal mod is excluded on the wasm32 targets, which is as
expected.

The watch mod is excluded because of the upstream `watchexec` deps
introduced by ignore-files don't support the wasi target at this moment
(but we can improve it).

## Related Issues
Fixes #21860
Fixes #23821

---------

Co-authored-by: FrozenPandaz <[email protected]>
  • Loading branch information
Brooooooklyn and FrozenPandaz authored Jul 5, 2024
1 parent 23ce6af commit 981eb30
Show file tree
Hide file tree
Showing 51 changed files with 3,556 additions and 2,094 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 175,7 @@ jobs:
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf -y
build: |
pnpm nx run-many --target=build-native -- --target=armv7-unknown-linux-gnueabihf
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=/usr/bin/arm-linux-gnueabihf-gcc pnpm nx run-many --target=build-native -- --target=armv7-unknown-linux-gnueabihf
# Android (not needed)
# - host: ubuntu-latest
# target: aarch64-linux-android
Expand Down Expand Up @@ -203,7 203,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
repository: ${{ needs.resolve-required-data.outputs.repo }}
repository: ${{ needs.resolve-required-data.outputs.repo }}
ref: ${{ needs.resolve-required-data.outputs.ref }}

- uses: pnpm/action-setup@v4
Expand Down Expand Up @@ -281,7 281,9 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: bindings-${{ matrix.settings.target }}
path: packages/**/*.node
path: |
packages/**/*.node
packages/**/*.wasm
if-no-files-found: error

build-freebsd:
Expand All @@ -294,7 296,7 @@ jobs:
- uses: actions/checkout@v4
if: ${{ github.event_name != 'schedule' && !github.event.inputs.pr }}
with:
repository: ${{ needs.resolve-required-data.outputs.repo }}
repository: ${{ needs.resolve-required-data.outputs.repo }}
ref: ${{ needs.resolve-required-data.outputs.ref }}

- name: Build
Expand Down Expand Up @@ -396,7 398,8 @@ jobs:
- name: List artifacts
run: ls -R artifacts
shell: bash

- name: Build Wasm
run: pnpm build:wasm
- name: Publish
env:
VERSION: ${{ needs.resolve-required-data.outputs.version }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 56,5 @@ out
.npm/
.profile
.rustup/
target
*.wasm
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 17,11 @@ packages/nx/src/plugins/js/lock-file/__fixtures__/**/*.*
packages/**/schematics/**/files/**/*.html
packages/**/generators/**/files/**/*.html
packages/nx/src/native/**/*.rs
packages/nx/src/native/browser.js
packages/nx/src/native/nx.wasi-browser.js
packages/nx/src/native/nx.wasi.cjs
packages/nx/src/native/wasi-worker-browser.mjs
packages/nx/src/native/wasi-worker.mjs
packages/nx/src/native/native-bindings.js
packages/nx/src/native/index.d.ts
nx-dev/nx-dev/.next/
Expand Down
Loading

0 comments on commit 981eb30

Please sign in to comment.