-
Notifications
You must be signed in to change notification settings - Fork 110
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
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 0df54a2
Improve support for wasm32.
TheVeryDarkness 0b30251
Fix a warning.
TheVeryDarkness 651f28c
Make clippy happy
TheVeryDarkness c284d15
Merge remote-tracking branch 'upstream/master' into add-vcpkg
TheVeryDarkness 2d8d63f
Refactor the process.
TheVeryDarkness 02de1e7
Added a ci test for vcpkg-installed z3
TheVeryDarkness 7716650
Fix mistakes in ci
TheVeryDarkness e4bcbdc
Merge remote-tracking branch 'upstream' into add-vcpkg
TheVeryDarkness ed6b65b
Rename build_z3 to build_bundled_z3
TheVeryDarkness 728b962
Revert "Improve support for wasm32."
TheVeryDarkness 8eedfa7
Merge branch 'add-vcpkg' of https://github.com/TheVeryDarkness/z3.rs …
TheVeryDarkness d10c623
Merge branch 'add-vcpkg' of https://github.com/TheVeryDarkness/z3.rs …
TheVeryDarkness d4d3164
Fix an error in build script.
TheVeryDarkness a31eb7f
Fix an error in ci
TheVeryDarkness 9f0bd1d
Fixing ci errors.
TheVeryDarkness a5b44da
Force to set VCPKG_ROOT in CI
TheVeryDarkness ecb607b
Remove macos and a redundant step from workflows
TheVeryDarkness 63aa222
No fail fast
TheVeryDarkness 6c0f856
Test on windows only.
TheVeryDarkness 25a913e
Clean build trees after build.
TheVeryDarkness e5244a6
Test only on Windows indeed.
TheVeryDarkness bfb6a46
Show default toolchain of rust.
TheVeryDarkness af5bd2e
Merge pull request #1 from TheVeryDarkness/master
TheVeryDarkness File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,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")] | ||
build_z3(); | ||
|
@@ -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 &[ | ||
|
@@ -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") | ||
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. 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() | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
tobundled
as the static linking isn't what's actually getting handled here. Eithervcpkg
orstatic-link-z3
should be set, but not both.There was a problem hiding this comment.
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.