Skip to content

Commit

Permalink
Use existing examples
Browse files Browse the repository at this point in the history
  • Loading branch information
joyanta55 committed Nov 19, 2024
1 parent d737dd8 commit 501550c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 198 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"],
)
37 changes: 11 additions & 26 deletions examples/BUILD
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake", "make")

cmake(
name = "kube_c",
build_args = [
"--verbose",
"--", # <- Pass remaining options to the native tool.
"-j 1",
],
lib_source = "//:kubernetes",
out_shared_libs = ["libkubernetes.so"],
)
# Example of using bazel rules on the existing examples.

# create lib files (.so or .a)
# Example: bazel build list_pod_lib
cc_library(
name = "list_pod_lib",
srcs = ["bazel/list_pod.c"],
deps = [":kube_c"],
)
load("@rules_cc//cc:defs.bzl", "cc_binary")

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

# Run: bazel run //examples:list_event
cc_binary(
name = "create_pod",
srcs = ["bazel/create_pod.c"],
deps = [":kube_c"],
name = "list_event",
srcs = ["list_event/main.c"],
deps = ["//:kube_c_library"], #imported from BUILD file of root directory
)
103 changes: 0 additions & 103 deletions examples/bazel/create_pod.c

This file was deleted.

64 changes: 0 additions & 64 deletions examples/bazel/list_pod.c

This file was deleted.

0 comments on commit 501550c

Please sign in to comment.