API Reference and Customization
This page describes the Python package on main (backend/assemblage,
Python 3.12) and the contracts to keep when extending it.
Package layout
Module |
Responsibility |
|---|---|
|
enumerations; queue names and intervals; settings read from environment variables (pydantic-settings) |
|
the RabbitMQ messages (pydantic v2); their JSON shape is frozen |
|
|
|
topology, connection retry, consumer (one ack or nack per message), publisher with confirms |
|
SQLModel models matched to the live PostgreSQL schema, the coordinator store, first-boot database creation |
|
S3 client; |
|
command runner, build-system detection, binary discovery,
|
|
the DWARF extractor (pyelftools) and its out-of-process wrapper |
|
the three workers; |
|
host-side dataset tools ( |
|
frozen Windows/MSVC strategy and the Conan DeepHistory builder |
Workers
backend/scripts/start_worker.py is the entry point of every container.
TYPE selects coordinator, builder, scraper or
legacy_conan. Everything else is environment variables, read by
settings.py:
Variable |
Used by |
|---|---|
|
all workers |
|
coordinator |
|
coordinator, builder |
|
builder identity; together they name the build option |
|
builder limits |
|
scraper; |
|
coordinator; default |
Message flow
The scraper publishes bundles of 25 repositories on the
scrapequeue.The coordinator inserts them into
projectsand creates oneb_statusrow per repository per build option.One dispatch thread per build option publishes tasks to
build_opt_{id}(topic exchangebuild_opt). The thread starts when a builder registers onbuilder_regwith that build option.Builders acknowledge a task before building it, then report on the
clone,buildandbinaryqueues. Rust builders with IR dumps also report onir.
Queue names and message JSON are frozen; the golden files under
tests/fixtures/messages/ are the specification. Enum values are
lowercase on the wire ("success") and stored by name in the database
('SUCCESS').
Build strategies
A builder’s behaviour is a BuildStrategy (build/strategy.py). The
pipeline calls prepare, build, find_binaries and debug_info
in that order and handles source acquisition, uploads and reporting itself.
class BuildStrategy(ABC):
platform: str # "linux"
compiler: str # "gcc", "clang", "rustc"
language: str # "c++", "rust"
compiler_version: str | None
toolset_version: str | None
build_mode: str # "RelWithDebInfo", "Debug", "Release"
base_path: str # where repositories are cloned and built
def prepare(self, clone_dir: str, compiler_flag: str) -> object | None:
"""Pre-build configuration; the return value is passed to build()."""
def build(self, clone_dir: str, compiler_flag: str,
prepared: object | None) -> tuple[str, BuildStatus]:
"""Compile; return (combined output, status)."""
def find_binaries(self, path: str) -> set[str]:
"""Paths of the built binaries under path."""
def debug_info(self, clone_dir: str,
original_files: list[str]) -> list[dict[str, object]]:
"""One Binary_info_list entry per new binary."""
def own_dir(self, path: str) -> None:
"""Optional ownership fix-up of produced directories."""
make_strategy(settings) picks the implementation: LinuxBuildStrategy
for C/C++ (autotools, CMake or Make detected from the file list; -g
-DNDEBUG plus the optimization flag), RustBuildStrategy when
language is rust, and the frozen Windows strategy when the platform
is Windows.
RustBuildStrategy drives cargo through per-profile environment
variables, selects the backend through a RustCodegenAdapter (llvm,
cranelift, gcc), reads cargo’s JSON output to find the workspace’s
own bin, example and cdylib artifacts, and adds a demangled name
(rustfilt) and an origin tag (in_repo, dependency,
stdlib, other) to every extracted function. Each adapter declares
the debug information and IR stages its backend can produce
(DebugInfoCaps, IrCaps).
Adding a build target
Add the enum members in
enums.py(SupportedCompiler,SupportedLanguageand so on).Implement
BuildStrategyunderbuild/and register it inmake_strategy.Make sure
builder/artifacts.pyhandles the new outputs.Add a compose service with
TYPE=builderand the identity variables. It registers its build option at startup, and existing repositories are queued for it.
Adding an optimization level or build mode for an existing target needs only the last step.
Metadata
Every build produces assemblage_meta.json. The key set is frozen; Rust
builds add keys.
Platform, Build_mode, Compiler, Compiler_version, URL, Commit, Optimization,
Pushed_at, compiler_flag, language, library
Codegen_backend, Toolchain, Mangling, Backend_caps, Cargo_locked (Rust only)
Binary_info_list: [
{ file,
functions: [
{ function_name, source_file, intersect_ratio,
demangled_name, origin, (Rust only)
function_info: [ { rva_start, rva_end } ],
lines: [ { line_number, rva, length, source_code, source_file } ] } ] } ]
Binary_info_list comes from dwarf/extract.py, the same extractor the
dataset tools use. Extraction of a binary can be skipped
(DWARF_SIZE_LIMIT) or stopped (timeouts); the binary is still stored and
its entry is then empty.
Storage keys
All S3 keys come from storage/layout.py:
project-archive/{owner}/{project}/{sha12}.tar.gz
project-archive/{owner}/{project}/latest.txt
artifacts/{owner}_{project}_{sha12}-{flag}-{backend}-{mode}/binaries/{name}.zst
artifacts/{owner}_{project}_{sha12}-{flag}-{backend}-{mode}/metadata/assemblage_meta.json.zst
artifacts/{owner}_{project}_{sha12}-{flag}-{backend}-{mode}/ir/{stage}.tar.gz
artifacts/{owner}_{project}_{sha12}-{flag}-{backend}-{mode}/export.json
{backend} is the Rust codegen backend or the C compiler; {flag} has
no leading dash; {sha12} is the first 12 characters of the commit.
Compression is zstd level 12, matching the published dataset, so a release
is a copy rather than a recompression.
Database
PostgreSQL tables: projects, b_status (one row per repository per
build option), buildopt, binaries, ir_artifacts (one row per
build and IR stage) and scrapers. A build option row is identified by
nine columns, including platform, compiler, language, codegen backend,
build mode and flag. binaries.optimization is always empty; join
binaries to b_status and buildopt to recover compiler and flag.
Migrations are Alembic and handwritten; apply them with
docker exec -it assemblage-coordinator-1 alembic upgrade head.
Dataset tools
uv sync --extra dataset
uv run assemblage-dataset -g --data <folder of builds> --dbfile out.sqlite --functions --rvas --lines
DB_HOST=localhost MINIO_ENDPOINT=localhost:9010 uv run assemblage-daily [--since YYYY-MM-DD]
assemblage-dataset -g turns a folder of build directories, each with an
assemblage_meta.json, into the five-table SQLite database described on
the dataset page. assemblage-daily pulls builds newer than a date from
MinIO and PostgreSQL, re-extracts their DWARF and appends them to a
cumulative linux_licensed.sqlite under assemblage_dataset/; the
SQLite predecessor of the Linux GitHub dataset was produced this way. The
Rust dataset is produced by the export scripts on the deployment page.