Commit Graph

1463 Commits

Author SHA1 Message Date
452ce2916e Add support as a vanilla polyfill of WebIDL bindings
This commit adds support to `wasm-bindgen` to be a drop-in polyfill for
the WebIDL bindings proposal. Lots of internal refactoring has happened
previously to `wasm-bindgen` to make this possible, so this actually
ends up being a very small PR!

Most of `wasm-bindgen` is geared towards Rust-specific types and
Rust-specific support, but with the advent of WebIDL bindings this is a
standard way for a WebAssembly module to communicate its intended
interface in terms of higher level types. This PR allows `wasm-bindgen`
to be a polyfill for any WebAssembly module that has a valid WebIDL
bindings section, regardless of its producer. A standard WebIDL bindings
section is recognized in any input wasm module and that is slurped up
into wasm-bindgen's own internal data structures to get processed in the
same way that all Rust imports/exports are already processed.

The workflow for `wasm-bindgen` looks the same way that it does in Rust
today. You'd execute `wasm-bindgen path/to/foo.wasm --out-dir .` which
would output a new wasm file and a JS shim with the desired interface,
and the new wasm file would be suitable for loading in MVP
implementations of WebAssembly.

Note that this isn't super thoroughly tested, so there's likely still
some lingering assumptions that `wasm-bindgen` makes (such as
`__wbindgen_malloc` and others) which will need to be patched in the
future, but the intention of this commit is to start us down a road of
becoming a drop-in polyfill for WebIDL bindings, regardless of the
source. Also note that there's not actually any producer (AFAIK) of a
WebIDL bindings custom section, so it'd be that much harder to write
tests to do so!
2019-07-31 12:12:38 -07:00
8cb792474c Fully update threading support for LLVM 9
Support has landed in rust-lang/rust for full support for LLVM 9's
interpretation of WebAssembly threads. This commit updates our thread
transformation pass to take all this into account, namely:

* The threadign pass now runs by default and is keyed on whether memory
  is shared, not off an env var.
* TLS is initialized in addition to memory on each thread.
* Stack pointer finding is tweaked to account for the TLS base also
  being a mutable global.
* The build of the parallel raytrace example was updated to use today's
  nightly.
2019-07-30 09:17:23 -07:00
849c3453d9 Merge pull request #1687 from alexcrichton/in-memory
Add support to emit output to memory
2019-07-30 10:47:02 -05:00
10e400bee4 Add support to emit output to memory
Don't necessarily require a filesystem to execute `wasm-bindgen`,
allowing the `wasm-bindgen-cli-support` crate to be compiled to
WebAssembly, for example, and possibly run `wasm-bindgen` in your
browser! For now this is largely just an internal refactoring and won't
result in many use cases, but it felt like a good refactoring to have
regardless.
2019-07-30 08:08:17 -07:00
7158144932 Update to walrus 0.10.0
Ensure that we enable the new `parallel` feature in the CLI so our tools all use
parallelized parsing, but none of our specific crates need it for usage.
2019-07-30 07:56:18 -07:00
8940ba0ab2 Merge pull request #1682 from alexcrichton/update-walrs
Update to walrus 0.9.0
2019-07-30 09:12:51 -05:00
423bebbd14 Improve leniency of --no-modules output
Instead of assuming names like `URL` and `Request` are defined, instead
check to see if they exist first and otherwise skip the checks that
reference them.
2019-07-29 14:49:15 -07:00
0daa290129 Update to walrus 0.9.0
This commit updates the `walrus` dependency with recent upstream API
changes in `walrus` itself, namely updates to passive segements and how
memory data segments are handled
2019-07-29 13:25:32 -07:00
68a1519eaa Merge pull request #1612 from Pauan/cache
Initial interning implementation
2019-07-22 14:02:40 -05:00
10ab4cbc18 Fixing TypeScript types for cached strings 2019-07-19 22:11:45 +02:00
b9b8c209d0 Update 'threads-xform' for LLVM 9
In LLVM 9 LLD has been updated to emit shared memory and passive
segments by default for threaded code, and `__wasm_init_memory` is a
function exported used to initialize memory. Update our
transform/runtime here to hook up all those wires correctly.

Closes #1631
2019-07-19 11:10:38 -07:00
efacd8b74d Merge pull request #1514 from ibaryshnikov/threadsafe-futures
Threadsafe futures
2019-07-19 09:38:04 -05:00
ed778f5eb2 Adding in PartialEq and Eq to web-sys types 2019-07-18 23:12:49 +02:00
b13f757e90 Shared more betwee legacy with/without atomics 2019-07-18 14:11:59 -07:00
be294c8248 Remove a debugging statement 2019-07-18 14:04:45 -07:00
c8451d6f3e Rename some files
* Use "legacy" instead of "stable" since `futures 0.1` is quicly
  becoming "legacy"
* Rename "atomics" to "legacy_atomics" to leave room for the
  libstd-based futures atomics version.
* Rename "polyfill" to "wait_async_polyfill" to specify what it's
  polyfilling.
2019-07-18 14:00:45 -07:00
d590a9e053 Deduplicate JsFuture definitions
Turns out it's the exact same for both before and after atomics, so
let's use the same definition!
2019-07-18 13:59:14 -07:00
cde9684e4b Clean up atomics/futures + polyfill
* Remove now-unneeded `State` enum
* Remove timeout argument from polyfill since we don't need it
* Call `Atomics.waitAsync` if it's available instead of using our polyfill
* Remove some extraneous dead code from the polyfill
* Add a `val: i32` argument to the polyfill
* Simplify the flow of futures with `Package` since `waitAsync` handles
  all the heavy lifting for us.
* Remove `Arc<Package>` and just use `Package`
* Remove `RefCell` from inside of `Package` now that it is no longer
  needed.
2019-07-18 13:55:54 -07:00
c3676bc6f9 Removing unneeded if statement 2019-07-18 21:51:29 +02:00
adf21fe6cb Removing unneeded size argument 2019-07-18 21:51:29 +02:00
cc6ec867f7 Fixing compile errors 2019-07-18 21:51:28 +02:00
1723e9d024 More simplifications 2019-07-18 21:51:28 +02:00
1e4cac9c95 Simplifying the output 2019-07-18 21:51:28 +02:00
2ee4c54f00 Changing to use WasmSlice for the caching 2019-07-18 21:51:28 +02:00
86a8842f24 Changing IntoWasmAbi to use interning 2019-07-18 21:51:28 +02:00
6767371ca7 Initial interning implementation 2019-07-18 21:51:28 +02:00
d122bbca13 Emit a compiler error with futures 0.3 and atomics
Not implemented yet, and the one there doesn't work with atomics! (we'll
get around to this soon-ish)
2019-07-18 10:13:05 -07:00
02be3690cf removed AtomicBool from Waker struct 2019-07-17 01:52:55 +03:00
45d2c7ce93 updated to the latest master 2019-07-17 01:24:44 +03:00
cbaa1d302a added documentation comment for a stable version of wasm-bindgen-futures 2019-07-17 00:58:05 +03:00
6ab1a49a41 moved lib.rs to stable.rs in wasm-bindgen-futures, updated during review 2019-07-17 00:58:05 +03:00
221dc732af updated default timeout and wait_async signature in wasm-bindgen-futures 2019-07-17 00:48:00 +03:00
06c783d5e3 placed web-sys dependency behind a feature flag in wasm-bindgen-futures 2019-07-17 00:48:00 +03:00
16c6bdc966 moved threadsafe futures implementation to a separate file, made updates after review 2019-07-17 00:48:00 +03:00
e466e1a6f1 moved threadsafe futures behind a flag 2019-07-17 00:48:00 +03:00
2fdfe79574 added polyfill implementation in rust 2019-07-17 00:48:00 +03:00
c01575c1bc typo fixed in Atomics docs 2019-07-17 00:48:00 +03:00
d1d3021271 added polyfill for Atomics.wait and used it to notify futures 2019-07-17 00:48:00 +03:00
8fd5f4ed6a Check for use-after-move in JS glue when --debug is enabled again
Fixes #1669
2019-07-16 13:35:59 -07:00
170ce683d8 Add missing Element::get_elements_by_* methods 2019-07-15 19:47:09 +02:00
a48a0aeb93 Merge pull request #1654 from fitzgen/no-import-shims
Skip generating JS import shims when unnecessary
2019-07-15 10:13:11 -07:00
31ca527523 Bump wasm-webidl-bindings dep to 0.1.2 2019-07-15 09:35:22 -07:00
afb33e5cf4 Assert that a bunch more function signatures don't require JS glue 2019-07-12 12:34:29 -07:00
bce892b625 Add #[wasm_bindgen(assert_no_shim)] on imported functions for testing
This should not be used outside of wasm-bindgen's test suite.
2019-07-12 12:34:29 -07:00
4f86653e0d Fix parsing of final on Nightly Rust
This fixes an issue also reported to upstream (rust-lang/rust#62628) to
ensure that we parse the `final` attribute as either `r#final` or
`final`, since now the compiler is giving us `r#final` and we were
previously only accepting `final`.

The parsing here was a bit wonky, but this setup ended up working!
2019-07-12 10:05:11 -07:00
2d0866da9a cli-support: rustfmt 2019-07-11 15:44:16 -07:00
d5d3e46334 cli-support: Skip generating JS shims for imports when unnecessary
After this change, any import that only takes and returns ABI-safe numbers (signed
integers less than 64 bits and unrestricted floating point numbers) will be a
direct import, and will not have a little JS shim in the middle.

We don't have a great mechanism for testing the generated bindings' contents --
as opposed to its behavior -- but I manually verified that everything here does
the Right Thing and doesn't have a JS shim:

```rust
\#[wasm_bindgen]
extern "C" {
    fn trivial();

    fn incoming_i32() -> i32;
    fn incoming_f32() -> f32;
    fn incoming_f64() -> f64;

    fn outgoing_i32(x: i32);
    fn outgoing_f32(y: f32);
    fn outgoing_f64(z: f64);

    fn many(x: i32, y: f32, z: f64) -> i32;
}
```

Furthermore, I verified that when our support for emitting native `anyref` is
enabled, then we do not have a JS shim for the following import, but if it is
disabled, then we do have a JS shim:

```rust
\#[wasm_bindgen]
extern "C" {
    fn works_when_anyref_support_is_enabled(v: JsValue) -> JsValue;
}
```

Fixes #1636.
2019-07-11 15:44:16 -07:00
f2a4694c69 cli-support: Fix copy-pasted error message
This error case is for an invalid free function, not an invalid constructor.
2019-07-11 15:44:16 -07:00
21fe8dc706 cli-support: Fix typo in comment 2019-07-11 15:44:16 -07:00
e596ef596c Bump to 0.2.48 2019-07-11 15:02:39 -07:00