Ver Fonte

chore(build.rs): fix build script generation for Release targets

greatbridf há 8 meses atrás
pai
commit
ba4318f467
1 ficheiros alterados com 18 adições e 8 exclusões
  1. 18 8
      build.rs

+ 18 - 8
build.rs

@@ -1,11 +1,13 @@
+use std::{
+    io::{stderr, Write},
+    path::PathBuf,
+};
+
 fn main() {
     println!("cargo:rustc-link-search=native=./build/gblibstdc++");
     println!("cargo:rustc-link-lib=static=gblibstdc++");
 
-    let headers = [
-        "rust-headers.hpp",
-        "include/kernel/hw/pci.hpp",
-    ];
+    let headers = ["rust-headers.hpp", "include/kernel/hw/pci.hpp"];
 
     let bindings = bindgen::Builder::default()
         .use_core()
@@ -21,8 +23,16 @@ fn main() {
         .generate()
         .expect("Unable to generate bindings");
 
-    let out_path = std::path::PathBuf::from(std::env::var("PWD").unwrap());
-    bindings
-        .write_to_file(out_path.join("src/bindings.rs"))
-        .expect("Couldn't write bindings!");
+    let out_path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
+    let out = bindings.write_to_file(out_path.join("src/bindings.rs"));
+
+    if let Err(err) = out {
+        writeln!(
+            stderr().lock(),
+            "out_dir = {}",
+            out_path.as_path().display()
+        )
+        .unwrap();
+        Result::<(), _>::Err(err).expect("Couldn't write bindings!");
+    }
 }