diff --git a/.cargo/config.toml b/.cargo/config.toml index 1b4298a..6184c05 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,5 @@ [alias] -xtask = "run --package xtask --" \ No newline at end of file +xtask = "run --package xtask --" + +[target.x86_64-pc-windows-msvc] +rustflags = ["-Ctarget-feature=+crt-static"] diff --git a/llvm_zluda/build.rs b/llvm_zluda/build.rs index 722dc42..9505a86 100644 --- a/llvm_zluda/build.rs +++ b/llvm_zluda/build.rs @@ -19,8 +19,8 @@ fn main() { cmake // It's not like we can do anything about the warnings .define("LLVM_ENABLE_WARNINGS", "OFF") - // For some reason Rust always links to release MSVCRT - .define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreadedDLL") + // For some reason Rust always links to release CRT + .define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded") .define("LLVM_ENABLE_TERMINFO", "OFF") .define("LLVM_ENABLE_LIBXML2", "OFF") .define("LLVM_ENABLE_LIBEDIT", "OFF") diff --git a/zluda/Cargo.toml b/zluda/Cargo.toml index 0c6b5de..61de140 100644 --- a/zluda/Cargo.toml +++ b/zluda/Cargo.toml @@ -22,13 +22,13 @@ lz4-sys = "1.9" tempfile = "3" paste = "1.0" rustc-hash = "1.1" -dtor = "0.0.6" [target.'cfg(windows)'.dependencies] winapi = { version = "0.3", features = ["heapapi", "std"] } [target.'cfg(not(windows))'.dependencies] libc = "0.2" +dtor = "0.0.6" [package.metadata.zluda] linux_symlinks = [ diff --git a/zluda/src/lib.rs b/zluda/src/lib.rs index 2da4c76..b6ced82 100644 --- a/zluda/src/lib.rs +++ b/zluda/src/lib.rs @@ -1,12 +1,18 @@ use cuda_types::cuda::CUerror; use std::sync::atomic::{AtomicBool, Ordering}; + + +#[cfg_attr(windows, path = "os_win.rs")] +#[cfg_attr(not(windows), path = "os_unix.rs")] +mod os; pub(crate) mod r#impl; static INITIALIZED: AtomicBool = AtomicBool::new(true); pub(crate) fn initialized() -> bool { INITIALIZED.load(Ordering::SeqCst) } -#[dtor::dtor] + +#[cfg_attr(not(windows), dtor::dtor)] fn deinitialize() { INITIALIZED.store(false, Ordering::SeqCst); } diff --git a/zluda/src/os_unix.rs b/zluda/src/os_unix.rs new file mode 100644 index 0000000..e69de29 diff --git a/zluda/src/os_win.rs b/zluda/src/os_win.rs new file mode 100644 index 0000000..a2936d3 --- /dev/null +++ b/zluda/src/os_win.rs @@ -0,0 +1,13 @@ +use std::ffi::c_void; + +const DLL_PROCESS_DETACH: u32 = 0; + +#[allow(non_snake_case, unused_variables)] +#[no_mangle] +extern "system" fn DllMain(_dll_module: *const c_void, call_reason: u32, _: *const c_void) -> bool { + if call_reason == DLL_PROCESS_DETACH { + super::deinitialize(); + } + + true +}