Skip to content

Commit e99fb2e

Browse files
committed
fix cross compiling for windows with mingw
1 parent 2027d7b commit e99fb2e

4 files changed

Lines changed: 50 additions & 2 deletions

File tree

apply_linux_patches.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
cd openvr
3+
git reset --hard
4+
git apply ../patches/mingw_build.path

build.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ use std::env;
44
use std::path::PathBuf;
55

66
fn main() {
7+
#[cfg(unix)]
8+
{
9+
use std::{fs, process::Command};
10+
Command::new("bash")
11+
.current_dir(fs::canonicalize(".").unwrap())
12+
.arg("apply_linux_patches.sh")
13+
.spawn()
14+
.unwrap()
15+
.wait()
16+
.unwrap();
17+
}
18+
719
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("Missing OUT_DIR env var"));
820

921
println!("cargo:rerun-if-changed=wrapper.hpp");
@@ -24,13 +36,17 @@ fn main() {
2436
.define("CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE", &out_dir_str)
2537
.define("CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG", &out_dir_str)
2638
.define("CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE", &out_dir_str)
27-
.out_dir(&out_dir);
39+
.out_dir(&out_dir);
2840

2941
if target_os == "macos" {
3042
config.define("BUILD_UNIVERSAL", "OFF");
3143
} else if target_os == "windows" {
3244
// Work around broken cmake build.
33-
config.cxxflag("/DWIN32");
45+
if env::var("CARGO_CFG_TARGET_ENV").unwrap() == "gnu" {
46+
config.cxxflag("-DWIN32");
47+
} else {
48+
config.cxxflag("/DWIN32");
49+
}
3450
}
3551

3652
let dst = config.build();
@@ -61,4 +77,16 @@ fn main() {
6177
.expect("could not generate bindings")
6278
.write_to_file(out_dir.join("bindings.rs"))
6379
.expect("could not write bindings.rs");
80+
#[cfg(unix)]
81+
{
82+
use std::{fs, process::Command};
83+
//reset openvr submodule so git doesn't say it's dirty
84+
Command::new("bash")
85+
.current_dir(fs::canonicalize(".").unwrap())
86+
.arg("reset_openvr_submodule.sh")
87+
.spawn()
88+
.unwrap()
89+
.wait()
90+
.unwrap();
91+
}
6492
}

patches/mingw_build.path

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/headers/openvr_capi.h b/headers/openvr_capi.h
2+
index c4b6877..0d6fdbf 100644
3+
--- a/headers/openvr_capi.h
4+
+++ b/headers/openvr_capi.h
5+
@@ -48,7 +48,7 @@
6+
7+
#include <stdint.h>
8+
9+
-#if defined( __WIN32 )
10+
+#if defined( __WIN32 ) && !defined(__MINGW32__)
11+
typedef char bool;
12+
#else
13+
#include <stdbool.h>

reset_openvr_submodule.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
cd openvr
3+
git reset --hard

0 commit comments

Comments
 (0)