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

andreasbuhr-cppcoro: Conan 2.0 support #20611

Merged
merged 19 commits into from
Jan 11, 2024
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
7 changes: 0 additions & 7 deletions recipes/andreasbuhr-cppcoro/all/CMakeLists.txt

This file was deleted.

6 changes: 3 additions & 3 deletions recipes/andreasbuhr-cppcoro/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sources:
"cci.20210113":
url: "https://github.com/andreasbuhr/cppcoro/archive/7cc9433436fe8f2482138019cfaafce8e1d7a896.zip"
sha256: "5edc72bb19616ae5b794c7d83f9a5d4973f32c966f1966ab81779d3a38b36a2c"
"cci.20230629":
url: "https://github.com/andreasbuhr/cppcoro/archive/a3082f56ba135a659f7386b00ff797ba441207ba.zip"
sha256: "8c3283dd7587cdd18b871b290fda9394f262110140685e6de3760ede3b505736"
139 changes: 83 additions & 56 deletions recipes/andreasbuhr-cppcoro/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import os
from conans import ConanFile, tools, CMake
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import rmdir, get, copy
from conan.tools.microsoft import is_msvc
from conan.tools.scm import Version
from conan.errors import ConanInvalidConfiguration

required_conan_version = ">=1.33.0"
Ahajha marked this conversation as resolved.
Show resolved Hide resolved
required_conan_version = ">=1.53.0"

class AndreasbuhrCppCoroConan(ConanFile):
name = "andreasbuhr-cppcoro"
description = "A library of C++ coroutine abstractions for the coroutines TS"
topics = ("conan", "cpp", "async", "coroutines")
topics = ("cpp", "async", "coroutines")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/andreasbuhr/cppcoro"
license = "MIT"
settings = "os", "compiler", "build_type", "arch"
provides = "cppcoro"

exports_sources = "CMakeLists.txt"
generators = "cmake"
package_type = "library"

options = {
Ahajha marked this conversation as resolved.
Show resolved Hide resolved
"shared": [True, False],
Expand All @@ -26,87 +29,111 @@ class AndreasbuhrCppCoroConan(ConanFile):
"fPIC": True,
}

_cmake = None

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

@property
def _minimum_compilers_version(self):
return {
"Visual Studio": "15",
"msvc": "191",
"gcc": "10",
"clang": "8",
"apple-clang": "10",
}

@property
def _min_cppstd(self):
# Clang with libstdc++ always requires C++20
# Clang 17+ always requires C++20
# Otherwise, require C++17
compiler = self.settings.compiler
requires_cpp20 = compiler == "clang" and ("libstdc++" in compiler.get_safe("libcxx", "") or compiler.version >= Version("17"))
return 20 if requires_cpp20 else 17

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

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

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

# We can't simply check for C++20, because clang and MSVC support the coroutine TS despite not having labeled (__cplusplus macro) C++20 support
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
min_version = self._minimum_compilers_version.get(str(self.settings.compiler))
if not min_version:
self.output.warn("{} recipe lacks information about the {} compiler support.".format(
self.name, self.settings.compiler))
self.output.warning(f"{self.name} recipe lacks information about the {self.settings.compiler} compiler support.")
else:
if tools.Version(self.settings.compiler.version) < min_version:
raise ConanInvalidConfiguration("{} requires coroutine TS support. The current compiler {} {} does not support it.".format(
self.name, self.settings.compiler, self.settings.compiler.version))

# Currently clang expects coroutine to be implemented in a certain way (under std::experiemental::), while libstdc++ puts them under std::
# There are also other inconsistencies, see https://bugs.llvm.org/show_bug.cgi?id=48172
# This should be removed after both gcc and clang implements the final coroutine TS
if self.settings.compiler == "clang" and self.settings.compiler.get_safe("libcxx") == "libstdc++":
raise ConanInvalidConfiguration("{} does not support clang with libstdc++. Use libc++ instead.".format(self.name))
if Version(self.settings.compiler.version) < min_version:
raise ConanInvalidConfiguration(
f"{self.name} requires coroutine TS support. The current compiler {self.settings.compiler} {self.settings.compiler.version} does not support it."
)

# Older versions of clang expects coroutine to be put under std::experimental::, while libstdc++ puts them under std::,
# See https://bugs.llvm.org/show_bug.cgi?id=48172 for more context.
if self.settings.compiler == "clang" and "libstdc++" in self.settings.compiler.get_safe("libcxx", ""):
if self.settings.compiler.version < Version("14"):
raise ConanInvalidConfiguration("{self.name} does not support clang<14 with libstdc++. Use libc++ or upgrade to clang 14+ instead.")
if self.settings.compiler.version == Version("14"):
self.output.warning("This build may fail if using libstdc++13 or greater")

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

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

def _configure_cmake(self):
if not self._cmake:
self._cmake = CMake(self)
if self.settings.os == "Windows" and self.options.shared:
self._cmake.definitions["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = "ON"
self._cmake.configure()
return self._cmake
def generate(self):
tc = CMakeToolchain(self)
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = "ON"
tc.generate()

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

def package(self):
self.copy("LICENSE.txt", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE.txt", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.filenames["cmake_find_package"] = "cppcoro"
self.cpp_info.filenames["cmake_find_package_multi"] = "cppcoro"
self.cpp_info.names["cmake_find_package"] = "cppcoro"
self.cpp_info.names["cmake_find_package_multi"] = "cppcoro"
@property
def _needs_fcoroutines_ts_flag(self):
version = Version(self.settings.compiler.version)
if self.settings.compiler == "clang":
# clang 5: Coroutines support added
# somewhere between clang 5 and 11: the requirement to add -fcoroutines-ts was dropped, at least in the context of this recipe.
return version < 11
elif self.settings.compiler == "apple-clang":
# At some point before apple-clang 13, in the context of this recipe, the requirement for this flag was dropped.
return version < 13
else:
return False

comp = self.cpp_info.components["cppcoro"]
comp.names["cmake_find_package"] = "cppcoro"
comp.names["cmake_find_package_multi"] = "cppcoro"
comp.libs = ["cppcoro"]
def package_info(self):
self.cpp_info.libs = ["cppcoro"]

if self.settings.os == "Linux" and self.options.shared:
comp.system_libs = ["pthread"]
if self.settings.os in ["Linux", "FreeBSD"] and self.options.shared:
self.cpp_info.system_libs = ["pthread", "m"]
if self.settings.os == "Windows":
comp.system_libs = ["synchronization"]
self.cpp_info.system_libs = ["synchronization", "ws2_32", "mswsock"]

if self.settings.compiler == "Visual Studio":
comp.cxxflags.append("/await")
if is_msvc(self):
self.cpp_info.cxxflags.append("/await")
elif self.settings.compiler == "gcc":
comp.cxxflags.append("-fcoroutines")
comp.defines.append("CPPCORO_COMPILER_SUPPORTS_SYMMETRIC_TRANSFER=1")
elif self.settings.compiler == "clang" or self.settings.compiler == "apple-clang":
comp.cxxflags.append("-fcoroutines-ts")
self.cpp_info.cxxflags.append("-fcoroutines")
self.cpp_info.defines.append("CPPCORO_COMPILER_SUPPORTS_SYMMETRIC_TRANSFER=1")
elif self._needs_fcoroutines_ts_flag:
self.cpp_info.cxxflags.append("-fcoroutines-ts")
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved

self.cpp_info.set_property("cmake_file_name", "cppcoro")
self.cpp_info.set_property("cmake_target_name", "cppcoro::cppcoro")

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.filenames["cmake_find_package"] = "cppcoro"
self.cpp_info.filenames["cmake_find_package_multi"] = "cppcoro"
self.cpp_info.names["cmake_find_package"] = "cppcoro"
self.cpp_info.names["cmake_find_package_multi"] = "cppcoro"
5 changes: 1 addition & 4 deletions recipes/andreasbuhr-cppcoro/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package)

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

find_package(cppcoro CONFIG REQUIRED)

add_executable(${PROJECT_NAME} test_package.cpp)
Expand Down
22 changes: 16 additions & 6 deletions recipes/andreasbuhr-cppcoro/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os
from conans import ConanFile, CMake, tools


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "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 not tools.cross_building(self.settings):
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")
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)
17 changes: 17 additions & 0 deletions recipes/andreasbuhr-cppcoro/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(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 tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
2 changes: 1 addition & 1 deletion recipes/andreasbuhr-cppcoro/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
versions:
"cci.20210113":
"cci.20230629":
folder: "all"