From ec22cbbef9f89129975d53eb7149db8eb1f6db1f Mon Sep 17 00:00:00 2001 From: German Novikov Date: Tue, 11 Apr 2023 09:30:18 +0300 Subject: [PATCH] (#16701) wil: recipe added * wil recipe added * fix test_package * added _min_cpp to the recipe * fixed layot * fixes * removed camke_module_file_name/cmake_module_target_name * added patch for type conversion * Update 1.0.230202.1-0001-fix-type-conversion.patch * Update recipes/wil/all/conanfile.py Co-authored-by: Chris Mc * Update recipes/wil/all/test_package/CMakeLists.txt Co-authored-by: Chris Mc * Update conanfile.py * fix patch type and added source * removed gcc and clang from _compilers_min_version * fixed test_package.cpp * changed type of patch to bugfix * fixup: patch type should be portability since it adds support for vs 2017 --------- Co-authored-by: Chris Mc --- recipes/wil/all/conandata.yml | 12 +++ recipes/wil/all/conanfile.py | 93 +++++++++++++++++++ ....0.230202.1-0001-fix-type-conversion.patch | 11 +++ recipes/wil/all/test_package/CMakeLists.txt | 8 ++ recipes/wil/all/test_package/conanfile.py | 27 ++++++ recipes/wil/all/test_package/test_package.cpp | 12 +++ .../wil/all/test_v1_package/CMakeLists.txt | 8 ++ recipes/wil/all/test_v1_package/conanfile.py | 19 ++++ recipes/wil/config.yml | 3 + 9 files changed, 193 insertions(+) create mode 100644 recipes/wil/all/conandata.yml create mode 100644 recipes/wil/all/conanfile.py create mode 100644 recipes/wil/all/patches/1.0.230202.1-0001-fix-type-conversion.patch create mode 100644 recipes/wil/all/test_package/CMakeLists.txt create mode 100644 recipes/wil/all/test_package/conanfile.py create mode 100644 recipes/wil/all/test_package/test_package.cpp create mode 100644 recipes/wil/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/wil/all/test_v1_package/conanfile.py create mode 100644 recipes/wil/config.yml diff --git a/recipes/wil/all/conandata.yml b/recipes/wil/all/conandata.yml new file mode 100644 index 00000000000000..c9a6344cdb846e --- /dev/null +++ b/recipes/wil/all/conandata.yml @@ -0,0 +1,12 @@ +sources: + "1.0.230202.1": + url: "https://github.com/microsoft/wil/archive/refs/tags/v1.0.230202.1.tar.gz" + sha256: "7bf01e9d93fb93f0fe2614492fac4a423b3a97b435015db74f5ac4a0270ebc8a" +patches: + "1.0.230202.1": + - patch_file: "patches/1.0.230202.1-0001-fix-type-conversion.patch" + patch_description: "Explicitly writing the type instead of using decltype" + patch_source: | + https://github.com/microsoft/wil/issues/302#issuecomment-1482117200 + https://github.com/microsoft/wil/pull/316 + patch_type: portability diff --git a/recipes/wil/all/conanfile.py b/recipes/wil/all/conanfile.py new file mode 100644 index 00000000000000..32f511bb89acfa --- /dev/null +++ b/recipes/wil/all/conanfile.py @@ -0,0 +1,93 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy +from conan.tools.layout import basic_layout +from conan.tools.scm import Version +import os + + +required_conan_version = ">=1.52.0" + + +class WilConan(ConanFile): + name = "wil" + description = ( + "The Windows Implementation Libraries (WIL) is a header-only C++ library" + "created to make life easier for developers on Windows through readable" + "type-safe C++ interfaces for common Windows coding patterns." + ) + license = "MIT" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/microsoft/wil" + topics = ("win", "wil", "header-only") + package_type = "header-library" + # only arch is aplicable, windows library + settings = "os", "arch", "compiler", "build_type" + + no_copy_source = True + + @property + def _min_cppstd(self): + return 11 + + @property + def _compilers_minimum_version(self): + return { + "Visual Studio": "15", + "msvc": "14.1" + } + + # About compiler version: https://github.com/microsoft/wil/issues/207#issuecomment-991722592 + def export_sources(self): + export_conandata_patches(self) + + def layout(self): + basic_layout(self, src_folder="src") + + # same package ID for any package + def package_id(self): + self.info.clear() + + def validate(self): + if self.settings.compiler.get_safe("cppstd"): + # Validate the minimum cpp standard supported when installing the package. For C++ projects only + check_min_cppstd(self, self._min_cppstd) + 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.settings.os != "Windows": + raise ConanInvalidConfiguration(f"{self.ref} can be used only on Windows.") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def build(self): + apply_conandata_patches(self) + + def package(self): + copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + copy( + self, + pattern="*.h", + dst=os.path.join(self.package_folder, "include"), + src=os.path.join(self.source_folder, "include"), + ) + + def package_info(self): + # Folders not used for header-only + self.cpp_info.bindirs = [] + self.cpp_info.libdirs = [] + + # https://github.com/microsoft/wil/blob/56e3e5aa79234f8de3ceeeaf05b715b823bc2cca/CMakeLists.txt#L53 + self.cpp_info.set_property("cmake_file_name", "WIL") + self.cpp_info.set_property("cmake_target_name", "WIL::WIL") + + # TODO: to remove in conan v2 once cmake_find_package_* generators removed + self.cpp_info.filenames["cmake_find_package"] = "WIL" + self.cpp_info.filenames["cmake_find_package_multi"] = "WIL" + self.cpp_info.names["cmake_find_package"] = "WIL" + self.cpp_info.names["cmake_find_package_multi"] = "WIL" diff --git a/recipes/wil/all/patches/1.0.230202.1-0001-fix-type-conversion.patch b/recipes/wil/all/patches/1.0.230202.1-0001-fix-type-conversion.patch new file mode 100644 index 00000000000000..3144a0ddbd304f --- /dev/null +++ b/recipes/wil/all/patches/1.0.230202.1-0001-fix-type-conversion.patch @@ -0,0 +1,11 @@ +--- a/include/wil/resource.h ++++ b/include/wil/resource.h +@@ -2547,7 +2547,7 @@ namespace wil + } + + template +- using unique_private_namespace = unique_any_handle_null_only), &details::ClosePrivateNamespaceHelper>; ++ using unique_private_namespace = unique_any_handle_null_only>; + + using unique_private_namespace_close = unique_private_namespace<>; + using unique_private_namespace_destroy = unique_private_namespace; diff --git a/recipes/wil/all/test_package/CMakeLists.txt b/recipes/wil/all/test_package/CMakeLists.txt new file mode 100644 index 00000000000000..5cc9ea385c9848 --- /dev/null +++ b/recipes/wil/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES CXX) + +find_package(WIL REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE WIL::WIL) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) diff --git a/recipes/wil/all/test_package/conanfile.py b/recipes/wil/all/test_package/conanfile.py new file mode 100644 index 00000000000000..48499fa0989d9c --- /dev/null +++ b/recipes/wil/all/test_package/conanfile.py @@ -0,0 +1,27 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +# It will become the standard on Conan 2.x +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/wil/all/test_package/test_package.cpp b/recipes/wil/all/test_package/test_package.cpp new file mode 100644 index 00000000000000..73b8b076ec5af0 --- /dev/null +++ b/recipes/wil/all/test_package/test_package.cpp @@ -0,0 +1,12 @@ +#include +#include +#include "wil/resource.h" + + +int main(void) { + SetLastError(42); + // check for simple function call: + auto error42 = wil::last_error_context(); + + return EXIT_SUCCESS; +} diff --git a/recipes/wil/all/test_v1_package/CMakeLists.txt b/recipes/wil/all/test_v1_package/CMakeLists.txt new file mode 100644 index 00000000000000..9d54a092e0a67e --- /dev/null +++ b/recipes/wil/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES CXX) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ + ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/wil/all/test_v1_package/conanfile.py b/recipes/wil/all/test_v1_package/conanfile.py new file mode 100644 index 00000000000000..c492184eec19c2 --- /dev/null +++ b/recipes/wil/all/test_v1_package/conanfile.py @@ -0,0 +1,19 @@ +from conans import ConanFile, CMake +from conan.tools.build import cross_building +import os + + +# legacy validation with Conan 1.x +class TestPackageV1Conan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not cross_building(self): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/wil/config.yml b/recipes/wil/config.yml new file mode 100644 index 00000000000000..5d004c574dfa11 --- /dev/null +++ b/recipes/wil/config.yml @@ -0,0 +1,3 @@ +versions: + "1.0.230202.1": + folder: "all"