gentoo90 / winreg-rs

Rust bindings to MS Windows Registry API
MIT License
168 stars 36 forks source link

Make the crate empty on non-windows targets #37

Closed roblabla closed 4 years ago

roblabla commented 4 years ago

This makes it easier to use as a target-specific bulid-dependency. On any non-windows targets, the crate will simply become an empty crate, instead of causing compilation errors.

gentoo90 commented 4 years ago

There is [target.*.dependencies] syntax:

[target.'cfg(windows)'.dependencies]
winreg = "0.7"

which provides clear distinction between universal and platform-specific dependencies. Why do you think an empty crate is better? I'd say it's confusing. And even with it you will still have to write #![cfg(windows)] in the dependant crate whenever you want to actually use something from winreg.

roblabla commented 4 years ago

Correct me if I'm wrong, but I don't think this syntax works for build dependencies, which is how I'm using winreg. I have a build script similar to this one that uses winreg to find the install location of the Windows Driver Kit when on windows, but I want it to still build on linux (using another mechanism to locate the WDK installation), in an attempt to support cross-compilation.

The idea is that, in the build script, I could have a #[cfg(windows)] function using winreg, and a #[cfg(not(windows))] function using an environment variable to locate the WDK.

Furthermore, winapi follows the same pattern, and so do many other crates.

gentoo90 commented 4 years ago

[target.'cfg(windows)'.build-dependencies] seems to work. Could you check that one out?

Yes, I know about winapi and others using empty crate pattern. cfg dependencies were introduced in 1.8 and winapi is older then that, so they probably introduced it earlier and just keep it for backward compatibility.

roblabla commented 4 years ago

Huh, my bad. I must have typo'd something when I tested this yesterday ^^'. Thanks for the help, and sorry for the noise!