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

stduuid: fix conditional dependency on ms-gsl #20499

Merged
merged 5 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions recipes/stduuid/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ sources:
"1.0":
url: "https://github.com/mariusbancila/stduuid/archive/v1.0.tar.gz"
sha256: "e96f2ac7c950c3c24d7e2e44a84236277b7774ee346dcc620edf400d9eda0a3c"
patches:
"1.2.2":
- patch_file: "patches/1.2.2-handle-span-header.patch"
patch_description: "Conditionally include span header based on compiler definition"
patch_type: "conan"
"1.2.3":
- patch_file: "patches/1.2.3-handle-span-header.patch"
patch_description: "Conditionally include span header based on compiler definition"
patch_type: "conan"
39 changes: 25 additions & 14 deletions recipes/stduuid/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.files import copy, get
from conan.tools.build import check_min_cppstd, valid_min_cppstd
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get
from conan.tools.layout import basic_layout
from conan.tools.scm import Version
import os
Expand All @@ -18,16 +18,14 @@ class StduuidConan(ConanFile):
homepage = "https://github.com/mariusbancila/stduuid"
settings = "os", "arch", "compiler", "build_type"
options = {
# True: Use std::span
# False: Use gsl::span
"with_cxx20_span": [True, False],
}
default_options = {
"with_cxx20_span": False,
}
no_copy_source = True

@property
def _min_cppstd(self):
return "20" if self.options.with_cxx20_span else "17"
return "20" if self.options.get_safe("with_cxx20_span") else "17"

@property
def _compilers_minimum_version(self):
Expand All @@ -38,21 +36,34 @@ def _compilers_minimum_version(self):
"msvc": "191",
"Visual Studio": "15",
}

def export_sources(self):
export_conandata_patches(self)

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

def config_options(self):
if Version(self.version) == "1.0":
# Version 1.0 unconditionally depends on gsl span
del self.options.with_cxx20_span
else:
# Conditionally set the default value of with_cxx20_span
# if cppstd is set and is 20 or greater
self.options.with_cxx20_span = (self.settings.compiler.get_safe("cppstd", False)
and valid_min_cppstd(self, 20))

def requirements(self):
if not self.options.with_cxx20_span:
self.requires("ms-gsl/3.1.0", transitive_headers=True)
if not self.options.get_safe("with_cxx20_span") or Version(self.version) == "1.0":
self.requires("ms-gsl/4.0.0", transitive_headers=True)
if self.settings.os == "Linux" and Version(self.version) <= "1.0":
self.requires("util-linux-libuuid/2.39", transitive_headers=True, transitive_libs=True)

def package_id(self):
self.info.clear()

def validate(self):
if self.settings.compiler.get_safe("cppsd"):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)

minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
Expand All @@ -62,8 +73,8 @@ def validate(self):
)

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

def build(self):
pass
Expand All @@ -75,5 +86,5 @@ def package(self):
def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
if not self.options.with_cxx20_span:
self.cpp_info.includedirs.append(os.path.join(self.dependencies["ms-gsl"].cpp_info.includedirs[0], "gsl"))
if self.options.get_safe("with_cxx20_span"):
self.cpp_info.defines = ["LIBUUID_CPP20_OR_GREATER"]
26 changes: 26 additions & 0 deletions recipes/stduuid/all/patches/1.2.2-handle-span-header.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/include/uuid.h b/include/uuid.h
index 600846f..5f00a49 100644
--- a/include/uuid.h
+++ b/include/uuid.h
@@ -15,7 +15,11 @@
#include <chrono>
#include <numeric>
#include <atomic>
-#include <span>
+#if defined(LIBUUID_CPP20_OR_GREATER)
+# include <span>
+#else
+# include <gsl/span>
+#endif

#ifdef _WIN32

@@ -51,7 +55,7 @@

namespace uuids
{
-#ifdef __cpp_lib_span
+#if defined(LIBUUID_CPP20_OR_GREATER)
template <class ElementType, std::size_t Extent>
using span = std::span<ElementType, Extent>;
#else
29 changes: 29 additions & 0 deletions recipes/stduuid/all/patches/1.2.3-handle-span-header.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/include/uuid.h b/include/uuid.h
index d48059d..4d14e4d 100644
--- a/include/uuid.h
+++ b/include/uuid.h
@@ -17,15 +17,6 @@
#include <numeric>
#include <atomic>

-#ifdef __cplusplus
-
-# if (__cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
-# define LIBUUID_CPP20_OR_GREATER
-# endif
-
-#endif
-
-
#ifdef LIBUUID_CPP20_OR_GREATER
#include <span>
#else
@@ -66,7 +57,7 @@

namespace uuids
{
-#ifdef __cpp_lib_span
+#if defined(LIBUUID_CPP20_OR_GREATER)
template <class ElementType, std::size_t Extent>
using span = std::span<ElementType, Extent>;
#else