Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link and version #377

Merged
merged 4 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

- Set the link flag of gdal-sys to "libgdal". Emit the libgdal version via cargo:version_number. Remove wrong build-dependency on gdal-sys and remove docs_rs workaround.

- <https://github.com/georust/gdal/pull/377>

- Added `Geometry::from_geojson`

- <https://github.com/georust/gdal/pull/375>
Expand Down Expand Up @@ -42,7 +46,7 @@

- <https://github.com/georust/gdal/pull/355>

- Exposed various functions on `Geometry`: `make_valid`, `geometry_name`, and `point_count`.
- Exposed various functions on `Geometry`: `make_valid`, `geometry_name`, and `point_count`.

- <https://github.com/georust/gdal/pull/356>

Expand All @@ -53,7 +57,7 @@
- Exposed spatial predicates over `Geometry`: `intersects`, `contains`, `disjoint`, `touches`, `crosses`, `within`, and `overlaps`.

- <https://github.com/georust/gdal/pull/366>

- Added `Geometry::envelope` and `Geometry::envelope_3d`.

- <https://github.com/georust/gdal/pull/370>
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ bitflags = "1.3"
once_cell = "1.9"

[build-dependencies]
gdal-sys = { path = "gdal-sys", version = "^0.8" }
semver = "1.0"

[dev-dependencies]
Expand Down
9 changes: 3 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use std::str::FromStr;

fn gdal_version_info() -> String {
gdal_sys::gdal_version_docs_rs_wrapper()
}
use std::{env, str::FromStr};

fn main() {
let gdal_version_string = gdal_version_info();
let gdal_version_string = env::var("DEP_GDAL_VERSION_NUMBER")
.expect("The GDAL-SYS crate must emit the version of libgdal via cargo:version_number");
println!("GDAL version string: \"{gdal_version_string}\"");

// this version string is the result of:
Expand Down
1 change: 1 addition & 0 deletions gdal-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repository = "https://github.com/georust/gdal"
authors = ["Johannes Drönner <[email protected]>"]
edition = "2018"
rust-version = "1.58"
links="gdal"

[dependencies]
libc = "0.2"
Expand Down
42 changes: 14 additions & 28 deletions gdal-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,45 +59,24 @@ fn find_gdal_dll(lib_dir: &Path) -> io::Result<Option<String>> {
Ok(None)
}

fn add_docs_rs_helper(version: Option<&str>) {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("docs_rs_helper.rs");
let docs_helper_code = if let Some(version) = version {
format!(
r#"
pub fn gdal_version_docs_rs_wrapper() -> String {{
"{version}".to_string()
}}"#
)
} else {
r#"
pub fn gdal_version_docs_rs_wrapper() -> String {
let key = "VERSION_NUM";
let c_key = std::ffi::CString::new(key.as_bytes()).unwrap();

unsafe {
let res_ptr = crate::GDALVersionInfo(c_key.as_ptr());
let c_res = std::ffi::CStr::from_ptr(res_ptr);
c_res.to_string_lossy().into_owned()
}
}"#
.to_string()
};
std::fs::write(out_path, docs_helper_code.as_bytes()).unwrap();
}

jdroenner marked this conversation as resolved.
Show resolved Hide resolved
fn main() {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs");

// Hardcode a prebuilt binding version while generating docs.
// Otherwise docs.rs will explode due to not actually having libgdal installed.
if std::env::var("DOCS_RS").is_ok() {
let version = Version::parse("3.5.0").expect("invalid version for docs.rs");
add_docs_rs_helper(Some("3050000"));
println!(
"cargo:rustc-cfg=gdal_sys_{}_{}_{}",
version.major, version.minor, version.patch
);

// this version string is the result of:
// #define GDAL_COMPUTE_VERSION(maj,min,rev) ((maj)*1000000+(min)*10000+(rev)*100)
let gdal_version_number_string =
version.major * 1_000_000 + version.minor * 10_000 + version.patch * 100;
println!("cargo:version_number={}", gdal_version_number_string);

let binding_path = PathBuf::from(format!(
"prebuilt-bindings/gdal_{}.{}.rs",
version.major, version.minor
Expand All @@ -112,7 +91,6 @@ fn main() {
return;
}

add_docs_rs_helper(None);
println!("cargo:rerun-if-env-changed=GDAL_STATIC");
println!("cargo:rerun-if-env-changed=GDAL_DYNAMIC");
println!("cargo:rerun-if-env-changed=GDAL_INCLUDE_DIR");
Expand Down Expand Up @@ -231,6 +209,14 @@ fn main() {
}
}

if let Some(gdal_version) = &version {
// this version string is the result of:
// #define GDAL_COMPUTE_VERSION(maj,min,rev) ((maj)*1000000+(min)*10000+(rev)*100)
let gdal_version_number_string =
gdal_version.major * 1_000_000 + gdal_version.minor * 10_000 + gdal_version.patch * 100;
println!("cargo:version_number={}", gdal_version_number_string);
}

#[cfg(feature = "bindgen")]
write_bindings(include_paths, &out_path);

Expand Down
1 change: 0 additions & 1 deletion gdal-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
#![allow(rustdoc::bare_urls)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
include!(concat!(env!("OUT_DIR"), "/docs_rs_helper.rs"));
jdroenner marked this conversation as resolved.
Show resolved Hide resolved