Skip to content

Commit fbe4574

Browse files
authored
Merge pull request #230 from ydcpp/conan
Conan support is added
2 parents 07648ed + 1592302 commit fbe4574

File tree

4 files changed

+146
-2
lines changed

4 files changed

+146
-2
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ sudo make install
5252
## (Optional) Installing using vcpkg on Windows
5353
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)
5454

55+
## (Optional) Installing using conan on Windows, Linux, Mac
56+
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)
57+
5558
## Building an example
5659
```bash
5760
cd ${CLIENT_REPO_ROOT}/examples/list_pod

docs/conan.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Installing using conan
2+
## Prerequisites
3+
1- Python 3
4+
https://www.python.org/downloads/
5+
6+
2- Conan package manager
7+
https://docs.conan.io/2/installation.html
8+
9+
## Build and Install the repo to local system by using conan
10+
1- Navigate to `kubernetes` directory, then use `conan create` command. This will build the repo from source as static library.
11+
```
12+
cd kubernetes
13+
conan create . --build=missing
14+
```
15+
16+
Validate `kubernetes_client_c` package exists by using following command to list all installed packages in local conan cache:
17+
```
18+
conan list "*"
19+
```
20+
21+
## Using kubernetes_client_c library in your project
22+
1- Create `conanfile.py` or `conanfile.txt` file in the root of your project.
23+
24+
**conanfile.txt**
25+
```
26+
[requires]
27+
kubernetes_client_c/0.9.0
28+
29+
[generators]
30+
CMakeDeps
31+
CMakeToolchain
32+
33+
[layout]
34+
cmake_layout
35+
```
36+
37+
**conanfile.py**
38+
```python
39+
from conan import ConanFile
40+
from conan.tools.cmake import cmake_layout
41+
42+
class ExampleRecipe(ConanFile):
43+
settings = "os", "compiler", "build_type", "arch"
44+
generators = "CMakeDeps", "CMakeToolchain"
45+
46+
def requirements(self):
47+
self.requires("kubernetes_client_c/0.9.0")
48+
49+
def layout(self):
50+
cmake_layout(self)
51+
```
52+
53+
2- Use following command (in the root directory of project) to install all dependencies that are specified in the `conanfile`:
54+
```
55+
conan install . --build=missing
56+
```
57+
58+
3- Finally, edit `CMakeLists.txt` of your project to link against libraries. In this case, we link to `kubernetes_client_c` library.
59+
60+
Add these lines after declaring the target in CMakeLists.
61+
62+
**CMakeLists.txt**
63+
```
64+
find_package(kubernetes_client_c)
65+
target_link_libraries(<your_target> kubernetes_client_c::kubernetes_client_c)
66+
```
67+
68+
Make sure to edit `<your_target>` with the actual target name.
69+
70+
4- Example `#include` headers:
71+
```c
72+
#include <kubernetes/api/CoreV1API.h>
73+
#include <kubernetes/model/v1_pod.h>
74+
#include <kubernetes/config/kube_config.h>
75+
```

kubernetes/conanfile.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from conan import ConanFile
2+
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
3+
from conan.tools.files import copy
4+
from os.path import join
5+
6+
class kubernetes_client_cRecipe(ConanFile):
7+
name = "kubernetes_client_c"
8+
version = "0.9.0"
9+
package_type = "library"
10+
11+
# Optional metadata
12+
license = "Apache-2.0"
13+
url = "https://github.com/kubernetes-client/c"
14+
description = "Official C client library for Kubernetes"
15+
topics = ("kubernetes", "k8s", "kubernetes-client", "k8s-client")
16+
17+
# Binary configuration
18+
settings = "os", "compiler", "build_type", "arch"
19+
options = {"shared": [True, False], "fPIC": [True, False], "openssl_shared":[True, False], "curl_version": ["7", "8"]}
20+
default_options = {"shared": False, "fPIC": True, "openssl_shared": True, "curl_version": "8"}
21+
22+
# Sources are located in the same place as this recipe, copy them to the recipe
23+
exports_sources = "config.h.in", "ConfigureChecks.cmake", "PreTarget.cmake", "PostTarget.cmake", "CMakeLists.txt", "src/*", "external/*", "api/*", "model/*", "include/*", "config/*", "watch/*", "websocket/*"
24+
25+
def config_options(self):
26+
if self.settings.os == "Windows":
27+
self.options.rm_safe("fPIC")
28+
29+
def configure(self):
30+
if self.options.shared:
31+
self.options.rm_safe("fPIC")
32+
self.options["openssl/*"].shared = self.options.openssl_shared
33+
34+
def layout(self):
35+
cmake_layout(self)
36+
37+
def generate(self):
38+
deps = CMakeDeps(self)
39+
deps.generate()
40+
tc = CMakeToolchain(self)
41+
tc.generate()
42+
43+
def build(self):
44+
cmake = CMake(self)
45+
cmake.configure()
46+
cmake.build()
47+
48+
def package(self):
49+
copy(self, "*.h", src=join(self.source_folder, "api"), dst=join(self.package_folder, "include/kubernetes/api"), keep_path=False)
50+
copy(self, "*.h", src=join(self.source_folder, "model"), dst=join(self.package_folder, "include/kubernetes/model"), keep_path=False)
51+
copy(self, "*.h", src=join(self.source_folder, "config"), dst=join(self.package_folder, "include/kubernetes/config"), keep_path=False)
52+
copy(self, "*.h", src=join(self.source_folder, "include"), dst=join(self.package_folder, "include/kubernetes/include"), keep_path=False)
53+
copy(self, "*.h", src=join(self.source_folder, "websocket"), dst=join(self.package_folder, "include/kubernetes/websocket"), keep_path=False)
54+
copy(self, "*.h", src=join(self.source_folder, "external"), dst=join(self.package_folder, "include/kubernetes/external"), keep_path=False)
55+
copy(self, "*.h", src=join(self.source_folder, "watch"), dst=join(self.package_folder, "include/kubernetes/watch"), keep_path=False)
56+
cmake = CMake(self)
57+
cmake.install()
58+
59+
def package_info(self):
60+
self.cpp_info.libs = ["kubernetes"]
61+
62+
def requirements(self):
63+
self.requires("libcurl/[~{}]".format(self.options.curl_version), transitive_headers=True)
64+
self.requires("openssl/[^3]", force=True)
65+
self.requires("libwebsockets/[^4.2]", transitive_headers=True)
66+
self.requires("libyaml/[^0.2.5]")

kubernetes/websocket/wsclient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
extern "C" {
99
#endif
1010

11-
typedef void (*data_callback_func) (void **, long *);
11+
typedef void (*data_callback_function) (void **, long *);
1212

1313
typedef enum wsc_mode_t {
1414
WSC_MODE_NORMAL = 0,
@@ -23,7 +23,7 @@ typedef struct wsclient_t {
2323
long data_to_send_len;
2424
void *data_received;
2525
long data_received_len;
26-
data_callback_func data_callback_func;
26+
data_callback_function data_callback_func;
2727
int log_mask;
2828
lws_sorted_usec_list_t sul; /* schedule connection retry */
2929
struct lws *wsi; /* related wsi if any */

0 commit comments

Comments
 (0)