-
Couldn't load subscription status.
- Fork 585
Introducing the windows-link crate
#3450
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
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.
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.
No, that cannot be true. rust-lang/rust#110505 got closed by rust-lang/rust#119587 which just adds an unstable feature that's still unstable.
EDIT: See #3672 for more context.
This update introduces the
windows-linkcrate as a simpler alternative to thewindows-targetscrate. It provides the exact samelinkmacro but usesraw-dylibunconditionally and thus has no target-specific dependencies to include import libs. This means that thewindows-linkcrate requires Rust 1.71 or later as that was the first version to stabilizeraw-dylibfor all Windows targets.The
windows-bindgencrate is also updated to default to usewindows-linkfor functions. You can opt-out by using the new--linkoption and specify a different module for thelinkmacro. For example, thewindows-syscrate continues to usewindows-targetsas it has an older MSRV. It does so by using the following optionbindgenarguments:--link windows_targetsThe
windows-targetscrate is unchanged and will continue to be updated for the time being to supportwindows-sys. It continues to support thewindows_raw_dylibcfg option for opting in toraw-dylibwhereas the newwindows-linkcrate ignores thewindows_raw_dylibcfg option and usesraw-dylibin all cases.As an example, consider the following build script.
This will produce the following output:
Add a dependency on the
windows-linkcrate and you're all set!You can then use the new
--linkargument only if you need to change this.This will produce the following altered output to once again use the
windows-targetscrate.