diff --git a/apply_linux_patches.sh b/apply_linux_patches.sh new file mode 100644 index 0000000..28c0eb3 --- /dev/null +++ b/apply_linux_patches.sh @@ -0,0 +1,4 @@ +#!/bin/bash +cd openvr +git reset --hard +git apply ../patches/mingw_build.path \ No newline at end of file diff --git a/build.rs b/build.rs index f0d0024..e250b39 100644 --- a/build.rs +++ b/build.rs @@ -4,6 +4,18 @@ use std::env; use std::path::PathBuf; fn main() { + #[cfg(unix)] + { + use std::{fs, process::Command}; + Command::new("bash") + .current_dir(fs::canonicalize(".").unwrap()) + .arg("apply_linux_patches.sh") + .spawn() + .unwrap() + .wait() + .unwrap(); + } + let out_dir = PathBuf::from(env::var("OUT_DIR").expect("Missing OUT_DIR env var")); println!("cargo:rerun-if-changed=wrapper.hpp"); @@ -24,13 +36,17 @@ fn main() { .define("CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE", &out_dir_str) .define("CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG", &out_dir_str) .define("CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE", &out_dir_str) - .out_dir(&out_dir); + .out_dir(&out_dir); if target_os == "macos" { config.define("BUILD_UNIVERSAL", "OFF"); } else if target_os == "windows" { // Work around broken cmake build. - config.cxxflag("/DWIN32"); + if env::var("CARGO_CFG_TARGET_ENV").unwrap() == "gnu" { + config.cxxflag("-DWIN32"); + } else { + config.cxxflag("/DWIN32"); + } } let dst = config.build(); @@ -61,4 +77,16 @@ fn main() { .expect("could not generate bindings") .write_to_file(out_dir.join("bindings.rs")) .expect("could not write bindings.rs"); + #[cfg(unix)] + { + use std::{fs, process::Command}; + //reset openvr submodule so git doesn't say it's dirty + Command::new("bash") + .current_dir(fs::canonicalize(".").unwrap()) + .arg("reset_openvr_submodule.sh") + .spawn() + .unwrap() + .wait() + .unwrap(); + } } diff --git a/patches/mingw_build.path b/patches/mingw_build.path new file mode 100644 index 0000000..39aa07c --- /dev/null +++ b/patches/mingw_build.path @@ -0,0 +1,13 @@ +diff --git a/headers/openvr_capi.h b/headers/openvr_capi.h +index c4b6877..0d6fdbf 100644 +--- a/headers/openvr_capi.h ++++ b/headers/openvr_capi.h +@@ -48,7 +48,7 @@ + + #include + +-#if defined( __WIN32 ) ++#if defined( __WIN32 ) && !defined(__MINGW32__) + typedef char bool; + #else + #include diff --git a/reset_openvr_submodule.sh b/reset_openvr_submodule.sh new file mode 100644 index 0000000..b29dc27 --- /dev/null +++ b/reset_openvr_submodule.sh @@ -0,0 +1,3 @@ +#!/bin/bash +cd openvr +git reset --hard \ No newline at end of file