Skip to content

Commit 680ebe6

Browse files
authored
Fix packaging errors due to modifying outside of OUT_DIR (#16)
* Move generated files into OUT_DIR as cargo package fails if we don't. * Workaround for forced paths in openvr CMakeLists.txt.
1 parent 9eb4e7b commit 680ebe6

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "openvr_sys"
3-
version = "2.1.0"
3+
version = "2.1.1"
44
edition = "2021"
55
rust-version = "1.82.0"
66
authors = [

build.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
1-
extern crate bindgen;
2-
extern crate cmake;
3-
1+
use bindgen;
2+
use cmake;
43
use std::env;
4+
use std::path::PathBuf;
55

66
fn main() {
7-
let mut config = cmake::Config::new("openvr");
7+
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("Missing OUT_DIR env var"));
8+
9+
println!("cargo:rerun-if-changed=wrapper.hpp");
10+
811
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
912
let target_pointer_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap();
1013

14+
// Configure cmake to place build output in OUT_DIR
15+
let out_dir_str = out_dir.to_string_lossy().into_owned();
16+
let mut config = cmake::Config::new("openvr");
17+
let config = config
18+
.define("CMAKE_LIBRARY_OUTPUT_DIRECTORY", &out_dir_str)
19+
.define("CMAKE_ARCHIVE_OUTPUT_DIRECTORY", &out_dir_str)
20+
.define("CMAKE_RUNTIME_OUTPUT_DIRECTORY", &out_dir_str)
21+
.define("CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG", &out_dir_str)
22+
.define("CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE", &out_dir_str)
23+
.define("CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG", &out_dir_str)
24+
.define("CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE", &out_dir_str)
25+
.define("CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG", &out_dir_str)
26+
.define("CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE", &out_dir_str)
27+
.out_dir(&out_dir);
28+
1129
if target_os == "macos" {
1230
config.define("BUILD_UNIVERSAL", "OFF");
1331
} else if target_os == "windows" {
@@ -16,6 +34,7 @@ fn main() {
1634
}
1735

1836
let dst = config.build();
37+
1938
println!("cargo:rustc-link-search=native={}/lib", dst.display());
2039

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

54+
// Generate bindings and write them into OUT_DIR
3555
bindgen::builder()
3656
.header("wrapper.hpp")
3757
.constified_enum(".*")
3858
.prepend_enum_name(false)
3959
.generate()
4060
.expect("could not generate bindings")
41-
.write_to_file("bindings.rs")
61+
.write_to_file(out_dir.join("bindings.rs"))
4262
.expect("could not write bindings.rs");
4363
}

lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
22

3-
include!("bindings.rs");
3+
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
44

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

0 commit comments

Comments
 (0)