diff options
author | Andrzej Janik <[email protected]> | 2021-01-03 18:45:48 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-03 18:45:48 +0100 |
commit | 2c0e9b912fe341bd1e513614014fa43b666d257d (patch) | |
tree | b5d3aa00a5192230657792833450848ceb557a1a /detours-sys/build.rs | |
parent | 659b2c6ec431c3f1103e700a20da4c66467aa35d (diff) | |
download | ZLUDA-2c0e9b912fe341bd1e513614014fa43b666d257d.tar.gz ZLUDA-2c0e9b912fe341bd1e513614014fa43b666d257d.zip |
Fix Windows ZLUDA injector (#26)
Fix various bugs in injector and redirector, make them more robust and enable building them by default
Diffstat (limited to 'detours-sys/build.rs')
-rw-r--r-- | detours-sys/build.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/detours-sys/build.rs b/detours-sys/build.rs new file mode 100644 index 0000000..f3da0e6 --- /dev/null +++ b/detours-sys/build.rs @@ -0,0 +1,54 @@ +use std::error::Error; + +#[cfg(not(target_os = "windows"))] +fn main() {} + +#[cfg(target_os = "windows")] +fn main() -> Result<(), Box<dyn Error>> { + windows::main_impl() +} + +#[cfg(target_os = "windows")] +mod windows { + use std::error::Error; + + const CPP_FILES: [&'static str; 5] = [ + "../ext/detours/src/creatwth.cpp", + "../ext/detours/src/detours.cpp", + "../ext/detours/src/disasm.cpp", + "../ext/detours/src/image.cpp", + "../ext/detours/src/modules.cpp", + ]; + + pub fn main_impl() -> Result<(), Box<dyn Error>> { + println!("cargo:rerun-if-changed=build/wrapper.h"); + for f in &CPP_FILES { + println!("cargo:rerun-if-changed={}", f); + } + build_detours() + } + + fn build_detours() -> Result<(), Box<dyn Error>> { + add_target_options( + cc::Build::new() + .include("../ext/detours/src") + .files(&CPP_FILES), + ) + .try_compile("detours")?; + Ok(()) + } + + #[cfg(target_env = "msvc")] + fn add_target_options(build: &mut cc::Build) -> &mut cc::Build { + build + } + + #[cfg(not(target_env = "msvc"))] + fn add_target_options(build: &mut cc::Build) -> &mut cc::Build { + build + .compiler("clang") + .cpp(true) + .flag("-fms-extensions") + .flag("-Wno-everything") + } +} |