Skip to content

Enables experimental support for raw-dylib #977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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