-
Notifications
You must be signed in to change notification settings - Fork 441
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
Build Z3 from source for P4Tools. #4697
Draft
fruffy
wants to merge
2
commits into
main
Choose a base branch
from
fruffy/z3_source
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+151
−92
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
macro(p4tools_obtain_z3) | ||
option(TOOLS_USE_PREINSTALLED_Z3 "Look for a preinstalled version of Z3 instead of installing a prebuilt binary using FetchContent." OFF) | ||
|
||
if(TOOLS_USE_PREINSTALLED_Z3) | ||
# We need a fairly recent version of Z3. | ||
set(Z3_MIN_VERSION "4.8.14") | ||
# But 4.12+ is currently broken with libGC | ||
set(Z3_MAX_VERSION_EXCL "4.12") | ||
find_package(Z3 ${Z3_MIN_VERSION} REQUIRED) | ||
|
||
if(NOT DEFINED Z3_VERSION_STRING OR ${Z3_VERSION_STRING} VERSION_LESS ${Z3_MIN_VERSION}) | ||
message(FATAL_ERROR "The minimum required Z3 version is ${Z3_MIN_VERSION}. Has ${Z3_VERSION_STRING}.") | ||
endif() | ||
if(${Z3_VERSION_STRING} VERSION_GREATER_EQUAL ${Z3_MAX_VERSION_EXCL}) | ||
message(FATAL_ERROR "The Z3 version has to be lower than ${Z3_MAX_VERSION_EXCL} (the latter currently does no work with libGC). Has ${Z3_VERSION_STRING}.") | ||
endif() | ||
# Set variables for later consumption. | ||
set(P4TOOLS_Z3_LIB z3::z3) | ||
set(P4TOOLS_Z3_INCLUDE_DIR ${Z3_INCLUDE_DIR}) | ||
else() | ||
# Pull in a specific version of Z3 and link against it. | ||
set(P4TOOLS_Z3_VERSION "4.13.0") | ||
message(STATUS "Fetching Z3 version ${P4TOOLS_Z3_VERSION} for P4Tools...") | ||
|
||
# Unity builds do not work for Protobuf... | ||
set(CMAKE_UNITY_BUILD_PREV ${CMAKE_UNITY_BUILD}) | ||
set(CMAKE_UNITY_BUILD OFF) | ||
# Print out download state while setting up Z3. | ||
set(FETCHCONTENT_QUIET_PREV ${FETCHCONTENT_QUIET}) | ||
set(FETCHCONTENT_QUIET OFF) | ||
|
||
set(Z3_BUILD_LIBZ3_SHARED OFF CACHE BOOL "Build libz3 as a shared library if true, otherwise build a static library") | ||
set(Z3_INCLUDE_GIT_HASH OFF CACHE BOOL "Include git hash in version output") | ||
set(Z3_INCLUDE_GIT_DESCRIBE OFF CACHE BOOL "Include git describe output in version output") | ||
set(Z3_BUILD_TEST_EXECUTABLES OFF CACHE BOOL "Include git describe output in version output") | ||
set(Z3_SAVE_CLANG_OPTIMIZATION_RECORDS OFF CACHE BOOL "Include git describe output in version output") | ||
set(Z3_ENABLE_TRACING_FOR_NON_DEBUG OFF CACHE BOOL "Include git describe output in version output") | ||
set(Z3_ENABLE_EXAMPLE_TARGETS OFF CACHE BOOL "Include git describe output in version output") | ||
set(Z3_BUILD_DOTNET_BINDINGS OFF CACHE BOOL "Include git describe output in version output") | ||
set(Z3_BUILD_PYTHON_BINDINGS OFF CACHE BOOL "Include git describe output in version output") | ||
set(Z3_BUILD_JAVA_BINDINGS OFF CACHE BOOL "Include git describe output in version output") | ||
set(Z3_BUILD_JULIA_BINDINGS OFF CACHE BOOL "Include git describe output in version output") | ||
set(Z3_BUILD_DOCUMENTATION OFF CACHE BOOL "Include git describe output in version output") | ||
set(Z3_ALWAYS_BUILD_DOCS OFF CACHE BOOL "Include git describe output in version output") | ||
set(Z3_API_LOG_SYNC OFF CACHE BOOL "Include git describe output in version output") | ||
set(Z3_BUILD_EXECUTABLE OFF CACHE BOOL "Include git describe output in version output") | ||
fetchcontent_declare( | ||
z3 | ||
GIT_REPOSITORY https://github.com/Z3Prover/z3.git | ||
GIT_TAG 51fcb10b2ff0e4496a3c0c2ed7c32f0876c9ee49 # 4.13.0 | ||
GIT_PROGRESS TRUE | ||
# GIT_SHALLOW TRUE | ||
# We need to patch because the Z3 CMakeLists.txt also adds an uinstall target. | ||
# This leads to a namespace clash. | ||
PATCH_COMMAND | ||
git apply ${P4TOOLS_SOURCE_DIR}/cmake/z3.patch || git apply | ||
${P4TOOLS_SOURCE_DIR}/cmake/z3.patch -R --check && echo | ||
"Patch does not apply because the patch was already applied." | ||
) | ||
fetchcontent_makeavailable_but_exclude_install(z3) | ||
|
||
# Suppress warnings for all Z3 targets. | ||
get_all_targets(Z3_BUILD_TARGETS ${z3_SOURCE_DIR}) | ||
foreach(target ${Z3_BUILD_TARGETS}) | ||
# Do not suppress warnings for Z3 library targets that are aliased. | ||
get_target_property(target_type ${target} TYPE) | ||
if (NOT ${target_type} STREQUAL "INTERFACE_LIBRARY") | ||
target_compile_options(${target} PRIVATE "-Wno-error" "-w") | ||
# Z3 does not add its own include directories for compilation, which can lead to conflicts. | ||
target_include_directories(${target} BEFORE PRIVATE ${z3_SOURCE_DIR}/src) | ||
endif() | ||
endforeach() | ||
|
||
# Reset temporary variable modifications. | ||
set(CMAKE_UNITY_BUILD ${CMAKE_UNITY_BUILD_PREV}) | ||
set(FETCHCONTENT_QUIET ${FETCHCONTENT_QUIET_PREV}) | ||
|
||
# Other projects may also pull in Z3. | ||
# We have to make sure we only include our local version with P4Tools. | ||
set(P4TOOLS_Z3_LIB libz3) | ||
set(P4TOOLS_Z3_INCLUDE_DIR ${z3_SOURCE_DIR}/src/api ${z3_SOURCE_DIR}/src/api/c++) | ||
endif() | ||
|
||
message(STATUS "Done with setting up Z3 for P4Tools.") | ||
endmacro(p4tools_obtain_z3) |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index ba3ec7bce..7ca1894fd 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -446,13 +446,13 @@ configure_file( | ||
|
||
# Target needs to be declared before the components so that they can add | ||
# dependencies to this target so they can run their own custom uninstall rules. | ||
-add_custom_target(uninstall | ||
- COMMAND | ||
- "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" | ||
- COMMENT "Uninstalling..." | ||
- USES_TERMINAL | ||
- VERBATIM | ||
-) | ||
+# add_custom_target(uninstall | ||
+# COMMAND | ||
+# "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" | ||
+# COMMENT "Uninstalling..." | ||
+# USES_TERMINAL | ||
+# VERBATIM | ||
+# ) | ||
|
||
################################################################################ | ||
# CMake build file locations | ||
diff --git a/src/util/memory_manager.cpp b/src/util/memory_manager.cpp | ||
index 290881ba5..a3db94d7a 100644 | ||
--- a/src/util/memory_manager.cpp | ||
+++ b/src/util/memory_manager.cpp | ||
@@ -29,6 +29,8 @@ Copyright (c) 2015 Microsoft Corporation | ||
# define malloc_usable_size _msize | ||
#endif | ||
|
||
+#undef HAS_MALLOC_USABLE_SIZE | ||
+ | ||
// The following two function are automatically generated by the mk_make.py script. | ||
// The script collects ADD_INITIALIZER and ADD_FINALIZER commands in the .h files. | ||
// For example, rational.h contains |
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
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
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
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
Oops, something went wrong.
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.
It seems odd that Z#_MAX_VERSION_EXCL above is 4.12, but you are explicitly pulling in 4.13.0 here. Do you expect one of those two things to change before this PR is ready to merge?
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.
Z3 versions above 4.12 added malloc_usable_size which causes problems with P4C's garbage collector. I have not figured out a fix for BDWGC yet.
When we build from scratch we do not have this problem because we can patch the Z3 installation.
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.
That should be a comment clarifying that.
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.
There is some more work to be done first, need to figure out whether it is possible to patch bdwgc instead.