Skip to content

Commit 6e09815

Browse files
Fixed webidl output formatting on Windows (#4335)
1 parent 04ca6f3 commit 6e09815

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

crates/web-sys/README.md

-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ If you don't see a particular web API in `web-sys`, here is how to add it.
3232
2. Annotate the functions that can throw with `[Throws]`
3333
3. `cd crates/web-sys`
3434
4. Run `cargo run --release --package wasm-bindgen-webidl -- webidls src/features ./Cargo.toml`
35-
36-
If formatting fails, you can run `cargo fmt` in the `crates/web-sys` directory. On Windows, you might also want to run `cargo fmt -- --config newline_style=Unix` depending on your git configuration.
37-
3835
5. Run `git add .` to add all the generated files into git.
3936
6. Add an entry in CHANGELOG.md like the following
4037

crates/webidl/src/lib.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -997,14 +997,21 @@ pub fn generate(from: &Path, to: &Path, options: Options) -> Result<String> {
997997

998998
fn rustfmt(paths: impl IntoIterator<Item = PathBuf>) -> Result<()> {
999999
// run rustfmt on the generated file - really handy for debugging
1000-
let result = Command::new("rustfmt")
1001-
.arg("--edition")
1002-
.arg("2021")
1003-
.args(paths)
1004-
.status()
1005-
.context("rustfmt failed")?;
1006-
1007-
assert!(result.success(), "rustfmt failed");
1000+
1001+
// On Windows, the command line length is limited to 32k characters, so
1002+
// we need to split the command into multiple invocations. I've
1003+
// arbitrarily chosen to format 400 files at a time, because it works.
1004+
let paths: Vec<_> = paths.into_iter().collect();
1005+
for chunk in paths.chunks(400) {
1006+
let result = Command::new("rustfmt")
1007+
.arg("--edition")
1008+
.arg("2021")
1009+
.args(chunk)
1010+
.status()
1011+
.context("rustfmt failed")?;
1012+
1013+
assert!(result.success(), "rustfmt failed");
1014+
}
10081015

10091016
Ok(())
10101017
}

0 commit comments

Comments
 (0)