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

Feature/nsync #6085

Merged
merged 32 commits into from
Sep 25, 2021
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5f1419d
[boost] Add 'algorithm' lib #3961
CAMOBAP Dec 21, 2020
99b049c
Merge remote-tracking branch 'upstream/master'
CAMOBAP Apr 3, 2021
89c0a21
Revert "[boost] Add 'algorithm' lib #3961"
CAMOBAP Apr 5, 2021
5b138bc
Merge remote-tracking branch 'upstream/master'
CAMOBAP Apr 10, 2021
87ed6a8
Merge remote-tracking branch 'upstream/master'
CAMOBAP May 29, 2021
49efd36
Merge branch 'conan-io:master' into master
CAMOBAP Jun 20, 2021
25f9752
Merge branch 'conan-io:master' into master
CAMOBAP Jun 21, 2021
0b171a8
Merge branch 'conan-io:master' into master
CAMOBAP Jun 29, 2021
90345d4
#4806 add nsync because required by onnxruntime
CAMOBAP Jun 29, 2021
d5d3786
#4806 nsync add LICENSE file package
CAMOBAP Jun 29, 2021
0e85191
Add homepage, update source dowload, using components to seaprate nsy…
CAMOBAP Jun 29, 2021
ae8c9b3
#4806 nsync: add pthread as system_lib for Linux
CAMOBAP Jun 30, 2021
8a7107c
#4806 nsync: simplify tests
CAMOBAP Aug 19, 2021
8410cac
#4806 nsync: fix missing nsync_mu_init in tests
CAMOBAP Sep 10, 2021
93121cd
#4806 nsync: add missing CMakeLists.txt wrapper with conan_basic_setup
CAMOBAP Sep 10, 2021
d87aa70
#4806 nsync remove with_tests option
CAMOBAP Sep 10, 2021
0c6f4a7
#4806 nsync remove with_tests option
CAMOBAP Sep 10, 2021
2c88b10
#4806 nsync: remove chdir from test receipt
CAMOBAP Sep 10, 2021
5f45f40
#4806 nsync: improve test CMakeLists.txt
CAMOBAP Sep 10, 2021
3ef05d4
#4806 nsync: add build_folder to cmake.configure
CAMOBAP Sep 10, 2021
8e913da
#4806 nsync: remove redundant pthread flags
CAMOBAP Sep 10, 2021
db3df8c
#4806 nsync: replace cmake_find_package generator with cmake_find_pac…
CAMOBAP Sep 10, 2021
b536769
#4806 nsync: fix include(conanbuildinfo.cmake)
CAMOBAP Sep 10, 2021
a3db04d
#4806 nsync: fix test c library
CAMOBAP Sep 10, 2021
411b55a
#4806 nsync: add shared and fPIC options
CAMOBAP Sep 10, 2021
d088f49
#4806 nsync: fix redundant semaphore_mutex.c compilation during nsync…
CAMOBAP Sep 11, 2021
aa8f759
#4806 nsync: fix copy dlls to lib
CAMOBAP Sep 11, 2021
26c62b8
#4806 nsync: remove code duplication in nsync_c and nsync_cpp components
CAMOBAP Sep 15, 2021
17bd7b2
#4806 nsync: add CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS
CAMOBAP Sep 15, 2021
4180c78
#4806 nsync: remove unnecessary code
CAMOBAP Sep 17, 2021
0f213ec
Apply suggestions from code review
CAMOBAP Sep 20, 2021
b48c151
Update recipes/nsync/all/conanfile.py
CAMOBAP Sep 21, 2021
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/nsync/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.4)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

add_subdirectory(source_subfolder)
7 changes: 7 additions & 0 deletions recipes/nsync/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sources:
"1.23.0":
sha256: "b7e75b17957c62bd02dd73890bde22da3a564903fcaad651b395453d41d3325b"
url: "https://github.com/google/nsync/archive/refs/tags/1.23.0.tar.gz"
patches:
"1.23.0":
- patch_file: "patches/0001-darwin-exclude_semaphore_mutex_c_from_nsync_cpp_lib.patch"
99 changes: 99 additions & 0 deletions recipes/nsync/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import os
from conans import ConanFile, CMake, tools

required_conan_version = ">=1.33.0"


class NsyncConan(ConanFile):
name = "nsync"
homepage = "https://github.com/google/nsync"
description = "Library that exports various synchronization primitive"
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
topics = ("c", "thread", "multithreading", "google")
settings = "os", "compiler", "build_type", "arch"
options = {"fPIC": [True, False], "shared": [True, False]}
default_options = {"fPIC": True, "shared": False}
exports_sources = ["CMakeLists.txt", "patches/**"]

generators = "cmake", "cmake_find_package"
_cmake = None

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

@property
def _build_subfolder(self):
return "build_subfolder"

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

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

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

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["NSYNC_ENABLE_TESTS"] = False
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def _patch_sources(self):
for patch in self.conan_data["patches"][self.version]:
patch["base_path"] = self._source_subfolder
tools.patch(**patch)

tools.replace_in_file(
os.path.join(self._source_subfolder, "CMakeLists.txt"),
"set (CMAKE_POSITION_INDEPENDENT_CODE ON)", "")

if self.settings.os == "Windows" and self.options.shared:
ar_dest = \
"ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} " \
"COMPONENT Development"
rt_dest = 'RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"'
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd apply this change regardless of the OS and build type, even if only makes sense there.
Also keep in mind you're removing the COMPONENT, I don't know the implications of this in this particular case.

Copy link
Contributor Author

@CAMOBAP CAMOBAP Sep 21, 2021

Choose a reason for hiding this comment

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

Per documentation in https://cmake.org/cmake/help/latest/command/install.html:

COMPONENT
Specify an installation component name with which the install rule is associated, such as "runtime" or "development". During component-specific installation only install rules associated with the given component name will be executed. During a full installation all components are installed unless marked with EXCLUDE_FROM_ALL. If COMPONENT is not provided a default component "Unspecified" is created. The default component name may be controlled with the CMAKE_INSTALL_DEFAULT_COMPONENT_NAME variable.

Because we don't perform component-specific installation probably this is not the case for us.

As another solution, I think we can safely add COMPONENT RuntimeLibraries

tools.replace_in_file(
os.path.join(self._source_subfolder, "CMakeLists.txt"),
f"{ar_dest})", f"{ar_dest}\n{rt_dest})")

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy("LICENSE", dst='licenses', src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()

def package_info(self):
self.cpp_info.filenames["cmake_find_package"] = "nsync"
self.cpp_info.filenames["cmake_find_package_multi"] = "nsync"
self.cpp_info.names["cmake_find_package"] = "nsync"
self.cpp_info.names["cmake_find_package_multi"] = "nsync"

self._def_compoment("nsync_c", "nsync")
self._def_compoment("nsync_cpp")

def _def_compoment(self, name, lib=None):
lib = lib if lib else name

component = self.cpp_info.components[name]
component.name = name
component.libs = [lib]
component.names["cmake_find_package"] = name
component.names["cmake_find_package_multi"] = name
component.names["pkg_config"] = lib

if self.settings.os in ["Linux", "FreeBSD"]:
component.system_libs = ["pthread"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -123,7 +123,6 @@
${NSYNC_OS_CPP_SRC}
"platform/c++11/src/nsync_semaphore_mutex.cc"
"platform/posix/src/clock_gettime.c"
- "platform/posix/src/nsync_semaphore_mutex.c"
)
elseif ("${CMAKE_SYSTEM_NAME}X" STREQUAL "LinuxX")
set (NSYNC_POSIX ON)
14 changes: 14 additions & 0 deletions recipes/nsync/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C CXX)

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

find_package(nsync CONFIG REQUIRED)

add_executable(${PROJECT_NAME} example_c.c)
target_link_libraries(${PROJECT_NAME} nsync::nsync_c)

add_executable(${PROJECT_NAME}_cpp example_cpp.cpp)
target_link_libraries(${PROJECT_NAME}_cpp nsync::nsync_cpp)

20 changes: 20 additions & 0 deletions recipes/nsync/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os

from conans import ConanFile, CMake, tools


class NsyncTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
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):
test_package_c = os.path.join("bin", "test_package")
test_package_cpp = os.path.join("bin", "test_package_cpp")
self.run(test_package_c, run_environment=True)
self.run(test_package_cpp, run_environment=True)
9 changes: 9 additions & 0 deletions recipes/nsync/all/test_package/example_c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <nsync.h>

int main() {
nsync_mu testing_mu;
nsync_mu_init (&testing_mu);
nsync_mu_lock (&testing_mu);
nsync_mu_unlock (&testing_mu);
return 0;
}
9 changes: 9 additions & 0 deletions recipes/nsync/all/test_package/example_cpp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <nsync.h>

int main() {
nsync::nsync_mu testing_mu;
nsync::nsync_mu_init (&testing_mu);
nsync::nsync_mu_lock (&testing_mu);
nsync::nsync_mu_unlock (&testing_mu);
return 0;
}
3 changes: 3 additions & 0 deletions recipes/nsync/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.23.0":
folder: "all"