Skip to content
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 examples that uses bazel c kubernetes library #255

Merged
merged 2 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)