Skip to content

Commit

Permalink
Merge pull request #255 from joyanta55/example_bazel
Browse files Browse the repository at this point in the history
Add examples that uses bazel c kubernetes library
  • Loading branch information
k8s-ci-robot authored Nov 23, 2024
2 parents 66c5243 + 501550c commit 221732e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,5 @@ jobs:
curl -LO "https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-amd64"
chmod +x bazelisk-linux-amd64
sudo mv bazelisk-linux-amd64 /usr/local/bin/bazel
cd examples/
bazel build kube_c
bazel build kube_c_library
26 changes: 23 additions & 3 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,33 @@
# deps = [":kube_c"],
# )

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

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

# 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.
filegroup(
name = "kubernetes",
srcs = glob(["kubernetes/**"]),
visibility = ["//visibility:public"],
)

cmake(
name = "kube_c",
build_args = [
"--verbose",
"--", # <- Pass remaining options to the native tool.
"-j 1",
],
lib_source = ":kubernetes",
out_shared_libs = ["libkubernetes.so"],
)

# create lib files (.so or .a)
cc_library(
name = "kube_c_library",
hdrs = [":kubernetes"], # Explicitly add headers if needed
strip_include_prefix = "kubernetes",
visibility = ["//visibility:public"],
deps = [":kube_c"],
)
27 changes: 17 additions & 10 deletions examples/BUILD
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# Example of using bazel rules on the existing examples.

load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "make")
cmake(
name = "kube_c",
build_args = [
"--verbose",
"--", # <- Pass remaining options to the native tool.
"-j 1",

# create and run executable file.
# Run: bazel run //examples:list_pod
cc_binary(
name = "list_pod",
srcs = [
"list_pod/main.c",
],
lib_source = "//:kubernetes",
out_shared_libs = ["libkubernetes.so"],
deps = ["//:kube_c_library"], #imported from BUILD file of root directory
)

# Run: bazel run //examples:list_event
cc_binary(
name = "list_event",
srcs = ["list_event/main.c"],
deps = ["//:kube_c_library"], #imported from BUILD file of root directory
)

0 comments on commit 221732e

Please sign in to comment.