mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-11-28 14:27:36 +03:00
269c491380
* Gate `web-sys` APIs on activated features Currently the compile times of `web-sys` are unfortunately prohibitive, increasing the barrier to using it. This commit updates the crate to instead have all APIs gated by a set of Cargo features which affect what bindings are generated at compile time (and which are then compiled by rustc). It's significantly faster to activate only a handful of features vs all thousand of them! A magical env var is added to print the list of all features that should be generated, and then necessary logic is added to ferry features from the build script to the webidl crate which then uses that as a filter to remove items after parsing. Currently parsing is pretty speedy so we'll unconditionally parse all WebIDL files, but this may change in the future! For now this will make the `web-sys` crate a bit less ergonomic to use as lots of features will need to be specified, but it should make it much more approachable in terms of first-user experience with compile times. * Fix AppVeyor testing web-sys * FIx a typo * Udpate feature listings from rebase conflicts * Add some crate docs and such |
||
---|---|---|
.. | ||
add | ||
asm.js | ||
canvas | ||
char | ||
closures | ||
comments | ||
console_log | ||
dom | ||
fetch | ||
guide-supported-types-examples | ||
hello_world | ||
import_js | ||
julia_set | ||
math | ||
no_modules | ||
performance | ||
smorgasboard | ||
wasm-in-wasm | ||
webaudio | ||
README.md |
Examples
This directory contains a number of examples of the #[wasm_bindgen]
macro and
how to display them in the browser. Each directory contains a README with a link
to https://webassembly.studio so you can also explore the example online
(apologies if they're out of sync!), and each directory also contains a
build.sh
which assembles all the relevant files locally. If you open up
index.html
in a web browser you should be able to see everything in action
when using build.sh
!
The examples here are:
add
- an example of generating a tiny wasm binary, one that only adds two numbers.asm.js
- an example of using thewasm2js
tool from binaryen to convert the generated WebAssembly to normal JSchar
- an example of passing the rustchar
type to and from the jsstring
typeclosures
- an example of how to invoke functions likesetInterval
or use theonclick
property in conjunction with closures.comments
- an example of how Rust comments are copied into js bindingsconsole_log
- a showcase of#[wasm_bindgen]
importing classes and how to bindconsole.log
dom
- an example of accessing the globaldocument
object and appending HTML to itfetch
-- how to use the Fetch API to make async http requestshello_world
- the "hello world" of#[wasm_bindgen]
, aka throwing up a dialog greeting youimport_js
- an example of importing local JS functionality into a cratemath
- likeconsole_log
except showing how to import Math-related functions insteadno_modules
- an example of how to use the--no-modules
flag to thewasm-bindgen
CLI toolperformance
- how to import APIs likeperformance.now()
and time various operations in Rustsmorgasboard
- a bunch of features all thrown into one, showing off the various capabilities of the#[wasm_bindgen]
macro and what you can do with it from JSwasm-in-wasm
- how to interact with namespaced APIs likeWebAssembly.Module
and shows off creation of a WebAssembly module from Rustwebaudio
- how to use the Web Audio APIs to generate sounds