-
Notifications
You must be signed in to change notification settings - Fork 762
feat: Implement support for link type 'raw-dylib' on Windows #3257
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// bindgen-flags: --windows-link-as-raw-dylib foo.exe --windows-link-as-raw-dylib-verbatim | ||
|
||
void test_function(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// bindgen-flags: --windows-link-as-raw-dylib foolib | ||
|
||
void test_function(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4717,10 +4717,24 @@ impl CodeGenerator for Function { | |
// Unfortunately this can't piggyback on the `attributes` list because | ||
// the #[link(wasm_import_module)] needs to happen before the `extern | ||
// "C"` block. It doesn't get picked up properly otherwise | ||
let wasm_link_attribute = | ||
ctx.options().wasm_import_module_name.as_ref().map(|name| { | ||
quote! { #[link(wasm_import_module = #name)] } | ||
}); | ||
let link_attribute = match ( | ||
ctx.options().wasm_import_module_name.as_ref(), | ||
&ctx.options().windows_link_as_raw_dylib, | ||
) { | ||
(Some(_), (Some(_), _)) => { | ||
panic!("Cannot link against a wasm import module and a raw dylib at the same time"); | ||
} | ||
(Some(name), (None, _)) => { | ||
Some(quote! { #[link(wasm_import_module = #name)] }) | ||
} | ||
(None, (Some(name), false)) => Some( | ||
quote! { #[cfg_attr(windows, link(name = #name, kind = "raw-dylib"))] }, | ||
), | ||
(None, (Some(name), true)) => Some( | ||
quote! { #[cfg_attr(windows, link(name = #name, kind = "raw-dylib", modifiers = "+verbatim"))] }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What other modifiers are there? Should we support them? |
||
), | ||
_ => None, | ||
}; | ||
|
||
let should_wrap = is_internal && | ||
ctx.options().wrap_static_fns && | ||
|
@@ -4774,7 +4788,7 @@ impl CodeGenerator for Function { | |
.then(|| quote!(unsafe)); | ||
|
||
let tokens = quote! { | ||
#wasm_link_attribute | ||
#link_attribute | ||
#safety extern #abi { | ||
#(#attributes)* | ||
pub fn #ident ( #( #args ),* ) #ret; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's just add both attributes rather than panicking if the user requests it. It also makes the code simpler.
So: