Skip to content
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

Add vcpkg support and corresponding CI. #251

Merged
merged 24 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
163f80c
Add basic support for vcpkg.
TheVeryDarkness Oct 13, 2023
0df54a2
Improve support for wasm32.
TheVeryDarkness Oct 13, 2023
0b30251
Fix a warning.
TheVeryDarkness Oct 13, 2023
651f28c
Make clippy happy
TheVeryDarkness Oct 13, 2023
c284d15
Merge remote-tracking branch 'upstream/master' into add-vcpkg
TheVeryDarkness Oct 18, 2023
2d8d63f
Refactor the process.
TheVeryDarkness Oct 18, 2023
02de1e7
Added a ci test for vcpkg-installed z3
TheVeryDarkness Oct 18, 2023
7716650
Fix mistakes in ci
TheVeryDarkness Oct 18, 2023
e4bcbdc
Merge remote-tracking branch 'upstream' into add-vcpkg
TheVeryDarkness Oct 18, 2023
ed6b65b
Rename build_z3 to build_bundled_z3
TheVeryDarkness Oct 18, 2023
728b962
Revert "Improve support for wasm32."
TheVeryDarkness Oct 18, 2023
8eedfa7
Merge branch 'add-vcpkg' of https://github.com/TheVeryDarkness/z3.rs …
TheVeryDarkness Oct 18, 2023
d10c623
Merge branch 'add-vcpkg' of https://github.com/TheVeryDarkness/z3.rs …
TheVeryDarkness Oct 18, 2023
d4d3164
Fix an error in build script.
TheVeryDarkness Oct 18, 2023
a31eb7f
Fix an error in ci
TheVeryDarkness Oct 18, 2023
9f0bd1d
Fixing ci errors.
TheVeryDarkness Oct 18, 2023
a5b44da
Force to set VCPKG_ROOT in CI
TheVeryDarkness Oct 18, 2023
ecb607b
Remove macos and a redundant step from workflows
TheVeryDarkness Oct 18, 2023
63aa222
No fail fast
TheVeryDarkness Oct 18, 2023
6c0f856
Test on windows only.
TheVeryDarkness Oct 18, 2023
25a913e
Clean build trees after build.
TheVeryDarkness Oct 18, 2023
e5244a6
Test only on Windows indeed.
TheVeryDarkness Oct 18, 2023
bfb6a46
Show default toolchain of rust.
TheVeryDarkness Oct 18, 2023
af5bd2e
Merge pull request #1 from TheVeryDarkness/master
TheVeryDarkness Oct 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
51 changes: 45 additions & 6 deletions z3-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::env;

#[cfg(not(feature = "vcpkg"))]
const Z3_HEADER_VAR: &str = "Z3_SYS_Z3_HEADER";

#[cfg(not(feature = "vcpkg"))]
fn main() {
#[cfg(feature = "static-link-z3")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to rename static-link-z3 to bundled as the static linking isn't what's actually getting handled here. Either vcpkg or static-link-z3 should be set, but not both.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I see. I may do that tomorrow as it's midnight here. Thanks.

build_z3();
Expand All @@ -17,6 +19,33 @@ fn main() {
};
println!("cargo:rerun-if-env-changed={}", Z3_HEADER_VAR);
println!("cargo:rerun-if-changed={}", header);

generate_binding(&header);
}

#[cfg(feature = "vcpkg")]
TheVeryDarkness marked this conversation as resolved.
Show resolved Hide resolved
fn main() {
let lib = vcpkg::Config::new()
.emit_includes(true)
.find_package("z3")
.unwrap();
let found_header = lib.include_paths.iter().any(|include| {
TheVeryDarkness marked this conversation as resolved.
Show resolved Hide resolved
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 All @@ -31,16 +60,26 @@ fn main() {
"symbol_kind",
] {
let mut enum_bindings = bindgen::Builder::default()
.header(&header)
.header(header)
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate_comments(false)
.rustified_enum(format!("Z3_{}", x))
.allowlist_type(format!("Z3_{}", x));
if env::var("TARGET").unwrap() == "wasm32-unknown-emscripten" {
enum_bindings = enum_bindings.clang_arg(format!(
"--sysroot={}/upstream/emscripten/cache/sysroot",
env::var("EMSDK").expect("$EMSDK env var missing. Is emscripten installed?")
));
let target = env::var("TARGET").unwrap();
TheVeryDarkness marked this conversation as resolved.
Show resolved Hide resolved
let wasm32 = target.starts_with("wasm32-unknown");
let wasm32_emscripten = target == "wasm32-unknown-emscripten";
if wasm32 {
let sysroot = env::var("EMSDK")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that sometimes the cache may be missing for fresh emscripten installation. So I'm not sure whether we should add some notices here.

.map(|emsdk| format!("{}/upstream/emscripten/cache/sysroot", emsdk))
.or_else(|_err| {
env::var("EMSCRIPTEN_ROOT")
.map(|emscripten_root| format!("{}/cache/sysroot", emscripten_root))
});
if let Ok(sysroot) = sysroot {
enum_bindings = enum_bindings.clang_arg(format!("--sysroot={}", sysroot));
} else if wasm32_emscripten {
panic!("$EMSDK and $EMSCRIPTEN_ROOT env var missing. Is emscripten installed?");
}
}
enum_bindings
.generate()
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
2 changes: 1 addition & 1 deletion z3/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ fn test_tactic_fail() {

let tactic = Tactic::new(&ctx, "fail");
let apply_results = tactic.apply(&goal, Some(&params));
assert!(matches!(apply_results, Err(_)));
assert!(apply_results.is_err());
TheVeryDarkness marked this conversation as resolved.
Show resolved Hide resolved
}

#[test]
Expand Down