Skip to content

Commit

Permalink
Merge pull request #230 from ydcpp/conan
Browse files Browse the repository at this point in the history
Conan support is added
  • Loading branch information
k8s-ci-robot authored Apr 28, 2024
2 parents 07648ed + 1592302 commit fbe4574
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ sudo make install
## (Optional) Installing using vcpkg on Windows
If you want to install the C client using vcpkg, please refer to [vcpkg.md](https://github.com/kubernetes-client/c/blob/master/docs/vcpkg.md)

## (Optional) Installing using conan on Windows, Linux, Mac
If you want to install the C client using conan, please refer to [conan.md](https://github.com/kubernetes-client/c/blob/master/docs/conan.md)

## Building an example
```bash
cd ${CLIENT_REPO_ROOT}/examples/list_pod
Expand Down
75 changes: 75 additions & 0 deletions docs/conan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Installing using conan
## Prerequisites
1- Python 3
https://www.python.org/downloads/

2- Conan package manager
https://docs.conan.io/2/installation.html

## Build and Install the repo to local system by using conan
1- Navigate to `kubernetes` directory, then use `conan create` command. This will build the repo from source as static library.
```
cd kubernetes
conan create . --build=missing
```

Validate `kubernetes_client_c` package exists by using following command to list all installed packages in local conan cache:
```
conan list "*"
```

## Using kubernetes_client_c library in your project
1- Create `conanfile.py` or `conanfile.txt` file in the root of your project.

**conanfile.txt**
```
[requires]
kubernetes_client_c/0.9.0
[generators]
CMakeDeps
CMakeToolchain
[layout]
cmake_layout
```

**conanfile.py**
```python
from conan import ConanFile
from conan.tools.cmake import cmake_layout

class ExampleRecipe(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain"

def requirements(self):
self.requires("kubernetes_client_c/0.9.0")

def layout(self):
cmake_layout(self)
```

2- Use following command (in the root directory of project) to install all dependencies that are specified in the `conanfile`:
```
conan install . --build=missing
```

3- Finally, edit `CMakeLists.txt` of your project to link against libraries. In this case, we link to `kubernetes_client_c` library.

Add these lines after declaring the target in CMakeLists.

**CMakeLists.txt**
```
find_package(kubernetes_client_c)
target_link_libraries(<your_target> kubernetes_client_c::kubernetes_client_c)
```

Make sure to edit `<your_target>` with the actual target name.

4- Example `#include` headers:
```c
#include <kubernetes/api/CoreV1API.h>
#include <kubernetes/model/v1_pod.h>
#include <kubernetes/config/kube_config.h>
```
66 changes: 66 additions & 0 deletions kubernetes/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.files import copy
from os.path import join

class kubernetes_client_cRecipe(ConanFile):
name = "kubernetes_client_c"
version = "0.9.0"
package_type = "library"

# Optional metadata
license = "Apache-2.0"
url = "https://github.com/kubernetes-client/c"
description = "Official C client library for Kubernetes"
topics = ("kubernetes", "k8s", "kubernetes-client", "k8s-client")

# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False], "openssl_shared":[True, False], "curl_version": ["7", "8"]}
default_options = {"shared": False, "fPIC": True, "openssl_shared": True, "curl_version": "8"}

# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources = "config.h.in", "ConfigureChecks.cmake", "PreTarget.cmake", "PostTarget.cmake", "CMakeLists.txt", "src/*", "external/*", "api/*", "model/*", "include/*", "config/*", "watch/*", "websocket/*"

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

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
self.options["openssl/*"].shared = self.options.openssl_shared

def layout(self):
cmake_layout(self)

def generate(self):
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.generate()

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

def package(self):
copy(self, "*.h", src=join(self.source_folder, "api"), dst=join(self.package_folder, "include/kubernetes/api"), keep_path=False)
copy(self, "*.h", src=join(self.source_folder, "model"), dst=join(self.package_folder, "include/kubernetes/model"), keep_path=False)
copy(self, "*.h", src=join(self.source_folder, "config"), dst=join(self.package_folder, "include/kubernetes/config"), keep_path=False)
copy(self, "*.h", src=join(self.source_folder, "include"), dst=join(self.package_folder, "include/kubernetes/include"), keep_path=False)
copy(self, "*.h", src=join(self.source_folder, "websocket"), dst=join(self.package_folder, "include/kubernetes/websocket"), keep_path=False)
copy(self, "*.h", src=join(self.source_folder, "external"), dst=join(self.package_folder, "include/kubernetes/external"), keep_path=False)
copy(self, "*.h", src=join(self.source_folder, "watch"), dst=join(self.package_folder, "include/kubernetes/watch"), keep_path=False)
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["kubernetes"]

def requirements(self):
self.requires("libcurl/[~{}]".format(self.options.curl_version), transitive_headers=True)
self.requires("openssl/[^3]", force=True)
self.requires("libwebsockets/[^4.2]", transitive_headers=True)
self.requires("libyaml/[^0.2.5]")
4 changes: 2 additions & 2 deletions kubernetes/websocket/wsclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
extern "C" {
#endif

typedef void (*data_callback_func) (void **, long *);
typedef void (*data_callback_function) (void **, long *);

typedef enum wsc_mode_t {
WSC_MODE_NORMAL = 0,
Expand All @@ -23,7 +23,7 @@ typedef struct wsclient_t {
long data_to_send_len;
void *data_received;
long data_received_len;
data_callback_func data_callback_func;
data_callback_function data_callback_func;
int log_mask;
lws_sorted_usec_list_t sul; /* schedule connection retry */
struct lws *wsi; /* related wsi if any */
Expand Down

0 comments on commit fbe4574

Please sign in to comment.