3 use std
::{env
, path
::PathBuf
};
5 // From: https://rust-lang.github.io/rust-bindgen/tutorial-0.html
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");
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");
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");
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")
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.
38 // Unwrap the Result and panic on failure.
39 .expect("Unable to generate bindings for winring0");
41 // Write the bindings to the $OUT_DIR/bindings.rs file.
42 let out_path
= PathBuf
::from(env
::var("OUT_DIR").unwrap());
45 .write_to_file(out_path
.join("ols_api.rs"))
46 .expect("Couldn't write bindings for winring0!");
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")
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.
66 // Unwrap the Result and panic on failure.
67 .expect("Unable to generate bindings for IntelArc");
69 // Write the bindings to the $OUT_DIR/bindings.rs file.
70 let out_path
= PathBuf
::from(env
::var("OUT_DIR").unwrap());
73 .write_to_file(out_path
.join("intel_arc.rs"))
74 .expect("Couldn't write bindings for intel arc!");
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");
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})")