Windows-rs: Cross-compiling from Linux results in: "No `windir` environment variable found

Created on 16 May 2020  ·  3Comments  ·  Source: microsoft/windows-rs

I'm on x86_64 Manjaro running Rust trying to build this library. It'd be helpful to know what targets (as defined by Rust) are supported. I'm trying to compile for x86_64-pc-windows-gnu (x86_64-pc-windows-msvc has the same error):

$ cargo build --features win_rt --target x86_64-pc-windows-gnu
   Compiling serialport v3.3.1-alpha.0 (/home/susurrus/Projects/serialport-rs)
error: proc macro panicked
  --> src/windows/winrt.rs:12:1
   |
12 | / import!(
13 | |     dependencies
14 | |     os
15 | |     modules
...  |
18 | |         "windows.storage.streams"
19 | | );
   | |__^
   |
   = help: message: No `windir` environment variable found

error: aborting due to previous error

error: could not compile `serialport`.

To learn more, run the command again with --verbose.

Most helpful comment

The code itself is portable. We have had versions of WinRT support written in C++ that run on Linux. But as Robert points out, metadata is required to describe available APIs and certain PAL functions are required for loading libraries. So we could support this in future, but it is not an immediate goal. If this is something that folks would like to do, feel free to chime in on this issue and let us know.

All 3 comments

In order to generate the projection, the metadata files that define the WinRT API surface are required. Normally on a Windows installation, you can find these metadata files in a directory like C:\Windows\System32\WinMetadata. Since Windows isn't necessarily always installed to the C drive, the %windir% environment variable is used. You can also get the metadata through the Windows SDK or packaged inside of 3rd party components like the Win2D nuget package (although that metadata will only contain the metadata for the Win2D API). Currently the metadata is taken from the operating system and recently from nuget (see #93).

For your situation, I'm not sure what's the best way forward, as you also need other libs. In order for the projection to work, it needs to be able to call into RoGetActivationFactory and other functions found in the onecore lib found in the Windows SDK.

If you can define a windir environment variable that will point to the correct metadata and provide the required libs, then you might be able to get this to work. No promises though, I don't think any of us have tried this on any of the Linux distros yet.

At the moment only *-windows-msvc is supported, (see #142).

The code itself is portable. We have had versions of WinRT support written in C++ that run on Linux. But as Robert points out, metadata is required to describe available APIs and certain PAL functions are required for loading libraries. So we could support this in future, but it is not an immediate goal. If this is something that folks would like to do, feel free to chime in on this issue and let us know.

Okay, thanks for clarifying that. Would it be possible to add that info to the README? Definitely wasn't clear that this only supports building on Windows.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kennykerr picture kennykerr  ·  5Comments

tim-weis picture tim-weis  ·  3Comments

Zymlex picture Zymlex  ·  3Comments

rylev picture rylev  ·  5Comments

ctaggart picture ctaggart  ·  4Comments