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

Added Wasmer Js API #2460

Merged
merged 112 commits into from
Jul 24, 2021
Merged

Added Wasmer Js API #2460

merged 112 commits into from
Jul 24, 2021

Conversation

syrusakbary
Copy link
Member

@syrusakbary syrusakbary commented Jul 12, 2021

Description

This PR adds support for compiling Wasmer into JS/Wasm via wasm-bindgen, so 3rd party dependencies can use Wasmer to target the web also.

Things working:

  • Type introspection: we have to decide how to do it, either run our own parser on the data or rely on the future APIs for introspect Wasm types (this APIs are yet available in the browser, but a proposal is on the way: wasm-js-types proposal).
  • Wasm-pack wasmer-js tests
  • Assert 0 warnings in lint
  • Allow for custom JS errors (via RuntimeError)
  • Externals
    • Functions with and without Environments
      • Native functions
      • Dynamic functions
    • Memory
    • Globals
    • Tables

Review

  • Add a short description of the change to the CHANGELOG.md file

@bors
Copy link
Contributor

bors bot commented Jul 23, 2021

Comment on lines +63 to +66
#[deprecated(
since = "2.1.0",
note = "ModuleInfo, ExportsIterator, ImportsIterator should be imported from wasmer_types."
)]
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why we should make it deprecated. It's fine to re-export types from another crate here. What do you think?

Comment on lines 287 to 294
pub fn view<T: ValueType>(&self) -> MemoryView<T> {
unimplemented!("The view function is not yet implemented in Wasmer Javascript");
}

/// example view
pub fn uint8view(&self) -> js_sys::Uint8Array {
js_sys::Uint8Array::new(&self.vm_memory.memory.buffer())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

uint8view is an example here, not a real method it seems like.

However, we can improve the view method to produce a Uint8Array or simply to provide an ArrayBuffer. We could even mark view as unimplemented, and provide a buffer method. Or just re-use data_ptr to provide an ArrayBuffer.

I think we should try to make view working with ArrayBuffer, that would be the best.

Hywan added 5 commits July 23, 2021 12:10
This patch takes the entire `wasmer-js` crate and merges it into the
`wasmer` crate.

Inside the `lib/api/src/` directory, there are 2 new directories:

1. a new `sys` directory, which contains the usual `wasmer` crate
   implementation,
2. a new directory `js`, which contains the implementation of
   `wasmer-js`.

The `Cargo.toml` file is still compatible. The `default` feature
fallbacks to `sys-default`, which enables the `sys` feature. All
features related to compilers or engines or anything else prior this
patch, activates the `sys` feature.

Parallel to that, there is a `js-default` and `js` features.

The `Cargo.toml` file is extensively documented to explain what are
dependencies, dev-dependencies, features and other sections related to
`sys` or to `js`.

There is a bug with `wasm_bindgen_test` where it doesn't compile or
look for tests in `tests/*/<test>.rs`. The hack is to name files
`tests/js_<test>.rs`. Ugly, but it works.
@Hywan
Copy link
Contributor

Hywan commented Jul 23, 2021

It is possible to merge wasmer-js into wasmer-api, which makes a lot of sense, as discussed in private in Slack. Here is the PR, #2489.

@syrusakbary
Copy link
Member Author

bors r+

@bors
Copy link
Contributor

bors bot commented Jul 24, 2021

@bors bors bot merged commit baebb43 into master Jul 24, 2021
@bors bors bot deleted the js-api branch July 24, 2021 00:11
@syrusakbary syrusakbary added this to the v2.1 milestone Nov 5, 2021
@syrusakbary syrusakbary added the 🚨 breaking change This Issue or PR involves a breaking change label Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 breaking change This Issue or PR involves a breaking change 🎉 enhancement New feature! project-hotg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants