Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "openvr_sys"
version = "2.1.0"
version = "2.1.1"
edition = "2021"
rust-version = "1.82.0"
authors = [
Expand Down
30 changes: 25 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
extern crate bindgen;
extern crate cmake;

use bindgen;
use cmake;
use std::env;
use std::path::PathBuf;

fn main() {
let mut config = cmake::Config::new("openvr");
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("Missing OUT_DIR env var"));

println!("cargo:rerun-if-changed=wrapper.hpp");

let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let target_pointer_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap();

// Configure cmake to place build output in OUT_DIR
let out_dir_str = out_dir.to_string_lossy().into_owned();
let mut config = cmake::Config::new("openvr");
let config = config
.define("CMAKE_LIBRARY_OUTPUT_DIRECTORY", &out_dir_str)
.define("CMAKE_ARCHIVE_OUTPUT_DIRECTORY", &out_dir_str)
.define("CMAKE_RUNTIME_OUTPUT_DIRECTORY", &out_dir_str)
.define("CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG", &out_dir_str)
.define("CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE", &out_dir_str)
.define("CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG", &out_dir_str)
.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);

if target_os == "macos" {
config.define("BUILD_UNIVERSAL", "OFF");
} else if target_os == "windows" {
Expand All @@ -16,6 +34,7 @@ fn main() {
}

let dst = config.build();

println!("cargo:rustc-link-search=native={}/lib", dst.display());

if target_os == "windows" && target_pointer_width == "64" {
Expand All @@ -32,12 +51,13 @@ fn main() {
println!("cargo:rustc-link-lib=shell32");
}

// Generate bindings and write them into OUT_DIR
bindgen::builder()
.header("wrapper.hpp")
.constified_enum(".*")
.prepend_enum_name(false)
.generate()
.expect("could not generate bindings")
.write_to_file("bindings.rs")
.write_to_file(out_dir.join("bindings.rs"))
.expect("could not write bindings.rs");
}
2 changes: 1 addition & 1 deletion lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]

include!("bindings.rs");
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

#[cfg(target_os = "macos")]
#[link(name = "Foundation", kind = "framework")]
Expand Down