Commit Graph

243 Commits

Author SHA1 Message Date
Alex Crichton
b71f3374c5 Tweak introductory and deployment documentation.
This commit rejiggers some documentation of `wasm-bindgen` in a few
significant ways:

* The main landing page now has text and links to the Game of Life
  tutorial and `wasm-pack`.
* The "whirlwind tour" was deleted as it wasn't really serving any
  purpose that the Game of Life plus the later references weren't already
  serving.
* The "no modules" example was renamed to "without a bundler"
* A dedicated section on "Deployment" was added which replaces the
  previous "No ES Modules" page. This is hopefully more descriptive and
  also prominently mentions the various options for deployment.
2019-02-22 07:50:32 -08:00
Alex Crichton
b8f080d523 Update idioms of a few examples
* Use `TypedArray::view` now that it exists.
* Don't hack around `instantiateStreaming`
2019-02-19 13:27:30 -08:00
Sven Sauleau
5e7187a95f
chore: update pinned Webpack versions 2019-02-15 19:26:08 +01:00
Alex Crichton
e9f423d57e Bump to 0.2.37 2019-02-15 08:16:24 -08:00
Camille TJHOA
768b654b58 Fix warning on ATOMIC_USIZE_INIT & ATOMIC_BOOL_INIT 2019-02-15 11:58:48 +00:00
Nick Fitzgerald
802cfedcbd Bump to 0.2.36 2019-02-12 13:19:02 -08:00
Nick Fitzgerald
d9cf9b3735 Bump to version 0.2.35 2019-02-12 11:36:19 -08:00
Alex Crichton
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
Nick Fitzgerald
078257943d Bump to 0.2.34 2019-02-11 18:58:54 -08:00
Jonathan Kingston
5c81125b86 Fixup compiler warnings for Todo MVC example 2019-02-11 18:43:23 +00:00
Andrew Chin
153acdb4fd Fix webaudio example
The rust set_* functions except numbers, not strings.
2019-01-28 23:54:40 -05:00
Alex Crichton
78c4075e40 Bump to 0.2.33 2019-01-18 15:32:17 -08:00
Alex Crichton
32c611d16d Convert all examples to using wasm-pack
This commit migrates all our examples to using `wasm-pack build` to
compile their code and run `wasm-bindgen`. This should make it a bit
easier to understand the examples as there's less to follow during the
build step.

Webpack projects are all using `@wasm-tool/wasm-pack-plugin` as well so
the build step is simple `npm run serve`. Other examples which retain
`build.sh` are just using `wasm-pack build` now
2019-01-17 08:37:32 -08:00
Nick Fitzgerald
31fdede9fc Bump to 0.2.32 2019-01-16 13:11:13 -08:00
Alex Crichton
b04f60cf2b Bump to 0.2.31 2019-01-09 09:17:50 -08:00
Alex Crichton
fbf000a508 Bump to 0.2.30 2019-01-07 07:47:07 -08:00
Alex Crichton
fcee465692 Add a comment about memory management 2018-12-19 12:00:42 -08:00
Roberto Vidal
08680276ae Fixes outdated links 2018-12-13 15:25:15 +01:00
LachezarLechev
f29f78e302 [examples] performance - remove one more unnecessary import 2018-12-12 08:16:36 +01:00
LachezarLechev
a211e4af9c [examples] performance - port to rust 2018 2018-12-12 08:14:08 +01:00
LachezarLechev
55f199ee77 [examples] paint - port to rust 2018 2018-12-12 08:12:51 +01:00
LachezarLechev
e1d11fda95 [examples] no_modules - port to rust 2018 2018-12-12 08:11:18 +01:00
LachezarLechev
dd82cd4722 [examples] julia_set - port to rust 2018 2018-12-12 08:10:02 +01:00
Alex Crichton
82b322a12f
Merge pull request #1103 from T5uku5hi/port-examples-to-rust-2018
Port dom, fetch, guide-supported-types-examples, import_js examples to Rust 2018 edition
2018-12-11 16:37:16 -06:00
T5uku5hi
b6db977795 removed extern crate lines 2018-12-12 07:14:26 +09:00
T5uku5hi
0003fc9115 remove unnecessary lines 2018-12-12 06:56:09 +09:00
André Luis Leal Cardoso Junior
9aa15bf600 Update wasm2js to rust 2018 2018-12-11 19:31:50 -02:00
André Luis Leal Cardoso Junior
bfcecb426e Update raytrace-parallel to rust 2018 2018-12-11 19:28:11 -02:00
T5uku5hi
7cf2942e25 [examples] import_js - port to rust 2018 2018-12-12 00:53:11 +09:00
T5uku5hi
56b3e0a318 run cargo fix --edition-idioms 2018-12-12 00:51:23 +09:00
T5uku5hi
48cc61147b [examples] guide-supported-types-examples - port to rust 2018 2018-12-12 00:50:41 +09:00
T5uku5hi
2d9dcf6ace run cargo fix --edition-idioms 2018-12-12 00:48:10 +09:00
T5uku5hi
f148164cd3 [examples] fetch - port to rust 2018 2018-12-12 00:47:22 +09:00
T5uku5hi
b2afc0e38a run cargo fix --edition-idioms 2018-12-12 00:40:00 +09:00
André Luis Leal Cardoso Junior
2c30818b7c Update todomvc example to the 2018 edition 2018-12-11 13:39:36 -02:00
T5uku5hi
493130ee36 [examples] dom - port to rust 2018 2018-12-12 00:39:22 +09:00
André Luis Leal Cardoso Junior
a8fb4c3bf8 Update wasm-in-wasm example to the 2018 edition 2018-12-11 13:36:24 -02:00
André Luis Leal Cardoso Junior
00d4c6b5a5 Update webaudio example to the 2018 edition 2018-12-11 13:36:08 -02:00
André Luis Leal Cardoso Junior
67c99a8b08 Update webgl example to the 2018 edition 2018-12-11 13:35:48 -02:00
Alex Crichton
639724a85e
Merge pull request #1100 from elpiel/port-examples-to-rust-2018
Port examples - console-log, closures and duck-typed-interfaces to Rust 2018
2018-12-11 08:53:35 -05:00
LachezarLechev
90ed520394 [examples] closure - remove unnecessary use statement 2018-12-11 14:50:27 +01:00
André Luis Leal Cardoso Junior
c6a9d4851a Remove extra web_sys call 2018-12-11 11:50:25 -02:00
André Luis Leal Cardoso Junior
ceb269b28a run cargo fix --edition-idioms 2018-12-11 08:53:21 -02:00
LachezarLechev
573c14118a [examples] duck-typed-interfaces - port to rust 2018 2018-12-11 08:45:26 +01:00
LachezarLechev
7107a896da [examples] closures - port to rust 2018 2018-12-11 08:39:49 +01:00
LachezarLechev
26737a2888 [examples] console_log - port to rust 2018 2018-12-11 08:37:53 +01:00
André Luis Leal Cardoso Junior
88c8b9059e Add edition 2018 to Cargo.toml 2018-12-10 23:44:59 -02:00
Nick Fitzgerald
77ddf5ebcd examples: Add a requestAnimationFrame loop example 2018-12-10 12:50:19 -08:00
Alex Crichton
63e3ba722d Bump to 0.2.29 2018-12-04 06:04:47 -08:00
Daniel Schindler
53c65039b9 Change module import 2018-12-03 11:37:30 +01:00
Daniel Schindler
a25925346a Add index.css to build 2018-12-02 21:22:37 +01:00
ibaryshnikov
2cdc45cef7 fixed link to compiled raytrace-parallel in examples 2018-11-30 23:36:27 +03:00
Daniel Schindler
caac2eba53 Add #[wasm_bindgen(start)], plugins to webpack config, Update deps 2018-11-30 17:42:36 +01:00
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
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
ibaryshnikov
873898e6c0 updated no_modules example to show web-sys usage 2018-11-27 14:44:57 +01: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
Alex Crichton
22ca15f81e Bump to 0.2.28 2018-11-12 09:28:01 -08:00
Alex Crichton
5b76a6291e Implement Deref for all imported JS types
This commit implements the first half of [RFC #5] where the `Deref`
trait is implemented for all imported types. The target of `Deref` is
either the first entry of the list of `extends` attribute or `JsValue`.

All examples using `.as_ref()` with various `web-sys` types have been
updated to the more ergonomic deref casts now. Additionally the
`web-sys` generation of the `extends` array has been fixed slightly to
explicitly list implementatoins in the hierarchy order to ensure the
correct target for `Deref` is chosen.

[RFC #5]: https://github.com/rustwasm/rfcs/blob/master/text/005-structural-and-deref.md
2018-11-08 11:01:34 -08:00
Alex Crichton
56400c3738 Don't use path dependencies in examples
This commit updates all examples to not use `path` dependencies but
rather use versioned dependencies like would typically be found in the
wild. This should hopefully make the examples more copy-pastable and
less alien to onlookers!

The development of the examples remains the same where they continue to
use the `wasm-bindgen`, `js-sys`, `web-sys`, etc from in-tree. The
workspace-level `[patch]` section ensures that they use the in-tree
versions instead of the crates.io versions.
2018-11-07 11:27:43 -08:00
Alex Crichton
93564f159f Fix build of TODO MVC on stable 2018-10-29 13:47:09 -07:00
Alex Crichton
9a3ef7b747
Merge pull request #961 from jonathanKingston/todo-mvc
Todo mvc
2018-10-29 13:24:59 -07:00
Alex Crichton
cfa4aa0e3e Promote CI jobs to using stable Rust
Everything should be stable now so let's test it!
2018-10-28 13:28:02 -07:00
Alex Crichton
f016ae5846 Indicate workable browsers 2018-10-23 08:50:58 -07:00
Jonathan Kingston
b322f46303 Adding in TODO MVC example using web-sys 2018-10-23 14:15:42 +01:00
Alex Crichton
25b26f41e7 Implement support for WebAssembly threads
... and add a parallel raytracing demo!

This commit adds enough support to `wasm-bindgen` to produce a workable
wasm binary *today* with the experimental WebAssembly threads support
implemented in Firefox Nightly. I've tried to comment what's going on in
the commits and such, but at a high level the changes made here are:

* A new transformation, living in a new `wasm-bindgen-threads-xform`
  crate, prepares a wasm module for parallel execution. This performs a
  number of mundane tasks which I hope to detail in a blog post later on.
* The `--no-modules` output is enhanced with more support for when
  shared memory is enabled, allowing passing in the module/memory to
  initialize the wasm instance on multiple threads (sharing both module
  and memory).
* The `wasm-bindgen` crate now offers the ability, in `--no-modules`
  mode, to get a handle on the `WebAssembly.Module` instance.
* The example itself requires Xargo to recompile the standard library
  with atomics and an experimental feature enabled. Afterwards it
  experimentally also enables threading support in wasm-bindgen.

I've also added hopefully enough CI support to compile this example in a
builder so we can upload it and poke around live online. I hope to
detail more about the technical details here in a blog post soon as
well!
2018-10-23 01:20:18 -07:00
David Jozis
b369932b37 Fixed typo 2018-10-14 17:00:56 -04:00
David Jozis
30bb9b09d3 Switched from raw pointer casts to using as_ptr() 2018-10-14 16:50:35 -04:00
David Jozis
52128e9baa Cleaned up memory buffer access 2018-10-14 13:28:27 -04:00
David Jozis
f408310ab7 Removed buffer copy from webgl example 2018-10-14 13:28:27 -04:00
Pascal Hertleif
959deeea5d Fix unimportant typo 2018-10-06 21:09:18 +02:00
Alex Crichton
3f357f46eb Fix the no_modules example by fixing --browser
Recent refactorings forgot a case of emitting code for
`cachedTextDecoder`!
2018-10-03 15:54:57 -07:00
Alex Crichton
991e61931e Switch Closure::new to wrap in paint example
Show off stable usage!
2018-10-03 09:53:55 -07:00
Alex Crichton
32fd1227e4
Merge pull request #910 from alexcrichton/fix-text-encoder-edge
Fix polyfill of `TextEncoder` and `TextDecoder`
2018-10-03 00:07:30 -07:00
Alex Crichton
bb7271aa43 Fix our WebIDL for Safari
This commit employs the strategy described in #908 to apply a
non-breaking change to fix WebIDL to be compatible with all browsers,
including Safari.

The problem here is that `BaseAudioContext` and `AudioScheduledSourceNode`
are not types in Safari, but they are types in Firefox/Chrome. The fix
here was to move the contents of these two interfaces into mixins, and
then include the mixins in all classes which inherit from these two
classes. That should have the same effect as defining the methods
inherently on the original interface.

Additionally a special `[RustDeprecated]` attribute to WebIDL was added
to signify interfaces this has happened to. Currently it's directly
tailored towards this case of "this intermediate class doesn't exist in
all browsers", but we may want to refine and extend the deprecation
message over time.

Although it's possible we could do this as a breaking change to
`web-sys` I'm hoping that we can do this as a non-breaking change for
now and then eventually on the next breaking release batch all these
changes together, deleting the intermediate classes. This is also
hopefully a good trial run for how stable web-sys can be when it's
actually stable!

cc #897
cc #908
2018-10-01 12:24:37 -07:00
Alex Crichton
717cfa303d Fix polyfill of TextEncoder and TextDecoder
This commit does a few things, including:

* Fixing the generated JS of `wasm-bindgen` to allow polyfills to work.
  (a minor tweak of the generated JS)

* All examples are updated to include a Webpack-specific polyfill for
  these two types to get examples working in Edge.

* A new page has been added to the guide about supported browsers. This
  mentions known caveats like IE 11 requiring `wasm2js` as well as
  documenting some `TextEncoder` and `TextDecoder` workarounds for Edge.

Closes #895
2018-09-30 10:16:20 -07:00
Alex Crichton
bc36b6f84b Add catch(console.error) to all examples
Some examples have been failing to load in some browsers, and this
ensures that whenever the promise to load Rust code fails we log any
errors happening instead of accidentally failing silently.

This helped debug a bit in #897
2018-09-28 13:55:07 -07:00
Alex Crichton
35a7233101
Merge pull request #891 from alexcrichton/rustfmt
cargo +nightly fmt --all
2018-09-26 14:20:33 -05:00
Nick Fitzgerald
826619870f examples(webaudio): allow turning the noise off again 2018-09-26 10:37:12 -07:00
Alex Crichton
7ecf4aae87 cargo +nightly fmt --all
Rustfmt all the things!
2018-09-26 08:26:00 -07:00
Cameron Taggart
052b41b84c update to "webpack-cli": "^3.1.1" 2018-09-25 18:50:27 -07:00
Nick Fitzgerald
ee0e4bc089
Merge pull request #887 from fitzgen/iterating-over-js-values
Iterating over js values
2018-09-25 16:04:50 -07:00
Nick Fitzgerald
e3d2ea2628 js-sys: Catch exceptions thrown in Reflect APIs
Proxies passed to Reflect APIs can throw for any of these operations and it is a
bit of a mess.
2018-09-25 14:30:26 -07:00
Alex Crichton
9b99ebfc87
Merge pull request #886 from alexcrichton/tweak-features
Update and improve crate features in `web-sys`
2018-09-25 12:26:45 -07:00
Alex Crichton
97cceebe7e Update and improve crate features in web-sys
* Regenerate the list of features for the crate given recent
  improvements, enabling some more types to be bound.
* Add feature gates for the `css` and `console` namespaces (modules),
  gating the APIs by default. Now `web_sys` has zero APIs unless they're
  requested.
* Improved the "required feature" documentation for `struct` types to
  not list parent classes and mention just the `struct` type instead.
2018-09-25 11:27:22 -07:00
Alex Crichton
7b495468f6 Implement support for Uint8ClampedArray
This commit implements support for binding APIs that take
`Uint8ClampedArray` in JS. This is pretty rare but comes up in a
`web-sys` binding or two, and we're now able to bind these APIs instead
of having to omit the bindings.

The `Uint8ClampedArray` type is bound by using the `Clamped` marker
struct in Rust. For example this is declaring a JS API that takes
`Uint8ClampedArray`:

    use wasm_bindgen::Clamped;

    #[wasm_bindgen]
    extern {
        fn takes_clamped(a: Clamped<&[u8]>);
    }

The `Clamped` type currently only works when wrapping the `&[u8]`, `&mut
[u8]`, and `Vec<u8>` types. Everything else will produce an error at
`wasm-bindgen` time.

Closes #421
2018-09-24 13:58:37 -07:00
Alex Crichton
e353c1cf6f Build examples and deploy to gh-pages
Rejigger Travis slightly to take advantage of build stages to build the
`gh-pages` branch amongst a set of builders, and then when they're all
done we synchronize and deploy the site. For now use S3 as a backing
store for data between jobs.
2018-09-20 20:55:02 -07:00
Alex Crichton
3efe51eb8b Reorganize and rewrite examples
This commit is a large-ish scale reorganization of our examples. The
main goal here is to have a dedicated section of the guide for example,
and all examples will be listed there. Each example's `README` is now
just boilerplate pointing at the guide along with a blurb about how to
run it.

Some examples like `math` and `smorgasboard` have been deleted as they
didn't really serve much purpose, and others like `closures` have been
rewritten with `web-sys` instead of hand-bound bindings.

Overall it's hoped that this puts us in a good and consistent state for
our examples, with all of them being described in the guide, excerpts
are in the guide, and they're all relatively idiomatically using
`web-sys`.
2018-09-20 16:45:30 -07:00
Nick Fitzgerald
5a267d109a examples(webgl): run rustfmt 2018-09-19 13:19:41 -07:00
Nick Fitzgerald
0c41c0b432 examples(webgl): stop using old window static methods
These were removed and replaced with normal methods on window and a standalone
function to get the global window.
2018-09-19 13:18:48 -07:00
Alex Crichton
4ca187cc2b
Merge pull request #835 from blm768/webgl-example
Create basic WebGL example
2018-09-19 11:56:43 -07:00
Alex Crichton
5832ff3ca1
Merge pull request #847 from alexcrichton/fix-window
Move all methods on `Window` back to methods
2018-09-18 16:59:46 -07:00
Ben Merritt
426671d83c Create basic WebGL example 2018-09-17 20:59:26 -07:00
Alex Crichton
285c734a6a Fix an example on nightly 2018-09-17 18:35:41 -07:00
Alex Crichton
4ea5d701bb Tweak package.json for fetch example 2018-09-17 17:38:07 -07:00
Alex Crichton
f24828a16b Add a top-level web_sys::window function
Returns `Option<Window>` and can be used as a convenience to get a handle to the
global `window` object.
2018-09-17 17:36:53 -07:00
Anton Danilkin
b9cc8e1270 Use Cell instead of RefCell 2018-09-13 03:38:22 +03:00
Anton Danilkin
62b04e44c4 Add paint example 2018-09-13 02:10:36 +03:00
Nick Fitzgerald
4e86ecd2c5
Merge pull request #813 from fitzgen/duck-typed-interfaces
Duck typed interfaces
2018-09-12 11:20:26 -07:00