Skip to content

Commit a412806

Browse files
authored
Revert "Use raw-dylib for windows-sys (#1137)" (#1157)
1 parent d010d56 commit a412806

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

dev-tools/gen-windows-sys-binding/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ publish = false
77
[dependencies]
88
windows-bindgen = "0.58"
99
tempfile = "3"
10+
regex = "1"

dev-tools/gen-windows-sys-binding/src/main.rs

+23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use std::{
66
io::{BufWriter, Write as _},
77
};
88

9+
use regex::Regex;
10+
911
/// This is printed to the file before the rest of the contents.
1012
const PRELUDE: &str = r#"// This file is autogenerated.
1113
//
@@ -58,6 +60,27 @@ fn main() {
5860

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

63+
let mut dll_names: Vec<&str> = Regex::new(r#"link!\("(.*)\.dll""#)
64+
.unwrap()
65+
.captures_iter(&bindings)
66+
.map(|caps| caps.extract().1)
67+
.map(|[dll_name]| dll_name)
68+
.filter(|dll_name| *dll_name != "kernel32")
69+
.collect();
70+
71+
if !dll_names.is_empty() {
72+
dll_names.sort_unstable();
73+
dll_names.dedup();
74+
75+
for dll_name in dll_names {
76+
write!(&mut f, r#"#[link(name = "{dll_name}")]"#).unwrap();
77+
f.write_all("\n".as_bytes()).unwrap();
78+
}
79+
80+
f.write_all(r#"extern "C" {}"#.as_bytes()).unwrap();
81+
f.write_all("\n".as_bytes()).unwrap();
82+
}
83+
6184
f.write_all(r#"use super::windows_targets;"#.as_bytes())
6285
.unwrap();
6386
f.write_all("\n".as_bytes()).unwrap();

src/windows/windows_sys.rs

+4
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,8 @@ pub const WAIT_OBJECT_0: WAIT_EVENT = 0u32;
114114
pub const WAIT_TIMEOUT: WAIT_EVENT = 258u32;
115115
pub type WIN32_ERROR = u32;
116116

117+
#[link(name = "advapi32")]
118+
#[link(name = "ole32")]
119+
#[link(name = "oleaut32")]
120+
extern "C" {}
117121
use super::windows_targets;

src/windows/windows_targets.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ macro_rules! link_macro {
99
// have in this repo. So instead we always link kernel32.lib and add the rest of the import
1010
// libraries below by using an empty extern block. This works because extern blocks are not
1111
// connected to the library given in the #[link] attribute.
12-
#[cfg_attr(not(target_arch = "x86"), link(name = $library, kind = "raw-dylib", modifiers = "+verbatim"))]
13-
#[cfg_attr(target_arch = "x86", link(name = $library, kind = "raw-dylib", modifiers = "+verbatim", import_name_type = "undecorated"))]
12+
#[link(name = "kernel32")]
1413
extern $abi {
1514
$(#[link_name=$link_name])?
1615
pub fn $($function)*;

0 commit comments

Comments
 (0)