Skip to content

Commit

Permalink
Merge pull request #128 from michaelkirk/mkirk/fix-docsrs
Browse files Browse the repository at this point in the history
fix docs.rs build for gdal-sys (hopefully)
  • Loading branch information
jdroenner authored Dec 28, 2020
2 parents 296eb3c + 90f33b2 commit fef31b2
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions gdal-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,31 @@ fn find_gdal_dll(lib_dir: &Path) -> io::Result<Option<String>> {
}

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 let Ok(_) = std::env::var("DOCS_RS") {
let version = Version::parse("3.2.0").expect("invalid version for docs.rs");
println!(
"cargo:rustc-cfg=gdal_sys_{}_{}_{}",
version.major, version.minor, version.patch
);

let binding_path = PathBuf::from(format!(
"prebuilt-bindings/gdal_{}.{}.rs",
version.major, version.minor
));

if !binding_path.exists() {
panic!("Missing bindings for docs.rs (version {})", version);
}

std::fs::copy(&binding_path, &out_path).expect("Can't copy bindings to output directory");

return;
}

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 @@ -154,8 +179,6 @@ fn main() {
need_metadata = false;
}

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs");

let mut include_paths = Vec::new();
if let Some(ref dir) = include_dir {
include_paths.push(dir.as_path().to_str().unwrap().to_string());
Expand Down

0 comments on commit fef31b2

Please sign in to comment.