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

Strip .dll extension from raw-dylib link names #2431

Closed
wants to merge 1 commit into from

Conversation

Jake-Shadle
Copy link
Contributor

As noted in the comment, currently windows-bindgen emits the full name of the dll including the extension, which will cause runtime failures since somewhere (linker? dynamic loader?) the extension is automatically added, causing the dll not to be found and abort.

I think the confusion may come from the RFC containing example code which does include the extension.

#[cfg(windows)]
#[link(name = "kernel32.dll", kind = "raw-dylib")]
#[allow(non_snake_case)]
extern "system" {
    fn GetStdHandle(nStdHandle: u32) -> *mut u8;
}

Note this doesn't impact bthprops.cpl which is the 1? case I could find of a dynamic lib having an extension other than .dll.

I was opening an issue and realized it was easier to just fix it.

@riverar
Copy link
Collaborator

riverar commented Apr 5, 2023

Note this doesn't impact bthprops.cpl which is the 1? case I could find of a dynamic lib having an extension other than .dll.

There are plenty of other cases, see:

It's not optimal or really possible to guess the correct answer so we make it explicit in metadata.

Do you have a repro that demonstrates a failure? If so, please open an issue. Be aware raw-dylib is in use by rustc today.

@riverar riverar closed this Apr 5, 2023
@ChrisDenton
Copy link
Collaborator

I think the issue here is that it needs the +verbatim modifier.

#[cfg(windows)]
-#[link(name = "kernel32.dll", kind = "raw-dylib")]
+#[link(name = "kernel32.dll", kind = "raw-dylib", modifiers = "+verbatim")]
#[allow(non_snake_case)]
extern "system" {
    fn GetStdHandle(nStdHandle: u32) -> *mut u8;
}

@kennykerr
Copy link
Collaborator

This is a complicated issue, but it has been discussed at length here:

rust-lang/rust#58713

The windows-targets crate support for raw-dylib can be found here:

https://github.com/microsoft/windows-rs/blob/master/crates/libs/targets/src/lib.rs

And it is tested here:

https://github.com/microsoft/windows-rs/blob/master/.github/workflows/raw_dylib.yml

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.

4 participants