Skip to content

Commit cc26ee1

Browse files
committed
Add basic raw_dylib test
1 parent 326067e commit cc26ee1

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

build_system/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
9797
),
9898
TestCase::build_bin_and_run("aot.float-minmax-pass", "example/float-minmax-pass.rs", &[]),
9999
TestCase::build_bin_and_run("aot.mod_bench", "example/mod_bench.rs", &[]),
100+
TestCase::build_bin_and_run("aot.raw_dylib", "example/raw-dylib.rs", &[]),
100101
TestCase::build_bin_and_run("aot.issue-72793", "example/issue-72793.rs", &[]),
101102
TestCase::build_bin("aot.issue-59326", "example/issue-59326.rs"),
102103
];

config.txt

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ aot.subslice-patterns-const-eval
4040
aot.track-caller-attribute
4141
aot.float-minmax-pass
4242
aot.mod_bench
43+
aot.raw_dylib
4344
aot.issue-72793
4445
aot.issue-59326
4546

example/raw-dylib.rs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
fn main() {
2+
#[cfg(all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"))]
3+
x86_64_pc_windows_msvc::test();
4+
}
5+
6+
#[cfg(all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"))]
7+
mod x86_64_pc_windows_msvc {
8+
#![allow(clippy::upper_case_acronyms)]
9+
10+
// Expanded windows_sys, with --cfg windows_raw_dylib, on not(target_arch = "x86").
11+
//
12+
// With target_arch = "x86", #[link] needs import_name_type = "undecorated" for windows APIs for
13+
// windows APIs - and the extern abi depends on the specific API.
14+
15+
// use windows_sys::core::PWSTR;
16+
// use windows_sys::{Win32::Foundation::*, Win32::UI::WindowsAndMessaging::*};
17+
type PWSTR = *mut u16;
18+
type BOOL = i32;
19+
type HWND = isize;
20+
type LPARAM = isize;
21+
type WNDENUMPROC = Option<unsafe extern "system" fn(hwnd: HWND, param: LPARAM) -> BOOL>;
22+
23+
#[link(name = "user32.dll", kind = "raw-dylib", modifiers = "+verbatim")]
24+
extern "system" {
25+
fn EnumWindows(lpenumfunc: WNDENUMPROC, lparam: LPARAM) -> BOOL;
26+
27+
fn GetWindowTextW(hwnd: HWND, buf: PWSTR, buflen: i32) -> i32;
28+
}
29+
30+
pub fn test() {
31+
unsafe { EnumWindows(Some(enum_window), 0) };
32+
}
33+
34+
extern "system" fn enum_window(window: HWND, _: LPARAM) -> BOOL {
35+
let mut text: [u16; 512] = [0; 512];
36+
37+
let len = unsafe { GetWindowTextW(window, text.as_mut_ptr(), text.len() as i32) };
38+
let text = String::from_utf16_lossy(&text[..len as usize]);
39+
40+
1 // TRUE
41+
}
42+
}

0 commit comments

Comments
 (0)