-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 1.2 version, and add more features to sys
- Loading branch information
1 parent
5f6fcda
commit f868df4
Showing
8 changed files
with
8,598 additions
and
4,740 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "sys/MobilityDB"] | ||
path = sys/MobilityDB | ||
url = https://github.com/MobilityDB/MobilityDB.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "meos-sys" | ||
version = "0.1.4" | ||
version = "0.1.3" | ||
authors = ["David García Morillo <[email protected]>"] | ||
|
||
repository = "https://github.com/MobilityDB/RustMEOS" | ||
|
@@ -16,4 +16,13 @@ links = "meos" | |
[dependencies] | ||
|
||
[build-dependencies] | ||
pkg-config = "0.3.30" | ||
pkg-config = "0.3.30" | ||
cmake = "0.1" | ||
bindgen = { version = "0.70.1", optional = true} | ||
|
||
[features] | ||
default = ["v1_2"] | ||
v1_1 = [] | ||
v1_2 = [] | ||
buildtime_bindgen = ["dep:bindgen"] | ||
bundled_proj = ["buildtime_bindgen"] |
Submodule MobilityDB
added at
60048b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,84 @@ | ||
use std::env; | ||
use std::ffi::OsString; | ||
use std::path::PathBuf; | ||
|
||
/// Detect MEOS config parameters using pkg-config (not available for all GEOS | ||
/// versions) | ||
fn detect_meos_via_pkg_config() -> bool { | ||
fn detect_meos_via_pkg_config() -> Option<PathBuf> { | ||
use pkg_config::Config; | ||
|
||
let meos_pkg_config = Config::new().probe("meos"); | ||
|
||
meos_pkg_config.is_ok() | ||
meos_pkg_config.map(|pk| pk.include_paths[0].clone()).ok() | ||
} | ||
|
||
fn main() { | ||
println!("cargo:rerun-if-changed=build.rs"); | ||
println!("cargo:rerun-if-env-changed=MEOS_LIB_DIR"); | ||
|
||
let success = detect_meos_via_pkg_config(); | ||
// If `bundled_proj` is on, use the git submodule to build MEOS from scratch | ||
let include_path = if cfg!(feature = "bundled_proj") { | ||
let dst = cmake::Config::new("MobilityDB").define("MEOS", "1").build(); | ||
|
||
// Try to find the library manually | ||
if !success { | ||
let lib_dir_env = env::var_os("MEOS_LIB_DIR") | ||
.map(OsString::into_string) | ||
.transpose() | ||
.ok() | ||
.flatten() | ||
.unwrap_or(String::from("/usr/local/lib/")); | ||
|
||
// Tell cargo to look for shared libraries in the specified directory | ||
println!("cargo:rustc-link-search={lib_dir_env}"); | ||
println!( | ||
"cargo:rustc-link-search=dylib={}", | ||
dst.join("lib").display() | ||
); | ||
|
||
// Tell cargo to tell rustc to link the system meos shared library. | ||
println!("cargo:rustc-link-lib=dylib=meos"); | ||
} | ||
println!("cargo:rustc-link-lib=meos"); | ||
|
||
dst.join("lib") | ||
// Else use pkg-config, using a default as a fallback | ||
} else { | ||
let pk_include_path = detect_meos_via_pkg_config(); | ||
|
||
// Try to find the library manually | ||
if !pk_include_path.is_some() { | ||
let default_include_path = String::from("/usr/local/lib/"); | ||
let lib_dir_env = env::var_os("MEOS_LIB_DIR") | ||
.map(OsString::into_string) | ||
.transpose() | ||
.ok() | ||
.flatten() | ||
.unwrap_or(default_include_path.clone()); | ||
|
||
// Tell cargo to look for shared libraries in the specified directory | ||
println!("cargo:rustc-link-search={lib_dir_env}"); | ||
|
||
// Tell cargo to tell rustc to link the system meos shared library. | ||
println!("cargo:rustc-link-lib=dylib=meos"); | ||
PathBuf::from(default_include_path) | ||
} else { | ||
pk_include_path.unwrap() | ||
} | ||
}; | ||
|
||
#[cfg(feature = "buildtime_bindgen")] | ||
generate_bindings(include_path).unwrap(); | ||
|
||
#[cfg(not(feature = "buildtime_bindgen"))] | ||
let _ = include_path; | ||
} | ||
|
||
#[cfg(feature = "buildtime_bindgen")] | ||
fn generate_bindings(include_path: std::path::PathBuf) -> Result<(), Box<dyn std::error::Error>> { | ||
// The bindgen::Builder is the main entry point | ||
// to bindgen, and lets you build up options for | ||
// the resulting bindings. | ||
let bindings = bindgen::Builder::default() | ||
.clang_arg(format!("-I{}", include_path.to_string_lossy())) | ||
// The input header we would like to generate | ||
// bindings for. | ||
.header("wrapper.h") | ||
// Finish the builder and generate the bindings. | ||
.generate() | ||
// Unwrap the Result and panic on failure. | ||
.expect("Unable to generate bindings"); | ||
|
||
// Write the bindings to the $OUT_DIR/bindings.rs file. | ||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
bindings.write_to_file(out_path.join("bindings.rs"))?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.