Skip to content

Commit

Permalink
Merge pull request #345 from fpelliccioni/use-libdispatch
Browse files Browse the repository at this point in the history
Conan task_system option.
  • Loading branch information
FelixPetriconi authored Jan 23, 2021
2 parents 6af4db7 + ddb532e commit c65d1b6
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 32 deletions.
29 changes: 29 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ option( stlab.boost_variant "Prefer Boost::variant to std::variant" OFF )
option( stlab.boost_optional "Prefer Boost::optional to std::optional" OFF )
option( stlab.coroutines "Leverage the coroutine TS in stlab" OFF )

set(stlab.task_system "portable" CACHE STRING "Select the task system (portable|libdispatch|emscripten|pnacl|windows).")

#
# On apple we have to force the usage of boost.variant, because Apple's
# implementation of C++17 is not complete
Expand Down Expand Up @@ -156,6 +158,33 @@ if ( stlab.testing OR stlab.boost_variant OR stlab.boost_optional )
unset( either_generator )
endif()

if (NOT APPLE AND (${stlab.task_system} STREQUAL "libdispatch"))
message(STATUS "CMAKE_PROJECT_NAME: ${CMAKE_PROJECT_NAME}")

add_library( libdispatch::libdispatch INTERFACE IMPORTED )
set_property( TARGET libdispatch::libdispatch
APPEND PROPERTY INTERFACE_LINK_LIBRARIES CONAN_PKG::libdispatch )

target_link_libraries(${CMAKE_PROJECT_NAME} INTERFACE libdispatch::libdispatch)
endif()

if (${stlab.task_system} STREQUAL "portable")
target_compile_definitions( stlab INTERFACE -DSTLAB_FORCE_TASK_SYSTEM_PORTABLE )
elseif (${stlab.task_system} STREQUAL "libdispatch")
target_compile_definitions( stlab INTERFACE -DSTLAB_FORCE_TASK_SYSTEM_LIBDISPATCH )
elseif (${stlab.task_system} STREQUAL "emscripten")
target_compile_definitions( stlab INTERFACE -DSTLAB_FORCE_TASK_SYSTEM_EMSRIPTEN )
elseif (${stlab.task_system} STREQUAL "pnacl")
target_compile_definitions( stlab INTERFACE -DSTLAB_FORCE_TASK_SYSTEM_PNACL )
elseif (${stlab.task_system} STREQUAL "windows")
target_compile_definitions( stlab INTERFACE -DSTLAB_FORCE_TASK_SYSTEM_WINDOWS )
else()
message(FATAL_ERROR "Invalid Task System: ${stlab.task_system}")
endif()

message(STATUS "stlab: Task System: ${stlab.task_system}")


list( APPEND CMAKE_MODULE_PATH "${stlab_SOURCE_DIR}/cmake" )
include( stlab/coroutines )
target_link_libraries( stlab INTERFACE stlab::coroutines )
Expand Down
14 changes: 14 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import copy
from cpt.packager import ConanMultiPackager

if __name__ == "__main__":
builder = ConanMultiPackager(build_policy = "missing", archs = ["x86_64"], options = ["stlab:testing=True"])
# apple_clang_versions= ["12.0"]
builder.add_common_builds()

filtered_builds = []
for settings, options, env_vars, build_requires, reference in builder.items:

if settings["compiler"] == "clang":
opts_libdispatch = copy.deepcopy(options)
opts_libdispatch["stlab:task_system"] = "libdispatch"
filtered_builds.append([settings, opts_libdispatch, env_vars, build_requires, reference])

filtered_builds.append([settings, options, env_vars, build_requires, reference])

builder.builds = filtered_builds

builder.run()
72 changes: 70 additions & 2 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class StlabLibrariesConan(ConanFile):
"boost_optional": [True, False],
"boost_variant": [True, False],
"coroutines": [True, False],
"task_system": ["portable", "libdispatch", "emscripten", "pnacl", "windows", "auto"],
}

default_options = {
Expand All @@ -36,17 +37,30 @@ class StlabLibrariesConan(ConanFile):
"boost_optional": False,
"boost_variant": False,
"coroutines": False,
"task_system": "auto",
}

def _log(self, str):
self.output.info(str)
self.output.warn(str)

def _use_boost(self):
return self.options.testing or \
self.options.boost_optional or \
self.options.boost_variant

def _requires_libdispatch(self):
# On macOS it is not necessary to use the libdispatch conan package, because the library is included in the OS.
return self.options.task_system == "libdispatch" and \
self.settings.os != "Macos"

def requirements(self):
if self._use_boost():
self.requires("boost/1.75.0@")

if self._requires_libdispatch():
self.requires("libdispatch/5.3.2@")

def package_id(self):
ConanFile.package_id(self)
self.info.header_only()
Expand Down Expand Up @@ -92,7 +106,6 @@ def _configure_boost(self):
self.options["boost"].without_type_erasure = True
self.options["boost"].without_wave = True


def _fix_boost_components(self):
if self.settings.os != "Macos": return
if self.settings.compiler != "apple-clang": return
Expand All @@ -101,10 +114,60 @@ def _fix_boost_components(self):
#
# On Apple we have to force the usage of boost.variant, because Apple's implementation of C++17 is not complete.
#
self.output.warn("Apple-Clang versions less than 12 do not correctly support std::optional or std::variant, so we will use boost::optional and boost::variant instead.")
self._log("Apple-Clang versions less than 12 do not correctly support std::optional or std::variant, so we will use boost::optional and boost::variant instead.")
self.options.boost_optional = True
self.options.boost_variant = True

# TODO(fernando): pnacl
def _default_task_system(self):
if self.settings.os == "Macos":
return "libdispatch"

if self.settings.os == "Windows":
return "windows"

if self.settings.os == "Emscripten":
return "emscripten"

return "portable"

def _configure_task_system_auto(self):
self.options.task_system = self._default_task_system()

def _configure_task_system_libdispatch(self):
if self.settings.os == "Linux":
if self.settings.compiler != "clang":
self.options.task_system = self._default_task_system()
self._log("Libdispatch requires Clang compiler on Linux. The task system is changed to {}.".format(self.options.task_system))
return

elif self.settings.os != "Macos":
self.options.task_system = self._default_task_system()
self._log("Libdispatch is not supported on {}. The task system is changed to {}.".format(self.settings.os, self.options.task_system))
return

def _configure_task_system_windows(self):
if self.settings.os != "Windows":
self.options.task_system = self._default_task_system()
self._log("Libdispatch is not supported on {}. The task system is changed to {}.".format(self.settings.os, self.options.task_system))
return

def _configure_task_system_emscripten(self):
if self.settings.os != "Emscripten":
self.options.task_system = self._default_task_system()
self._log("Libdispatch is not supported on {}. The task system is changed to {}.".format(self.settings.os, self.options.task_system))
return

def _configure_task_system(self):
if self.options.task_system == "auto":
self._configure_task_system_auto()
elif self.options.task_system == "libdispatch":
self._configure_task_system_libdispatch()
elif self.options.task_system == "windows":
self._configure_task_system_windows()
elif self.options.task_system == "emscripten":
self._configure_task_system_emscripten()

def configure(self):
ConanFile.configure(self)

Expand All @@ -113,6 +176,9 @@ def configure(self):
if self._use_boost():
self._configure_boost()

self._configure_task_system()
self.output.info("Task System: {}.".format(self.options.task_system))

def build(self):
if self.options.testing:
cmake = CMake(self)
Expand All @@ -124,6 +190,7 @@ def build(self):
cmake.definitions["stlab.boost_variant"] = option_on_off(self.options.boost_variant)
cmake.definitions["stlab.boost_optional"] = option_on_off(self.options.boost_optional)
cmake.definitions["stlab.coroutines"] = option_on_off(self.options.coroutines)
cmake.definitions["stlab.task_system"] = self.options.task_system

cmake.configure()
cmake.build()
Expand All @@ -135,3 +202,4 @@ def package(self):
def imports(self):
self.copy("*.dll", "./bin", "bin")
self.copy("*.dylib", "./bin", "lib")

31 changes: 2 additions & 29 deletions stlab/concurrency/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef STLAB_CONCURRENCY_CONFIG_HPP
#define STLAB_CONCURRENCY_CONFIG_HPP

#include <stlab/concurrency/config_task_system.hpp>

/**************************************************************************************************/

#define STLAB_FEATURE_PRIVATE_OBJC_ARC() 0
Expand All @@ -18,45 +20,21 @@

/**************************************************************************************************/

#define STLAB_TASK_SYSTEM_PRIVATE_PORTABLE() 0
#define STLAB_TASK_SYSTEM_PRIVATE_LIBDISPATCH() 0
#define STLAB_TASK_SYSTEM_PRIVATE_EMSCRIPTEN() 0
#define STLAB_TASK_SYSTEM_PRIVATE_PNACL() 0
#define STLAB_TASK_SYSTEM_PRIVATE_WINDOWS() 0

#define STLAB_TASK_SYSTEM(X) (STLAB_TASK_SYSTEM_PRIVATE_##X())

#define STLAB_CPP_VERSION(X) (STLAB_CPP_VERSION_PRIVATE() == (X))
#define STLAB_CPP_VERSION_LESS_THAN(X) (STLAB_CPP_VERSION_PRIVATE() < (X))
#define STLAB_CPP_VERSION_AT_LEAST(X) (STLAB_CPP_VERSION_PRIVATE() >= (X))

#if __APPLE__

#undef STLAB_TASK_SYSTEM_PRIVATE_LIBDISPATCH
#define STLAB_TASK_SYSTEM_PRIVATE_LIBDISPATCH() 1

#if defined(__has_feature)
#if __has_feature(objc_arc)
#undef STLAB_FEATURE_PRIVATE_OBJC_ARC
#define STLAB_FEATURE_PRIVATE_OBJC_ARC() 1
#endif
#endif

#elif __EMSCRIPTEN__

#undef STLAB_TASK_SYSTEM_PRIVATE_EMSCRIPTEN
#define STLAB_TASK_SYSTEM_PRIVATE_EMSCRIPTEN() 1

#elif __pnacl__

#undef STLAB_TASK_SYSTEM_PRIVATE_PNACL
#define STLAB_TASK_SYSTEM_PRIVATE_PNACL() 1

#elif _MSC_VER

#undef STLAB_TASK_SYSTEM_PRIVATE_WINDOWS
#define STLAB_TASK_SYSTEM_PRIVATE_WINDOWS() 1

#if _MSVC_LANG == 201103L
#define STLAB_CPP_VERSION_PRIVATE() 11
#elif _MSVC_LANG == 201402L
Expand All @@ -68,11 +46,6 @@
#define STLAB_CPP_VERSION_PRIVATE() 20
#endif

#else

#undef STLAB_TASK_SYSTEM_PRIVATE_PORTABLE
#define STLAB_TASK_SYSTEM_PRIVATE_PORTABLE() 1

#endif

#if !defined(STLAB_CPP_VERSION_PRIVATE)
Expand Down
82 changes: 82 additions & 0 deletions stlab/concurrency/config_task_system.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Copyright 2015-2021 Adobe
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/

/**************************************************************************************************/

#ifndef STLAB_CONCURRENCY_CONFIG_TASK_SYSTEM_HPP
#define STLAB_CONCURRENCY_CONFIG_TASK_SYSTEM_HPP

/**************************************************************************************************/

#define STLAB_TASK_SYSTEM_PRIVATE_PORTABLE() 0
#define STLAB_TASK_SYSTEM_PRIVATE_LIBDISPATCH() 0
#define STLAB_TASK_SYSTEM_PRIVATE_EMSCRIPTEN() 0
#define STLAB_TASK_SYSTEM_PRIVATE_PNACL() 0
#define STLAB_TASK_SYSTEM_PRIVATE_WINDOWS() 0

#define STLAB_TASK_SYSTEM(X) (STLAB_TASK_SYSTEM_PRIVATE_##X())

#if defined(STLAB_FORCE_TASK_SYSTEM_LIBDISPATCH)

#undef STLAB_TASK_SYSTEM_PRIVATE_LIBDISPATCH
#define STLAB_TASK_SYSTEM_PRIVATE_LIBDISPATCH() 1

#elif defined(STLAB_FORCE_TASK_SYSTEM_EMSRIPTEN)

#undef STLAB_TASK_SYSTEM_PRIVATE_EMSCRIPTEN
#define STLAB_TASK_SYSTEM_PRIVATE_EMSCRIPTEN() 1

#elif defined(STLAB_FORCE_TASK_SYSTEM_PNACL)

#undef STLAB_TASK_SYSTEM_PRIVATE_PNACL
#define STLAB_TASK_SYSTEM_PRIVATE_PNACL() 1

#elif defined(STLAB_FORCE_TASK_SYSTEM_WINDOWS)

#undef STLAB_TASK_SYSTEM_PRIVATE_WINDOWS
#define STLAB_TASK_SYSTEM_PRIVATE_WINDOWS() 1

#elif defined(STLAB_FORCE_TASK_SYSTEM_PORTABLE)

#undef STLAB_TASK_SYSTEM_PRIVATE_PORTABLE
#define STLAB_TASK_SYSTEM_PRIVATE_PORTABLE() 1

#else

#if __APPLE__

#undef STLAB_TASK_SYSTEM_PRIVATE_LIBDISPATCH
#define STLAB_TASK_SYSTEM_PRIVATE_LIBDISPATCH() 1

#elif __EMSCRIPTEN__

#undef STLAB_TASK_SYSTEM_PRIVATE_EMSCRIPTEN
#define STLAB_TASK_SYSTEM_PRIVATE_EMSCRIPTEN() 1

#elif __pnacl__

#undef STLAB_TASK_SYSTEM_PRIVATE_PNACL
#define STLAB_TASK_SYSTEM_PRIVATE_PNACL() 1

#elif _MSC_VER

#undef STLAB_TASK_SYSTEM_PRIVATE_WINDOWS
#define STLAB_TASK_SYSTEM_PRIVATE_WINDOWS() 1

#else

#undef STLAB_TASK_SYSTEM_PRIVATE_PORTABLE
#define STLAB_TASK_SYSTEM_PRIVATE_PORTABLE() 1

#endif

#endif

/**************************************************************************************************/

#endif // STLAB_CONCURRENCY_CONFIG_TASK_SYSTEM_HPP

/**************************************************************************************************/
1 change: 1 addition & 0 deletions test/executor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <array>
#include <cmath>
#include <condition_variable>
#include <iostream>
#include <thread>

Expand Down
4 changes: 3 additions & 1 deletion test/future_test_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
#include <stlab/concurrency/future.hpp>

#include <atomic>
#include <boost/test/unit_test.hpp>
#include <condition_variable>
#include <exception>
#include <string>
#include <thread>

#include <boost/test/unit_test.hpp>

using lock_t = std::unique_lock<std::mutex>;

namespace future_test_helper {
Expand Down

0 comments on commit c65d1b6

Please sign in to comment.