Skip to content

Commit b7f337e

Browse files
committed
Replace windows-sys with a dummy crate in the library workspace
This reduces the vendor size of the standard library from 37MB to 20MB.
1 parent 2347dc4 commit b7f337e

5 files changed

Lines changed: 23 additions & 14 deletions

File tree

library/Cargo.lock

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ dependencies = [
347347
"wasip1",
348348
"wasip2",
349349
"wasip3",
350-
"windows-link 0.0.0",
350+
"windows-link",
351351
]
352352

353353
[[package]]
@@ -443,20 +443,9 @@ dependencies = [
443443
name = "windows-link"
444444
version = "0.0.0"
445445

446-
[[package]]
447-
name = "windows-link"
448-
version = "0.2.1"
449-
source = "registry+https://github.com/rust-lang/crates.io-index"
450-
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
451-
452446
[[package]]
453447
name = "windows-sys"
454-
version = "0.61.2"
455-
source = "registry+https://github.com/rust-lang/crates.io-index"
456-
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
457-
dependencies = [
458-
"windows-link 0.2.1",
459-
]
448+
version = "0.61.100"
460449

461450
[[package]]
462451
name = "wit-bindgen"

library/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,6 @@ rustflags = [
8585
rustc-std-workspace-core = { path = 'rustc-std-workspace-core' }
8686
rustc-std-workspace-alloc = { path = 'rustc-std-workspace-alloc' }
8787
rustc-std-workspace-std = { path = 'rustc-std-workspace-std' }
88+
89+
# See comments in `library/windows-sys/Cargo.toml` for why this is patched
90+
windows-sys = { path = 'windows-sys' }

library/windows-sys/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# dlmalloc has a dependency on windows-sys for when it gets compiled for Windows.
2+
# std however never actually uses dlmalloc on Windows. As dlmalloc is the only
3+
# user of windows-sys in the standard library, the windows-sys crate unnecessarily
4+
# increases the size of the vendored crates. By replacing it with an empty crate
5+
# we save about 19MB.
6+
7+
[package]
8+
name = "windows-sys"
9+
version = "0.61.100"
10+
edition = "2024"
11+
12+
[features]
13+
Win32_Foundation = []
14+
Win32_System_Memory = []
15+
Win32_System_Threading = []
16+
Win32_System_SystemInformation = []

library/windows-sys/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
compile_error!("This crate should never be compiled");

src/tools/tidy/src/deps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ const PERMITTED_STDLIB_DEPENDENCIES: &[&str] = &[
543543
"wasip2",
544544
"wasip3",
545545
"windows-link",
546-
"windows-sys",
546+
"windows-sys@0.61.100", // Enforce the usage of our dummy windows-sys patch. Keep version in sync.
547547
"wit-bindgen",
548548
// tidy-alphabetical-end
549549
];

0 commit comments

Comments
 (0)