Commit Graph

1961 Commits

Author SHA1 Message Date
Alex Crichton
a2aa28e4d3 Add a #[wasm_bindgen(start)] attribute
This commit adds a new attribute to `#[wasm_bindgen]`: `start`. The
`start` attribute can be used to indicate that a function should be
executed when the module is loaded, configuring the `start` function of
the wasm executable. While this doesn't necessarily literally configure
the `start` section, it does its best!

Only one crate in a crate graph may indicate `#[wasm_bindgen(start)]`,
so it's not recommended to be used in libraries but only end-user
applications. Currently this still must be used with the `crate-type =
["cdylib"]` annotation in `Cargo.toml`.

The implementation here is somewhat tricky because of the circular
dependency between our generated JS and the wasm file that we emit. This
circular dependency makes running initialization routines (like the
`start` shim) particularly fraught with complications because one may
need to run before the other but bundlers may not necessarily respect
it. Workarounds have been implemented for various emission strategies,
for example calling the start function directly after exports are wired
up with `--no-modules` and otherwise working around what appears to be
a Webpack bug with initializers running in a different order than we'd
like. In any case, this in theory doesn't show up to the end user!

Closes #74
2018-11-28 22:11:15 -08:00
Alex Crichton
f4c1c64078
Merge pull request #1055 from alexcrichton/strict
Assert all attributes are used by default
2018-11-28 13:43:04 -06:00
Alex Crichton
c8a352189b Assert all attributes are used by default
This commit implements a system that will assert that all
`#[wasm_bindgen]` attributes are actually used during compilation. This
should help ensure that we don't sneak in stray attributes that don't
actually end up having any meaning, and hopefully make it a bit easier
to learn `#[wasm_bindgen]`!
2018-11-28 11:42:48 -08:00
Alex Crichton
e3b628689f
Merge pull request #1053 from alexcrichton/dts-wasm
Generate a `*.d.ts` file for wasm files
2018-11-27 16:55:25 -06:00
Alex Crichton
d54340e5a2
Merge pull request #1051 from alexcrichton/extern
Consistently use `extern "C"`
2018-11-27 16:55:15 -06:00
Alex Crichton
047c41c1ec Generate a *.d.ts file for wasm files
This generates a `*.d.ts` file for the wasm file that wasm-bindgen emits
whenever typescript is enable *in addition* to the `*.d.ts` file that
already exists for the JS shim.

Closes #1040
2018-11-27 12:36:55 -08:00
Alex Crichton
151ed58b69 Consistently use extern "C"
This is what rustfmt favors, so let's favor it too!

Closes #1042
2018-11-27 12:27:00 -08:00
Alex Crichton
48f4adfa8c Run rustfmt over everything 2018-11-27 12:07:59 -08:00
Alex Crichton
4a70198143
Merge pull request #997 from jonathanKingston/todo-clean
Remove compiler warnings in todo example
2018-11-27 11:52:47 -06:00
Alex Crichton
6fd33a73fd
Merge pull request #1044 from ibaryshnikov/dom-example-without-bundlers
Added web-sys dom example withot npm and webpack
2018-11-27 11:52:00 -06:00
ibaryshnikov
873898e6c0 updated no_modules example to show web-sys usage 2018-11-27 14:44:57 +01:00
Alex Crichton
a202f1cd1f
Merge pull request #1048 from tcr/master
Adds support for #[wasm_bindgen(typescript_custom_section)].
2018-11-26 16:48:38 -06:00
Jonathan Kingston
d59716ba5b Remove compiler warnings in todo example, simplify usage of elements into element.rs and fix a bug with focus not working on edit. 2018-11-25 00:29:28 +00:00
Tim Ryan
90193eab51 Adds support for #[wasm_bindgen(typescript_custom_section)]. 2018-11-24 00:49:28 -05:00
Sendil Kumar N
fc0d6528fc
Merge pull request #1047 from RReverser/patch-1
Fix variable name reference for path_or_module
2018-11-22 21:43:39 +01:00
Ingvar Stepanyan
26f1903bee
Fix variable name reference for path_or_module 2018-11-22 18:26:37 +00:00
Alex Crichton
4e4a273f19
Merge pull request #1045 from mstange/mstange-fix-bindgn-typo
Fix typo: wasm-bindgn -> wasm-bindgen
2018-11-22 09:44:14 -06:00
Markus Stange
4c44f7d2db
Fix typo: wasm-bindgn -> wasm-bindgen 2018-11-22 10:34:31 -05:00
Alex Crichton
091eaa66f3
Merge pull request #1041 from alexcrichton/producers-sectino
Add `wasm-bindgen` to the producers section
2018-11-20 11:35:19 -06:00
Alex Crichton
6f1e3c8135 Add wasm-bindgen to the producers section
Recently proposed in WebAssembly/tool-conventions#65 each wasm file will
now have an optional `producers` section listing the tooling that went
into producing it. Let's add `wasm-bindgen` in when it processes a wasm
file!
2018-11-19 15:52:58 -08:00
Alex Crichton
f741ccd005
Merge pull request #1037 from WAFFO/patch-2
Revert js-sys link change, added web-sys link
2018-11-18 09:47:42 +02:00
Garrett Steffen
92ce73d197
Revert js-sys link change, added web-sys link
Correction to Pull Request #1035

limira is correct, that particular paragraph is referencing another crate. Considering the wasm-bindgen tutorial links here for the web-sys crate I added another link to the correct cargo link.

Sorry for the mistake.
2018-11-17 09:57:43 -06:00
Alex Crichton
adbd71fea9
Merge pull request #1035 from WAFFO/patch-1
Fixed link to the correct crate
2018-11-17 10:19:26 +02:00
Garrett Steffen
0452fbc639
Fixed link to the wrong crate 2018-11-16 19:22:19 -06:00
Alex Crichton
992fad85ab
Merge pull request #1030 from alexcrichton/wire-up-directly
Add an optimization to directly wire up imported functions
2018-11-14 09:05:47 -06:00
Alex Crichton
68537b9649 Add an optimization to directly wire up imported functions
This commit adds an optimization to `wasm-bindgen` to directly import
and invoke other modules' functions from the wasm module, rather than
going through a shim in the imported bindings. This will be an important
optimization in the future for the host bindings proposal, but for now
it's largely just a proof-of-concept to show that we can do it and is
unlikely to bring about many performance benefits.

The implementation in this commit is largely refactoring to reorganize a
bit how functions are imported, but the implementation happens in
`generate_import_function`.

With this commit, 71/287 imports in the `tests/wasm/main.rs` suite get
hooked up directly to the ES modules, no shims needed!
2018-11-13 13:16:38 -08:00
Alex Crichton
c20f80c1d6
Merge pull request #1033 from alexcrichton/no-return-array
Remove temporary object allocation
2018-11-13 12:05:35 -06:00
Alex Crichton
c915870526 Remove temporary object allocation
When returning a ptr/length for allocations and such wasm-bindgen's
generated JS would previously return an array with two elements. It
turns out this doesn't optimize well in all engines! (See #1031). It
looks like we can optimize the array destructuring a bit more, but this
is all generated code which doesn't need to be too readable so we can
also remove the temporary allocation entirely and just pass the second
element of this array through a global instead of the return value.

Closes #1031
2018-11-13 08:10:05 -08:00
Alex Crichton
8520a54f63
Merge pull request #1032 from derekdreery/window_docs
Add manual docs for single manual function.
2018-11-13 09:56:45 -06:00
Richard Dodd
4fa9865cc9 Add manual docs for single manual function. 2018-11-13 14:36:33 +00:00
Alex Crichton
c85f1b74e8
Merge pull request #1028 from alexcrichton/bump
Bump to 0.2.28
2018-11-12 12:31:26 -06:00
Alex Crichton
22ca15f81e Bump to 0.2.28 2018-11-12 09:28:01 -08:00
Alex Crichton
dc4e78550a
Merge pull request #1019 from alexcrichton/rfc-5
Implement rustwasm/rfcs#5, implement `Deref` for imports and `structural` by default
2018-11-12 10:59:46 -06:00
Alex Crichton
f3b9c69903
Merge pull request #1027 from rustwasm/dependabot/cargo/env_logger-0.6
Update env_logger requirement from 0.5 to 0.6
2018-11-12 09:12:35 -06:00
dependabot[bot]
d673d5cfff
Update env_logger requirement from 0.5 to 0.6
Updates the requirements on [env_logger](https://github.com/sebasmagri/env_logger) to permit the latest version.
- [Release notes](https://github.com/sebasmagri/env_logger/releases)
- [Commits](https://github.com/sebasmagri/env_logger/commits/v0.6.0)

Signed-off-by: dependabot[bot] <support@dependabot.com>
2018-11-12 08:17:10 +00:00
Alex Crichton
406581da7e
Merge pull request #1024 from alexcrichton/remove-names
Add a flag to remove the wasm name section
2018-11-09 16:15:14 -06:00
Alex Crichton
02cd0c5837
Merge pull request #1026 from alexcrichton/less-throw
Don't worry about descriptive strings for malloc errors
2018-11-09 16:14:22 -06:00
Nick Fitzgerald
d37052f8b4
Merge pull request #1025 from alexcrichton/fix-create
Fix `--no-modules` passing in `WebAssembly.Module`
2018-11-09 12:49:10 -08:00
Alex Crichton
2e82fdbe16 Don't worry about descriptive strings for malloc errors
This commit updates the `__wbindgen_malloc` shim to avoid throwing a
descriptive error in release mode. This is primarily done for two
reasons:

* If the function is gc'd out in release mode the `"invalid malloc
  request"` string is part of data and can't be gc'd automatically.

* In some esoteric JS environments `TextDecoder` isn't always available,
  and this relatively core function is very quick to bring in that
  requirement early on. For example some recent experimentation with
  WebAudio worklets shows that they currently don't have the
  `TextDecoder` type available!
2018-11-09 12:19:48 -08:00
Alex Crichton
37889d9fcd Fix --no-modules passing in WebAssembly.Module
This fixes a mistake in allowing a `WebAssembly.Module` to be passed to
the initialization function in `--no-modules` mode by ensuring that it
resolves to a map of an instance/module instead of just resolving to an
instance.
2018-11-09 12:15:36 -08:00
Alex Crichton
cb246e38fb Rename host_binding to final 2018-11-09 08:00:41 -08:00
Alex Crichton
2c9084d0e2 Update web-sys test to only test compilation 2018-11-09 07:56:48 -08:00
Alex Crichton
12fc09a124 Add a flag to remove the wasm name section
This commit adds a `--remove-name-section` flag to the `wasm-bindgen`
command which will remove the `name` section of the wasm file, used to
indicate the names of functions typically used in debugging. This flag
is off-by-default and will primarily be controlled by wasm-pack,
typically being passed by default with `wasm-pack build --release`.

Closes #1021
2018-11-09 07:45:19 -08:00
Alex Crichton
4c4f8f16bd
Merge pull request #1023 from jrvidal/master
Fix reference to unexisting method
2018-11-09 09:24:14 -06:00
Roberto Vidal
2faf44250d Fix reference to unexisting method 2018-11-09 13:14:16 +01:00
Alex Crichton
8ba467e905 Disallow both structural and host_binding 2018-11-08 16:47:46 -08:00
Nick Fitzgerald
227e836e04
Merge pull request #1020 from fitzgen/move-by-value-debug-asserts
Only emit JS glue assertions for move arguments in debug mode
2018-11-08 15:37:41 -08:00
Nick Fitzgerald
75c18f0916 Only emit JS glue assertions for move arguments in debug mode 2018-11-08 15:08:46 -08:00
Alex Crichton
4c42aba007 Switch all imports to structural by default
This commit switches all imports of JS methods to `structural` by
default. Proposed in [RFC 5] this should increase the performance of
bindings today while also providing future-proofing for possible
confusion with the recent addition of the `Deref` trait for all imported
types by default as well.

A new attribute, `host_binding`, is introduced in this PR as well to
recover the old behavior of binding directly to an imported function
which will one day be the precise function on the prototype. Eventually
`web-sys` will switcsh over entirely to being driven via `host_binding`
methods, but for now it's been measured to be not quite as fast so we're
not making that switch yet.

Note that `host_binding` differs from the proposed name of `final` due
to the controversy, and its hoped that `host_binding` is a good
middle-ground!

[RFC 5]: https://rustwasm.github.io/rfcs/005-structural-and-deref.html
2018-11-08 13:52:18 -08:00
Alex Crichton
6093fd29d1 Don't convert boolean arguments going to wasm
The wasm spec defines boolean conversion when crossing to the wasm type
i32 as 1 for `true` and 0 for `false`, so no need for us to do it
ourselves!
2018-11-08 13:06:03 -08:00