aboutsummaryrefslogtreecommitdiffhomepage
path: root/detours-sys/build.rs
diff options
context:
space:
mode:
Diffstat (limited to 'detours-sys/build.rs')
-rw-r--r--detours-sys/build.rs54
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")
+ }
+}