Skip to content

Commit

Permalink
feat: link against system GMP to remove gmp-mpfr-sys dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
uulm-janbaudisch committed Jun 25, 2024
1 parent 3930276 commit 51cfa2e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ repository = "https://github.com/SoftVarE-Group/d4-oxide.git"
[dependencies]
cxx = { version = "1.0", features = ["c++17"] }
mt-kahypar-sys = "0.1"
gmp-mpfr-sys = { version = "1.6", default-features = false }

[build-dependencies]
cxx-build = { version = "1.0", features = ["parallel"] }
glob = "0.3"
pkg-config = "0.3"

[dev-dependencies]
clap = { version = "4.4", features = ["derive"] }
clap = { version = "4.5", features = ["derive"] }
31 changes: 19 additions & 12 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ use std::env;
use std::path::PathBuf;

fn main() {
// Find and link GMP.
let gmp_library = pkg_config::Config::new()
.probe("gmp")
.expect("Failed to find GMP library.");

for path in gmp_library.link_paths {
println!("cargo:rustc-link-search={}", path.display());
}

// Find and link the C++ interface of GMP.
let gmpxx_library = pkg_config::Config::new()
.probe("gmpxx")
.expect("Failed to find GMP C++ library.");

for path in gmpxx_library.link_paths {
println!("cargo:rustc-link-search={}", path.display());
}

// Find d4 sources to build.
let d4_sources: Vec<PathBuf> = glob("d4/src/**/*.cpp")
.expect("Failed to create glob pattern for d4 sources.")
Expand Down Expand Up @@ -33,18 +51,7 @@ fn main() {
.define("D4_PREPORC_SOLVER", "minisat")
.compile("d4");

// FIXME: Currently, `gmp-mpfr-sys` does not build the C++ interface. Once it does, GMPXX could be used from it.
// println!("cargo:rustc-link-search={}", env::var("DEP_GMP_OUT_DIR").expect("GMP library directory not passed."));

// Find and link the C++ interface of GMP.
let gmpxx_library = pkg_config::Config::new()
.probe("gmpxx")
.expect("Failed to find GMP C++ library.");

for path in gmpxx_library.link_paths {
println!("cargo:rustc-link-search={}", path.display());
}

println!("cargo:rustc-link-lib=dylib=gmp");
println!("cargo:rustc-link-lib=dylib=gmpxx");

// Link Mt-KaHyPar.
Expand Down

0 comments on commit 51cfa2e

Please sign in to comment.