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

Developing with windows crate on linux #3361

Closed
Libadoxon opened this issue Dec 5, 2024 · 9 comments
Closed

Developing with windows crate on linux #3361

Libadoxon opened this issue Dec 5, 2024 · 9 comments
Labels
question Further information is requested

Comments

@Libadoxon
Copy link

Summary

Using the feature Win32_Devices_DeviceAndDriverInstallation, which feature seach tells me to use, doesn't work as rust can't find the Win32 module. This is a regression and doesn't happen with 0.57.0.

Crate manifest

[package]
name = "ms-device-test"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0.94"
windows = { version = "0.57.0", features = [
  "Win32_Devices_DeviceAndDriverInstallation",
] }

Crate code

use windows::Win32::Devices::DeviceAndDriverInstallation::{
    SetupDiGetClassDevsA, DIGCF_DEVICEINTERFACE, DIGCF_PRESENT,
};

fn main() {
    let dev_info_set =
        unsafe { SetupDiGetClassDevsA(None, None, None, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE) };
}
@Libadoxon Libadoxon added the bug Something isn't working label Dec 5, 2024
@riverar riverar added question Further information is requested and removed bug Something isn't working labels Dec 5, 2024
@riverar
Copy link
Collaborator

riverar commented Dec 5, 2024

I upgraded your sample to 0.58.0 and it compiled fine. What are you seeing, exactly?

@Libadoxon
Copy link
Author

Running my code (with version 0.58.0, sry for copying the wrong version) fails with:

error[E0433]: failed to resolve: could not find `Win32` in `windows`
 --> src/main.rs:1:14
  |
1 | use windows::Win32::Devices::DeviceAndDriverInstallation::{
  |              ^^^^^ could not find `Win32` in `windows`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `ms-device-test` (bin "ms-device-test") due to 1 previous error

Using cargo version cargo 1.83.0 (5ffbef321 2024-10-29) installed using rustup toolchain install stable. When changing version to 0.57.0 (or lower) it finds the module. I'm on Linux, I'm not sure if this is important.

@riverar
Copy link
Collaborator

riverar commented Dec 5, 2024

Ah right, support for Linux (targets) changed as part of #3143 (additional discussion #3155 (comment)).

Unless you're working with DirectWrite Core or maybe DirectX Shader Compiler, I don't believe anything else is in scope from a support perspective. (Sorry!)

@Libadoxon
Copy link
Author

Well that's annoying, I really don't like the development experience on windows. I of course understand, that most of this crate only works on windows, but after 0.57.0 rust-analyzer is no longer able to see the semantics of the crate, which makes developing with it on Linux a lot harder. Is there some way to still see the semantics while on Linux?

@Libadoxon Libadoxon changed the title Rust doesn't find Win32 with Win32_Devices_DeviceAndDriverInstallation feature on 0.58.0 Developing with windows crate on linux Dec 6, 2024
@kennykerr
Copy link
Collaborator

You can cross-compile on Linux - e.g. compile with --target x86_64-pc-windows-gnu - this should work fine and tested as part of cross.yml.

What you can't do is target Linux, which doesn't make sense anyway since these are Windows operating system APIs.

@Libadoxon
Copy link
Author

I know but how can I make rust-analyzer see the semantics of the crate, to get auto completion and diagnostics?

@kennykerr
Copy link
Collaborator

That sounds like a good question for the rust-analyzer folks. Maybe open an issue on their repo. 🙂

@riverar
Copy link
Collaborator

riverar commented Dec 9, 2024

I think you want to set rust-analyzer.cargo.target (preference) to x86_64-pc-windows-gnu or the target you wish for it to use.

@Libadoxon
Copy link
Author

I fixed it by setting

[build]
target = "x86_64-pc-windows-gnu"

in .cargo/config.toml

Thx for the help

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

No branches or pull requests

3 participants