use std::error::Error;
#[cfg(feature = "bundled")]
fn bundled() -> Result<(), Box<dyn Error>> {
use std::{env, path::PathBuf, process::Command};
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?);
let go_dir = manifest_dir.ancestors().nth(3).unwrap().join("go");
let go_pkg = go_dir.join("adbc/pkg/snowflake");
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
let archive = out_dir.join("libsnowflake.a");
let status = Command::new("go")
.current_dir(go_pkg.as_path())
.arg("build")
.arg("-tags")
.arg("driverlib")
.arg("-buildmode=c-archive")
.arg("-o")
.arg(&archive)
.arg(".")
.status()?;
assert!(status.success(), "Go build failed");
println!("cargo:rerun-if-changed={}", go_pkg.display());
println!("cargo:rustc-link-search=native={}", out_dir.display());
println!("cargo:rustc-link-lib=static=snowflake");
println!("cargo:rustc-link-lib=resolv");
#[cfg(target_os = "macos")]
{
println!("cargo:rustc-link-lib=framework=CoreFoundation");
println!("cargo:rustc-link-lib=framework=Security");
}
Ok(())
}
#[cfg(feature = "linked")]
fn linked() -> Result<(), Box<dyn Error>> {
println!("cargo:rerun-if-env-changed=ADBC_SNOWFLAKE_GO_LIB_DIR");
if let Some(path) = option_env!("ADBC_SNOWFLAKE_GO_LIB_DIR") {
println!("cargo:rustc-link-search={path}");
}
println!("cargo:rustc-link-lib=adbc_driver_snowflake");
Ok(())
}
fn main() -> Result<(), Box<dyn Error>> {
#[cfg(feature = "bundled")]
bundled()?;
#[cfg(feature = "linked")]
linked()?;
println!("cargo:rerun-if-env-changed=ADBC_SNOWFLAKE_TESTS");
Ok(())
}