Commit Graph

109 Commits

Author SHA1 Message Date
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
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
e596ef596c Bump to 0.2.48 2019-07-11 15:02:39 -07:00
d71ab78fc6 Bump to 0.2.47 2019-06-19 11:14:37 -07:00
00d47c1958 Remove unnecessary Result return 2019-06-16 22:24:27 -03:00
8fc0a38402 Bump to 0.2.46 2019-06-14 11:44:58 -07:00
39b5f1845d Fix a warning 2019-05-28 07:03:42 -07:00
9b04fe9e45 Merge pull request #1545 from infinity0/master
Work around rust-lang/rust#58516
2019-05-21 08:58:59 -05:00
81fb2d97d3 Work around rust-lang/rust#58516 2019-05-20 20:18:24 -07:00
137bbdf2e3 Bump to 0.2.45 2019-05-20 09:44:03 -07:00
773c6ff430 Bump to 0.2.44 2019-05-16 07:47:23 -07:00
578d59ebc0 Merge pull request #1440 from c410-f3r/getters
Getters/Setters for fields
2019-04-30 12:07:34 -05:00
470eea9fb0 Getters/Setters for fields 2019-04-30 10:26:03 -03:00
f2429be07f Bump to 0.2.43 2019-04-29 08:28:41 -07:00
3a7d384dc8 Generate bindings for indexed struct properties
This allows to export fields of tuple-like structs as indexed JS properties.
2019-04-17 12:56:14 +01:00
ff1addbbaa Run cargo fmt 2019-04-16 10:52:27 -07:00
00c4dd9b6f Merge branch 'master' into add-wasm-bindgen-skip-attr 2019-04-14 23:43:21 +03:00
cb880bdbff Add customisable is_type_of 2019-04-12 17:23:42 +01:00
df6e15e3ab Bump to 0.2.42 2019-04-11 07:39:45 -07:00
02394724ea Bump to 0.2.41 2019-04-10 10:53:32 -07:00
f48fdec21e Fix imported usage of wasm_bindgen macro
Make sure it refers to `__wasm_bindgen_class_marker` via an absolute
path!

Closes #1422
2019-04-04 09:56:16 -07:00
1dcf468c9d add wasm_bindgen(skip) attr to disable getters and setters exposure of pub fields 2019-03-30 05:09:02 +02:00
a6fe0cefa8 Migrate all crates to the 2018 edition
Most of the CLI crates were already in the 2018 edition, and it turns
out that one of the macro crates was already in the 2018 edition so we
may as well move everything to the 2018 edition!

Always nice to remove those `extern crate` statements nowadays!

This commit also does a `cargo fmt --all` to make sure we're conforming
with style again.
2019-03-26 08:10:53 -07:00
6803c619bb Bump to 0.2.40 2019-03-21 17:08:48 -07:00
0d592fffb0 Add a raw_module attribute to #[wasm_bindgen]
This allows subverting the checks and resolution performed by the
`module` attribute added as part of [RFC 6] and has been discussed in #1343.

Closes #1343

[RFC 6]: https://github.com/rustwasm/rfcs/pull/6
2019-03-15 08:08:09 -07:00
228f58dca3 Bump to 0.2.39 2019-03-13 11:02:27 -07:00
b762948456 Implement the local JS snippets RFC
This commit is an implementation of [RFC 6] which enables crates to
inline local JS snippets into the final output artifact of
`wasm-bindgen`. This is accompanied with a few minor breaking changes
which are intended to be relatively minor in practice:

* The `module` attribute disallows paths starting with `./` and `../`.
  It requires paths starting with `/` to actually exist on the filesystem.
* The `--browser` flag no longer emits bundler-compatible code, but
  rather emits an ES module that can be natively loaded into a browser.

Otherwise be sure to check out [the RFC][RFC 6] for more details, and
otherwise this should implement at least the MVP version of the RFC!
Notably at this time JS snippets with `--nodejs` or `--no-modules` are
not supported and will unconditionally generate an error.

[RFC 6]: https://github.com/rustwasm/rfcs/pull/6

Closes #1311
2019-03-05 08:00:47 -08:00
a659f27c07 Bump to 0.2.38 2019-03-04 09:11:23 -08:00
e9f423d57e Bump to 0.2.37 2019-02-15 08:16:24 -08:00
802cfedcbd Bump to 0.2.36 2019-02-12 13:19:02 -08:00
d9cf9b3735 Bump to version 0.2.35 2019-02-12 11:36:19 -08:00
894b479213 Migrate wasm-bindgen to using walrus
This commit moves `wasm-bindgen` the CLI tool from internally using
`parity-wasm` for wasm parsing/serialization to instead use `walrus`.
The `walrus` crate is something we've been working on recently with an
aim to replace the usage of `parity-wasm` in `wasm-bindgen` to make the
current CLI tool more maintainable as well as more future-proof.

The `walrus` crate provides a much nicer AST to work with as well as a
structured `Module`, whereas `parity-wasm` provides a very raw interface
to the wasm module which isn't really appropriate for our use case. The
many transformations and tweaks that wasm-bindgen does have a huge
amount of ad-hoc index management to carefully craft a final wasm
binary, but this is all entirely taken care for us with the `walrus`
crate.

Additionally, `wasm-bindgen` will ingest and rewrite the wasm file,
often changing the binary offsets of functions. Eventually with DWARF
debug information we'll need to be sure to preserve the debug
information throughout the transformations that `wasm-bindgen` does
today. This is practically impossible to do with the `parity-wasm`
architecture, but `walrus` was designed from the get-go to solve this
problem transparently in the `walrus` crate itself. (it doesn't today,
but this is planned work)

It is the intention that this does not end up regressing any
`wasm-bindgen` use cases, neither in functionality or in speed. As a
large change and refactoring, however, it's likely that at least
something will arise! We'll want to continue to remain vigilant to any
issues that come up with this commit.

Note that the `gc` crate has been deleted as part of this change, as the
`gc` crate is no longer necessary since `walrus` does it automatically.
Additionally the `gc` crate was one of the main problems with preserving
debug information as it often deletes wasm items!

Finally, this also starts moving crates to the 2018 edition where
necessary since `walrus` requires the 2018 edition, and in general it's
more pleasant to work within the 2018 edition!
2019-02-12 07:25:53 -08:00
078257943d Bump to 0.2.34 2019-02-11 18:58:54 -08:00
9224455077 Support Option with custom enums in JS
Find a hole automatically to use a sentinel value for `None`, and then
just wire everything up!

Closes #1198
2019-01-28 14:27:57 -08:00
c35d6f4b0a Fix conditional #[wasm_bindgen] in impls
Reported in #1191 the fix requires us to get a bit creative I think. The
general gist is that a block like this:

    #[wasm_bindgen]
    impl Foo {
        pub fn foo() {}
    }

was previously expanded all in one go. Now, however, it's expanded into:

    impl Foo {
        #[__wasm_bindgen_class_marker(Foo = "Foo")]
        pub fn foo() {}
    }

    // goop generated by orginal #[wasm_bindgen]

This method of expansion takes advantage of rustc's recursive expansion
feature. It also allows us to expand `impl` blocks and allow inner items
to not be fully expanded yet, such as still having `#[cfg]` attributes
(like in the original bug report).

We use theinternal `__wasm_bindgen_class_marker` to indicate that we're
parsing an `ImplItemMethod` unconditionally, and then generation
proceeds as usual. The only final catch is that when we're expanding in
an `impl` block we have to generate tokens for the `Program`
(wasm-bindgen injected goop like the custom section) inside the body
of the function itself instead of next to it. Otherwise we'd get syntax
errors inside of impl blocks!

Closes #1191
2019-01-28 12:29:01 -08:00
78c4075e40 Bump to 0.2.33 2019-01-18 15:32:17 -08:00
31fdede9fc Bump to 0.2.32 2019-01-16 13:11:13 -08:00
b04f60cf2b Bump to 0.2.31 2019-01-09 09:17:50 -08:00
fbf000a508 Bump to 0.2.30 2019-01-07 07:47:07 -08:00
63e3ba722d Bump to 0.2.29 2018-12-04 06:04:47 -08:00
29531c0abf Run rustfmt 2018-11-30 13:04:27 -08:00
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
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
48f4adfa8c Run rustfmt over everything 2018-11-27 12:07:59 -08:00
90193eab51 Adds support for #[wasm_bindgen(typescript_custom_section)]. 2018-11-24 00:49:28 -05:00
22ca15f81e Bump to 0.2.28 2018-11-12 09:28:01 -08:00
cb246e38fb Rename host_binding to final 2018-11-09 08:00:41 -08:00
8ba467e905 Disallow both structural and host_binding 2018-11-08 16:47:46 -08:00
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