Skip to content

Latest commit

 

History

History
154 lines (120 loc) · 7.04 KB

build_dependencies.md

File metadata and controls

154 lines (120 loc) · 7.04 KB

Standalone and custom builds

This repository builds independently with Bazel 6.4.0 and WORKSPACE. The version is pinned in .bazelversion; dependency recipes pin source versions, download checksums and patches. This change does not migrate the build to Bzlmod.

For a standalone Linux build, run from the repository root:

bazelisk build //src/master:main

open_source/deps/ holds public dependency recipes, 3rdparty/ holds build adaptations and vendored sources, and patches/ holds dependency patches. bazel/ provides shared build macros. Optional accelerator configurations still require their corresponding installed SDKs.

Building custom features in a separate workspace

The included defaults are sufficient for normal builds and usage. The following setup is for developers who need custom backends or other extensions. A separate extension project can pin this repository as a submodule at core/ and register it in its own WORKSPACE:

local_repository(name = "kv_cache_manager", path = "core")
load("@kv_cache_manager//bazel:build_rules.bzl", "build_rules_dependencies")
build_rules_dependencies()

# Declare any custom dependency selections before public defaults.
load("@kv_cache_manager//bazel:dependencies.bzl", "public_dependencies")
public_dependencies()

The extension project also invokes the rule initialization, toolchain and pip setup stages shown in this repository's WORKSPACE. An external repository's WORKSPACE is not executed as part of the custom build. Python requirement selection is an explicit argument to pip_deps, owned by the root workspace.

The extension project must also select its build options: Bazel does not load an external repository's .bazelrc. To use the same native DNS resolver as the standalone build, add this to the extension project's .bazelrc:

build --define=grpc_no_ares=true

The public dependency recipes do not register c-ares. Omitting this option selects gRPC's c-ares resolver and requires the extension project to register a compatible com_github_cares_cares repository explicitly.

Public dependency macros preserve an existing repository of the same name. Register a shared dependency once, using the same repository name for every consumer, to select one version and patch set in the combined build. Dependency changes require validation in both the standalone and combined builds. The same rule applies to vendored repositories and installed SDK configuration: public_toolchains() preserves predeclared configuration repositories such as local_config_python, local_config_cuda, python_abi and python_platform. Separate workspace builds have separate compilation graphs; sharing a download cache does not imply shared compiled outputs.

The public workspace selects only public recipes and default implementations. It does not read parent directories, register extension project repositories, or load their build files. Existing Python runtime configurations (py3, py310, py311, py312) continue to select an installed interpreter.

Selecting extensions

Public interfaces are separate targets from the implementations and their callers. Factories have public defaults; the embedding root can select another target via a label flag. The selected target depends on the interface and its own libraries. The embedding root supplies its own compiler configuration and final linkage.

Capability Public label flag
Storage backend factory //src/master/data_storage:backend_factory
Process lifecycle //src/master/service:process_extension_impl
Client SDK extension //kv_cache_manager/client/src/internal/sdk:sdk_extension_impl
Service discovery //src/master/common:service_discovery_extension_impl
Metrics reporter //src/master/metrics:reporter_extension

For example, an extension project with //extensions:process_extension uses:

bazelisk build @kv_cache_manager//src/master:main \
  --define=grpc_no_ares=true \
  --@kv_cache_manager//src/master/service:process_extension_impl=//extensions:process_extension

This is build-time selection. The public sources do not name the extension project's repository, load its build rules, or discover its source paths. The concrete implementation may be called at runtime through the public interface.

An explicit sdk_extension_impl selection is always linked; it does not require the standalone ENABLE_TAIR_MEMPOOL define. Without a selection, the standalone defaults retain their existing optional-backend configuration.

The default C++ service discovery supports static://. Other schemes require a selected discovery extension; the default extension logs a warning and returns nullptr. A working custom extension is not logged as unsupported.

Recording both source revisions

For a custom build, configure both the workspace status command and //package/git_commit:embedding_workspace. The status command records the revisions; the label tells the history generator where to read the second checkout. Neither setting discovers or configures the other.

For example, in the extension project's bazel/workspace_status.sh:

#!/usr/bin/env bash
set -euo pipefail
root=$(cd "$(dirname "$0")/.." && pwd -P)
cd "$root/core"
exec bash bazel/workspace_status.sh "$root"

Export WORKSPACE from that project's root BUILD with exports_files(["WORKSPACE"]), then configure its .bazelrc:

build --workspace_status_command="bash bazel/workspace_status.sh"
build --@kv_cache_manager//package/git_commit:embedding_workspace=//:WORKSPACE

This records the public checkout in STABLE_GIT_* and the extension project in STABLE_STUB_GIT_*. Standalone builds need neither custom setting; the second revision is unknown. See Version stamping for details.

Optional gRPC dependencies

The gRPC dependency-label patch preserves upstream mappings such as @upb and @io_opencensus_cpp. The default C++ targets do not select these optional code paths, so the public WORKSPACE does not register those repositories. Enabling a target that uses them also requires explicit, compatible dependency recipes and validation of that target.

Connector wheels collect HF3FS runtime libraries from their C++ target into kv_cache_manager/client/pybind/hf3fs.libs when ENABLE_HF3FS=true. The Python extension uses a relative RPATH to that directory; CUDA and NUMA libraries remain system dependencies. To check both wheel archives from the extension project, use its accelerator configuration with bazelisk test @kv_cache_manager//kv_cache_manager/py_connector/test:wheel_contents_test. Run the same target without the HF3FS define to check the disabled configuration. Python proto generation can be checked in either repository layout by building @kv_cache_manager//src/master/protocol/protobuf:meta_service_py, with and without --experimental_sibling_repository_layout.

Source compatibility

Existing C++ namespaces, public class names and source directories are unchanged. An embedding product owns any facade or naming adapter. Extension interfaces use the existing kv_cache_manager types.