Hi, I am attempting to port my code from the winapi crate to the windows bindings, and I am hitting a road block where VS Code stops being able to use the language service when I integrate the windows crate.
Steps to reproduce:
cargo new windows-vscode-test.rs files)This happens whether or not there's a build.rs, and with a bog standard "hello world" main.rs. The Problems tab simply says "Cargo.toml: failed to run custom build command for windows v0.3.1":
{
"resource": "/c:/dev/windows-vscode-test/Cargo.toml",
"owner": "rust-file:///c%3A/dev/windows-vscode-test",
"severity": 8,
"message": "failed to run custom build command for `windows v0.3.1`",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 10000,
"endColumn": 1
}
Running cargo build completes as expected with no errors.
Minimal Cargo.toml:
[package]
name = "windows-vscode-test"
version = "0.1.0"
authors = ["J酶rgen P. Tjern酶 <[email protected]>"]
edition = "2018"
[dependencies]
windows = "0.3.1"
[build-dependencies]
windows = "0.3.1"
This was tested with Visual Studio Code v1.53.1 on Windows 10, Rust extension v0.7.8, rustc 1.49.0.
If I turn on "Rust-client: Log To File" in the Rust extension settings, I find the following in the generated log file:
{"message":"proc macro panicked","code":null,"level":"error","spans":[{"file_name":"C:\\Users\\jorgenpt\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\windows-0.3.1\\build.rs","byte_start":16,"byte_end":41,"line_start":2,"line_end":2,"column_start":5,"column_end":30,"is_primary":true,"text":[{"text":" windows_macros::build!();","highlight_start":5,"highlight_end":30}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"message: Cargo metadata did not contain `workspace_root` key.","code":null,"level":"help","spans":[],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[38;5;9merror\u001b[0m\u001b[0m\u001b[1m\u001b[38;5;15m: proc macro panicked\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;14m--> \u001b[0m\u001b[0mC:\\Users\\jorgenpt\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\windows-0.3.1\\build.rs:2:5\u001b[0m\n\u001b[0m
\u001b[0m\u001b[0m\u001b[1m\u001b[38;5;14m|\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;14m2\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;14m| \u001b[0m\u001b[0m windows_macros::build!();\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;14m| \u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;9m^^^^^^^^^^^^^^^^^^^^^^^^^\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;14m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;14m= \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;15mhelp\u001b[0m\u001b[0m: message: Cargo metadata did not contain `workspace_root` key.\u001b[0m\n\n"}
{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[38;5;9merror\u001b[0m\u001b[0m\u001b[1m\u001b[38;5;15m: aborting due to previous error\u001b[0m\n\n"}
Is there any other information I can provide to help debug this issue?
I don't know anything about this extension, but might I suggest you open an issue on their repo: https://github.com/rust-lang/vscode-rust
Also, I have been told that the rust-analyzer extension is preferred and it does appear to work more reliably in my limited experience.
I helped @jorgenpt set up rust-analyzer and they have windows-rs working successfully now.
Thanks Joshua!
Yep, I switched to the rust-analyzer plugin, and I had to manually enable "Load Out Dirs From Check" for it to be compatible with windows-rs (but the Problems window did direct me in that general direction). Thanks to both of you for your assistance!
Yes, I wish that option were enabled by default. Glad you're up and running!
Yes, I wish that option were enabled by default. Glad you're up and running!
Most helpful comment
https://github.com/rust-analyzer/rust-analyzer/issues/7328