Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed build on Windows even it is specifically not dependent #68

Closed
AkinoKaede opened this issue Aug 18, 2024 · 2 comments
Closed

Failed build on Windows even it is specifically not dependent #68

AkinoKaede opened this issue Aug 18, 2024 · 2 comments

Comments

@AkinoKaede
Copy link

AkinoKaede commented Aug 18, 2024

I know this package cannot support Windows. So I require it in Cargo.toml by:

[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "linux", target_os = "android"))'.dependencies]
sysctl = "0.5.5"

I think it's follow The Cargo Book.

But when I build on Windows, I got this error:

   Compiling sysctl v0.5.5
error[E0433]: failed to resolve: maybe a missing crate `sys`?
Error:   --> C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sysctl-0.5.5\src\lib.rs:77:9
   |
77 | pub use sys::ctl::*;
   |         ^^^ maybe a missing crate `sys`?
   |
   = help: consider adding `extern crate sys` to use the `sys` crate

error[E0433]: failed to resolve: maybe a missing crate `sys`?
Error:   --> C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sysctl-0.5.5\src\lib.rs:78:9
   |
78 | pub use sys::ctl_iter::*;
   |         ^^^ maybe a missing crate `sys`?
   |
   = help: consider adding `extern crate sys` to use the `sys` crate

error[E0432]: unresolved imports `sys::ctl::*`, `sys::ctl_iter::*`
Error:   --> C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sysctl-0.5.5\src\lib.rs:77:9
   |
77 | pub use sys::ctl::*;
   |         ^^^^^^^^^^^
78 | pub use sys::ctl_iter::*;
   |         ^^^^^^^^^^^^^^^^

Some errors have detailed explanations: E0432, E0433.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `sysctl` (lib) due to 3 previous errors

It's seems a bug of Cargo, but it has not been solved for a long time.
rust-lang/cargo#10801

I think we should add some platform-specific conditional compilation before imports for workaround, like:

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd",
    target_os = "linux", target_os = "android"))]
pub use sys::ctl::*;
pub use sys::ctl_iter::*;
@AkinoKaede AkinoKaede closed this as not planned Won't fix, can't repro, duplicate, stale Aug 18, 2024
@AkinoKaede
Copy link
Author

My bad, I mistakenly added a dependency to a crate that didn't need systcl for all targets.

@orhun
Copy link

orhun commented Aug 18, 2024

Just a comment, maybe using not(target_os = "windows") would be cleaner in your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants