From d6aefb55d65b8d6f04e58d321aec05e8c240016d Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Tue, 13 Jul 2021 18:02:41 -0700 Subject: [PATCH 1/2] dylib --- tests/raw_dylib/tests/test.rs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/raw_dylib/tests/test.rs diff --git a/tests/raw_dylib/tests/test.rs b/tests/raw_dylib/tests/test.rs new file mode 100644 index 0000000000..24f3ad4625 --- /dev/null +++ b/tests/raw_dylib/tests/test.rs @@ -0,0 +1,8 @@ +use bindings::Windows::Win32::Gaming::HasExpandedResources; + +#[test] +fn test() { + unsafe { + HasExpandedResources().unwrap(); + } +} From be1ef17ed9a0bb0e786abf06aa57d0092dc5e651 Mon Sep 17 00:00:00 2001 From: Kenny Kerr Date: Tue, 13 Jul 2021 18:57:53 -0700 Subject: [PATCH 2/2] raw_dylib --- Cargo.toml | 1 + crates/gen/Cargo.toml | 3 +++ crates/gen/src/types/function.rs | 21 +++++++++++++++++---- tests/raw_dylib/tests/test.rs | 8 -------- 4 files changed, 21 insertions(+), 12 deletions(-) delete mode 100644 tests/raw_dylib/tests/test.rs diff --git a/Cargo.toml b/Cargo.toml index 265769a769..bee09f8f13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,3 +31,4 @@ targets = ["x86_64-pc-windows-msvc"] [features] default = ["macros"] macros = ["gen", "windows_macros"] +raw_dylib = ["gen/raw_dylib"] # TODO: remove feature once raw-dylib has stablized diff --git a/crates/gen/Cargo.toml b/crates/gen/Cargo.toml index d0b2c76708..c207cbc604 100644 --- a/crates/gen/Cargo.toml +++ b/crates/gen/Cargo.toml @@ -7,3 +7,6 @@ license = "MIT OR Apache-2.0" description = "Code generation for the windows crate" [dependencies] + +[features] +raw_dylib = [] diff --git a/crates/gen/src/types/function.rs b/crates/gen/src/types/function.rs index 1e54150b04..1eeec69eb4 100644 --- a/crates/gen/src/types/function.rs +++ b/crates/gen/src/types/function.rs @@ -29,9 +29,14 @@ impl Function { let args = signature.params.iter().map(|p| p.gen_win32_abi_arg()); let mut link = def.impl_map().expect("Function").scope().name(); - // TODO: workaround for https://github.com/microsoft/windows-rs/issues/463 - if link.contains("-ms-win-") || link == "D3DCOMPILER_47" || link == "SspiCli" { - link = "onecoreuap"; + let raw_dylib = cfg!(feature = "raw_dylib"); + + // TODO: remove this whole block once raw-dylib has stabilized as the workarounds + // will no longer be necessary. + if !raw_dylib { + if link.contains("-ms-win-") || link == "D3DCOMPILER_47" || link == "SspiCli" { + link = "onecoreuap"; + } } let static_lib = def @@ -41,9 +46,17 @@ impl Function { _ => None, }) .next(); + let link_attr = match static_lib { Some(link) => quote! { #[link(name = #link, kind = "static")] }, - None => quote! { #[link(name = #link)] }, + None => { + // TODO: switch to always using raw-dylib once it has stabilized + if raw_dylib { + quote! { #[link(name = #link, kind="raw-dylib")] } + } else { + quote! { #[link(name = #link)] } + } + } }; if signature.has_query_interface() { diff --git a/tests/raw_dylib/tests/test.rs b/tests/raw_dylib/tests/test.rs deleted file mode 100644 index 24f3ad4625..0000000000 --- a/tests/raw_dylib/tests/test.rs +++ /dev/null @@ -1,8 +0,0 @@ -use bindings::Windows::Win32::Gaming::HasExpandedResources; - -#[test] -fn test() { - unsafe { - HasExpandedResources().unwrap(); - } -}