Skip to content

Commit f1dbad9

Browse files
committed
Replace prebuild binary dll's with a version build at test time
This commit replaces the prebuild binary dlls with a version build as at test time via an dev-dependency crate.
1 parent 0695e98 commit f1dbad9

6 files changed

Lines changed: 43 additions & 15 deletions

File tree

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ version = "1"
3333
[dev-dependencies]
3434
libc = "0.2"
3535
static_assertions = "1.1"
36+
windows_test_dll = { path = "windows_test_dll" }
3637

3738
[package.metadata.docs.rs]
3839
all-features = true
@@ -43,3 +44,9 @@ unexpected_cfgs = { level = "warn", check-cfg = [
4344
'cfg(libloading_docs)',
4445
'cfg(target_os, values("cygwin"))',
4546
] }
47+
48+
[workspace]
49+
members = [
50+
"windows_test_dll",
51+
"."
52+
]

tests/nagisa32.dll

-3 KB
Binary file not shown.

tests/nagisa64.dll

-2.5 KB
Binary file not shown.

tests/windows.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,29 @@ extern crate libloading;
33
use libloading::os::windows::*;
44
use std::ffi::CStr;
55
use std::os::raw::c_void;
6-
// The ordinal DLL contains exactly one function (other than DllMain, that is) with ordinal number
7-
// 1. This function has the sugnature `fn() -> *const c_char` and returns a string "bunny\0" (in
8-
// reference to WindowsBunny).
9-
//
10-
// Both x86_64 and x86 versions of the .dll are functionally the same. Ideally we would compile the
11-
// dlls with well known ordinals from our own testing helpers library, but rustc does not allow
12-
// specifying a custom .def file (https://github.com/rust-lang/rust/issues/35089)
13-
//
14-
// The DLLs were kindly compiled by WindowsBunny (aka. @retep998).
156

16-
#[cfg(target_arch = "x86")]
7+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
178
fn load_ordinal_lib() -> Library {
18-
unsafe { Library::new("tests/nagisa32.dll").expect("nagisa32.dll") }
19-
}
9+
use std::path::PathBuf;
2010

21-
#[cfg(target_arch = "x86_64")]
22-
fn load_ordinal_lib() -> Library {
23-
unsafe { Library::new("tests/nagisa64.dll").expect("nagisa64.dll") }
11+
const TEST_DLL: &'static str = "windows_test_dll.dll";
12+
13+
let library_path = std::env::var("LD_LIBRARY_PATH").unwrap();
14+
let path = std::env::var("PATH").unwrap();
15+
println!("{library_path}");
16+
println!("{path}");
17+
let library_path = library_path.split(":").find(|s| s.ends_with("deps"));
18+
let path = path.split(":").find(|s| s.ends_with("deps"));
19+
let path = match (path, library_path) {
20+
(Some(p), _) if PathBuf::from(p).join(TEST_DLL).exists() => PathBuf::from(p).join(TEST_DLL),
21+
(_, Some(p)) if PathBuf::from(p).join(TEST_DLL).exists() => PathBuf::from(p).join(TEST_DLL),
22+
_ => panic!("No test DLL found"),
23+
};
24+
let path = path.display().to_string();
25+
26+
println!("Windows test dll path: {path}");
27+
28+
unsafe { Library::new(format!("{path}")).expect("Windows test dll not found") }
2429
}
2530

2631
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]

windows_test_dll/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "windows_test_dll"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[lib]
7+
crate-type = ["cdylib"]
8+
9+
[dependencies]

windows_test_dll/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![crate_type = "cdylib"]
2+
use std::ffi::c_char;
3+
4+
#[unsafe(no_mangle)]
5+
pub extern "C" fn test() -> *const c_char {
6+
"bunny\0".as_ptr().cast()
7+
}

0 commit comments

Comments
 (0)