1
- extern crate bindgen;
2
- extern crate cmake;
3
-
1
+ use bindgen;
2
+ use cmake;
4
3
use std:: env;
4
+ use std:: path:: PathBuf ;
5
5
6
6
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
+
8
11
let target_os = env:: var ( "CARGO_CFG_TARGET_OS" ) . unwrap ( ) ;
9
12
let target_pointer_width = env:: var ( "CARGO_CFG_TARGET_POINTER_WIDTH" ) . unwrap ( ) ;
10
13
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
+
11
29
if target_os == "macos" {
12
30
config. define ( "BUILD_UNIVERSAL" , "OFF" ) ;
13
31
} else if target_os == "windows" {
@@ -16,6 +34,7 @@ fn main() {
16
34
}
17
35
18
36
let dst = config. build ( ) ;
37
+
19
38
println ! ( "cargo:rustc-link-search=native={}/lib" , dst. display( ) ) ;
20
39
21
40
if target_os == "windows" && target_pointer_width == "64" {
@@ -32,12 +51,13 @@ fn main() {
32
51
println ! ( "cargo:rustc-link-lib=shell32" ) ;
33
52
}
34
53
54
+ // Generate bindings and write them into OUT_DIR
35
55
bindgen:: builder ( )
36
56
. header ( "wrapper.hpp" )
37
57
. constified_enum ( ".*" )
38
58
. prepend_enum_name ( false )
39
59
. generate ( )
40
60
. expect ( "could not generate bindings" )
41
- . write_to_file ( "bindings.rs" )
61
+ . write_to_file ( out_dir . join ( "bindings.rs" ) )
42
62
. expect ( "could not write bindings.rs" ) ;
43
63
}
0 commit comments