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() {