mirror of
https://github.com/vosen/ZLUDA.git
synced 2025-08-01 22:37:48 +03:00
Try to make ZLUDA more robust on Windows (#442)
On my machine ZLUDA seems to segfault when initializing LLVM's C++ statics in Blender. Blender ships with C++ runtime. It seems that compiling C++ runtime statically fixes the issue. Might be actually unrelated. Additionally, dtor crate on Windows seem to use a slightly dodgy method, so replace it with something more straightforward
This commit is contained in:
@ -1,2 +1,5 @@
|
||||
[alias]
|
||||
xtask = "run --package xtask --"
|
||||
xtask = "run --package xtask --"
|
||||
|
||||
[target.x86_64-pc-windows-msvc]
|
||||
rustflags = ["-Ctarget-feature=+crt-static"]
|
||||
|
@ -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")
|
||||
|
@ -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 = [
|
||||
|
@ -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);
|
||||
}
|
||||
|
0
zluda/src/os_unix.rs
Normal file
0
zluda/src/os_unix.rs
Normal file
13
zluda/src/os_win.rs
Normal file
13
zluda/src/os_win.rs
Normal file
@ -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
|
||||
}
|
Reference in New Issue
Block a user