Commit Graph

62 Commits

Author SHA1 Message Date
02b7021053 Leverage new rustc wasm features
This commit leverages two new attributes in the Rust compiler,
`#[wasm_custom_section]` and `#[wasm_import_module]`. These two attributes allow
removing a lot of hacks found in wasm-bindgen and also allows removing the
requirement of `wasm-opt` to remove the unused data sections.

This does require two new nightly features but we already required the
`proc_macro` nightly feature and these will hopefully be stabilized before that
feature!
2018-03-24 10:36:19 -07:00
7ebc428646 Implement a js_name customization
This'll allow binding multiple signatures of a JS function as well as otherwise
changing the name of the JS function you're calling from the Rust function that
you're defining.

Closes #72
2018-03-22 19:05:14 -07:00
30936a6b22 Allow specifying getter/setter properties
Should help with style clashes!
2018-03-22 18:21:41 -07:00
8830f540a9 Add a structural bindgen attribute
This attribute indicates that methods are to be accessed in a structural method
rather than through their class. This should allow direct access to properties
embedded on objects rather than forcing all objects to have a class/prototype.
2018-03-22 17:37:27 -07:00
0e1fee5ddd Rename namespace to js_namespace
Along the way remove the namespace in Rust as this ended up causing too many
problems, alas! The `js_namespace` attribute now almost exclusively modifies the
JS bindings, hence the "js" in the name now.
2018-03-22 17:03:51 -07:00
fc81d8f6d3 Add From/Into JsValue for imported types 2018-03-21 12:37:10 -07:00
48b34604cb Add some #[allow] directives to generated code
No need to warn about JS/Rust conventions not lining up!
2018-03-21 10:23:03 -07:00
4a4f8b18b6 Rename static to namespace
This commit renames the `static` attribute to `namespace` and simultaneously
reduces and expands the scope. The `namespace` attribute can now be applied to
all imports in addition to functions, and it no longer recognizes full typed
paths but rather just a bare identifier. The `namespace` attribute will generate
a Rust namespace to invoke the item through if one doesn't already exist (aka
bindign a type).
2018-03-21 09:55:16 -07:00
8e894fcfc5 Implement static imports
This allows importing static objects like `document`, `window`, or an arbitrary
JS object from a module
2018-03-21 08:09:59 -07:00
92436069bd wasm-bindgen-macro: Formalize building literals with a trait 2018-03-07 16:29:25 -08:00
c2e9a4b71e Implement quote::ToTokens for AST types
They were already implemented, just without the formalization ;)
2018-03-07 14:49:40 -08:00
800376010d Bump wasm-bindgen-macro to 0.1.1 2018-03-06 13:50:45 -08:00
3ad3123882 Disambiguate generated wrappers 2018-03-06 13:45:44 -08:00
f58c436f77 Prep work for the 0.1 release 2018-03-05 20:24:35 -08:00
98030e0e4a Switch from version strings to schema versions
Should help reduce some churn a bit!
2018-03-05 20:05:44 -08:00
0dd8a77757 fix: remove unwanted no_mangle and extern wherever applicable 2018-03-05 23:25:15 +01:00
31853ad0ba Require version agreement between CLI and dep
One day may be able to relax this but for now its not tenable!

Closes #47
2018-03-01 19:36:59 -08:00
dab6ba1df8 Enable returning a vector of js values 2018-02-28 10:56:56 +01:00
f1b300c8aa get rid of unnecessary mutable var 2018-02-23 19:06:23 +01:00
f783876192 Support C-Style enums with custom int values 2018-02-23 17:38:02 +01:00
b78343a551 Fix enum formatting issues 2018-02-22 12:11:47 +01:00
7f8316f89b Clean up warnings 2018-02-22 12:08:28 +01:00
f11121b095 Generate enum js code 2018-02-22 12:01:38 +01:00
45543c545e Pass numbers in js as enums to Rust successfully 2018-02-22 10:55:44 +01:00
01c31cb33d Create Rust wrapping code for enums 2018-02-22 00:55:11 +01:00
9e7a4e7e60 Fix a few more mistakes from slices 2018-02-16 19:19:31 -08:00
3c58aa7310 Support integer/float slices/vectors
Closes #5
2018-02-16 18:58:37 -08:00
7802535948 Fix #[wasm_bindgen] on structs with no exports
It should still be usable in other types!

Closes #27
2018-02-16 13:50:14 -08:00
9183236522 Implement getter/setter bindings 2018-02-14 13:16:02 -08:00
f3c0fc369a Fix compatibility with LLD
Ensure the runtime library is always at least linked as it has important symbols
that we'll use later.
2018-02-10 10:06:56 -08:00
75837925e9 Find static descriptions inside data nodes
Right now this library only works if the static description is the entire data
node, but with upcoming LLD support everything will be in one data node. This
updates the logic for finding/parsing the program to search through the entire
data node and also know how big a program description is when it finds it.
2018-02-10 10:05:43 -08:00
29771b574c Migrate from a macro to an attribute
This commit migrates from `wasm_bindgen!`-the-macro to
`#[wasm_bindgen]`-the-attribute. The actual mechanics of the macro are
relatively simple in just generating some shims here and there, but wrapping
everything in one huge macro invocation can often seem intimidating as it gives
off this feeling of "oh dear anything can happen here!" Using an attribute
should curb expectations much more greatly of "oh there's just some extra stuff
happening behind the scenes".

The usage is otherwise relatively straightforward and close to what it was
before, but check out the DESIGN.md/README.md changes for more info!
2018-02-08 10:18:16 -08:00
70614f808e Remove stray mut 2018-02-06 19:14:54 -08:00
e9d612a343 Implement optionally catching exceptions 2018-02-06 19:04:12 -08:00
43ee52bcbf Change schemes for encoding custom type names
Store JSON a utf-32, map hashes of names to a `char` and store that name
in the map, and then do a reverse mapping when generating JS
2018-02-06 16:56:26 -08:00
ec5f0a29f7 Add a #[wasm_bindgen(constructor)] attribute
This can be used for specifying that a static function should actually delegate
to `new`
2018-02-06 15:25:46 -08:00
e60aa6a990 Rename JsObject to JsValue
Let's reserve `JsObject` for something we actually know is an object
2018-02-06 15:04:46 -08:00
56b7fa453a Fix some class import methods and auto gc
The runtime functions are now moved to the `wasm-bindgen` crate and are
auto-gc'd if they don't end up actually being required.
2018-02-06 08:58:15 -08:00
28966d9853 Fix String type in imports 2018-02-06 08:39:49 -08:00
d2f2ed8c1a Get the import-class test working 2018-02-06 08:23:51 -08:00
d5ff725913 Greatly simplify handling of types in Rust
Push the compiler to do trait resolution to figure out what each type is bound
with in JS, and that way we can accept effectively all types (so long as they
implement a trait).
2018-02-06 07:56:14 -08:00
0320bc0d7c more-wip 2018-02-05 16:39:11 -08:00
8f8da49dab wip 2018-02-05 14:24:25 -08:00
c51a342cb3 Rewrite wasm-bindgen with ES6 modules in mind
This commit is a mostly-rewrite of the `wasm-bindgen` tool. After some recent
discussions it's clear that the previous model wasn't quite going to cut it, and
this iteration is one which primarily embraces ES6 modules and the idea that
this is a polyfill for host bindings.

The overall interface and functionality hasn't changed much but the underlying
technology has now changed significantly. Previously `wasm-bindgen` would emit a
JS file that acted as an ES6 module but had a bit of a wonky interface. It
exposed an async function for instantiation of the wasm module, but that's the
bundler's job, not ours!

Instead this iteration views each input and output as a discrete ES6 module. The
input wasm file is interpreted as "this *should* be an ES6 module with rich
types" and the output is "well here's some ES6 modules that fulfill that
contract". Notably the tool now replaces the original wasm ES6 module with a JS
ES6 module that has the "rich interface". Additionally a second ES6 module is
emitted (the actual wasm file) which imports and exports to the original ES6
module.

This strategy is hoped to be much more amenable to bundlers and controlling how
the wasm itself is instantiated. The emitted files files purely assume ES6
modules and should be able to work as-is once ES6 module integration for wasm is
completed.

Note that there aren't a ton of tools to pretend a wasm module is an ES6 module
at the moment but those should be coming soon! In the meantime a local
`wasm2es6js` hack was added to help make *something* work today. The README has
also been updated with instructions for interacting with this model.
2018-01-29 21:50:01 -08:00
28a25ef8b9 Update to released syn/quote verisons 2018-01-08 10:42:01 -08:00
5c0f9613f6 Update for syn master 2018-01-02 12:30:47 -08:00
b2ce19bd3c Update to master quote 2017-12-31 15:53:29 -08:00
8ba64bab68 Update to syn master 2017-12-31 14:40:57 -08:00
33679a2b02 Removed synom due to regression in c5ab8c6b9f 2017-12-27 10:27:58 +01:00
294c5e147b Support passing booleans back and forth 2017-12-20 10:22:18 -08:00