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

wil: recipe added #16701

Merged
merged 19 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
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
10 changes: 10 additions & 0 deletions recipes/wil/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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"
patch_type: bugfix
93 changes: 93 additions & 0 deletions recipes/wil/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

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

this msvc value is incorrect, it should be 191

}

# About compiler version: https://github.com/microsoft/wil/issues/207#issuecomment-991722592
def export_sources(self):
export_conandata_patches(self)
Comment on lines +41 to +43
Copy link
Contributor

Choose a reason for hiding this comment

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

why this comment is attached to export_sources?


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"
Comment on lines +85 to +93
Copy link
Contributor

@SpaceIm SpaceIm Apr 13, 2023

Choose a reason for hiding this comment

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

If I follow this link, I see that config file name is incorrect here, it should be lowercase:

        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"

Copy link
Contributor

Choose a reason for hiding this comment

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

I must have missed the _LOWER when I was reading it 😞

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/include/wil/resource.h
+++ b/include/wil/resource.h
@@ -2547,7 +2547,7 @@ namespace wil
}

template <ULONG flags = 0>
- using unique_private_namespace = unique_any_handle_null_only<decltype(details::ClosePrivateNamespaceHelper<flags>), &details::ClosePrivateNamespaceHelper<flags>>;
+ using unique_private_namespace = unique_any_handle_null_only<void(__stdcall*)(HANDLE) WI_PFN_NOEXCEPT, &details::ClosePrivateNamespaceHelper<flags>>;

using unique_private_namespace_close = unique_private_namespace<>;
using unique_private_namespace_destroy = unique_private_namespace<PRIVATE_NAMESPACE_FLAG_DESTROY>;
8 changes: 8 additions & 0 deletions recipes/wil/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 27 additions & 0 deletions recipes/wil/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
12 changes: 12 additions & 0 deletions recipes/wil/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <cstdlib>
#include <iostream>
#include "wil/resource.h"


int main(void) {
SetLastError(42);
// check for simple function call:
auto error42 = wil::last_error_context();

return EXIT_SUCCESS;
}
8 changes: 8 additions & 0 deletions recipes/wil/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.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/)
19 changes: 19 additions & 0 deletions recipes/wil/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions recipes/wil/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.0.230202.1":
folder: "all"