Skip to content

Commit

Permalink
Add basic support for vcpkg.
Browse files Browse the repository at this point in the history
Use vcpkg-rs to manage z3 instead. A non-default feature vcpkg is added.

However, vcpkg-rs does not support wasm32 target currently. I created a pull request there at mcgoo/vcpkg-rs#53
  • Loading branch information
TheVeryDarkness committed Oct 13, 2023
1 parent 3c97663 commit 163f80c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions z3-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ repository = "https://github.com/prove-rs/z3.rs.git"
[build-dependencies]
bindgen = { version = "0.66.0", default-features = false, features = ["runtime"] }
cmake = { version = "0.1.49", optional = true }
vcpkg = { version = "0.2.15", optional = true }

[features]
# Enable this feature to statically link our own build of Z3, rather than
# dynamically linking to the system's `libz3.so`.
static-link-z3 = ["cmake"]
vcpkg = ["dep:vcpkg"]
28 changes: 28 additions & 0 deletions z3-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::env;

const Z3_HEADER_VAR: &str = "Z3_SYS_Z3_HEADER";

#[cfg(not(feature = "vcpkg"))]
fn main() {
#[cfg(feature = "static-link-z3")]
build_z3();
Expand All @@ -17,6 +18,33 @@ fn main() {
};
println!("cargo:rerun-if-env-changed={}", Z3_HEADER_VAR);
println!("cargo:rerun-if-changed={}", header);

generate_binding(&header);
}

#[cfg(feature = "vcpkg")]
fn main() {
let lib = vcpkg::Config::new()
.emit_includes(true)
.find_package("z3")
.unwrap();
let found_header = lib.include_paths.iter().any(|include| {
let mut include = include.clone();
include.push("z3.h");
if include.exists() {
generate_binding(include.to_str().unwrap());
true
} else {
false
}
});
assert!(
found_header,
"z3.h is not found in include path of installed z3."
);
}

fn generate_binding(header: &str) {
let out_path = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());

for x in &[
Expand Down
2 changes: 2 additions & 0 deletions z3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ arbitrary-size-numeral = ["num"]
# dynamically linking to the system's `libz3.so`.
static-link-z3 = ["z3-sys/static-link-z3"]

vcpkg = ["z3-sys/vcpkg"]

[dependencies]
log = "0.4"

Expand Down

0 comments on commit 163f80c

Please sign in to comment.