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

Z3: Revise the recipe to support Conan v2 and add the latest four minor releases. #17244

Merged
merged 21 commits into from
Jun 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
15d9d39
z3: Remove the entry `base_path` from each patch descriptor.
0xFireWolf Apr 26, 2023
65ada13
z3: Create the test package for Conan 1.x.
0xFireWolf Apr 26, 2023
d610395
z3: Make the test package compatible with Conan 2.x.
0xFireWolf Apr 26, 2023
94041c5
z3: Make the recipe compatible with Conan 2.x.
0xFireWolf Apr 26, 2023
64aa0b9
z3: Add the latest three stable releases, 4.12.1, 4.11.2, 4.10.2.
0xFireWolf Apr 26, 2023
c80efa4
z3: Add a new boolean option `use_gmp` to specify whether the GMP lib…
0xFireWolf Apr 26, 2023
c8fad7b
z3: Patch `CMakeLists.txt` for all supported versions to use the GMP …
0xFireWolf Apr 26, 2023
8e98135
z3: Add `gmp/6.2.1` as its dependency if and only if users have speci…
0xFireWolf Apr 26, 2023
f2329a1
z3: Remove the deprecated option `multiprecision`.
0xFireWolf Apr 26, 2023
68ec002
z3: Remove unneeded import statements from the recipe.
0xFireWolf Apr 26, 2023
2c9283e
z3: Remove deprecated patches.
0xFireWolf Apr 26, 2023
fbc6f82
z3: Remove deprecated old versions.
0xFireWolf Apr 26, 2023
375635e
z3: Fix an issue that `CMakeLists.txt` is not patched.
0xFireWolf Apr 26, 2023
5c4a696
z3: Add version 4.9.1.
0xFireWolf Apr 26, 2023
d43c6a4
z3: Specify the encoding when accessing `CMakeLists.txt`.
0xFireWolf Apr 26, 2023
4a058b8
z3: Raise the minimum GCC version to 8 because compiling with GCC 7 l…
0xFireWolf Apr 26, 2023
f58e51b
z3: Set the flag `stdlib` for Clang on Linux to fix the linker errors.
0xFireWolf Apr 27, 2023
f437b13
z3: Disable the `DeMorgan` test suite because it triggers a page faul…
0xFireWolf Apr 27, 2023
744c79b
z3: Use `replace_in_file` to patch `CMakeLists.txt`.
0xFireWolf Apr 27, 2023
8690259
z3: Use `CMakeDeps.set_property()` to override the name of the GMP li…
0xFireWolf May 10, 2023
df86366
z3: Add v4.12.2.
0xFireWolf May 29, 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
40 changes: 13 additions & 27 deletions recipes/z3/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
sources:
"4.8.8":
url: "https://github.com/Z3Prover/z3/archive/z3-4.8.8.tar.gz"
sha256: "6962facdcdea287c5eeb1583debe33ee23043144d0e5308344e6a8ee4503bcff"
"4.12.2":
url: "https://github.com/Z3Prover/z3/archive/refs/tags/z3-4.12.2.tar.gz"
sha256: "9f58f3710bd2094085951a75791550f547903d75fe7e2fcb373c5f03fc761b8f"
"4.12.1":
url: "https://github.com/Z3Prover/z3/archive/refs/tags/z3-4.12.1.tar.gz"
sha256: "a3735fabf00e1341adcc70394993c05fd3e2ae167a3e9bb46045e33084eb64a3"
"4.11.2":
url: "https://github.com/Z3Prover/z3/archive/refs/tags/z3-4.11.2.tar.gz"
sha256: "e3a82431b95412408a9c994466fad7252135c8ed3f719c986cd75c8c5f234c7e"
"4.10.2":
url: "https://github.com/Z3Prover/z3/archive/z3-4.10.2.tar.gz"
url: "https://github.com/Z3Prover/z3/archive/refs/tags/z3-4.10.2.tar.gz"
sha256: "889fd035b833775c8cd2eb4723eb011bf916a3e9bf08ce66b31c548acee7a321"

patches:
"4.8.8":
- patch_file: "patches/0001-cmake-use-conan-mpir-4.8.8.patch"
patch_description: "Support building with MPIR"
patch_type: "conan"
base_path: "source_subfolder"

- patch_file: "patches/0002-python-interp-3-4.8.8.patch"
patch_description: "Fix finding the Python interpreter"
patch_type: "backport"
base_path: "source_subfolder"

"4.10.2":
- patch_file: "patches/0001-cmake-use-conan-mpir-4.10.2.patch"
patch_description: "Support building with MPIR"
patch_type: "conan"
base_path: "source_subfolder"

- patch_file: "patches/0003-cmake-try-compile-flags-4.10.2.patch"
patch_description: "Fix flag transmission to CMake try_compile"
patch_type: "portability"
base_path: "source_subfolder"
"4.9.1":
url: "https://github.com/Z3Prover/z3/archive/refs/tags/z3-4.9.1.tar.gz"
sha256: "ca08ba933481242507b2f8b303c3ebdf5d16b0005d397fb45018321dc639a0d7"
154 changes: 66 additions & 88 deletions recipes/z3/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from conans import CMake, ConanFile, tools
from conan.tools.files import apply_conandata_patches, get, rmdir
from conan import ConanFile
from conan.tools.microsoft import check_min_vs
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import export_conandata_patches, apply_conandata_patches, replace_in_file, get, copy, rmdir, save
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.errors import ConanException, ConanInvalidConfiguration
from conan.errors import ConanInvalidConfiguration
import os
import textwrap

required_conan_version = ">=1.50.0"
required_conan_version = ">=1.53.0"


class Z3Conan(ConanFile):
Expand All @@ -21,109 +23,94 @@ class Z3Conan(ConanFile):
"shared": [True, False],
"fPIC": [True, False],
"multithreaded": [True, False],
"multiprecision": ["internal", "gmp", "mpir"]
"use_gmp": [True, False]
Copy link
Contributor

Choose a reason for hiding this comment

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

I've read your rational about this change, but do you know that there is set_property in CMakeDeps to avoid patching upstream CMakeLists? I think we can keep this option without any maintenance burden with some smart set_property.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see what you means. We can pretend that the target name of the MPIR library is GMP::GMP. I will give a try. Thanks for the suggestions.

}
default_options = {
"shared": False,
"fPIC": True,
"multithreaded": True,
"multiprecision": "gmp"
"use_gmp": False
}

generators = "cmake"
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"
def _min_cppstd(self):
return "17"

@property
def _build_subfolder(self):
return "build_subfolder"
def _compilers_minimum_version(self):
# Compiling z3 with GCC 7 results in a segfault
return {
"17": {
"gcc": "8",
"clang": "5",
"apple-clang": "9.1",
},
}.get(self._min_cppstd, {})

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
if self.options.multiprecision == "internal":
self.provides.append("gmp")
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.output.info(
f"{self.name} will build using {self.options.multiprecision} multiprecision implementation.")
if self.options.multiprecision == "mpir":
self.requires("mpir/3.0.0")
elif self.options.multiprecision == "gmp":
if self.options.use_gmp:
self.requires("gmp/6.2.1")
elif self.options.multiprecision == "internal":
pass

def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["Z3_USE_LIB_GMP"] = self.options.multiprecision != "internal"
self._cmake.definitions["Z3_USE_LIB_MPIR"] = self.options.multiprecision == "mpir"
self._cmake.definitions["SINGLE_THREADED"] = not self.options.multithreaded
self._cmake.definitions["Z3_BUILD_LIBZ3_SHARED"] = self.options.shared
self._cmake.definitions["Z3_INCLUDE_GIT_HASH"] = False
self._cmake.definitions["Z3_INCLUDE_GIT_DESCRIBE"] = False
self._cmake.definitions["Z3_ENABLE_EXAMPLE_TARGETS"] = False
self._cmake.definitions["Z3_BUILD_DOCUMENTATION"] = False
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
def validate(self):
# Z3 requires C++17, and it is recommended to use VS2019 or later
check_min_vs(self, "192")

@property
def _compilers_minimum_version(self):
return {
"gcc": "7",
"Visual Studio": "15.7",
"clang": "5",
"apple-clang": "10",
}
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)

def validate(self):
if Version(self.version) >= "4.8.11":
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, "17")
compiler = self.settings.compiler
min_version = self._compilers_minimum_version\
.get(str(compiler), False)
if min_version:
if Version(compiler.version) < min_version:
raise ConanInvalidConfiguration(
f"{self.name} requires C++17, which {compiler} {compiler.version} does not support.")
else:
self.output.info(
f"{self.name} requires C++17. Your compiler is unknown. Assuming it supports C++17.")
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["Z3_USE_LIB_GMP"] = self.options.use_gmp
tc.variables["Z3_SINGLE_THREADED"] = not self.options.multithreaded
tc.variables["Z3_BUILD_LIBZ3_SHARED"] = self.options.shared
tc.variables["Z3_INCLUDE_GIT_HASH"] = False
tc.variables["Z3_INCLUDE_GIT_DESCRIBE"] = False
tc.variables["Z3_ENABLE_EXAMPLE_TARGETS"] = False
tc.variables["Z3_BUILD_DOCUMENTATION"] = False
# Set the flag `stdlib` for Clang on Linux to fix the linker errors
if self.settings.os == "Linux" and self.settings.compiler == "clang":
# Possible values: `libc++`, `libstdc++11` and `libstdc++`
stdlib = f" -stdlib={self.settings.compiler.libcxx}".rstrip("1")
tc.variables["CMAKE_CXX_FLAGS"] = tc.variables.get("CMAKE_CXX_FLAGS", "") + stdlib
tc.generate()
tc = CMakeDeps(self)
# Override the target name of the GMP library provided by Conan Center
if self.options.use_gmp:
tc.set_property("gmp", "cmake_target_name", "GMP::GMP")
tc.generate()

def build(self):
apply_conandata_patches(self)

if self.options.multiprecision == "mpir":
tools.save(os.path.join(self._build_subfolder, "gmp.h"), textwrap.dedent("""\
#pragma once
#include <mpir.h>
"""))

cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE.txt", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
copy(self, "LICENSE.txt", src=os.path.join(self.source_folder), dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
Expand All @@ -146,14 +133,5 @@ def package_info(self):
self.cpp_info.names["cmake_find_package_multi"] = "z3"
self.cpp_info.components["libz3"].names["cmake_find_package"] = "libz3"
self.cpp_info.components["libz3"].names["cmake_find_package_multi"] = "libz3"
self.cpp_info.components["libz3"].set_property(
"cmake_target_name", "z3::libz3")

libz3_requirements = []
if self.options.multiprecision == "mpir":
libz3_requirements.append("mpir::mpir")
elif self.options.multiprecision == "gmp":
libz3_requirements.append("gmp::gmp")
elif self.options.multiprecision == "internal":
pass
self.cpp_info.components["libz3"].requires = libz3_requirements
self.cpp_info.components["libz3"].set_property("cmake_target_name", "z3::libz3")
self.cpp_info.components["libz3"].requires = ["gmp::gmp"] if self.options.use_gmp else []
22 changes: 0 additions & 22 deletions recipes/z3/all/patches/0001-cmake-use-conan-mpir-4.10.2.patch

This file was deleted.

23 changes: 0 additions & 23 deletions recipes/z3/all/patches/0001-cmake-use-conan-mpir-4.8.8.patch

This file was deleted.

11 changes: 0 additions & 11 deletions recipes/z3/all/patches/0002-python-interp-3-4.8.8.patch

This file was deleted.

17 changes: 0 additions & 17 deletions recipes/z3/all/patches/0003-cmake-try-compile-flags-4.10.2.patch

This file was deleted.

6 changes: 2 additions & 4 deletions recipes/z3/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
project(test_package LANGUAGES CXX)

find_package(Z3 REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE z3::libz3)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
19 changes: 14 additions & 5 deletions recipes/z3/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
3 changes: 2 additions & 1 deletion recipes/z3/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,6 @@ void demorgan()

int main() {
simple_example();
demorgan();
// Z3 v4.11.2: Trigger a page fault when compiled with and Clang in release mode
// demorgan();
}
8 changes: 8 additions & 0 deletions recipes/z3/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)
Loading