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

wasi: add support for version when creating WASI #46469

Closed
wants to merge 12 commits into from

Conversation

mhdawson
Copy link
Member

@mhdawson mhdawson commented Feb 1, 2023

Refs: #46254

  • add version to options when creating WASI object
  • add convenience function to return importObject

Signed-off-by: Michael Dawson [email protected]

Refs: nodejs#46254

- add version to options when creating WASI object
- add convenience function to return importObject

Signed-off-by: Michael Dawson <[email protected]>
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/wasi

@mhdawson mhdawson added the wasi Issues and PRs related to the WebAssembly System Interface. label Feb 1, 2023
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Feb 1, 2023
@richardlau richardlau added the semver-minor PRs that contain new features and should be released in the next minor version. label Feb 1, 2023
@devsnek
Copy link
Member

devsnek commented Feb 1, 2023

why do we need to explicitly pass a version? each version already has its own import namespace, so they can just coexist right?

@mhdawson
Copy link
Member Author

mhdawson commented Feb 1, 2023

@devsnek you can read some of the discussion suggestion for a version in #46254

Copy link
Contributor

@guybedford guybedford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @mhdawson. Looks good to me and the importObject seems useful, although I was hoping we could discuss some more API changes before removing the flag as well.

doc/api/wasi.md Outdated
@@ -16,21 +16,18 @@ import { WASI } from 'wasi';
import { argv, env } from 'node:process';

const wasi = new WASI({
version: 'wasi_snapshot_preview1',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth considering making this just preview1. The current expectation for WASI itself is that preview1 is effectively being moved to be considered stable at this point, even if that hasn't been properly announced yet.

Copy link
Contributor

@guybedford guybedford Feb 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the very least, snapshot-preview1 may be a bit briefer.

Apparently, the shapshot part isn't expected to change, so that preview1 may well be sufficient.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjihrig I'd defer to you on how to best name the versions. I just used exactly what was documented as that makes it obvious what it maps to.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guybedford probably has better access to the folks that are determining the names of the versions. I'd be in favor of at least dropping the "wasi_" prefix though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will update to 'preview1'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I started doing that I realised that the other thing is it means that the mapping between the version requested and what goes into the import object is not as clear. In terms of the discussion about documenting { wasi_unstable: wasi.wasiImport } adding it as a version that could be requested would make less sense if we don't have a 1 to 1 mapping between the version requested and the name of the field in the import object.

I'll wait until next week to give a bit more time for you two to comment on that aspect. If we still think usigin preview1 is better I'll document the { wasi_unstable: wasi.wasiImport } some other way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked with @guybedford seems like for preview2 the binding between the version and the imports is not direct anyway so my reasoning for keeping them in line would no longer make sense. Updating to 'preview1'

doc/api/wasi.md Outdated Show resolved Hide resolved
doc/api/wasi.md Outdated Show resolved Hide resolved
doc/api/wasi.md Outdated Show resolved Hide resolved
doc/api/wasi.md Outdated Show resolved Hide resolved
doc/api/wasi.md Outdated Show resolved Hide resolved
Comment on lines -26 to -29
// Some WASI binaries require:
// const importObject = { wasi_unstable: wasi.wasiImport };
const importObject = { wasi_snapshot_preview1: wasi.wasiImport };

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We appear to be losing this information, which could be important to some users. I think we either need to keep this somewhere in the docs, or support passing in "wasi_unstable" as a version which would return the same API as wasi_snapshot_preview1, but with a different version string.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to either add it back to the doc or add to "wasi_unstable" to what can be passed in as a version depending on what people think is best.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like a pretty easy thing to support since it would be an alias for preview1, so I'd suggest supporting it and removing this note from the docs (but we would need to document that "wasi_unstable" is a valid version).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

lib/wasi.js Show resolved Hide resolved
lib/wasi.js Outdated Show resolved Hide resolved
@cjihrig
Copy link
Contributor

cjihrig commented Feb 3, 2023

although I was hoping we could discuss some more API changes before removing the flag as well.

@guybedford what else did you have in mind? Maybe open another issue. I'd hate for us to remove the flag and have something slip through the cracks.

mhdawson and others added 9 commits February 3, 2023 14:42
Co-authored-by: Colin Ihrig <[email protected]>
Co-authored-by: Colin Ihrig <[email protected]>
Co-authored-by: Colin Ihrig <[email protected]>
Co-authored-by: Colin Ihrig <[email protected]>
Signed-off-by: Michael Dawson <[email protected]>
Signed-off-by: Michael Dawson <[email protected]>
Signed-off-by: Michael Dawson <[email protected]>
Signed-off-by: Michael Dawson <[email protected]>
@mhdawson
Copy link
Member Author

mhdawson commented Feb 6, 2023

@cjihrig, @guybedford I think I've addressed all the comments so far.

The one outstanding thing is that the tests are not run for 'unstable' since they were compiled against 'wasi_snapshot_preview1'. I think we would need a new set of the compiled wasm test files. Does that need to be handled in this PR or is it ok since there seems to have been no prior testing of unstable anyway?

@guybedford
Copy link
Contributor

The unstable import interface is very old at this point so I think it is fine to treat that as a legacy path that we can support but that we don't need to explicitly test.

@mhdawson
Copy link
Member Author

mhdawson commented Feb 7, 2023

Pushed commit to remove disabled testing related to unstable version. Should be ready to go at this point.

@mhdawson mhdawson added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 7, 2023
@github-actions github-actions bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Feb 7, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2023

Failed to start CI
- Validating Jenkins credentials
✖  Jenkins credentials invalid
https://github.com/nodejs/node/actions/runs/4118977794

Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for doing this.

@mhdawson mhdawson added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 17, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 17, 2023
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@mhdawson
Copy link
Member Author

Looks like status from CI did not post correct. CI is complete and passed, going to land.

mhdawson added a commit that referenced this pull request Feb 22, 2023
Refs: #46254

- add version to options when creating WASI object
- add convenience function to return importObject

Signed-off-by: Michael Dawson <[email protected]>

PR-URL: #46469
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
@mhdawson
Copy link
Member Author

Landed in 2d35f66

@mhdawson mhdawson closed this Feb 22, 2023
toyobayashi added a commit to toyobayashi/wasm-util that referenced this pull request Feb 26, 2023
@juanarbol juanarbol added the backport-requested-v18.x PRs awaiting manual backport to the v18.x-staging branch. label Mar 1, 2023
@juanarbol
Copy link
Member

Would you mind backporting this to v18.x?

targos pushed a commit that referenced this pull request Mar 13, 2023
Refs: #46254

- add version to options when creating WASI object
- add convenience function to return importObject

Signed-off-by: Michael Dawson <[email protected]>

PR-URL: #46469
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
targos added a commit that referenced this pull request Mar 14, 2023
Notable changes:

buffer:
  * (SEMVER-MINOR) add Buffer.copyBytesFrom(...) (James M Snell) #46500
doc:
  * add marco-ippolito to collaborators (Marco Ippolito) #46816
events:
  * (SEMVER-MINOR) add listener argument to listenerCount (Paolo Insogna) #46523
lib:
  * (SEMVER-MINOR) add AsyncLocalStorage.bind() and .snapshot() (flakey5) #46387
src:
  * (SEMVER-MINOR) add `fs.openAsBlob` to support File-backed Blobs (James M Snell) #45258
tls:
  * (SEMVER-MINOR) support automatic DHE (Tobias Nießen) #46978
url:
  * (SEMVER-MINOR) implement URLSearchParams size getter (James M Snell) #46308
wasi:
  * (SEMVER-MINOR) add support for version when creating WASI (Michael Dawson) #46469
worker:
  * (SEMVER-MINOR) add support for worker name in inspector and trace_events (Debadree Chatterjee) #46832

PR-URL: #47086
targos added a commit that referenced this pull request Mar 14, 2023
Notable changes:

buffer:
  * (SEMVER-MINOR) add Buffer.copyBytesFrom(...) (James M Snell) #46500
doc:
  * add marco-ippolito to collaborators (Marco Ippolito) #46816
events:
  * (SEMVER-MINOR) add listener argument to listenerCount (Paolo Insogna) #46523
lib:
  * (SEMVER-MINOR) add AsyncLocalStorage.bind() and .snapshot() (flakey5) #46387
src:
  * (SEMVER-MINOR) add `fs.openAsBlob` to support File-backed Blobs (James M Snell) #45258
tls:
  * (SEMVER-MINOR) support automatic DHE (Tobias Nießen) #46978
url:
  * (SEMVER-MINOR) implement URLSearchParams size getter (James M Snell) #46308
wasi:
  * (SEMVER-MINOR) add support for version when creating WASI (Michael Dawson) #46469
worker:
  * (SEMVER-MINOR) add support for worker name in inspector and trace_events (Debadree Chatterjee) #46832

PR-URL: #47087
targos added a commit that referenced this pull request Mar 14, 2023
Notable changes:

buffer:
  * (SEMVER-MINOR) add Buffer.copyBytesFrom(...) (James M Snell) #46500
doc:
  * add marco-ippolito to collaborators (Marco Ippolito) #46816
events:
  * (SEMVER-MINOR) add listener argument to listenerCount (Paolo Insogna) #46523
lib:
  * (SEMVER-MINOR) add AsyncLocalStorage.bind() and .snapshot() (flakey5) #46387
src:
  * (SEMVER-MINOR) add `fs.openAsBlob` to support File-backed Blobs (James M Snell) #45258
tls:
  * (SEMVER-MINOR) support automatic DHE (Tobias Nießen) #46978
url:
  * (SEMVER-MINOR) implement URLSearchParams size getter (James M Snell) #46308
wasi:
  * (SEMVER-MINOR) add support for version when creating WASI (Michael Dawson) #46469
worker:
  * (SEMVER-MINOR) add support for worker name in inspector and trace_events (Debadree Chatterjee) #46832

PR-URL: #47087
targos added a commit that referenced this pull request Mar 14, 2023
Notable changes:

buffer:
  * (SEMVER-MINOR) add Buffer.copyBytesFrom(...) (James M Snell) #46500
doc:
  * add marco-ippolito to collaborators (Marco Ippolito) #46816
events:
  * (SEMVER-MINOR) add listener argument to listenerCount (Paolo Insogna) #46523
lib:
  * (SEMVER-MINOR) add AsyncLocalStorage.bind() and .snapshot() (flakey5) #46387
src:
  * (SEMVER-MINOR) add `fs.openAsBlob` to support File-backed Blobs (James M Snell) #45258
tls:
  * (SEMVER-MINOR) support automatic DHE (Tobias Nießen) #46978
url:
  * (SEMVER-MINOR) implement URLSearchParams size getter (James M Snell) #46308
wasi:
  * (SEMVER-MINOR) add support for version when creating WASI (Michael Dawson) #46469
worker:
  * (SEMVER-MINOR) add support for worker name in inspector and trace_events (Debadree Chatterjee) #46832

PR-URL: #47087
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-requested-v18.x PRs awaiting manual backport to the v18.x-staging branch. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. semver-minor PRs that contain new features and should be released in the next minor version. wasi Issues and PRs related to the WebAssembly System Interface.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants