Skip to content

Commit

Permalink
add build.rs for GDAL crate, remove version feat.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdroenner committed Sep 25, 2020
1 parent 91e440c commit 3ed5656
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ edition = "2018"

[features]
bindgen = ["gdal-sys/bindgen"]
gdal_2_2 = ["gdal-sys/min_gdal_version_2_2"]
gdal_2_4 = ["gdal-sys/min_gdal_version_2_4"]
gdal_3_0 = ["gdal-sys/min_gdal_version_3_0"]
array = ["ndarray"]
datetime = ["chrono"]

Expand All @@ -25,10 +22,13 @@ failure_derive = "0.1"
libc = "0.2"
geo-types = "0.4"
gdal-sys = { path = "gdal-sys", version = "0.2"}
#gdal-sys = "0.2"
num-traits = "0.2"
ndarray = {version = "0.12.1", optional = true }
chrono = { version = "0.4", optional = true }

[build-dependencies]
gdal-sys = { path = "gdal-sys", version = "0.2"}
semver = "0.11"

[workspace]
members = ["gdal-sys"]
45 changes: 45 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use gdal_sys;
use semver::Version;

pub fn gdal_version_info(key: &str) -> String {
let c_key = std::ffi::CString::new(key.as_bytes()).unwrap();
let version_string = unsafe {
let res_ptr = gdal_sys::GDALVersionInfo(c_key.as_ptr());
let c_res = std::ffi::CStr::from_ptr(res_ptr);
c_res.to_string_lossy().into_owned()
};
version_string
}

fn main() {
let gdal_version_string = gdal_version_info("--version"); // This expects GDAL to repond with "GDAL Semver , RELEASE DATE"
println!("GDAL version string: \"{}\"", gdal_version_string);

let semver_substring = &gdal_version_string[4..gdal_version_string.find(",").unwrap_or(12)];
println!("GDAL semver string: \"{}\"", semver_substring);

let detected_version = Version::parse(semver_substring).expect("Could not parse gdal version!");

println!("cargo:rustc-cfg=gdal_{}", detected_version.major);
println!(
"cargo:rustc-cfg=gdal_{}_{}",
detected_version.major, detected_version.minor
);
println!(
"cargo:rustc-cfg=gdal_{}_{}_{}",
detected_version.major, detected_version.minor, detected_version.patch
);

// we only support GDAL >= 2.0.
for major in 2..=detected_version.major {
println!("cargo:rustc-cfg=major_ge_{}", major);
}

for minor in 0..=detected_version.minor {
println!("cargo:rustc-cfg=minor_ge_{}", minor);
}

for patch in 0..=detected_version.patch {
println!("cargo:rustc-cfg=patch_ge_{}", patch);
}
}

0 comments on commit 3ed5656

Please sign in to comment.