Windows-rs: Support architecture-specific builds

Created on 12 Jun 2021  路  3Comments  路  Source: microsoft/windows-rs

in ver.0.11.0: Windows::Win32::UI::Shell::NOTIFYICONDATAW is "#[repr(C, packed(1))]" so Shell_NotifyIconW fails

in ver.0.10.0: it is "#[repr(C)]", Shell_NotifyIconW goes OK

enhancement

Most helpful comment

The issue can be reproduced using the following:

Cargo.toml:

[package]
name = "shell_test"
version = "0.0.0"
edition = "2018"

[dependencies]
windows = "0.11.0"

[build-dependencies]
windows = "0.11.0"

build.rs:

fn main() {
    windows::build!(
        Windows::Win32::UI::Shell::NOTIFYICONDATAW,
    );
}

main.rs:

mod bindings {
    windows::include_bindings!();
}

fn main() {}
  • cargo build --target i686-pc-windows-msvc produces the 32-bit bindings
  • cargo build --target x86_64-pc-windows-msvc produces the 64-bit bindings

According to the Windows SDK headers, the NOTIFIYICONDATAW structure should be packed(1), unless the target architecture is _WIN64 (not sure whether that includes ARM64).

The metadata contains type definitions for both byte-packed and natural type layout, presumably gated on the SupportedArchitecture attribute (which ILSpy won't display, though it should), but those don't translate into the generated bindings.

All 3 comments

The issue can be reproduced using the following:

Cargo.toml:

[package]
name = "shell_test"
version = "0.0.0"
edition = "2018"

[dependencies]
windows = "0.11.0"

[build-dependencies]
windows = "0.11.0"

build.rs:

fn main() {
    windows::build!(
        Windows::Win32::UI::Shell::NOTIFYICONDATAW,
    );
}

main.rs:

mod bindings {
    windows::include_bindings!();
}

fn main() {}
  • cargo build --target i686-pc-windows-msvc produces the 32-bit bindings
  • cargo build --target x86_64-pc-windows-msvc produces the 64-bit bindings

According to the Windows SDK headers, the NOTIFIYICONDATAW structure should be packed(1), unless the target architecture is _WIN64 (not sure whether that includes ARM64).

The metadata contains type definitions for both byte-packed and natural type layout, presumably gated on the SupportedArchitecture attribute (which ILSpy won't display, though it should), but those don't translate into the generated bindings.

unless the target architecture is _WIN64 (not sure whether that includes ARM64).

ARM64 sets _WIN64 - doc says:

_WIN64 Defined as 1 when the compilation target is 64-bit ARM or x64. Otherwise, undefined.

The metadata now includes arch-specific struct definitions, but the Windows crate doesn't yet sniff out the target for the build and generate the appropriate definitions.

Was this page helpful?
0 / 5 - 0 ratings