mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-24 21:52:13 +00:00
Making WebIDL generation deterministic (#2101)
* Making webidl generation deterministic * Fixing line endings * Regenerating WebIDL * Running rustfmt
This commit is contained in:
parent
7bc9147258
commit
a22bbca92c
@ -105,18 +105,6 @@ extern "C" {
|
||||
#[doc = "*This API requires the following crate features to be activated: `CredentialsContainer`, `Navigator`*"]
|
||||
pub fn credentials(this: &Navigator) -> CredentialsContainer;
|
||||
#[cfg(web_sys_unstable_apis)]
|
||||
#[cfg(feature = "Xr")]
|
||||
# [ wasm_bindgen ( structural , method , getter , js_class = "Navigator" , js_name = xr ) ]
|
||||
#[doc = "Getter for the `xr` field of this object."]
|
||||
#[doc = ""]
|
||||
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/xr)"]
|
||||
#[doc = ""]
|
||||
#[doc = "*This API requires the following crate features to be activated: `Navigator`, `Xr`*"]
|
||||
#[doc = ""]
|
||||
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
|
||||
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
|
||||
pub fn xr(this: &Navigator) -> Xr;
|
||||
#[cfg(web_sys_unstable_apis)]
|
||||
#[cfg(feature = "Gpu")]
|
||||
# [ wasm_bindgen ( structural , method , getter , js_class = "Navigator" , js_name = gpu ) ]
|
||||
#[doc = "Getter for the `gpu` field of this object."]
|
||||
@ -128,6 +116,18 @@ extern "C" {
|
||||
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
|
||||
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
|
||||
pub fn gpu(this: &Navigator) -> Gpu;
|
||||
#[cfg(web_sys_unstable_apis)]
|
||||
#[cfg(feature = "Xr")]
|
||||
# [ wasm_bindgen ( structural , method , getter , js_class = "Navigator" , js_name = xr ) ]
|
||||
#[doc = "Getter for the `xr` field of this object."]
|
||||
#[doc = ""]
|
||||
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/xr)"]
|
||||
#[doc = ""]
|
||||
#[doc = "*This API requires the following crate features to be activated: `Navigator`, `Xr`*"]
|
||||
#[doc = ""]
|
||||
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
|
||||
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
|
||||
pub fn xr(this: &Navigator) -> Xr;
|
||||
# [ wasm_bindgen ( structural , method , getter , js_class = "Navigator" , js_name = hardwareConcurrency ) ]
|
||||
#[doc = "Getter for the `hardwareConcurrency` field of this object."]
|
||||
#[doc = ""]
|
||||
|
@ -25,7 +25,7 @@ use crate::generator::{
|
||||
use crate::idl_type::ToIdlType;
|
||||
use crate::traverse::TraverseType;
|
||||
use crate::util::{
|
||||
camel_case_ident, is_structural, shouty_snake_case_ident, snake_case_ident, throws,
|
||||
camel_case_ident, is_structural, read_dir, shouty_snake_case_ident, snake_case_ident, throws,
|
||||
webidl_const_v_to_backend_const_v, TypePosition,
|
||||
};
|
||||
use anyhow::Context;
|
||||
@ -749,11 +749,9 @@ pub fn generate(from: &Path, to: &Path, options: Options) -> Result<String> {
|
||||
|
||||
/// Read all WebIDL files in a directory into a single `SourceFile`
|
||||
fn read_source_from_path(dir: &Path) -> Result<SourceFile> {
|
||||
let entries = fs::read_dir(dir).context("reading webidls directory")?;
|
||||
let entries = read_dir(dir).context("reading webidls directory")?;
|
||||
let mut source = SourceFile::default();
|
||||
for entry in entries {
|
||||
let entry = entry.context(format!("getting {}/*.webidl entry", dir.display()))?;
|
||||
let path = entry.path();
|
||||
for path in entries {
|
||||
if path.extension() != Some(OsStr::new("webidl")) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
use std::collections::BTreeSet;
|
||||
use std::fs;
|
||||
use std::iter::FromIterator;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::ptr;
|
||||
|
||||
use heck::{CamelCase, ShoutySnakeCase, SnakeCase};
|
||||
@ -23,6 +25,21 @@ use crate::Options;
|
||||
/// in their names, where `n` is this constant.
|
||||
const MAX_VARIADIC_ARGUMENTS_COUNT: usize = 7;
|
||||
|
||||
/// Similar to std::fs::read_dir except it returns a sorted Vec,
|
||||
/// which is important to make the code generation deterministic.
|
||||
pub(crate) fn read_dir<P>(path: P) -> std::io::Result<Vec<PathBuf>>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
let mut entries = fs::read_dir(path)?
|
||||
.map(|entry| Ok(entry?.path()))
|
||||
.collect::<std::io::Result<Vec<_>>>()?;
|
||||
|
||||
entries.sort();
|
||||
|
||||
Ok(entries)
|
||||
}
|
||||
|
||||
/// Take a type and create an immutable shared reference to that type.
|
||||
pub(crate) fn shared_ref(ty: syn::Type, mutable: bool) -> syn::Type {
|
||||
syn::TypeReference {
|
||||
|
Loading…
x
Reference in New Issue
Block a user