diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7ac268e6..cb0bdcb1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 \ No newline at end of file diff --git a/BUILD b/BUILD index 0a43b720..7e04f3cd 100644 --- a/BUILD +++ b/BUILD @@ -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"], +) diff --git a/examples/BUILD b/examples/BUILD index fb7a362e..e4145005 100644 --- a/examples/BUILD +++ b/examples/BUILD @@ -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 )