Skip to content

Commit

Permalink
Enables experimental support for raw-dylib (#977)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Jul 14, 2021
1 parent d29314d commit ae22551
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions crates/gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ license = "MIT OR Apache-2.0"
description = "Code generation for the windows crate"

[dependencies]

[features]
raw_dylib = []
21 changes: 17 additions & 4 deletions crates/gen/src/types/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down

0 comments on commit ae22551

Please sign in to comment.