rust-lang / stdarch

Rust's standard library vendor-specific APIs and run-time feature detection
https://doc.rust-lang.org/stable/core/arch/
Apache License 2.0
598 stars 255 forks source link

std_detect: Don't unnecessarily depend on libc for windows-msvc #1563

Closed ChrisDenton closed 2 months ago

ChrisDenton commented 2 months ago

I'm trying to reduce std's dependency on libc when it isn't actually needed.

Currently std_detect depends on libc for these features: https://github.com/rust-lang/stdarch/blob/9814fb0ec86e12ca68a3999660cee9617e232651/crates/std_detect/Cargo.toml#L37-L39

However, for windows-msvc, the only feature actually using libc in std_detect is std_detect_env_override https://github.com/rust-lang/stdarch/blob/9814fb0ec86e12ca68a3999660cee9617e232651/crates/std_detect/src/detect/cache.rs#L120-L137

The easier way to address this issue is to make it so the on windows-msvc targets, libc is only used for this feature. The harder way is to use the Windows native equivalent of libc::getenv.

dpaoliello commented 2 months ago

@ChrisDenton getenv can be replaced with GetEnvironmentVariableA - would you be ok with a hand-coded binding, or would you want windows-rs pulled in so that the binding can be generated?

ChrisDenton commented 2 months ago

While this feature isn't enabled by our std builds, it could be, So a hand-coded binding would be better.

dpaoliello commented 2 months ago

While this feature isn't enabled by our std builds, it could be, So a hand-coded binding would be better.

Done: #1571