microsoft / windows-rs

Rust for Windows
https://kennykerr.ca/rust-getting-started/
Apache License 2.0
10.1k stars 473 forks source link

Don't compile `windows` and `windows-sys` in unit test mode #3112

Closed sivadeilra closed 2 weeks ago

sivadeilra commented 2 weeks ago

This PR improves cycle time for running cargo test --all.

The windows and windows-sys crates do not contain unit tests or doc tests. Cargo doesn't know that, so it compiles these two very large crates in the #[cfg(test)] mode and wastes time scanning for doc tests.

This PR simply disables unit tests and doc tests in both of these crates. This saves a significant amount of time in running tests.

kennykerr commented 2 weeks ago

Should we be seeing a reduction here? https://github.com/microsoft/windows-rs/actions/workflows/test.yml

sivadeilra commented 2 weeks ago

Should we be seeing a reduction here? https://github.com/microsoft/windows-rs/actions/workflows/test.yml

I certainly see a reduction locally.

kennykerr commented 2 weeks ago

Can you illustrate? I just don't see cargo test doing much for the windows crate unless you explicitly add --all-features.

sivadeilra commented 2 weeks ago

Can you illustrate? I just don't see cargo test doing much for the windows crate unless you explicitly add --all-features.

What I see happening is that we spend a bunch of time compiling the windows crate in test mode, even though it doesn't contain any tests. Then we "run" it and of course that takes no time, but we spent a long time compiling a useless executable.

I see this happening when I run cargo test from the repo root. When you run cargo test directly on the windows crate you won't see it because no features are activated.

kennykerr commented 2 weeks ago

Ah, strangely this affects 'cargo test' but not 'cargo test --all' which is what I've trained myself to do. 🤷‍♂️