-
Notifications
You must be signed in to change notification settings - Fork 55
add support of vcpkg with msvc toolchain #79
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
b74dd9b
b665fd3
0faa5b8
ec20eb3
e8ae779
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,67 @@ use cmake; | |
use flate2::read::GzDecoder; | ||
use std::fs::File; | ||
|
||
#[cfg(target_env = "msvc")] | ||
use vcpkg; | ||
#[cfg(target_env = "msvc")] | ||
lapoigne marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
use build; | ||
use pkg_config; | ||
use std::env; | ||
use std::path::PathBuf; | ||
use tar::Archive; | ||
|
||
const MINIMUM_PROJ_VERSION: &str = "7.2.1"; | ||
|
||
#[cfg(target_env = "msvc")] | ||
fn try_vcpkg() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> { | ||
build::link("shell32", true); | ||
build::link("ole32", true); | ||
let lib = vcpkg::Config::new() | ||
.emit_includes(true) | ||
.find_package("proj"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to constrain the version based on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I look you to check the version There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't get the library version with vcpkg. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the incredibly long delay (almost a year!). The nightmare scenario is that someone has an old unsupported version of libproj and this library then gives them weird results because of it. On non-windows platforms we can enforce that this doesn't happen. I'm not sure how likely this is in practice. Anybody else want to weigh in? |
||
|
||
if let Err(_e) = lib { | ||
eprintln!("vcpkg proj library not found, trying pkg_config"); | ||
return try_pkg_config() | ||
lapoigne marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
let include_path = lib.unwrap() | ||
.include_paths[0] | ||
.clone(); | ||
|
||
Ok(include_path) | ||
} | ||
|
||
#[cfg(not(target_env = "msvc"))] | ||
fn try_vcpkg() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> { | ||
lapoigne marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
try_pkg_config() | ||
} | ||
|
||
fn try_pkg_config() -> Result<std::path::PathBuf, Box<dyn std::error::Error>> { | ||
pkg_config::Config::new() | ||
.atleast_version(MINIMUM_PROJ_VERSION) | ||
.probe("proj") | ||
.and_then(|pk| { | ||
eprintln!("found acceptable libproj already installed at: {:?}", pk.link_paths[0]); | ||
if let Ok(val) = &env::var("_PROJ_SYS_TEST_EXPECT_BUILD_FROM_SRC") { | ||
if val != "0" { | ||
panic!("for testing purposes: existing package was found, but should not have been"); | ||
} | ||
} | ||
|
||
// Tell cargo to tell rustc to link the system proj | ||
// shared library. | ||
println!("cargo:rustc-link-search=native={:?}", pk.link_paths[0]); | ||
println!("cargo:rustc-link-lib=proj"); | ||
|
||
Ok(pk.include_paths[0].clone()) | ||
}) | ||
.or_else(|err| { | ||
eprintln!("pkg-config unable to find existing libproj installation: {}", err); | ||
build_from_source() | ||
}) | ||
} | ||
|
||
#[cfg(feature = "nobuild")] | ||
fn main() {} // Skip the build script on docs.rs | ||
lapoigne marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
|
@@ -19,28 +73,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { | |
eprintln!("feature flags specified source build"); | ||
build_from_source()? | ||
} else { | ||
pkg_config::Config::new() | ||
.atleast_version(MINIMUM_PROJ_VERSION) | ||
.probe("proj") | ||
.and_then(|pk| { | ||
eprintln!("found acceptable libproj already installed at: {:?}", pk.link_paths[0]); | ||
if let Ok(val) = &env::var("_PROJ_SYS_TEST_EXPECT_BUILD_FROM_SRC") { | ||
if val != "0" { | ||
panic!("for testing purposes: existing package was found, but should not have been"); | ||
} | ||
} | ||
|
||
// Tell cargo to tell rustc to link the system proj | ||
// shared library. | ||
println!("cargo:rustc-link-search=native={:?}", pk.link_paths[0]); | ||
println!("cargo:rustc-link-lib=proj"); | ||
|
||
Ok(pk.include_paths[0].clone()) | ||
}) | ||
.or_else(|err| { | ||
eprintln!("pkg-config unable to find existing libproj installation: {}", err); | ||
build_from_source() | ||
})? | ||
try_vcpkg()? | ||
}; | ||
|
||
// The bindgen::Builder is the main entry point | ||
|
Uh oh!
There was an error while loading. Please reload this page.