Skip to content

Commit 3f4acc4

Browse files
Pauanalexcrichton
andauthored
Dramatically improving the build time of web-sys (#2012)
* Pre-generating web-sys * Fixing build errors * Minor refactor for the unit tests * Changing to generate #[wasm_bindgen} annotations * Fixing code generation * Adding in main bin to wasm-bindgen-webidl * Fixing more problems * Adding in support for unstable APIs * Fixing bug with code generation * More code generation fixes * Improving the webidl program * Removing unnecessary cfg from the generated code * Splitting doc comments onto separate lines * Improving the generation for unstable features * Adding in support for string values in enums * Now runs rustfmt on the mod.rs file * Fixing codegen for constructors * Fixing webidl-tests * Fixing build errors * Another fix for build errors * Renaming typescript_name to typescript_type * Adding in docs for typescript_type * Adding in CI script to verify that web-sys is up to date * Fixing CI script * Fixing CI script * Don't suppress git diff output * Remove duplicate definitions of `Location` Looks to be a preexisting bug in wasm-bindgen? * Regenerate webidl * Try to get the git diff command right * Handle named constructors in WebIDL * Remove stray rustfmt.toml * Add back NamedConstructorBar definition in tests * Run stable rustfmt over everything * Don't run Cargo in a build script Instead refactor things so webidl-tests can use the Rust-code-generation as a library in a build script. Also fixes `cargo fmt` in the repository. * Fixup generated code * Running web-sys checks on stable * Improving the code generation a little * Running rustfmt Co-authored-by: Alex Crichton <[email protected]>
1 parent eb04cf2 commit 3f4acc4

File tree

1,344 files changed

+142082
-2883
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,344 files changed

+142082
-2883
lines changed

azure-pipelines.yml

+7
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ jobs:
114114
env:
115115
RUSTFLAGS: --cfg=web_sys_unstable_apis
116116

117+
- job: check_web_sys
118+
displayName: "Verify that web-sys is compiled correctly"
119+
steps:
120+
- template: ci/azure-install-rust.yml
121+
- script: cd crates/web-sys && cargo run --release --package wasm-bindgen-webidl webidls src/features
122+
- script: git diff --exit-code
123+
117124
- job: test_js_sys
118125
displayName: "Run js-sys crate tests"
119126
steps:

crates/backend/src/ast.rs

+13-59
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,24 @@ pub struct Program {
1717
pub enums: Vec<Enum>,
1818
/// rust structs
1919
pub structs: Vec<Struct>,
20-
/// rust consts
21-
pub consts: Vec<Const>,
22-
/// "dictionaries", generated for WebIDL, which are basically just "typed
23-
/// objects" in the sense that they represent a JS object with a particular
24-
/// shape in JIT parlance.
25-
pub dictionaries: Vec<Dictionary>,
2620
/// custom typescript sections to be included in the definition file
2721
pub typescript_custom_sections: Vec<String>,
2822
/// Inline JS snippets
2923
pub inline_js: Vec<String>,
3024
}
3125

26+
impl Program {
27+
/// Returns true if the Program is empty
28+
pub fn is_empty(&self) -> bool {
29+
self.exports.is_empty()
30+
&& self.imports.is_empty()
31+
&& self.enums.is_empty()
32+
&& self.structs.is_empty()
33+
&& self.typescript_custom_sections.is_empty()
34+
&& self.inline_js.is_empty()
35+
}
36+
}
37+
3238
/// A rust to js interface. Allows interaction with rust objects/functions
3339
/// from javascript.
3440
#[cfg_attr(feature = "extra-traits", derive(Debug))]
@@ -51,8 +57,6 @@ pub struct Export {
5157
/// Whether or not this function should be flagged as the wasm start
5258
/// function.
5359
pub start: bool,
54-
/// Whether the API is unstable. This is only used internally.
55-
pub unstable_api: bool,
5660
}
5761

5862
/// The 3 types variations of `self`.
@@ -73,7 +77,6 @@ pub struct Import {
7377
pub module: ImportModule,
7478
pub js_namespace: Option<Ident>,
7579
pub kind: ImportKind,
76-
pub unstable_api: bool,
7780
}
7881

7982
#[cfg_attr(feature = "extra-traits", derive(Debug))]
@@ -129,7 +132,6 @@ pub struct ImportFunction {
129132
pub kind: ImportFunctionKind,
130133
pub shim: Ident,
131134
pub doc_comment: Option<String>,
132-
pub unstable_api: bool,
133135
}
134136

135137
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
@@ -185,8 +187,7 @@ pub struct ImportType {
185187
pub rust_name: Ident,
186188
pub js_name: String,
187189
pub attrs: Vec<syn::Attribute>,
188-
pub typescript_name: Option<String>,
189-
pub unstable_api: bool,
190+
pub typescript_type: Option<String>,
190191
pub doc_comment: Option<String>,
191192
pub instanceof_shim: String,
192193
pub is_type_of: Option<syn::Expr>,
@@ -207,8 +208,6 @@ pub struct ImportEnum {
207208
pub variant_values: Vec<String>,
208209
/// Attributes to apply to the Rust enum
209210
pub rust_attrs: Vec<syn::Attribute>,
210-
/// Whether the enum is part of an unstable WebIDL
211-
pub unstable_api: bool,
212211
}
213212

214213
#[cfg_attr(feature = "extra-traits", derive(Debug))]
@@ -244,7 +243,6 @@ pub struct StructField {
244243
pub getter: Ident,
245244
pub setter: Ident,
246245
pub comments: Vec<String>,
247-
pub unstable_api: bool,
248246
}
249247

250248
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
@@ -254,7 +252,6 @@ pub struct Enum {
254252
pub variants: Vec<Variant>,
255253
pub comments: Vec<String>,
256254
pub hole: u32,
257-
pub unstable_api: bool,
258255
}
259256

260257
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
@@ -279,49 +276,6 @@ pub enum TypeLocation {
279276
ExportRet,
280277
}
281278

282-
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq))]
283-
#[derive(Clone)]
284-
pub struct Const {
285-
pub vis: syn::Visibility,
286-
pub name: Ident,
287-
pub class: Option<Ident>,
288-
pub ty: syn::Type,
289-
pub value: ConstValue,
290-
pub unstable_api: bool,
291-
}
292-
293-
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq))]
294-
#[derive(Clone)]
295-
/// same as webidl::ast::ConstValue
296-
pub enum ConstValue {
297-
BooleanLiteral(bool),
298-
FloatLiteral(f64),
299-
SignedIntegerLiteral(i64),
300-
UnsignedIntegerLiteral(u64),
301-
Null,
302-
}
303-
304-
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
305-
#[derive(Clone)]
306-
pub struct Dictionary {
307-
pub name: Ident,
308-
pub fields: Vec<DictionaryField>,
309-
pub ctor: bool,
310-
pub doc_comment: Option<String>,
311-
pub ctor_doc_comment: Option<String>,
312-
pub unstable_api: bool,
313-
}
314-
315-
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
316-
#[derive(Clone)]
317-
pub struct DictionaryField {
318-
pub rust_name: Ident,
319-
pub js_name: String,
320-
pub required: bool,
321-
pub ty: syn::Type,
322-
pub doc_comment: Option<String>,
323-
}
324-
325279
impl Export {
326280
/// Mangles a rust -> javascript export, so that the created Ident will be unique over function
327281
/// name and class name, if the function belongs to a javascript class.

0 commit comments

Comments
 (0)