-
Notifications
You must be signed in to change notification settings - Fork 584
Experimental raw-dylib support
#2149
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
| #[doc(hidden)] | ||
| #[macro_export] | ||
| macro_rules! windows_link { | ||
| ($library:literal, $abi:literal fn $name:ident($($arg:ident: $argty:ty),*)->$ret:ty) => ( |
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.
The comma between the library and abi seems a little awkward...
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.
I can remove it - wasn't sure if that was better/worse esthetically.
| #[macro_export] | ||
| macro_rules! windows_link { | ||
| ($library:literal, $abi:literal fn $name:ident($($arg:ident: $argty:ty),*)->$ret:ty) => ( | ||
| #[cfg(all(feature = "raw_dylib", target_arch = "x86"))] |
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.
Maybe move the cfg's from the macro body to the macro definition. That is have 4 windows_link macros each producing only a single extern block with the cfg determining which macro is enabled. This should reduce the amount of code rustc has to churn through to a fourth of what it currently has to.
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.
Ah, good idea!
| @@ -5,6 +5,7 @@ Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs | |||
| #![no_std] | |||
| #![doc(html_no_source)] | |||
| #![allow(non_snake_case, clashing_extern_declarations)] | |||
| #![cfg_attr(feature = "raw_dylib", feature(raw_dylib), feature(native_link_modifiers_verbatim))] | |||
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.
You can enable multiple featurs with a single #![feature(a, b)].
Rustfmt doesn't format macro invocation bodies at all as it has no semantic knowledge about if it should format as expression, item, pattern, ... I would have expected it to be able to turn |
You could still use it within the body of the macro. A macro will see a doc comment as |
| Win32_UI_Xaml_Diagnostics = ["Win32_UI_Xaml"] | ||
|
|
||
| # These features are unstable and require the nightly Rust compiler: | ||
| raw_dylib = [] |
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.
If you're confident in your compatibility layer and want to merge this feature; you could opt for putting it behind a --cfg windows_nightly option instead of a feature flag. Such a flag wouldn't be prone to transitive activation through dependencies, and it would allow people to more easily experiment with unstable features and avoid the bitrot associated with maintaining a branch.
See e.g. tokio_unstable for reference.
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.
Ooh, that looks handy - thanks! Features really aren't great for this kind of thing.
|
Thanks for the great feedback everyone! I'm going to close this draft PR and open a new PR to introduce |
This is a branch to validate and experiment with
raw-dylibsupport in thewindowsandwindows-syscrates. I don't think I'll merge this until the necessary features are stabilized but it will let us kick the tires. The main change is the introduction of thewindows_linkmacro that abstracts away all of the differences between the oldlinkattribute and the new link modes necessary forraw-dylibto work. Thewindows-bindgencrate can then generate something like this:Rather than the traditional form:
The
windows_linkmacro will generate the traditional form if theraw_dylibfeature is not activated. In that mode, it continues to rely on the target libs provided by thewindowsandwindows-syscrates. However, theraw_dylibfeature ensures that no libs are needed and the name of the DLL is used to instruct the Rust compiler to inject the appropriate import table entry directly and without the use of an import lib.You can try this today with the nightly compiler. I added the optional
raw_dylibfeature to a few of the samples so that you can experiment with this as follows:Some thoughts:
windows_linkmacro generates a lot more code than the traditional form but it doesn't appear to impact build time in any meaningful way.docattribute on imports since it cannot be applied to thewindows_linkmacro.raw-dylibfeature is stable and ubiquitous, but it would be great if we didn't have to download those anymore.windowscrate over toraw-dylibunconditionally but keep thewindows-sysoptional to retain support for an older MSRV.windows_linkmacro could enable optional support for delay loading, similar to the MSVC linker's/DELAYLOADoption. I'm not sure how popular that would be, but I do know a few crates that would benefit.rustfmthas a hard time formatting thewindows_linkmacros. Instead of this desirable format:We end up with something like this: