Commit Graph

1005 Commits

Author SHA1 Message Date
Alex Crichton
800376010d Bump wasm-bindgen-macro to 0.1.1 2018-03-06 13:50:45 -08:00
Nick Fitzgerald
3ad3123882 Disambiguate generated wrappers 2018-03-06 13:45:44 -08:00
Alex Crichton
46f1b5680f Add the wasm category to wasm-bindgen-cli 2018-03-05 20:28:45 -08:00
Alex Crichton
f58c436f77 Prep work for the 0.1 release 2018-03-05 20:24:35 -08:00
Alex Crichton
98030e0e4a Switch from version strings to schema versions
Should help reduce some churn a bit!
2018-03-05 20:05:44 -08:00
Alex Crichton
1db5b3fb50 Add Travis/AppVeyor deployments 2018-03-05 20:05:39 -08:00
Sendil Kumar
49a7b9fef5 Merge branch 'master' into fix-no-mangle 2018-03-05 23:26:22 +01:00
Sendil Kumar
0dd8a77757 fix: remove unwanted no_mangle and extern wherever applicable 2018-03-05 23:25:15 +01:00
Sendil Kumar
d5ac523fe2 feat: rename generated file to have bg instead of wasm 2018-03-05 22:25:14 +01:00
Alex Crichton
67601c4293 No more need to optimize in dev! 2018-03-04 18:23:23 -08:00
Alex Crichton
d9e1dae298 Migrate from rollup to webpack in tests
Building on the previous commit to invoke not invoke `npm install` this takes
the commit a step further (to hopefully fix some races) to use Webpack's native
bundled wasm support.

It turns out the circular dependencies between the wasm module and the module
using it wasn't quite working out so a number of imports had to be tweaked, but
otherwise it's a nice transition where we don't have to base64 encode anything
in tests any more!
2018-03-02 19:20:14 -08:00
Alex Crichton
353794417c Don't run npm install during tests
Instead add a `package.json` and use `yarn run`.
2018-03-02 15:44:28 -08:00
Alex Crichton
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
Alex Crichton
1c8061e675 Implement a version string
Add a `--version` and `-V` to the command to print out the version
2018-03-01 19:19:12 -08:00
Ryan Levick
37da9eba14 Address feedback on commit dab6ba1 2018-02-28 17:29:40 +01:00
Ryan Levick
dab6ba1df8 Enable returning a vector of js values 2018-02-28 10:56:56 +01:00
Alex Crichton
19f88f0fd2 Update parity-wasm dep 2018-02-26 17:11:56 -08:00
Ryan Levick
f1b300c8aa get rid of unnecessary mutable var 2018-02-23 19:06:23 +01:00
Ryan Levick
f783876192 Support C-Style enums with custom int values 2018-02-23 17:38:02 +01:00
Ryan Levick
71880b8a83 Enums are numbers 2018-02-23 17:34:08 +01:00
Ryan Levick
3a270b6510 Add test for enums 2018-02-23 17:30:18 +01:00
Ryan Levick
b78343a551 Fix enum formatting issues 2018-02-22 12:11:47 +01:00
Ryan Levick
7f8316f89b Clean up warnings 2018-02-22 12:08:28 +01:00
Ryan Levick
f11121b095 Generate enum js code 2018-02-22 12:01:38 +01:00
Ryan Levick
45543c545e Pass numbers in js as enums to Rust successfully 2018-02-22 10:55:44 +01:00
Ryan Levick
01c31cb33d Create Rust wrapping code for enums 2018-02-22 00:55:11 +01:00
Ryan Levick
0f8524da3c Ensure memory accesses are exposed before accessing 2018-02-18 23:55:34 +01:00
Alex Crichton
d66bc25749 Automatically bind float math functions
These tend to have one "pretty obvious" definition in JS anyway, so
let's paper over this deficiency in rustc for now by automatically
resolving any imports for these functions.

Closes #28
2018-02-17 16:44:31 -08:00
Alex Crichton
9e7a4e7e60 Fix a few more mistakes from slices 2018-02-16 19:19:31 -08:00
Alex Crichton
3c58aa7310 Support integer/float slices/vectors
Closes #5
2018-02-16 18:58:37 -08:00
Alex Crichton
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
Alex Crichton
c148a3b6dc Emit JS with some more newlines
Hopefully helps a bit with readability!
2018-02-16 13:36:37 -08:00
Alex Crichton
9183236522 Implement getter/setter bindings 2018-02-14 13:16:02 -08:00
Alex Crichton
be368a6570 Don't look up properties in import shims
This'll match more closely what wasm eventually does natively, which is
importing these functions directly and not allowing changing them over time.

Closes #25
2018-02-14 12:51:58 -08:00
David Flemström
c0f2773c4e Don't panic on unsupported exports
It's most likely safe for us to skip exports that we don't yet
support.  Doing nothing will at least not hurt in those cases.
2018-02-12 17:49:26 -05:00
Alex Crichton
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
Alex Crichton
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
Alex Crichton
f49be45a92 Fix a typo for typescript bindings 2018-02-08 10:22:54 -08:00
Alex Crichton
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
Alex Crichton
70614f808e Remove stray mut 2018-02-06 19:14:54 -08:00
Alex Crichton
e9d612a343 Implement optionally catching exceptions 2018-02-06 19:04:12 -08:00
Alex Crichton
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
Alex Crichton
8312f3ae9f Fix programs with two wasm_bindgen! invocations
Saw the bug coming. Added an assert. Assert tripped. Bug now fixed!
2018-02-06 15:52:44 -08:00
Alex Crichton
2c7c2e7ae1 Cache more objects in generated JS bindings
Cache the `Uint8Array` and `Uint32Array` views into wasm memory as well as the
instances of `TextEncoder` and `TextDecoder`. Should hopefully help cut down on
gc traffic and otherwise convince the engine to keep these as long-lived
objects.
2018-02-06 15:33:17 -08:00
Alex Crichton
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
Alex Crichton
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
Alex Crichton
aa90715896 Rename free functions to avoid gc'ing too much 2018-02-06 11:54:40 -08:00
Alex Crichton
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
Alex Crichton
28966d9853 Fix String type in imports 2018-02-06 08:39:49 -08:00
Alex Crichton
d2f2ed8c1a Get the import-class test working 2018-02-06 08:23:51 -08:00
Alex Crichton
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
Alex Crichton
0320bc0d7c more-wip 2018-02-05 16:39:11 -08:00
Alex Crichton
8f8da49dab wip 2018-02-05 14:24:25 -08:00
Alex Crichton
ec1c263480 Tweak path to rollup for Windows 2018-02-02 08:51:45 -08:00
Alex Crichton
baa144d141 Add a word of warning to wasm2es6js 2018-02-02 08:17:04 -08:00
Alex Crichton
b75c0354b7 Be a bit more tslint friendly in generated code 2018-01-30 07:58:44 -08:00
Alex Crichton
235bc2957e Tweak typescript option 2018-01-30 07:47:49 -08:00
Alex Crichton
1487288050 Expose typescript option in wasm2es6js 2018-01-30 07:45:36 -08:00
Alex Crichton
89c8621426 Flag free() as returning void 2018-01-30 07:37:25 -08:00
Alex Crichton
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
Alex Crichton
f27e4a9e94 Update parity-wasm dependency 2018-01-25 13:32:27 -08:00
Alex Crichton
b38c273ee5 Add an --output-js flag
This'll output just vanilla JS rather than TypeScript!

Closes #8
2018-01-24 19:15:34 -08:00
Alex Crichton
28a25ef8b9 Update to released syn/quote verisons 2018-01-08 10:42:01 -08:00
Alex Crichton
5c0f9613f6 Update for syn master 2018-01-02 12:30:47 -08:00
Alex Crichton
b2ce19bd3c Update to master quote 2017-12-31 15:53:29 -08:00
Alex Crichton
0b81185c99 Expose primitive information about JsObject
Adds bindings for wbindgen to fill in via JS bindings to read the various
primitive properties of a JS value.
2017-12-31 15:45:47 -08:00
Alex Crichton
996c296de8 Disable incremental for tests
Seems buggy?
2017-12-31 14:48:56 -08:00
Alex Crichton
4151461ab9 Expose construction of a JsObject as a string
Start fleshing out the `JsObject` API!
2017-12-31 14:44:44 -08:00
Alex Crichton
8ba64bab68 Update to syn master 2017-12-31 14:40:57 -08:00
Alex Crichton
e03ef1c2a4 Enable wasm-bindgen -h
Closes #3
2017-12-27 07:50:43 -08:00
Felix Schütt
33679a2b02 Removed synom due to regression in c5ab8c6b9f 2017-12-27 10:27:58 +01:00
Alex Crichton
bef908a9b1 Add an option to "uglify" imports
This commit adds an option to "uglify" the wasm module's imports/exports so
those which are controlled by bindgen are renamed to a shorter (probably one
letter) names. This'll hopefully help cut down on both the wasm size slightly
and also the generated JS as the glue we're talking to wasm over won't require
such large names all the time.
2017-12-24 15:32:40 -08:00
Alex Crichton
240d3cd1a1 Rename __wasmPtr field to ptr
May as well have it be a bit shorter so minifiers can be a little smaller.
2017-12-24 09:41:57 -08:00
Alex Crichton
6aacff6a80 Further optimize non-debug output
Remove a bunch of exception throws in favor of type casts in TypeScript and
remove some type assertions as well that TypeScript should uphold.
2017-12-20 13:24:18 -08:00
Alex Crichton
5d697c196f Only expose assertions in debug mode 2017-12-20 12:56:57 -08:00
Alex Crichton
f1d425b943 Hook up debug to the CLI 2017-12-20 12:50:10 -08:00
Alex Crichton
b548239e02 Don't generate code for dead imports 2017-12-20 11:34:53 -08:00
Alex Crichton
5e80b082a9 Allow imports to return JS objects 2017-12-20 10:44:08 -08:00
Alex Crichton
294c5e147b Support passing booleans back and forth 2017-12-20 10:22:18 -08:00
Alex Crichton
730ef1926e Enable the --declaration tsc argument 2017-12-20 08:25:45 -08:00
Alex Crichton
8d7e6f3cdd Ok, let's actually expose memory
May as well have it typed!
2017-12-20 08:22:30 -08:00
Alex Crichton
2fbd784002 Disable tslint automatically
This is generated code, no need to lint it
2017-12-20 08:21:19 -08:00
Alex Crichton
97957d98f1 Fix noUnusedParameters warning 2017-12-20 08:17:20 -08:00
Alex Crichton
5fe842e9bd Allow extra exports not part of wasm-bindgen
Currently throw them all in an interface under `extra` in the main exports
interface. May change in the future...
2017-12-20 08:11:06 -08:00
Alex Crichton
a12a8f414c Support imports outside of wasm_bindgen! 2017-12-20 07:58:41 -08:00
Alex Crichton
66ae545bff Add support for raw pointers in Rust 2017-12-20 07:35:14 -08:00
Alex Crichton
91fddfd10f Improve consistency of prefixes 2017-12-19 20:00:25 -08:00
Alex Crichton
d3387d591f Start optimizing code size:
* Use a bundled custom `WasmRefCell` instead of the one in the standard library.
  This one primarily doesn't panic via libstd which means that its code
  footprint is much smaller.
* Add a `throw` function to `wasm_bindgen`-the-crate which can be used to throw
  an exception in JS from Rust. This is useful as a cheap way to throw an
  exception code-wise (little code bloat) and it's also a great way of reporting
  error messages to JS!
* Cut down on the code size of `__wbindgen_malloc` by aborting on huge requests
  earlier.
* Use a custom `assert_not_null` function which delegates to `throw` to test for
  incoming null pointers
2017-12-19 19:53:55 -08:00
Alex Crichton
85cdb51719 Generate TypeScript by default instead of JS
This is what's needed in the immediate future anyway, so let's do that!
2017-12-19 19:06:48 -08:00
Alex Crichton
946e5317fe Support passing JS objects through Rust 2017-12-19 09:25:41 -08:00
Alex Crichton
eda9beae25 Get imports working in a basic capacity 2017-12-18 21:43:16 -08:00
Alex Crichton
1ffcb90d2d Ensure class arguments have the expected type 2017-12-18 19:01:37 -08:00
Alex Crichton
9eb63fd0df Try to fix tests on windows again 2017-12-18 16:35:04 -08:00
Alex Crichton
eebe8b21a2 Fix generation for a fn with two string args 2017-12-18 16:13:37 -08:00
Alex Crichton
d38a448f15 Fix a hygiene issue with me 2017-12-18 15:54:43 -08:00
Alex Crichton
ac1acf55ac Fix a typo in passStringToWasm 2017-12-18 15:37:28 -08:00
Alex Crichton
d768b42a64 First pass at implementing functions for browsers 2017-12-18 15:14:13 -08:00
Alex Crichton
ea36df2e01 Rename the cli tool to wasm-bindgen 2017-12-18 15:08:36 -08:00
Alex Crichton
62808e8d99 Add some tests for exceptions 2017-12-18 14:44:09 -08:00
Alex Crichton
6593b5ef69 Classes are now working! 2017-12-18 14:31:01 -08:00
Alex Crichton
7c510a8a7e Start adding support for classes 2017-12-18 12:39:14 -08:00
Alex Crichton
1b4f10217c Start handling strings 2017-12-14 21:55:21 -08:00
Alex Crichton
d5897c6e56 Test the eventual desired interface 2017-12-14 20:07:26 -08:00
Alex Crichton
d2d9f6be11 Avoid registry/git repo updates in tests
Use the main lockfile as a template, also print out how long each
command takes.
2017-12-14 19:36:41 -08:00
Alex Crichton
2926e6e9f4 Initial commit 2017-12-14 19:31:01 -08:00