Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ jobs:
mkdir -p .ci/windows-zig "$RUNNER_TEMP/cbm-zig-local" "$RUNNER_TEMP/cbm-zig-global"
# CBM's Zig modules read C declarations from a translate-c module "c".
zig translate-c -lc -target "$TARGET" -D_DEFAULT_SOURCE -D_GNU_SOURCE \
-DCBM_WITH_ZOVA=1 -I"$ZOVA_ROOT/include" \
-Isrc -Ivendored -Ivendored/sqlite3 -Ivendored/mimalloc/include \
-Iinternal/cbm -Iinternal/cbm/vendored/ts_runtime/include \
src/cbm_zig_c.h > "$RUNNER_TEMP/cbm_c.zig"
Expand Down
59 changes: 32 additions & 27 deletions Makefile.cbm
Original file line number Diff line number Diff line change
Expand Up @@ -149,32 +149,17 @@ PREPROCESSOR_SRC = $(CBM_DIR)/preprocessor.cpp

# SQLite writer

# Store module (new)
STORE_SRCS = src/store/store.c

# Optional Zova storage adapter. Compiles to no-op stubs unless
# CBM_WITH_ZOVA=1 is set for the build.
ZOVA_SRCS = \
src/zova/cbm_zova.c \
src/zova/cbm_zova_publish_model.c \
src/zova/cbm_zova_edge_payload.c \
src/zova/cbm_zova_delta.c \
src/zova/cbm_zova_operations.c \
src/zova/cbm_zova_v5_snapshot.c \
src/zova/cbm_zova_writer_gate.c \
src/zova/cbm_zova_coordination.c \
src/zova/cbm_zova_route.c \
src/zova/cbm_zova_repository.c \
src/zova/cbm_zova_bridge_stub.c \
src/zova/cbm_zova_plugin.c
# Optional Zova storage adapter: implemented in Zig (src/zova/*.zig, part of
# libcbm_zig). Its database functions are no-op stubs unless CBM_WITH_ZOVA=1
# is set for the build.
ZOVA_SRCS =

# MCP server module: implemented in Zig (src/mcp/*.zig, part of libcbm_zig)
MCP_SRCS =

# Discover module is Zig: see CBM_ZIG_SRC.

# Graph buffer module (new)
GRAPH_BUFFER_SRCS = src/graph_buffer/graph_buffer.c
# Graph buffer module is Zig: see CBM_ZIG_SRC.

# Pipeline module (new)
PIPELINE_SRCS = \
Expand Down Expand Up @@ -267,7 +252,7 @@ TRE_CFLAGS = -std=c11 -g -O1 -w -Ivendored/tre
YYJSON_SRC = vendored/yyjson/yyjson.c

# All production sources
PROD_SRCS = $(FOUNDATION_SRCS) $(STORE_SRCS) $(ZOVA_SRCS) $(MCP_SRCS) $(GRAPH_BUFFER_SRCS) $(PIPELINE_SRCS) $(SEMANTIC_SRCS) $(CLI_SRCS) $(YYJSON_SRC)
PROD_SRCS = $(FOUNDATION_SRCS) $(ZOVA_SRCS) $(MCP_SRCS) $(PIPELINE_SRCS) $(SEMANTIC_SRCS) $(CLI_SRCS) $(YYJSON_SRC)
EXISTING_C_SRCS = $(EXTRACTION_SRCS) $(LSP_SRCS) $(TS_RUNTIME_SRC) \
$(GRAMMAR_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS)

Expand Down Expand Up @@ -474,6 +459,7 @@ CBM_ZIG_SRCS = $(CBM_ZIG_SRC) src/cbm_zig_c.h src/cli_zig/cbm_cli_zig.zig src/cl
src/cli/tool_args.zig \
src/cli/hook_augment.zig src/cli/progress_sink.zig src/cli/progress_sink.h \
src/cli/cli.h src/mcp/mcp.h src/pipeline/pipeline.h \
src/pipeline/worker_pool.h \
src/mcp/mcp.zig src/mcp/server.zig src/mcp/code_tools.zig \
src/mcp/graph_tools.zig src/mcp/index_tools.zig src/mcp/project_tools.zig \
src/mcp/search_tools.zig src/mcp/index_supervisor.zig src/mcp/index_supervisor.h \
Expand All @@ -492,10 +478,29 @@ CBM_ZIG_SRCS = $(CBM_ZIG_SRC) src/cbm_zig_c.h src/cli_zig/cbm_cli_zig.zig src/cl
src/discover/userconfig.zig \
src/discover/discover.h src/discover/userconfig.h \
src/git/git_context.zig src/git/git_context.h \
src/graph_buffer/graph_buffer.zig src/graph_buffer/graph_buffer.h \
src/simhash/minhash.zig src/simhash/minhash.h \
src/watcher/watcher.zig src/watcher/watcher.h
src/store/store.zig src/store/store.h \
src/watcher/watcher.zig src/watcher/watcher.h \
src/zova/cbm_zova.zig \
src/zova/cbm_zova_bridge_stub.zig src/zova/cbm_zova_coordination.zig \
src/zova/cbm_zova_delta.zig src/zova/cbm_zova_edge_payload.zig \
src/zova/cbm_zova_operations.zig \
src/zova/cbm_zova_plugin.zig src/zova/cbm_zova_publish_model.zig \
src/zova/cbm_zova_repository.zig \
src/zova/cbm_zova_route.zig \
src/zova/cbm_zova_v5_snapshot.zig \
src/zova/cbm_zova_writer_gate.zig \
$(wildcard src/zova/*.h)
# The Zig modules see CBM_WITH_ZOVA and, with Zova, the SDK header too.
CBM_ZIG_C_INCLUDES = -Isrc -Ivendored -Ivendored/sqlite3 -Ivendored/mimalloc/include \
-I$(CBM_DIR) -I$(TS_INCLUDE)
ifeq ($(CBM_WITH_ZOVA),1)
CBM_ZIG_C_INCLUDES += -DCBM_WITH_ZOVA=1 -I$(ZOVA_ROOT)/include
CBM_ZIG_SRCS += $(ZOVA_ROOT)/include/zova.h $(ZOVA_ROOT)/include/zova_plugin.h
else
CBM_ZIG_C_INCLUDES += -DCBM_WITH_ZOVA=0
endif
CBM_ZIG_LIB = $(BUILD_DIR)/libcbm_zig.a
# Test runners link a ReleaseSafe copy: the sanitizers do not instrument Zig
# code, so its runtime safety checks are what catch bounds and overflow bugs.
Expand Down Expand Up @@ -695,8 +700,8 @@ $(BUILD_DIR)/test-runner: $(ALL_TEST_SRCS) $(PROD_SRCS) $(EXTRACTION_SRCS) $(AC_
$(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) \
$(OBJS_VENDORED_TEST) \
$(CBM_ZOVA_BRIDGE_LIB) \
$(ZOVA_LINK_LIBS) \
$(CBM_ZIG_TEST_LIB) \
$(ZOVA_LINK_LIBS) \
$(LDFLAGS_TEST)

test:
Expand Down Expand Up @@ -730,8 +735,8 @@ $(BUILD_DIR)/test-repro-runner: $(TEST_REPRO_SRCS) $(PROD_SRCS) $(EXTRACTION_SRC
$(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) \
$(OBJS_VENDORED_TEST) \
$(CBM_ZOVA_BRIDGE_LIB) \
$(ZOVA_LINK_LIBS) \
$(CBM_ZIG_TEST_LIB) \
$(ZOVA_LINK_LIBS) \
$(LDFLAGS_TEST)

test-repro: $(BUILD_DIR)/test-repro-runner
Expand Down Expand Up @@ -784,8 +789,8 @@ $(BUILD_DIR)/codebase-memory-mcp: $(MAIN_SRC) $(PROD_SRCS) $(EXTRACTION_SRCS) $(
$(EXTRACTION_SRCS) $(AC_LZ4_SRCS) $(ZSTD_SRCS) \
$(OBJS_VENDORED_PROD) \
$(CBM_ZOVA_BRIDGE_LIB) \
$(ZOVA_LINK_LIBS) \
$(CBM_ZIG_LIB) \
$(ZOVA_LINK_LIBS) \
$(LDFLAGS)

cbm:
Expand Down Expand Up @@ -819,8 +824,8 @@ SYSROOT = $(shell xcrun --show-sdk-path 2>/dev/null)
SYSROOT_FLAG = $(if $(SYSROOT),-isysroot $(SYSROOT),)

# Our source files (excluding vendored, grammars, tree-sitter runtime)
LINT_SRCS = $(FOUNDATION_SRCS) $(STORE_SRCS) $(MCP_SRCS) \
$(GRAPH_BUFFER_SRCS) $(PIPELINE_SRCS) $(SEMANTIC_SRCS) \
LINT_SRCS = $(FOUNDATION_SRCS) $(MCP_SRCS) \
$(PIPELINE_SRCS) $(SEMANTIC_SRCS) \
$(CLI_SRCS) $(EXTRACTION_SRCS) $(AC_LZ4_SRCS) \
$(ZSTD_SRCS) $(MAIN_SRC)
LINT_HDRS = $(wildcard src/**/*.h src/*.h $(CBM_DIR)/*.h)
Expand Down
18 changes: 4 additions & 14 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@ fn addCbmZigLibrary(b: *std.Build, cfg: Config, kind: BuildKind) *std.Build.Step
});
c_decls.defineCMacro("_DEFAULT_SOURCE", null);
c_decls.defineCMacro("_GNU_SOURCE", null);
c_decls.defineCMacro("CBM_WITH_ZOVA", if (cfg.with_zova) "1" else "0");
if (cfg.with_zova) {
c_decls.addIncludePath(.{ .cwd_relative = b.pathJoin(&.{ cfg.zova_root, "include" }) });
}
for ([_][]const u8{
"src",
"vendored",
Expand Down Expand Up @@ -532,20 +536,6 @@ fn grammarSources(b: *std.Build) []const []const u8 {
const native_sources = [_][]const u8{
"src/foundation/hash_table.c",
"src/foundation/c_shim.c",
"src/store/store.c",
"src/zova/cbm_zova.c",
"src/zova/cbm_zova_publish_model.c",
"src/zova/cbm_zova_edge_payload.c",
"src/zova/cbm_zova_delta.c",
"src/zova/cbm_zova_operations.c",
"src/zova/cbm_zova_v5_snapshot.c",
"src/zova/cbm_zova_writer_gate.c",
"src/zova/cbm_zova_coordination.c",
"src/zova/cbm_zova_route.c",
"src/zova/cbm_zova_repository.c",
"src/zova/cbm_zova_bridge_stub.c",
"src/zova/cbm_zova_plugin.c",
"src/graph_buffer/graph_buffer.c",
"src/pipeline/fqn.c",
"src/pipeline/path_alias.c",
"src/pipeline/laravel_routing.c",
Expand Down
2 changes: 1 addition & 1 deletion scripts/security-audit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ while IFS= read -r match; do
file=$(echo "$match" | cut -d: -f1)
relfile="${file#"$ROOT/"}"
case "$relfile" in
src/cli/cli.zig|src/store/store.c|src/pipeline/*.c|src/foundation/diagnostics.zig|src/mcp/search_tools.zig|src/mcp/index_tools.zig)
src/cli/cli.zig|src/pipeline/*.c|src/foundation/diagnostics.zig|src/mcp/search_tools.zig|src/mcp/index_tools.zig)
;; # Known safe (diagnostics.zig: atomic .tmp+rename metrics dump to configured path;
# search_tools.zig: search pattern/file-list temp files; index_tools.zig:
# index supervisor response/quarantine files)
Expand Down
17 changes: 16 additions & 1 deletion src/cbm_zig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ comptime {
checkExports(@import("foundation/system_info.zig").linux);
checkExports(@import("foundation/yaml.zig"));
checkExports(@import("git/git_context.zig"));
checkExports(@import("graph_buffer/graph_buffer.zig"));
checkExports(@import("mcp/code_tools.zig"));
checkExports(@import("mcp/graph_tools.zig"));
checkExports(@import("mcp/index_supervisor.zig"));
Expand All @@ -61,13 +62,27 @@ comptime {
checkExports(@import("mcp/search_tools.zig"));
checkExports(@import("mcp/server.zig"));
checkExports(@import("simhash/minhash.zig"));
checkExports(@import("store/store.zig"));
checkExports(@import("watcher/watcher.zig"));
checkExports(@import("zova/cbm_zova.zig"));
checkExports(@import("zova/cbm_zova.zig").zova_only);
if (c.CBM_WITH_ZOVA == 0) checkExports(@import("zova/cbm_zova_bridge_stub.zig"));
checkExports(@import("zova/cbm_zova_coordination.zig"));
checkExports(@import("zova/cbm_zova_delta.zig"));
checkExports(@import("zova/cbm_zova_edge_payload.zig"));
checkExports(@import("zova/cbm_zova_operations.zig"));
checkExports(@import("zova/cbm_zova_plugin.zig"));
checkExports(@import("zova/cbm_zova_publish_model.zig"));
checkExports(@import("zova/cbm_zova_repository.zig"));
checkExports(@import("zova/cbm_zova_route.zig"));
checkExports(@import("zova/cbm_zova_v5_snapshot.zig"));
checkExports(@import("zova/cbm_zova_writer_gate.zig"));
}

/// Checks every pub `cbm_*` function of `module` against the C declaration
/// of the same name in the translated headers.
fn checkExports(comptime module: type) void {
@setEvalBranchQuota(10000);
@setEvalBranchQuota(50000);
for (@typeInfo(module).@"struct".decl_names) |name| {
if (!std.mem.startsWith(u8, name, "cbm_")) continue;
const Impl = @TypeOf(@field(module, name));
Expand Down
21 changes: 19 additions & 2 deletions src/cbm_zig_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
* Makefile.cbm). Include only what a ported module calls, so a header that
* translate-c cannot handle never blocks an unrelated module.
*
* Translated without CBM_WITH_ZOVA: the declarations used here do not depend
* on it, and leaving it unset keeps the Zova SDK headers out of the build.
* The build passes -DCBM_WITH_ZOVA=0|1 to translate-c. With Zova, the SDK
* headers zova.h and zova_plugin.h are translated too, and the Zig Zova modules compile their
* real implementation instead of the no-Zova stubs.
*/
#ifndef CBM_ZIG_C_H
#define CBM_ZIG_C_H
Expand All @@ -21,6 +22,7 @@
#ifndef _WIN32
#include <fcntl.h>
#include <signal.h>
#include <sys/statvfs.h>
#include <sys/time.h>
#include <unistd.h>
#include <fnmatch.h>
Expand Down Expand Up @@ -91,12 +93,26 @@
#include "foundation/yaml.h"
#include "mcp/mcp.h"
#include "pipeline/pipeline.h"
#include "pipeline/worker_pool.h"
#include "semantic/semantic.h"
#include "store/store.h"
#include "tree_sitter/api.h"
#include "zova/cbm_zova.h"
#include "zova/cbm_zova_bridge.h"
#include "zova/cbm_zova_coordination.h"
#include "zova/cbm_zova_delta.h"
#include "zova/cbm_zova_edge_payload.h"
#include "zova/cbm_zova_operations.h"
#include "zova/cbm_zova_plugin.h"
#include "zova/cbm_zova_publish_model.h"
#include "zova/cbm_zova_repository.h"
#include "zova/cbm_zova_route.h"
#include "zova/cbm_zova_v5_snapshot.h"
#include "zova/cbm_zova_writer_gate.h"
#if CBM_WITH_ZOVA
#include <zova.h>
#include <zova_plugin.h>
#endif
#include <sqlite3.h>
#include <yyjson/yyjson.h>

Expand All @@ -121,6 +137,7 @@ static inline FILE *cbm_zig_stderr(void) {
#include "discover/discover.h"
#include "discover/userconfig.h"
#include "git/git_context.h"
#include "graph_buffer/graph_buffer.h"
#include "mcp/index_supervisor.h"
#include "simhash/minhash.h"
#include "watcher/watcher.h"
Expand Down
Loading
Loading