BUILD.Bazel rule support in c k8s client
joyantamishu opened this issue · comments
Hello All,
For my Bazel project, I need to add c kubernetes-client source as my Bazel repo. But looks like the bazel build is not working, as there is no BUILD.Bazel in the c/kubernetes/ folder. So, just wondering if Bazel support has not implemented yet or I am doing something wrong.
Thanks in Advance.
This library currently uses cmake for building.
This may help, I found it using web search so I know nothing about if it works for this :)
https://bazelbuild.github.io/rules_foreign_cc/main/cmake.html
Hi @brendandburns , thanks a lot for your response. I actually tried the link you shared and then found out C k8s repo, doesn't contain BUILD.Bazel file, which is essential for adding this repo as Bazel repo. Bazel can build this library using cmake following the content of CMakeList.txt, but it also requires one BUILD.Bazel file, to do the cmake build.
Just asking, can we add this issue as PR, I can work on that.
The exact error I am getting when I run bazel build
no such package '@kube-client-c//kubernetes': BUILD file not found in directory 'kubernetes' of external repository @kube-client-c. Add a BUILD file to a directory to mark it as a package. and referenced by '//src:kube-client-c'
kube-client-c is my repo name.
I think adding a PR for this is fine. Feel free to send one.
Thanks
Hi, I figured out a way to integrate this project in bazel.
In WORKSPACE file:
K8s_GENRULE_BUILD = """
package(default_visibility = ["//visibility:public"])
genrule(
name = "kubernetes_genrule",
srcs = glob(["**"]),
outs = ["libkubernetes.so"],
cmd = "ls external/kubernetes/kubernetes && cmake external/kubernetes/kubernetes && make && cp libkubernetes.so $(@D) && ls external/kubernetes/kubernetes"
)
cc_library(
name = "kubernetes",
srcs = ["libkubernetes.so"],
copts=["-Iexternal/kubernetes/kubernetes"]
)
"""
git_repository(
name = "kubernetes",
build_file_content = K8s_GENRULE_BUILD,
commit = "f5f12a807432824963bbea380cdf4d9ba412e00e",
remote = "https://github.com/kubernetes-client/c.git",
verbose = 1,
)
In the BUILD file, where you need to include this library:
package(default_visibility = ["//visibility:public"])
cc_library(
name = "nvg_k8s_event_agent",
srcs = ["sample.c"],
hdrs = [
"sample.h",
],
deps = [
"@kubernetes",
],
)
sample.c contents:
#include "kubernetes/config/kube_config.h"
#include "kubernetes/api/CoreV1API.h"
#include "kubernetes/model/core_v1_event.h"
#include "kubernetes/model/v1_object_reference.h"
int main(){return 0;}
So, closing this issue. Thanks
@joyantamishu
Great ! So would you like to create a PR to commit your guide to the docs directory? I think it's very helpful for developers using bazel.
Sure, sounds like a great idea. I will create the PR, and send it for your reviews.