Skip to content

Commit 99c59a7

Browse files
authored
[WIP] Add support for unstable WebIDL (#1997)
* Re-enable WebGPU WebIDL as experimental * Add `web_sys_unstable_apis` attribute * Add test for unstable WebIDL * Include unstable WebIDL in docs.rs builds * Add docs and doc comment for unstable APIs * Add unstable API checks to CI
1 parent d26068d commit 99c59a7

File tree

24 files changed

+1387
-792
lines changed

24 files changed

+1387
-792
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Easy support for interacting between JS and Rust.
1414
edition = "2018"
1515

1616
[package.metadata.docs.rs]
17-
features = ['serde-serialize']
17+
features = ["serde-serialize"]
18+
rustc-args = ["--cfg=web_sys_unstable_apis"]
1819

1920
[lib]
2021
test = false

azure-pipelines.yml

+10
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ jobs:
122122
- script: cargo build --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --features Element
123123
- script: cargo build --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --features Window
124124
- script: cargo test --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --all-features
125+
- script: cargo test --manifest-path crates/web-sys/Cargo.toml --target wasm32-unknown-unknown --all-features
126+
displayName: "web-sys unstable APIs"
127+
env:
128+
RUSTFLAGS: --cfg=web_sys_unstable_apis
125129

126130
- job: test_js_sys
127131
displayName: "Run js-sys crate tests"
@@ -150,6 +154,10 @@ jobs:
150154
- script: cargo test -p webidl-tests --target wasm32-unknown-unknown
151155
env:
152156
WBINDGEN_I_PROMISE_JS_SYNTAX_WORKS_IN_NODE: 1
157+
- script: cargo test -p webidl-tests --target wasm32-unknown-unknown
158+
displayName: "webidl-tests unstable APIs"
159+
env:
160+
RUSTFLAGS: --cfg=web_sys_unstable_apis
153161

154162
- job: test_ui
155163
displayName: "Run UI tests"
@@ -319,6 +327,8 @@ jobs:
319327
displayName: "Document js-sys"
320328
- script: cargo doc --no-deps --manifest-path crates/web-sys/Cargo.toml --all-features
321329
displayName: "Document web-sys"
330+
env:
331+
RUSTFLAGS: --cfg=web_sys_unstable_apis
322332
- script: cargo doc --no-deps --manifest-path crates/futures/Cargo.toml
323333
displayName: "Document wasm-bindgen-futures"
324334
# Make a tarball even though a zip is uploaded, it looks like the tarball

crates/backend/src/ast.rs

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ pub struct Export {
5151
/// Whether or not this function should be flagged as the wasm start
5252
/// function.
5353
pub start: bool,
54+
/// Whether the API is unstable. This is only used internally.
55+
pub unstable_api: bool,
5456
}
5557

5658
/// The 3 types variations of `self`.
@@ -71,6 +73,7 @@ pub struct Import {
7173
pub module: ImportModule,
7274
pub js_namespace: Option<Ident>,
7375
pub kind: ImportKind,
76+
pub unstable_api: bool,
7477
}
7578

7679
#[cfg_attr(feature = "extra-traits", derive(Debug))]
@@ -126,6 +129,7 @@ pub struct ImportFunction {
126129
pub kind: ImportFunctionKind,
127130
pub shim: Ident,
128131
pub doc_comment: Option<String>,
132+
pub unstable_api: bool,
129133
}
130134

131135
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
@@ -182,6 +186,7 @@ pub struct ImportType {
182186
pub js_name: String,
183187
pub attrs: Vec<syn::Attribute>,
184188
pub typescript_name: Option<String>,
189+
pub unstable_api: bool,
185190
pub doc_comment: Option<String>,
186191
pub instanceof_shim: String,
187192
pub is_type_of: Option<syn::Expr>,
@@ -202,6 +207,8 @@ pub struct ImportEnum {
202207
pub variant_values: Vec<String>,
203208
/// Attributes to apply to the Rust enum
204209
pub rust_attrs: Vec<syn::Attribute>,
210+
/// Whether the enum is part of an unstable WebIDL
211+
pub unstable_api: bool,
205212
}
206213

207214
#[cfg_attr(feature = "extra-traits", derive(Debug))]
@@ -237,6 +244,7 @@ pub struct StructField {
237244
pub getter: Ident,
238245
pub setter: Ident,
239246
pub comments: Vec<String>,
247+
pub unstable_api: bool,
240248
}
241249

242250
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
@@ -246,6 +254,7 @@ pub struct Enum {
246254
pub variants: Vec<Variant>,
247255
pub comments: Vec<String>,
248256
pub hole: u32,
257+
pub unstable_api: bool,
249258
}
250259

251260
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]
@@ -278,6 +287,7 @@ pub struct Const {
278287
pub class: Option<Ident>,
279288
pub ty: syn::Type,
280289
pub value: ConstValue,
290+
pub unstable_api: bool,
281291
}
282292

283293
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq))]
@@ -299,6 +309,7 @@ pub struct Dictionary {
299309
pub ctor: bool,
300310
pub doc_comment: Option<String>,
301311
pub ctor_doc_comment: Option<String>,
312+
pub unstable_api: bool,
302313
}
303314

304315
#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq))]

0 commit comments

Comments
 (0)