Conversation
ChrisDenton
approved these changes
Jan 16, 2025
Collaborator
ChrisDenton
left a comment
There was a problem hiding this comment.
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.
ChrisDenton
reviewed
Jan 16, 2025
| macro_rules! link { | ||
| ($library:literal $abi:literal $($link_name:literal)? fn $($function:tt)*) => ( | ||
| #[link(name = $library, kind = "raw-dylib", modifiers = "+verbatim")] | ||
| extern "C" { |
Collaborator
There was a problem hiding this comment.
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.
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 was referenced Feb 19, 2025
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.