Skip to content
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

Add optional support for raw-dylib #2164

Merged
merged 4 commits into from
Nov 16, 2022
Merged

Add optional support for raw-dylib #2164

merged 4 commits into from
Nov 16, 2022

Conversation

kennykerr
Copy link
Collaborator

@kennykerr kennykerr commented Nov 15, 2022

Following on from #2149, this update adds optional support for raw-dylib in the windows and windows-sys crates. This is currently only supported on nightly but is on track for stabilization. The link macro is "overloaded" to adjust the way the Rust link attribute is configured depending on whether the windows_raw_dylib flag is specified.

The link macro will generate the traditional form if the windows_raw_dylib flag is not specified. In that mode, it continues to rely on the target libs provided by the windows-targets crate. However, the windows_raw_dylib flag ensures that no libs are needed or downloaded. The name of the DLL is then used to instruct the Rust compiler to inject the appropriate import table entry directly and without the use of an import lib.

I'll probably switch the windows crate over to raw-dylib unconditionally once the feature is stabilized but keep the windows-sys crate optional to retain support for an older MSRV.

@kennykerr kennykerr marked this pull request as ready for review November 15, 2022 18:09
@kennykerr
Copy link
Collaborator Author

kennykerr commented Nov 15, 2022

In addition to waiting on stabilization, testing uncovered an issue blocking support on i686-pc-windows-gnu:
rust-lang/rust#104453

And cross compilation is also missing:
rust-lang/rust#103939

@kennykerr
Copy link
Collaborator Author

@kennykerr kennykerr merged commit e45740f into master Nov 16, 2022
@kennykerr kennykerr deleted the raw-dylib-2 branch November 16, 2022 13:19
@udoprog
Copy link

udoprog commented Nov 16, 2022

Thanks for doing this! Looking forward to taking it for a spin shortly!

@kennykerr
Copy link
Collaborator Author

You're welcome! This certainly makes it easier to kick the tires with raw-dylib. 😊

macro_rules! link {
($library:literal $abi:literal $(#[$($doc:tt)*])* fn $name:ident($($arg:ident: $argty:ty),*)->$ret:ty) => (
#[link(name = $library, kind = "raw-dylib", modifiers = "+verbatim")]
extern "system" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific reason this was made to ignore $abi? (it's now "C" rather than "system", as a workaround for variadic functions).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a workaround for this: rust-lang/rust#110505

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's why it's C now, but why was it "system" rather than $abi?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the ABI is generally only relevant for x86 and "system" should work for all ARM64 and x64 Windows APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants