-
Notifications
You must be signed in to change notification settings - Fork 534
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
Introducing the windows-link
crate
#3450
Conversation
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.
Looks great! --link
is a really useful feature on its own. And the more we can move toward not needing to bundle binary libs the better.
macro_rules! link { | ||
($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => ( | ||
#[link(name = $library, kind = "raw-dylib", modifiers = "+verbatim")] | ||
extern "C" { |
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.
This is just a comment but I had to look this up to recall why extern "C"
is used instead of $abi
. It was rust-lang/rust#110505 which wasn't fixed until 1.77, a fair bit above the current MSRV.
This update introduces the
windows-link
crate as a simpler alternative to thewindows-targets
crate. It provides the exact samelink
macro but usesraw-dylib
unconditionally and thus has no target-specific dependencies to include import libs. This means that thewindows-link
crate requires Rust 1.71 or later as that was the first version to stabilizeraw-dylib
for all Windows targets.The
windows-bindgen
crate is also updated to default to usewindows-link
for functions. You can opt-out by using the new--link
option and specify a different module for thelink
macro. For example, thewindows-sys
crate continues to usewindows-targets
as it has an older MSRV. It does so by using the following optionbindgen
arguments:--link windows_targets
The
windows-targets
crate is unchanged and will continue to be updated for the time being to supportwindows-sys
. It continues to support thewindows_raw_dylib
cfg option for opting in toraw-dylib
whereas the newwindows-link
crate ignores thewindows_raw_dylib
cfg option and usesraw-dylib
in all cases.As an example, consider the following build script.
This will produce the following output:
Add a dependency on the
windows-link
crate and you're all set!You can then use the new
--link
argument only if you need to change this.This will produce the following altered output to once again use the
windows-targets
crate.