-
Notifications
You must be signed in to change notification settings - Fork 57
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
Add zenoh-c-from-source Conan recipe #336
Open
oteffahi
wants to merge
8
commits into
eclipse-zenoh:main
Choose a base branch
from
oteffahi:conan/recipe-from-source
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9e1fab2
Add zenoh-c-from-source conan recipe
oteffahi c33d389
Add copyright file header
oteffahi c90d785
Update license field
oteffahi b8cf5e1
Move install static library to options
oteffahi e90582b
Patch source to force Rust 1.72.0 for 0.10.1-rc
oteffahi 20ec2cd
Overwrite url attribute
oteffahi 25e7990
Revert "Patch source to force Rust 1.72.0 for 0.10.1-rc"
oteffahi c75c4de
Add cmake to test_package build_requirements
oteffahi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
sources: | ||
"0.10.1-rc": | ||
url: "https://github.com/eclipse-zenoh/zenoh-c/archive/refs/tags/0.10.1-rc.tar.gz" | ||
sha256: "9fb703eff79b7c1ef216f411dadcb7f0132c8ba665823b5a8252b467b4937438" | ||
patches: | ||
"0.10.1-rc": | ||
- patch_file: patches/0001-cmakelists-remove-cargo-channel.patch | ||
- patch_file: patches/0002-cmakelists-build-lib-only.patch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# | ||
# Copyright (c) 2024 ZettaScale Technology | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Eclipse Public License 2.0 which is available at | ||
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
# which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
# | ||
# Contributors: | ||
# ZettaScale Zenoh Team, <[email protected]> | ||
# | ||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.files import apply_conandata_patches, get, copy, export_conandata_patches | ||
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout, CMakeDeps | ||
import os | ||
|
||
required_conan_version = ">=1.53.0" | ||
|
||
class ZenohCPackageConan(ConanFile): | ||
name = "zenohc" | ||
description = "C-API for Eclipse Zenoh: Zero Overhead Pub/sub, Store/Query and Compute protocol" | ||
tags = ["iot", "networking", "robotics", "messaging", "ros2", "edge-computing", "micro-controller"] | ||
license = "EPL-2.0 OR Apache-2.0" | ||
author = "ZettaScale Zenoh Team" | ||
|
||
url = "https://github.com/eclipse-zenoh/zenoh-c" | ||
homepage = "https://github.com/eclipse-zenoh/zenoh-c" | ||
|
||
package_type = "library" | ||
settings = "os", "compiler", "build_type", "arch" | ||
|
||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
"ZENOHC_BUILD_WITH_LOGGER_AUTOINIT":[True, False], | ||
"ZENOHC_BUILD_WITH_SHARED_MEMORY":[True, False], | ||
"ZENOHC_INSTALL_STATIC_LIBRARY":[True, False], | ||
"ZENOHC_CARGO_FLAGS": ["ANY"], | ||
} | ||
|
||
default_options = { | ||
"shared": False, | ||
"fPIC": True, | ||
"ZENOHC_BUILD_WITH_LOGGER_AUTOINIT": True, | ||
"ZENOHC_BUILD_WITH_SHARED_MEMORY": True, | ||
"ZENOHC_INSTALL_STATIC_LIBRARY": False, | ||
"ZENOHC_CARGO_FLAGS": "", | ||
} | ||
|
||
@property | ||
def _supported_platforms(self): | ||
return [ | ||
("Windows", "x86_64"), | ||
("Linux", "x86_64"), | ||
("Linux", "armv6"), | ||
("Linux", "armv7hf"), | ||
("Linux", "armv8"), | ||
("Macos", "x86_64"), | ||
("Macos", "armv8"), | ||
] | ||
|
||
def export_sources(self): | ||
export_conandata_patches(self) | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
self.options.rm_safe("fPIC") | ||
self.settings.rm_safe("compiler.cppstd") | ||
self.settings.rm_safe("compiler.libcxx") | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def validate(self): | ||
if (self.settings.os, self.settings.arch) not in self._supported_platforms: | ||
raise ConanInvalidConfiguration("{}/{} combination is not supported".format(self.settings.os, self.settings.arch)) | ||
|
||
def build_requirements(self): | ||
self.tool_requires("cmake/[>=3.16 <4]") | ||
|
||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||
|
||
def generate(self): | ||
tc = CMakeToolchain(self) | ||
for opt, val in self.options.items(): | ||
tc.variables[opt] = val | ||
tc.variables["ZENOHC_LIB_STATIC"] = str(not self.options.shared) | ||
|
||
tc.generate() | ||
deps = CMakeDeps(self) | ||
deps.generate() | ||
|
||
def build(self): | ||
apply_conandata_patches(self) | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def package(self): | ||
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) | ||
cmake = CMake(self) | ||
cmake.install() | ||
|
||
def package_info(self): | ||
if self.settings.build_type == "Debug": | ||
self.cpp_info.libs = ["zenohcd"] | ||
else: | ||
self.cpp_info.libs = ["zenohc"] | ||
|
||
self.cpp_info.set_property("cmake_file_name", "zenohc") | ||
self.cpp_info.set_property("cmake_target_name", "zenohc::lib") | ||
self.cpp_info.set_property("cmake_target_aliases", [f"zenohc::{'shared' if self.options.shared else 'static'}"]) | ||
|
||
if self.settings.os == "Windows": | ||
self.cpp_info.system_libs = ["ws2_32", "crypt32", "secur32", "bcrypt", "ncrypt", "userenv", "ntdll", "iphlpapi", "runtimeobject"] | ||
elif self.settings.os == "Linux": | ||
self.cpp_info.system_libs = ["rt", "pthread", "m", "dl"] | ||
elif self.settings.os == "Macos": | ||
self.cpp_info.frameworks = ["Foundation", "Security"] |
23 changes: 23 additions & 0 deletions
23
conan-recipes/from-source/all/patches/0001-cmakelists-remove-cargo-channel.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index 419b583..81527fb 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -27,7 +27,6 @@ declare_cache_var_true_if_vscode(ZENOHC_BUILD_IN_SOURCE_TREE "Do build inside so | ||
declare_cache_var(ZENOHC_BUILD_WITH_LOGGER_AUTOINIT TRUE BOOL "Enable logger-autoinit zenoh-c feature") | ||
declare_cache_var(ZENOHC_BUILD_WITH_SHARED_MEMORY TRUE BOOL "Enable shared-memory zenoh-c feature") | ||
declare_cache_var(ZENOHC_CUSTOM_TARGET "" STRING "Rust target for cross compilation, 'aarch64-unknown-linux-gnu' for example") | ||
-declare_cache_var(ZENOHC_CARGO_CHANNEL "stable" STRING "Cargo channel selected: stable or nightly") | ||
declare_cache_var(ZENOHC_CARGO_FLAGS "" STRING "Additional cargo flags") | ||
declare_cache_var(ZENOHC_LIB_STATIC FALSE BOOL "Alias zenohc::lib target to zenohc::static if TRUE, to zenohc::shared if FALSE") | ||
|
||
@@ -198,8 +197,8 @@ file(GLOB_RECURSE rust_sources "Cargo.toml.in" "src/*.rs" "build.rs" "splitguide | ||
add_custom_command( | ||
OUTPUT ${libs} | ||
COMMAND ${CMAKE_COMMAND} -E echo \"RUSTFLAGS = $$RUSTFLAGS\" | ||
- COMMAND ${CMAKE_COMMAND} -E echo \"cargo +${ZENOHC_CARGO_CHANNEL} build ${cargo_flags}\" | ||
- COMMAND cargo +${ZENOHC_CARGO_CHANNEL} build ${cargo_flags} | ||
+ COMMAND ${CMAKE_COMMAND} -E echo \"cargo build ${cargo_flags}\" | ||
+ COMMAND cargo build ${cargo_flags} | ||
VERBATIM | ||
COMMAND_EXPAND_LISTS | ||
DEPENDS "${rust_sources}" |
70 changes: 70 additions & 0 deletions
70
conan-recipes/from-source/all/patches/0002-cmakelists-build-lib-only.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt | ||
index c2aecbd..e69de29 100644 | ||
--- a/examples/CMakeLists.txt | ||
+++ b/examples/CMakeLists.txt | ||
@@ -1,32 +0,0 @@ | ||
-if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) | ||
- # Settings when 'examples' is the root projet | ||
- cmake_minimum_required(VERSION 3.16) | ||
- project(zenohc_examples LANGUAGES C) | ||
- set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../cmake" ${CMAKE_MODULE_PATH}) | ||
- include(helpers) | ||
- set_default_build_type(Release) | ||
- configure_include_project(ZENOHC zenohc zenohc::lib ".." zenohc "https://github.com/eclipse-zenoh/zenoh-c" "") | ||
- add_custom_target(examples ALL) | ||
-else() | ||
- message(STATUS "zenoh-c examples") | ||
- add_custom_target(examples) | ||
-endif() | ||
- | ||
-file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/*.c") | ||
- | ||
-foreach(file ${files}) | ||
- get_filename_component(target ${file} NAME_WE) | ||
- | ||
- if(NOT(UNIX) AND(${target} STREQUAL "z_ping" OR ${target} STREQUAL "z_pong")) | ||
- continue() | ||
- endif() | ||
- | ||
- add_executable(${target} EXCLUDE_FROM_ALL ${file}) | ||
- add_dependencies(examples ${target}) | ||
- | ||
- add_dependencies(${target} zenohc::lib) | ||
- target_link_libraries(${target} PRIVATE zenohc::lib) | ||
- copy_dlls(${target}) | ||
- | ||
- set_property(TARGET ${target} PROPERTY C_STANDARD 11) | ||
-endforeach() | ||
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt | ||
index 21695a4..e69de29 100644 | ||
--- a/tests/CMakeLists.txt | ||
+++ b/tests/CMakeLists.txt | ||
@@ -1,28 +0,0 @@ | ||
-message(STATUS "zenoh-c tests") | ||
- | ||
-add_custom_target(tests) | ||
- | ||
-file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/*.c") | ||
-foreach(file ${files}) | ||
- get_filename_component(target ${file} NAME_WE) | ||
- | ||
- # Check the filename prefix to determine the test type | ||
- if (${file} MATCHES "^.*z_api_.*$") | ||
- set(test_type "unit") | ||
- elseif (${file} MATCHES "^.*z_int_.*$") | ||
- set(test_type "integration") | ||
- elseif (${file} MATCHES "^.*z_build_.*$") | ||
- set(test_type "build") | ||
- else() | ||
- message(FATAL_ERROR "Test file ${file} does not match any known type (z_api_ or z_int_ or z_build)") | ||
- endif() | ||
- | ||
- add_executable(${target} EXCLUDE_FROM_ALL ${file}) | ||
- add_dependencies(tests ${target}) | ||
- add_dependencies(${target} zenohc::lib) | ||
- target_link_libraries(${target} PRIVATE zenohc::lib) | ||
- copy_dlls(${target}) | ||
- set_property(TARGET ${target} PROPERTY C_STANDARD 11) | ||
- add_test(NAME "${test_type}_${target}" COMMAND ${target}) | ||
-endforeach() | ||
- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
project(test_package LANGUAGES C) | ||
|
||
find_package(zenohc REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.c) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE zenohc::lib) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import os | ||
from conan import ConanFile | ||
from conan.tools.cmake import CMake, cmake_layout | ||
from conan.tools.build import can_run | ||
|
||
|
||
class ZenohCPackageTestConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
def build_requirements(self): | ||
self.tool_requires("cmake/[>=3.16 <4]") | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def configure(self): | ||
self.settings.rm_safe("compiler.cppstd") | ||
self.settings.rm_safe("compiler.libcxx") | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if can_run(self): | ||
cmd = os.path.join(self.cpp.build.bindir, "test_package") | ||
self.run(cmd, env="conanrun") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "zenoh.h" | ||
|
||
int main(int argc, char **argv) { | ||
(void)argc; | ||
(void)argv; | ||
z_owned_config_t config = z_config_default(); | ||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"0.10.1-rc": | ||
folder: all |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very experienced with conan packaging, so forgive me if the answer to this is obvious: Is there a way to build whatever is currently checked out in the git repo? There may be times where we want to test downstream projects using a specific commit of zenoh-c.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gregmedd it is possible to have a recipe that checks out a specific commit. However it would require a different logic for the "source" function. Another challenge to take into account is the expected Rust version which can vary between commits.
Finally, this feature breaks CCI's recipe rule about only supporting stable releases in the recipes. But I guess we're already past that point 😅
Is this something you would like to see in this recipe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oteffahi That makes sense. Let's keep this recipe as is - better to have something that is correct and in line with what CCI would want, even this can't be submitted there yet. If we do ever find a need to build a development package, we'll figure out how to do it then.
Feel free to mark this comment resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gregmedd We've experimented with compiling specific commits, and it seems pretty straight-forward to add. As far as I know this not in-line with CCI's recipe requirements, but since we're managing our own recipe we might as well add exclusive features that cannot be supported otherwise 😄