srdatalog.build

High-level project builder.

build_project(program, project_name, ...) runs the full pipeline in one call:

Program → HIR → MIR → emit per-rule complete runner structs → compute schema definitions + DB blueprint alias → write the .cpp tree to ~/.cache/srdatalog/jit/_/

Returns the same dict as cache.write_jit_project.

The resulting jit_batch_N.cpp files are byte-identical to what Nim’s codegen writes to its own JIT cache — they self-contain the schema + DB type alias, so the same compile flags / external deps that work for Nim’s output work here too.

This module is a thin wrapper over srdatalog.ir.pipeline.compile_program plus the file-emitting layer (cache.write_jit_project + optional shard/main file emission). The compile phase lives in pipeline.py so viz / other consumers can share it without touching disk.

Module Contents

Functions

build_project

Compile program end-to-end and write the .cpp tree.

API

srdatalog.build.build_project(program: srdatalog.dsl.Program, project_name: str, *, cache_base: str | None = None, emit_main_file: bool = True, shard_step_bodies: bool = False, unity: bool = False) srdatalog.ir.codegen.cuda.build.cache.JitProjectLayout[source]

Compile program end-to-end and write the .cpp tree.

Args: program: a srdatalog.Program (DSL output). project_name: human-readable name used in C++ identifiers + cache dir. The C++ side derives <project>_DB, <project>_DB_Blueprint, <project>_DB_DeviceDB, and the cache lives at ~/.cache/srdatalog/jit/<project>_DB_<hash>/. cache_base: override ~/.cache/srdatalog (e.g., a tmpdir for tests, or ./build for an in-tree project layout). emit_main_file: if True, also write a main.cpp containing the _Runner struct + relation typedefs. Set False if you only want the batch files (e.g., when integrating with an existing host binary that defines its own <Project>_Runner). shard_step_bodies: if True (default), emit each step_N and the run() dispatcher as its own compilable .cpp shard. This moves the heavy template instantiation out of main.cpp so the shards compile in parallel with the batch files. Set False to get the old layout (step bodies inline in main.cpp as template methods) — useful for byte-match tests against the Nim fragment fixture. unity: if True (default), emit ONE big .cpp containing the preamble + all JitRunner structs + _Runner + extern “C” shim. Parses srdatalog.h once per build instead of N times — the dominant cost when PCH isn’t available. On doop this cuts cold compile from ~100s to ~20s. Set False for the traditional main + batch layout (better for byte-match testing against the Nim reference or for partial recompiles once PCH works).

Returns the dict from cache.write_jit_project: { “dir”, “main”, “batches”: […], “schema_header”, “kernel_header” }