Skip to content

Commit 221732e

Browse files
authored
Merge pull request #255 from joyanta55/example_bazel
Add examples that uses bazel c kubernetes library
2 parents 66c5243 + 501550c commit 221732e

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

.github/workflows/build.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,5 @@ jobs:
6666
curl -LO "https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-amd64"
6767
chmod +x bazelisk-linux-amd64
6868
sudo mv bazelisk-linux-amd64 /usr/local/bin/bazel
69-
cd examples/
70-
bazel build kube_c
69+
bazel build kube_c_library
7170

BUILD

+23-3
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,33 @@
5656
# deps = [":kube_c"],
5757
# )
5858

59-
# Make sure you install the pre-requisites (libyaml,libwebsocket etc.) beforehand. A working example can be found here
59+
# Make sure you install the pre-requisites (libyaml,libwebsocket etc.) beforehand. A working example can be found in the example directory.
6060

61-
# https://github.com/joyanta55/kubernetes_c_bazel/tree/main
61+
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
62+
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake", "make")
6263

63-
# In summary, the below filegroup allows to import kubernetes C client (i.e. lib_source = "@kubernetes_c_client//:kubernetes"), use cmake or make bazel rule provided by rules_foreign_cc (https://github.com/bazel-contrib/rules_foreign_cc) to build and use.
6464
filegroup(
6565
name = "kubernetes",
6666
srcs = glob(["kubernetes/**"]),
6767
visibility = ["//visibility:public"],
6868
)
69+
70+
cmake(
71+
name = "kube_c",
72+
build_args = [
73+
"--verbose",
74+
"--", # <- Pass remaining options to the native tool.
75+
"-j 1",
76+
],
77+
lib_source = ":kubernetes",
78+
out_shared_libs = ["libkubernetes.so"],
79+
)
80+
81+
# create lib files (.so or .a)
82+
cc_library(
83+
name = "kube_c_library",
84+
hdrs = [":kubernetes"], # Explicitly add headers if needed
85+
strip_include_prefix = "kubernetes",
86+
visibility = ["//visibility:public"],
87+
deps = [":kube_c"],
88+
)

examples/BUILD

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
# Example of using bazel rules on the existing examples.
2+
13
load("@rules_cc//cc:defs.bzl", "cc_binary")
2-
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
3-
load("@rules_foreign_cc//foreign_cc:defs.bzl", "make")
4-
cmake(
5-
name = "kube_c",
6-
build_args = [
7-
"--verbose",
8-
"--", # <- Pass remaining options to the native tool.
9-
"-j 1",
4+
5+
# create and run executable file.
6+
# Run: bazel run //examples:list_pod
7+
cc_binary(
8+
name = "list_pod",
9+
srcs = [
10+
"list_pod/main.c",
1011
],
11-
lib_source = "//:kubernetes",
12-
out_shared_libs = ["libkubernetes.so"],
12+
deps = ["//:kube_c_library"], #imported from BUILD file of root directory
13+
)
14+
15+
# Run: bazel run //examples:list_event
16+
cc_binary(
17+
name = "list_event",
18+
srcs = ["list_event/main.c"],
19+
deps = ["//:kube_c_library"], #imported from BUILD file of root directory
1320
)

0 commit comments

Comments
 (0)