Skip to content

Generate proper function impl when cross-compiling #830

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
Jun 9, 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
44 changes: 25 additions & 19 deletions crates/gen/src/types/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,36 @@ impl Function {
link = "onecoreuap";
}

let body = if cfg!(windows) {
if signature.has_query_interface() {
let leading_params = &signature.params[..signature.params.len() - 2];
let args = leading_params.iter().map(|p| p.gen_win32_abi_arg());
let body = if signature.has_query_interface() {
let leading_params = &signature.params[..signature.params.len() - 2];
let args = leading_params.iter().map(|p| p.gen_win32_abi_arg());

quote! {
#[link(name = #link)]
extern "system" {
fn #name(#(#abi_params),*) #abi_return_type;
}
let mut result__ = ::std::option::Option::None;
#name(#(#args,)* &<T as ::windows::Interface>::IID, ::windows::Abi::set_abi(&mut result__)).and_some(result__)
}
} else {
quote! {
#[link(name = #link)]
extern "system" {
fn #name(#(#abi_params),*) #abi_return_type;
}
#name(#(#args),*)
quote! {
#[link(name = #link)]
extern "system" {
fn #name(#(#abi_params),*) #abi_return_type;
}
let mut result__ = ::std::option::Option::None;
#name(#(#args,)* &<T as ::windows::Interface>::IID, ::windows::Abi::set_abi(&mut result__)).and_some(result__)
}
} else {
quote! {
#[link(name = #link)]
extern "system" {
fn #name(#(#abi_params),*) #abi_return_type;
}
#name(#(#args),*)
}
};

// Don't link on windows dlls when generating code for non-windows:
let body = quote! {
#[cfg(windows)]
{
#body
}
#[cfg(not(windows))]
{
unimplemented!("Unsupported target OS");
}
};
Expand Down
Loading