diff --git a/Cargo.toml b/Cargo.toml index f895407..ebb4c93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ authors = [ "Erick Tryzelaar" ] -build = "./scripts/compile-for-cargo" +build = "scripts/build.rs" [lib] diff --git a/scripts/build.rs b/scripts/build.rs new file mode 100644 index 0000000..d9b1998 --- /dev/null +++ b/scripts/build.rs @@ -0,0 +1,31 @@ +use std::io::Command; +use std::io::fs; + +#[cfg(target_os = "linux")] +fn main() { + Command::new("make") + .arg("-C").arg("modules/oculus_sdk_linux/") + .status() + .ok().expect("Failed to build"); + fs::copy(&Path::new("modules/oculus_sdk_linux/LibOVR/Lib/Linux/Release/x86_64/libovr.a"), + &Path::new(env!("OUT_DIR")).join(Path::new("libovr.a"))) + .ok().expect("Failed to move file"); + + println!("cargo:rustc-flags=-L {} -l ovr:static", env!("OUT_DIR")); +} + + +#[cfg(target_os = "macos")] +fn main() { + Command::new("xcodebuild") + .arg("-project") + .arg("modules/oculus_sdk_mac/LibOVR/Projects/Mac/Xcode/LibOVR.xcodeproj") + .arg("build") + .status() + .ok().expect("Failed to build"); + fs::copy(&Path::new("modules/oculus_sdk_mac/LibOVR/Lib/MacOS/Release/libovr.a"), + &Path::new(env!("OUT_DIR")).join(Path::new("libovr.a"))) + .ok().expect("Failed to move file"); + println!("cargo:rustc-flags=-L {} -l ovr:static", env!("OUT_DIR")); + +} \ No newline at end of file diff --git a/scripts/compile-for-cargo b/scripts/compile-for-cargo deleted file mode 100755 index 293bd3a..0000000 --- a/scripts/compile-for-cargo +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -set -e - -OS=`uname` - -if [ "x$OS" = "xLinux" ] ; then - make -C modules/oculus_sdk_linux/ - cp modules/oculus_sdk_linux/LibOVR/Lib/Linux/Release/x86_64/libovr.a $OUT_DIR/ -elif [ "x$OS" = "xDarwin" ] ; then - xcodebuild -project modules/oculus_sdk_mac/LibOVR/Projects/Mac/Xcode/LibOVR.xcodeproj build - cp modules/oculus_sdk_mac/LibOVR/Lib/MacOS/Release/libovr.a $OUT_DIR/ -fi