Building SynergyDB

This page covers the toolchain, Cargo features, build profiles, the allocator choice and the Docker build. It describes main at 8a689c5c (2026-11-30). Paths in source pointers are relative to the repository root.

Toolchain

Item What the repository has Source
Language and edition Rust, edition 2021, crate synergydb version 0.1.0, publish = false Cargo.toml, [package]
Minimum Rust version No rust-version key and no rust-toolchain file. CONTRIBUTING.md asks for "Rust 1.75 or later". The Docker build uses the rust:1-bookworm image (latest Rust 1.x at build time). Cargo.toml; CONTRIBUTING.md, "Prerequisites"; Dockerfile
protoc Not needed on PATH. build.rs sets PROTOC to the binary shipped by the protoc-bin-vendored crate. The Dockerfile also installs protobuf-compiler. build.rs, main; Dockerfile
C toolchain Needed. mlua is built with features = ["lua51", "vendored"], which compiles Lua from C source. The Dockerfile installs cmake alongside the Rust image's compiler. Cargo.toml, mlua; Dockerfile

Not verified: the oldest Rust release that compiles the current tree. Nothing in the repository tests a minimum version, and CONTRIBUTING.md's "1.75" predates most of the code.

The comment above the mlua dependency says the vendored build compiles "Lua 5.4 from source via the MSVC C toolchain", while the next comment line and the lua51 feature say Lua 5.1 (source: Cargo.toml, mlua). The feature flag is what Cargo uses, so the build embeds Lua 5.1.

Targets

Target Path Notes Source
synergydb src/main.rs The server. Also dispatches the passwd, backup, restore, backup-verify, encryption and audit subcommands before normal argument parsing. Cargo.toml, [[bin]]; src/main.rs
synergydb-cli src/bin/cli.rs An 84-line stub. src/bin/cli.rs
synergydb-migrate src/bin/migrate.rs Import tool. Its source connectors are behind the migrate-* features. src/bin/migrate.rs
Benches benches/storage_bench.rs, vector_bench.rs, query_bench.rs, concurrent_workloads.rs Criterion benches with harness = false. See Benchmark harnesses. Cargo.toml, [[bench]]

Build script and generated code

build.rs runs tonic_build on proto/synergydb.proto, generating both server and client code. It writes a file descriptor set to OUT_DIR/synergydb_descriptor.bin, which gRPC server reflection uses, and prints cargo:rerun-if-changed=proto/synergydb.proto. The code is generated in every build. It is only compiled in when the grpc feature is on, through tonic::include_proto!("synergydb.v1") and tonic::include_file_descriptor_set!("synergydb_descriptor") in src/protocol/grpc/ (source: build.rs, main; src/protocol/grpc/mod.rs).

Cargo features

default = ["postgres-wire", "rest-api", "grpc"]. The Cargo comment records that grpc has been on by default since 2026-07-31 (source: Cargo.toml, [features]).

What matters for a developer is which features change compiled code. A search of src/, tests/ and benches/ for cfg(feature = ...) finds uses for only the features marked "Gates code" below. The others only pull in an optional crate or nothing at all. Every wire module under src/protocol/ is compiled into every build regardless of features (source: Cargo.toml, [features]; cfg(feature uses across src/).

Feature Enables crates Effect in the code Status
postgres-wire none No cfg use. The PostgreSQL wire is always compiled. Not wired: the flag has no effect.
mysql-wire none No cfg use. Not wired: no effect.
mongodb-wire bson No cfg use. Not wired: pulls a crate, gates no code.
bolt-protocol none No cfg use. Not wired: no effect.
graphql async-graphql No cfg use. No code imports async_graphql. The GraphQL code under src/query/graphql/ and the HTTP routes compile without it. Not wired: pulls an unused crate.
s3-api, arrow-flight, parquet, encryption-proxy none No cfg use. Not wired: no effect.
grpc tonic-health, tonic-reflection Gates code: src/protocol/grpc/ service, interceptors, health and reflection. Without it a fallback start() is compiled. In default.
rest-api axum, reqwest Gates code: HTTP routes, models and embeddings, auth::secrets, vector::embed, and parts of the proxy audit persistence. Without it the HTTP handler prints "HTTP REST API not enabled" and waits for shutdown. In default.
system-allocator none Gates code in src/lib.rs (see below). Opt-in.
aws-kms aws-config, aws-sdk-kms, aws-types, aws-smithy-* Gates code in src/proxy/mod.rs and src/proxy/crypto/kms.rs. Opt-in. Not wired: src/proxy/ is not called from the server (see Repository map).
migrate-postgres, -mysql, -sqlite, -mongodb, -couchdb tokio-postgres, mysql_async, rusqlite, mongodb, reqwest + url Gate the matching source connectors in src/migrate/source/ and src/bin/migrate.rs. migrate-sqlite also gates the SQLite audit store in src/proxy/audit/. Opt-in.
migrate-all the five above Convenience group. Opt-in.
full all of the above What make build and the proof pack build. Opt-in.

(source: Cargo.toml, [features]; src/lib.rs; src/protocol/grpc/mod.rs; src/protocol/http/mod.rs; src/proxy/mod.rs; src/migrate/; src/bin/migrate.rs)

Most of the effective build differences are therefore grpc, rest-api, aws-kms, the migrate-* connectors and the allocator. A default build already serves every wire.

tests/embeddings_test.rs is the only integration test that depends on a feature (rest-api). It runs in a default build (source: tests/embeddings_test.rs).

Build profiles

Profile Settings Source
release lto = true, codegen-units = 1, opt-level = 3 Cargo.toml, [profile.release]
bench lto = true, codegen-units = 1 Cargo.toml, [profile.bench]
dev Defaults, except opt-level = 3 for the sha2, hmac, pbkdf2, digest, aes, aes-gcm and ghash packages Cargo.toml, [profile.dev.package.*]

The comment on the dev overrides says debug builds of these crypto crates are about 50 times slower, and that PBKDF2 tests timed out under coverage without them (source: Cargo.toml, comment above [profile.dev.package.sha2]). The 50x figure is a comment claim. Not verified.

Fat LTO with one codegen unit makes release builds slow. The Makefile and prove/prove.sh set CARGO_PROFILE_RELEASE_DEBUG=0 to keep debug info out of release builds (source: Makefile, build; prove/prove.sh).

Common build commands

Goal Command Source
Debug build, default features cargo build CONTRIBUTING.md, "Building"
Release build used by the proof pack make build, which runs CARGO_PROFILE_RELEASE_DEBUG=0 cargo build --release --features full Makefile, build
Release build matching the Docker image cargo build --release --bin synergydb --bin synergydb-cli (default features) Dockerfile
Migration tool with all connectors cargo build --release --bin synergydb-migrate --features migrate-all Cargo.toml, [features]; src/bin/migrate.rs
Heap-profiler build cargo build --release --features system-allocator Cargo.toml, comment on system-allocator

Allocator

src/lib.rs installs a global allocator:

  • Default: heap::Counting<mimalloc::MiMalloc>.
  • With --features system-allocator: heap::Counting<std::alloc::System>, so heap profilers that hook malloc (heaptrack, valgrind) see every allocation.

(source: src/lib.rs, GLOBAL; Cargo.toml, system-allocator)

The comment in src/lib.rs explains the choice of mimalloc by profiling: with glibc's allocator, 38 to 44 percent of samples in a 2,000-row scan were in malloc, free and memcpy. That is a comment claim. Not verified.

heap::Counting wraps either allocator. When SYNERGYDB_MEMORY_LOG_SECS is set it counts live bytes in 64 shards and keeps a per-thread tracker of net, peak and gross bytes for the periodic memory log (source: src/heap.rs). Startup checkpoints per listener come from startup_memory::checkpoint, called in Server::start_handler (source: src/server/mod.rs, start_handler).

Docker build

The Dockerfile has three stages (source: Dockerfile):

Stage Base image What it does
1 node:20-slim (pinned by digest) Builds the synergy-studio web UI with npm ci and npm run build.
2 rust:1-bookworm (pinned by digest) Installs cmake and protobuf-compiler. Caches dependencies by building dummy main, cli, migrate, lib and bench files with cargo build --release --bin synergydb --bin synergydb-cli \|\| true, removes the dummies, then builds the real synergydb and synergydb-cli binaries.
3 debian:bookworm-slim Installs ca-certificates, libssl3 and curl. Creates the synergydb user, copies the two binaries and the UI to /app/static, creates /data, /wal and /config, and adds docker/synergydb.toml and docker/entrypoint.sh.

Runtime settings in stage 3 (source: Dockerfile):

Setting Value
Environment SYNERGYDB_DATA_DIR, SYNERGYDB_WAL_DIR, SYNERGYDB_CONFIG, SYNERGYDB_STATIC_DIR, SYNERGYDB_SUPERUSER=postgres, SYNERGYDB_DATABASE=synergydb, SYNERGYDB_NON_INTERACTIVE=1
EXPOSE 5432 3306 27017 7687 8080 9090 6379 9042 9200 1521 1433 8000 9000 8443 8086 11211 8124 9092 9100 5984 8182 8081
Volumes /data, /wal
Health check curl -fsS http://localhost:8080/readyz
User, entrypoint, command USER synergydb; ENTRYPOINT is entrypoint.sh; CMD ["-c", "/config/synergydb.toml"]

The entrypoint generates a superuser password when none is supplied (source: docker/entrypoint.sh). Where the generated password ends up is covered in the Quickstart.

Two differences between the image and a local proof build:

  1. Features. The image builds with default features. make build and prove/prove.sh build with --features full. As the feature table shows, the only functional differences are aws-kms (code that is not wired into the server) and the migrate-* connectors, which live in synergydb-migrate. The image does not ship synergydb-migrate (source: Dockerfile; Makefile; prove/prove.sh).
  2. Ports. The comment in the Dockerfile lists fewer ports than the EXPOSE lines. The EXPOSE lines are what Docker uses (source: Dockerfile).

Build the image from the repository root with docker build -t synergydb . (source: Dockerfile, which copies from the build context root).

Related pages