Gate web-sys APIs on activated features (#790)

* 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
This commit is contained in:
Alex Crichton
2018-09-05 12:55:30 -07:00
committed by GitHub
parent c6d3011cff
commit 269c491380
18 changed files with 1424 additions and 88 deletions

View File

@ -10,17 +10,10 @@ The `web-sys` crate has this file and directory layout:
├── src
│ └── lib.rs
└── webidls
├── available
│ └── ...
└── enabled
└── ...
```
### `webidls/available/*.webidl`
These are all the different WebIDL definitions we intend to support, but don't
yet. At the time of writing, these are the majority of `.webidl`s.
### `webidls/enabled/*.webidl`
These are the WebIDL interfaces that we will actually generate bindings for (or
@ -40,3 +33,12 @@ time in `build.rs`. Here is the whole `src/lib.rs` file:
```rust
{{#include ../../../crates/web-sys/src/lib.rs}}
```
### Cargo features
When compiled the crate is almost empty by default, which probably isn't what
you want! Due to the very large number of APIs, this crate uses features to
enable portions of its API to reduce compile times. The list of features in
`Cargo.toml` all correspond to types in the generated functions. Enabling a
feature enables that type. All methods should indicate what features need to be
activated to use the method.

View File

@ -5,8 +5,7 @@ You can test the `web-sys` crate by running `cargo test` within the
```sh
cd wasm-bindgen/crates/web-sys
cargo test
cargo test --target wasm32-unknown-unknown
cargo test --target wasm32-unknown-unknown --all-features
```
The Wasm tests all run within a headless browser. See [the `wasm-bindgen-test`