paleolimbot commented on code in PR #114:
URL: https://github.com/apache/sedona-db/pull/114#discussion_r2365002524


##########
c/sedona-proj/build.rs:
##########
@@ -16,19 +16,64 @@
 // under the License.
 use std::{env, path::PathBuf};
 
+// Since relative path differs between build.rs and a file under `src/`, use 
the
+// absolute path.
+fn get_absolute_path(path: String) -> PathBuf {
+    std::path::absolute(PathBuf::from(path)).expect("Failed to get absolute 
path")
+}
+
+fn configure_bindings_path(prebuilt_bindings_path: String) -> (PathBuf, bool) {
+    // If SEDONA_PROJ_BINDINGS_OUTPUT_PATH is set, honor the explicit output
+    // path to regenerate bindings.
+    if let Ok(output_path) = env::var("SEDONA_PROJ_BINDINGS_OUTPUT_PATH") {
+        let output_path = get_absolute_path(output_path);
+        if let Some(output_dir) = output_path.parent() {
+            std::fs::create_dir_all(output_dir).expect("Failed to create 
parent dirs");
+        }
+        return (output_path, true);
+    }
+
+    // If a prebuilt bindings exists, use it and skip bindgen.
+    let prebuilt_bindings_path = get_absolute_path(prebuilt_bindings_path);
+    if prebuilt_bindings_path.exists() {
+        return (prebuilt_bindings_path, false);
+    }
+
+    let output_dir = env::var("OUT_DIR").unwrap();
+    let output_path = get_absolute_path(format!("{output_dir}/bindings.rs"));
+
+    (output_path, true)
+}
+
 fn main() {
     println!("cargo:rerun-if-changed=src/proj_dyn.c");
     cc::Build::new().file("src/proj_dyn.c").compile("proj_dyn");
 
+    println!("cargo:rerun-if-env-changed=SEDONA_PROJ_BINDINGS_OUTPUT_PATH");
+
+    let os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
+    let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
+    let prebuilt_bindings_path = format!("src/bindings/{os}-{arch}.rs");

Review Comment:
   Should this also include the `gnu` part of the target (i.e., I imagine the 
bindings *might* be different under the gnu vs. msvc targets in the future?)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to