Update dependencies
[temp2RGB.git] / build.rs
1 extern crate bindgen;
2
3 use std::{env, path::PathBuf};
4
5 // From: https://rust-lang.github.io/rust-bindgen/tutorial-0.html
6
7 fn main() {
8 // Tell cargo to look for shared libraries in the specified directory
9 println!("cargo:rustc-link-search=winring0");
10 println!("cargo:rustc-link-search=IntelArc");
11
12 // Tell cargo to tell rustc to link the system 'WinRing0x64' shared library.
13 println!("cargo:rustc-link-lib=WinRing0x64");
14 println!("cargo:rustc-link-lib=IntelArc");
15
16 // Tell cargo to invalidate the built crate whenever the header changes
17 println!("cargo:rerun-if-changed=OlsApi.h");
18 println!("cargo:rerun-if-changed=IntelArc.h");
19
20 // The bindgen::Builder is the main entry point
21 // to bindgen, and lets you build up options for
22 // the resulting bindings.
23 let bindings_winring0 = bindgen::Builder::default()
24 // The input header we would like to generate bindings for.
25 .header("winring0/OlsApi.h")
26 // .clang_arg("-target")
27 // .clang_arg("i686-pc-windows-msvc")
28 .clang_arg("-x")
29 .clang_arg("c++")
30 .clang_arg("--std")
31 .clang_arg("c++14")
32 // Commented out: not needed.
33 // Tell cargo to invalidate the built crate whenever any of the
34 // included header files changed.
35 //.parse_callbacks(Box::new(bindgen::CargoCallbacks))
36 // Finish the builder and generate the bindings.
37 .generate()
38 // Unwrap the Result and panic on failure.
39 .expect("Unable to generate bindings for winring0");
40
41 // Write the bindings to the $OUT_DIR/bindings.rs file.
42 let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
43
44 bindings_winring0
45 .write_to_file(out_path.join("ols_api.rs"))
46 .expect("Couldn't write bindings for winring0!");
47
48 // The bindgen::Builder is the main entry point
49 // to bindgen, and lets you build up options for
50 // the resulting bindings.
51 let bindings_intel_arc = bindgen::Builder::default()
52 // The input header we would like to generate bindings for.
53 .header("IntelArc/IntelArc.h")
54 // .clang_arg("-target")
55 // .clang_arg("i686-pc-windows-msvc")
56 .clang_arg("-x")
57 .clang_arg("c++")
58 .clang_arg("--std")
59 .clang_arg("c++14")
60 // Commented out: not needed.
61 // Tell cargo to invalidate the built crate whenever any of the
62 // included header files changed.
63 //.parse_callbacks(Box::new(bindgen::CargoCallbacks))
64 // Finish the builder and generate the bindings.
65 .generate()
66 // Unwrap the Result and panic on failure.
67 .expect("Unable to generate bindings for IntelArc");
68
69 // Write the bindings to the $OUT_DIR/bindings.rs file.
70 let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
71
72 bindings_intel_arc
73 .write_to_file(out_path.join("intel_arc.rs"))
74 .expect("Couldn't write bindings for intel arc!");
75
76 // let out_dir = env::var("CARGO_TARGET_DIR").unwrap();
77 // println!("out_dir: {}", out_dir);
78 // TODO: How to properly get the (current) target directory?
79 copy_file("winring0/WinRing0x64.sys", "target/debug/WinRing0x64.sys");
80 copy_file("winring0/WinRing0x64.dll", "target/debug/WinRing0x64.dll");
81 copy_file("winring0/WinRing0x64.sys", "target/release/WinRing0x64.sys");
82 copy_file("winring0/WinRing0x64.dll", "target/release/WinRing0x64.dll");
83 }
84
85 fn copy_file(from: &str, to: &str) {
86 if let Err(e) = std::fs::copy(from, to) {
87 println!("cargo:warning={e:?} (copy {from} to {to})")
88 };
89 }