Merge pull request #255 from joyanta55/example_bazel
Add examples that uses bazel c kubernetes library
This commit is contained in:
3
.github/workflows/build.yml
vendored
3
.github/workflows/build.yml
vendored
@@ -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
BUILD
26
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"],
|
||||
)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user