kubernetes-client / c

Official C client library for Kubernetes
Apache License 2.0
148 stars 49 forks source link

Add bazel integration support in kubernetes c client #253

Closed joyanta55 closed 1 week ago

joyanta55 commented 1 week ago

Added BUILD file in the kubernetes c client repository that helps integrating the library to external Bazel users. Following are the changes needed from the external Bazel users to do.

WORKSPACE file:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
     name = "kubernetes_c_client",
     sha256 = "10d0c5af1a52a1d2da379e8e45b53978b9dedc90ff195bdff171ae17c1f1dd50",
     strip_prefix = "c-0.11.0",
     url = "https://github.com/kubernetes-client/c/archive/refs/tags/v0.11.0.zip",
)

http_archive(
      name = "rules_foreign_cc",
      sha256 = "a2e6fb56e649c1ee79703e99aa0c9d13c6cc53c8d7a0cbb8797ab2888bbc99a3",
      strip_prefix = "rules_foreign_cc-0.12.0",
      url = "https://github.com/bazelbuild/rules_foreign_cc/releases/download/0.12.0/rules_foreign_cc-0.12.0.tar.gz",
)

load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
rules_foreign_cc_dependencies()

load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()

BUILD file:

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",
    ],
    lib_source = "@kubernetes_c_client//:kubernetes",
    out_shared_libs = ["libkubernetes.so"],
)

cc_binary(
    name = "create_pod",
    srcs = ["create_pod.c"],
    deps = [":kube_c"],
)

cc_binary(
    name = "list_pod",
    srcs = ["list_pod.c"],
    deps = [":kube_c"],
)

The added 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.

Make sure you install the pre-requisites (libyaml,libwebsocket etc.) beforehand. A working example can be found here

k8s-ci-robot commented 1 week ago

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: joyanta55 Once this PR has been reviewed and has the lgtm label, please assign ityuhui for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files: - **[OWNERS](https://github.com/kubernetes-client/c/blob/master/OWNERS)** Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
linux-foundation-easycla[bot] commented 1 week ago

CLA Missing ID CLA Not Signed