Skip to content

Commit

Permalink
Add basic raw_dylib test
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbuchan committed Nov 27, 2023
1 parent 326067e commit cc26ee1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions build_system/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
),
TestCase::build_bin_and_run("aot.float-minmax-pass", "example/float-minmax-pass.rs", &[]),
TestCase::build_bin_and_run("aot.mod_bench", "example/mod_bench.rs", &[]),
TestCase::build_bin_and_run("aot.raw_dylib", "example/raw-dylib.rs", &[]),
TestCase::build_bin_and_run("aot.issue-72793", "example/issue-72793.rs", &[]),
TestCase::build_bin("aot.issue-59326", "example/issue-59326.rs"),
];
Expand Down
1 change: 1 addition & 0 deletions config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ aot.subslice-patterns-const-eval
aot.track-caller-attribute
aot.float-minmax-pass
aot.mod_bench
aot.raw_dylib
aot.issue-72793
aot.issue-59326

Expand Down
42 changes: 42 additions & 0 deletions example/raw-dylib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
fn main() {
#[cfg(all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"))]
x86_64_pc_windows_msvc::test();
}

#[cfg(all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"))]
mod x86_64_pc_windows_msvc {
#![allow(clippy::upper_case_acronyms)]

// Expanded windows_sys, with --cfg windows_raw_dylib, on not(target_arch = "x86").
//
// With target_arch = "x86", #[link] needs import_name_type = "undecorated" for windows APIs for
// windows APIs - and the extern abi depends on the specific API.

// use windows_sys::core::PWSTR;
// use windows_sys::{Win32::Foundation::*, Win32::UI::WindowsAndMessaging::*};
type PWSTR = *mut u16;
type BOOL = i32;
type HWND = isize;
type LPARAM = isize;
type WNDENUMPROC = Option<unsafe extern "system" fn(hwnd: HWND, param: LPARAM) -> BOOL>;

#[link(name = "user32.dll", kind = "raw-dylib", modifiers = "+verbatim")]
extern "system" {
fn EnumWindows(lpenumfunc: WNDENUMPROC, lparam: LPARAM) -> BOOL;

fn GetWindowTextW(hwnd: HWND, buf: PWSTR, buflen: i32) -> i32;
}

pub fn test() {
unsafe { EnumWindows(Some(enum_window), 0) };
}

extern "system" fn enum_window(window: HWND, _: LPARAM) -> BOOL {
let mut text: [u16; 512] = [0; 512];

let len = unsafe { GetWindowTextW(window, text.as_mut_ptr(), text.len() as i32) };
let text = String::from_utf16_lossy(&text[..len as usize]);

1 // TRUE
}
}

0 comments on commit cc26ee1

Please sign in to comment.