Skip to content

Commit

Permalink
Use raw-dylib for windows-sys (#1137)
Browse files Browse the repository at this point in the history
* Use raw-dylib for windows-sys

To avoid having to declare `#[link(name = "...")]`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Update windows_targets.rs

Co-authored-by: Chris Denton <chris@chrisdenton.dev>

---------

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Co-authored-by: Chris Denton <chris@chrisdenton.dev>
  • Loading branch information
NobodyXu and ChrisDenton authored Jul 8, 2024
1 parent 5a1efa2 commit f657ba1
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 29 deletions.
1 change: 0 additions & 1 deletion dev-tools/gen-windows-sys-binding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ publish = false
[dependencies]
windows-bindgen = "0.58"
tempfile = "3"
regex = "1"
23 changes: 0 additions & 23 deletions dev-tools/gen-windows-sys-binding/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use std::{
io::{BufWriter, Write as _},
};

use regex::Regex;

/// This is printed to the file before the rest of the contents.
const PRELUDE: &str = r#"// This file is autogenerated.
//
Expand Down Expand Up @@ -60,27 +58,6 @@ fn main() {

write!(&mut f, "{PRELUDE}\n{bindings}\n").unwrap();

let mut dll_names: Vec<&str> = Regex::new(r#"link!\("(.*)\.dll""#)
.unwrap()
.captures_iter(&bindings)
.map(|caps| caps.extract().1)
.map(|[dll_name]| dll_name)
.filter(|dll_name| *dll_name != "kernel32")
.collect();

if !dll_names.is_empty() {
dll_names.sort_unstable();
dll_names.dedup();

for dll_name in dll_names {
write!(&mut f, r#"#[link(name = "{dll_name}")]"#).unwrap();
f.write_all("\n".as_bytes()).unwrap();
}

f.write_all(r#"extern "C" {}"#.as_bytes()).unwrap();
f.write_all("\n".as_bytes()).unwrap();
}

f.write_all(r#"use super::windows_targets;"#.as_bytes())
.unwrap();
f.write_all("\n".as_bytes()).unwrap();
Expand Down
4 changes: 0 additions & 4 deletions src/windows/windows_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,4 @@ pub const WAIT_OBJECT_0: WAIT_EVENT = 0u32;
pub const WAIT_TIMEOUT: WAIT_EVENT = 258u32;
pub type WIN32_ERROR = u32;

#[link(name = "advapi32")]
#[link(name = "ole32")]
#[link(name = "oleaut32")]
extern "C" {}
use super::windows_targets;
3 changes: 2 additions & 1 deletion src/windows/windows_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ macro_rules! link_macro {
// have in this repo. So instead we always link kernel32.lib and add the rest of the import
// libraries below by using an empty extern block. This works because extern blocks are not
// connected to the library given in the #[link] attribute.
#[link(name = "kernel32")]
#[cfg_attr(not(target_arch = "x86"), link(name = $library, kind = "raw-dylib", modifiers = "+verbatim"))]
#[cfg_attr(target_arch = "x86", link(name = $library, kind = "raw-dylib", modifiers = "+verbatim", import_name_type = "undecorated"))]
extern $abi {
$(#[link_name=$link_name])?
pub fn $($function)*;
Expand Down

0 comments on commit f657ba1

Please sign in to comment.