From 52526d5dad66ef846f3452c5f4e8b5d44aee3c18 Mon Sep 17 00:00:00 2001 From: toge Date: Tue, 6 Feb 2024 12:47:57 +0900 Subject: [PATCH] (#22455) scnlib: add version 2.0.0, remove older version * scnlib: add version 2.0.0 * support other options * remove 0.4, preserve header_only option * add build_requirements * drop support gcc11 in 2.0.0 * drop support apple-clang 12, 13 due to std::regex_constants::multiline * update msvc version * drop support msvc on C++17 * update fast_float/6.1.0 --- recipes/scnlib/all/conandata.yml | 14 +-- recipes/scnlib/all/conanfile.py | 110 ++++++++++++++---- .../0.4-0001-install-dll-windows.patch | 10 -- .../2.0.0-0001-remove-re2-version.patch | 13 +++ .../scnlib/all/test_package/CMakeLists.txt | 7 +- .../scnlib/all/test_package/test_package.cpp | 26 ++++- recipes/scnlib/config.yml | 4 +- 7 files changed, 136 insertions(+), 48 deletions(-) delete mode 100644 recipes/scnlib/all/patches/0.4-0001-install-dll-windows.patch create mode 100644 recipes/scnlib/all/patches/2.0.0-0001-remove-re2-version.patch diff --git a/recipes/scnlib/all/conandata.yml b/recipes/scnlib/all/conandata.yml index fc615b57c8109..28c026a4701a3 100644 --- a/recipes/scnlib/all/conandata.yml +++ b/recipes/scnlib/all/conandata.yml @@ -1,4 +1,7 @@ sources: + "2.0.0": + url: "https://github.com/eliaskosunen/scnlib/archive/refs/tags/v2.0.0.tar.gz" + sha256: "2a35356a3a7485fdf97f28cfbea52db077cf4e7bab0a5a0fc3b04e89630334cd" "1.1.3": url: "https://github.com/eliaskosunen/scnlib/archive/refs/tags/v1.1.3.tar.gz" sha256: "32ca1baed2da5d86aa03273c87580ef32e95925697d252138507ec0545d86ab2" @@ -8,10 +11,11 @@ sources: "1.0": url: "https://github.com/eliaskosunen/scnlib/archive/refs/tags/v1.0.tar.gz" sha256: "5b8333e522206c2a74e57a9c9544c4fe4e7858cfe93e216905b463eaf91af5fe" - "0.4": - url: "https://github.com/eliaskosunen/scnlib/archive/refs/tags/v0.4.tar.gz" - sha256: "f23e66b00c9d38671b39b83c082a5b2db1cf05b3e3eff7b4a769487d9ed9d366" patches: + "2.0.0": + - patch_file: "patches/2.0.0-0001-remove-re2-version.patch" + patch_description: "remove re2 version on find_package" + patch_type: "portability" "1.1.3": - patch_file: "patches/1.1.3-0001-install-dll-windows.patch" patch_description: "add runtime destination path on install" @@ -42,7 +46,3 @@ patches: - patch_file: "patches/1.0-0003-use-conan-package.patch" patch_description: "use conan package of fast-float" patch_type: "conan" - "0.4": - - patch_file: "patches/0.4-0001-install-dll-windows.patch" - patch_description: "add runtime destination path on install" - patch_type: "portability" diff --git a/recipes/scnlib/all/conanfile.py b/recipes/scnlib/all/conanfile.py index 3760576fb6438..c08cd042027e8 100644 --- a/recipes/scnlib/all/conanfile.py +++ b/recipes/scnlib/all/conanfile.py @@ -1,10 +1,11 @@ from conan import ConanFile -from conan.tools.microsoft import check_min_vs from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir from conan.tools.build import check_min_cppstd from conan.tools.scm import Version from conan.tools.layout import basic_layout from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.microsoft import is_msvc +from conan.errors import ConanInvalidConfiguration import os @@ -23,16 +24,40 @@ class ScnlibConan(ConanFile): "header_only": [True, False], "shared": [True, False], "fPIC": [True, False], + "regex_backend": ["None", "std", "boost", "boost_icu", "re2"], } default_options = { "header_only": False, "shared": False, "fPIC": True, + "regex_backend": "std", } @property def _min_cppstd(self): - return 11 + if Version(self.version) < "2.0.0": + return "11" + else: + # scn/2.0.0 has complation error on MSVC c++17 + # we have to use versions which support c++20 + # https://github.com/eliaskosunen/scnlib/issues/97 + # https://github.com/conan-io/conan-center-index/pull/22455#issuecomment-1924444193 + return "20" if is_msvc(self) else "17" + + @property + def _compilers_minimum_version(self): + return { + "17": { + "gcc": "8", + "clang": "7", + # scn/2.0.0 requires std::regex_constants::multiline + "apple-clang": "14", + }, + "20": { + "Visual Studio": "17", + "msvc": "193", + } + }.get(self._min_cppstd, {}) def export_sources(self): export_conandata_patches(self) @@ -40,37 +65,61 @@ def export_sources(self): def config_options(self): if self.settings.os == "Windows": del self.options.fPIC + if Version(self.version) < "2.0": + del self.options.regex_backend def configure(self): - if self.options.header_only or self.options.shared: + if self.options.get_safe("header_only") or self.options.shared: self.options.rm_safe("fPIC") - if self.options.header_only: + if self.options.get_safe("header_only"): del self.options.shared + self.package_type = "header-library" def layout(self): - if self.options.header_only: + if self.options.get_safe("header_only"): basic_layout(self, src_folder="src") else: cmake_layout(self, src_folder="src") def requirements(self): - if Version(self.version) >= "1.0": - self.requires("fast_float/6.0.0") + self.requires("fast_float/6.1.0") + if Version(self.version) >= "2.0": + self.requires("simdutf/4.0.5") + if self.options.get_safe("regex_backend") in ["boost", "boost_icu"]: + self.requires("boost/1.83.0") + elif self.options.get_safe("regex_backend") == "re2": + self.requires("re2/20231101") + + def package_id(self): + if self.info.options.get_safe("header_only"): + self.info.clear() def validate(self): if self.settings.compiler.get_safe("cppstd"): check_min_cppstd(self, self._min_cppstd) - check_min_vs(self, 192 if Version(self.version) >= "1.0" else 191) - - def package_id(self): - if self.info.options.header_only: - self.info.clear() + 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." + ) + if self.options.get_safe("regex_backend") == "boost_icu" and \ + not self.dependencies["boost"].options.get_safe("i18n_backend_icu"): + raise ConanInvalidConfiguration( + f"{self.ref} with regex_backend=Boost_icu option requires boost::i18n_backend_icu to be enabled." + ) + if Version(self.version) >= "2.0.0" and self.options.header_only: + raise ConanInvalidConfiguration(f"{self.ref} doesn't support header only mode.") + if Version(self.version) >= "2.0.0" and self.settings.compiler == "gcc" and Version(self.settings.compiler.version).major == "11": + raise ConanInvalidConfiguration(f"{self.ref} doesn't support gcc 11.x due to std::regex_constants::multiline is not defined.") + + def build_requirements(self): + self.tool_requires("cmake/[>=3.16 <4]") def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) def generate(self): - if self.options.header_only: + if self.options.get_safe("header_only"): return tc = CMakeToolchain(self) @@ -80,8 +129,17 @@ def generate(self): tc.variables["SCN_DOCS"] = False tc.variables["SCN_INSTALL"] = True tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True - if Version(self.version) >= "1.0": + if Version(self.version) < "2.0": tc.variables["SCN_USE_BUNDLED_FAST_FLOAT"] = False + else: + tc.variables["SCN_USE_EXTERNAL_SIMDUTF"] = True + tc.variables["SCN_USE_EXTERNAL_FAST_FLOAT"] = True + tc.variables["SCN_BENCHMARKS_BUILDTIME"] = False + tc.variables["SCN_BENCHMARKS_BINARYSIZE"] = False + tc.variables["SCN_DISABLE_REGEX"] = self.options.regex_backend is None + if self.options.regex_backend is not None: + tc.variables["SCN_REGEX_BACKEND"] = self.options.regex_backend + tc.variables["SCN_USE_EXTERNAL_REGEX_BACKEND"] = True tc.generate() deps = CMakeDeps(self) @@ -89,14 +147,14 @@ def generate(self): def build(self): apply_conandata_patches(self) - if not self.options.header_only: + if not self.options.get_safe("header_only"): cmake = CMake(self) cmake.configure() cmake.build() def package(self): copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) - if self.options.header_only: + if self.options.get_safe("header_only"): copy(self, "*", dst=os.path.join(self.package_folder, "include"), src=os.path.join(self.source_folder, "include")) src_folder = os.path.join(self.source_folder, "src") if Version(self.version) >= "1.0": @@ -111,23 +169,27 @@ def package(self): cmake.install() rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) rmdir(self, os.path.join(self.package_folder, "share")) - if Version(self.version) >= "1.0": - rm(self, "*.cmake", os.path.join(self.package_folder, "include", "scn", "detail")) - rmdir(self, os.path.join(self.package_folder, "include", "scn", "detail", "CMakeFiles")) - rmdir(self, os.path.join(self.package_folder, "include", "scn", "detail", "deps", "CMakeFiles")) + rm(self, "*.cmake", os.path.join(self.package_folder, "include", "scn", "detail")) + rmdir(self, os.path.join(self.package_folder, "include", "scn", "detail", "CMakeFiles")) + rmdir(self, os.path.join(self.package_folder, "include", "scn", "detail", "deps", "CMakeFiles")) def package_info(self): - target = "scn-header-only" if self.options.header_only else "scn" + target = "scn-header-only" if self.options.get_safe("header_only") else "scn" self.cpp_info.set_property("cmake_file_name", "scn") self.cpp_info.set_property("cmake_target_name", f"scn::{target}") # TODO: back to global scope in conan v2 once cmake_find_package* generators removed - if self.options.header_only: + if self.options.get_safe("header_only"): self.cpp_info.components["_scnlib"].defines = ["SCN_HEADER_ONLY=1"] else: self.cpp_info.components["_scnlib"].defines = ["SCN_HEADER_ONLY=0"] self.cpp_info.components["_scnlib"].libs = ["scn"] - if Version(self.version) >= "1.0": - self.cpp_info.components["_scnlib"].requires = ["fast_float::fast_float"] + self.cpp_info.components["_scnlib"].requires.append("fast_float::fast_float") + if Version(self.version) >= "2.0": + self.cpp_info.components["_scnlib"].requires.append("simdutf::simdutf") + if self.options.get_safe("regex_backend") in ["boost", "boost_icu"]: + self.cpp_info.components["_scnlib"].requires.append("boost::regex") + elif self.options.get_safe("regex_backend") == "re2": + self.cpp_info.components["_scnlib"].requires.append("re2::re2") if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.components["_scnlib"].system_libs.append("m") diff --git a/recipes/scnlib/all/patches/0.4-0001-install-dll-windows.patch b/recipes/scnlib/all/patches/0.4-0001-install-dll-windows.patch deleted file mode 100644 index 8928ce2f8c250..0000000000000 --- a/recipes/scnlib/all/patches/0.4-0001-install-dll-windows.patch +++ /dev/null @@ -1,10 +0,0 @@ ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -145,6 +145,7 @@ if (SCN_INSTALL) - - install(TARGETS ${SCN_EXPORT_TARGETS_LIST} - EXPORT scnTargets -+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/recipes/scnlib/all/patches/2.0.0-0001-remove-re2-version.patch b/recipes/scnlib/all/patches/2.0.0-0001-remove-re2-version.patch new file mode 100644 index 0000000000000..a256652f48c41 --- /dev/null +++ b/recipes/scnlib/all/patches/2.0.0-0001-remove-re2-version.patch @@ -0,0 +1,13 @@ +diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake +index ae2832b..fec6359 100644 +--- a/cmake/dependencies.cmake ++++ b/cmake/dependencies.cmake +@@ -154,7 +154,7 @@ if (SCN_REGEX_BACKEND STREQUAL "re2") + message(FATAL_ERROR "SCN_REGEX_BOOST_USE_ICU isn't supported when SCN_REGEX_BACKEND is re2") + endif () + +- find_package(re2 11.0.0 REQUIRED) ++ find_package(re2 REQUIRED) + set(SCN_REGEX_BACKEND_TARGET re2::re2) + endif () + diff --git a/recipes/scnlib/all/test_package/CMakeLists.txt b/recipes/scnlib/all/test_package/CMakeLists.txt index 0c68330d44cd3..ebeda65ce06fe 100644 --- a/recipes/scnlib/all/test_package/CMakeLists.txt +++ b/recipes/scnlib/all/test_package/CMakeLists.txt @@ -9,4 +9,9 @@ if(TARGET scn::scn-header-only) else() target_link_libraries(${PROJECT_NAME} PRIVATE scn::scn) endif() -target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +if (scn_VERSION VERSION_LESS "2.0.0") + target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) +else() + target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17) + target_compile_definitions(${PROJECT_NAME} PUBLIC SCNLIB_V2) +endif() diff --git a/recipes/scnlib/all/test_package/test_package.cpp b/recipes/scnlib/all/test_package/test_package.cpp index 148a9caff4852..276439b1c0eb3 100644 --- a/recipes/scnlib/all/test_package/test_package.cpp +++ b/recipes/scnlib/all/test_package/test_package.cpp @@ -1,9 +1,27 @@ +#include +#include + +#ifndef SCNLIB_V2 + #include -#include +int main() { + std::string word; + auto result = scn::scan("Hello world", "{}", word); + std::cout << word << '\n'; + std::cout << result.range_as_string() << '\n'; +} + +#else + +#include int main() { - std::string s{"conan-center-index"}; - auto span = scn::make_span(s); - return 0; + if (auto result = scn::scan("Hello world!", "{}")) { + std::cout << result->value() << '\n'; + } else { + std::cout << "Couldn't parse a word: " << result.error().msg() << '\n'; + } } + +#endif diff --git a/recipes/scnlib/config.yml b/recipes/scnlib/config.yml index 3305d97b32797..8d8acc5534543 100644 --- a/recipes/scnlib/config.yml +++ b/recipes/scnlib/config.yml @@ -1,9 +1,9 @@ versions: + "2.0.0": + folder: all "1.1.3": folder: all "1.1.2": folder: all "1.0": folder: all - "0.4": - folder: all