Skip to main content
Documentation menu

Dependency kinds

Cabin classifies every dependency into one of three kinds, each declared under its own manifest section:

SectionKindWhat it means
[dependencies]normalLinked into ordinary builds.
[dev-dependencies]devFor tests / examples / local development tasks.
[build-dependencies]buildTools built for the build machine; never linked into the dependent.

An entry inside [dependencies] or [dev-dependencies] can additionally opt out of the Cabin registry / resolver / fetcher path and be sourced from the system instead by setting system = true:

[dependencies]
zlib = { version = ">=1.2", system = true }

This is where the dependency comes from; the when (always or test-time) is still driven by which table the entry lives in. For selected primary packages, Cabin probes active system = true entries through pkg-config at build time to obtain compile and link flags. Declarations in local path dependencies and registry packages are preserved as metadata but are not probed for the downstream build - see system-dependencies.md for the full probe behavior.

Every kind also accepts the platform-conditional form [target.'cfg(...)'.<kind>]. Resolution and the lockfile include the declaration whatever its condition; the build evaluates the condition for the platform it builds for (the build machine, or the --target platform) and leaves non-matching declarations out. The full grammar and evaluation rules live in target-dependencies.md.

Manifest syntax

[package]
name = "demo"
version = "0.1.0"

[dependencies]
fmt = ">=10 <11"
zlib = { version = ">=1.2", system = true }

[dev-dependencies]
gtest = "^1.14"

[build-dependencies]
gen = { path = "../gen" }

[dependencies], [dev-dependencies], and [build-dependencies] accept the following value forms:

  • bare version-requirement string (name = ">=10"),
  • { version = "..." },
  • { path = "../local" },
  • { workspace = true } (looks up the matching [workspace.<kind>-dependencies] table - see below),
  • { version = "...", system = true } - externally-provided system dep, probed via pkg-config at build time (not in [build-dependencies]).

system = true is mutually exclusive with path, workspace, features, default-features, and optional; mixing the flag with any of those surfaces a clear parser error. Every declared system = true dependency is required - the manifest has no required field.

Resolver behavior

The Cabin resolver runs over the union of dependency kinds that participate in ordinary commands:

  • Normal dependencies - included.
  • Build dependencies - included, with everything they reach, so cabin.lock, fetch, vendor, --locked, and --offline cover build tools. A package used as a build tool and as a library resolves to one version for both.
  • Dev dependencies - excluded by default. Declaration only for ordinary commands. They round-trip through metadata but are not resolved, fetched, or built. cabin test activates them as real graph edges for the selected primary packages so test executables can link against test-only packages - see docs/testing.md. The activation never propagates: a transitive dep’s own dev-deps stay declaration-only.
  • System dependencies - never resolved. They never reach the resolver.

The same package name may appear under multiple kinds (e.g. a package used both as a normal dep and as a dev dep). The resolver sees the normal- and build-kind requirements during ordinary commands; cabin test joins the selected packages’ dev-kind requirements on top.

Build dependencies

A build dependency is a tool for the build machine, such as a code generator. Cabin builds its package in the build context, apart from the packages it links for the platform it builds for (the target context):

  • The build dependency’s default targets (libraries and executables), or the targets its entry lists in targets, and the packages they link are built for the build machine, under <build-dir>/<profile>/build-machine/packages/<pkg>/. A package both contexts use is built twice, once per context, and the two never share objects.
  • Features unify per package within a context, never across: an edge in one context cannot turn on a feature of the other context’s copy.
  • A [target.'cfg(...)'.build-dependencies] condition is evaluated for the platform of the package that declares it; everything inside the build context evaluates cfg(...) for the build machine.
  • links uniqueness applies per context: a build tool and the program may each link one package claiming an identity, but neither may link two.
  • Without --target, the build context uses the build’s compilers and environment flags (CFLAGS and friends). With --target, it uses the build machine’s own toolchain, chosen by HOST_CC, HOST_CXX, and HOST_AR, and no environment flags. See toolchains.

A build-dependency entry may name the targets to build with targets:

[build-dependencies]
gen = { path = "../gen", targets = ["gen"] }

The build machine then builds the listed targets, and the libraries a listed executable links, instead of the dependency’s other targets. Each name must be a library, header-only, or executable target of that dependency; an unknown name, a test or example target, or a target whose required-features the build context leaves off is an error. When several edges reach one dependency, the build machine builds every listed target, plus the default targets if any edge omits targets. A member’s { workspace = true } entry may add targets. targets is rejected on [dependencies] and [dev-dependencies], and an empty list is an error. cabin metadata reports the list as the dependency’s targets.

cabin build, run, and test build build dependencies but run nothing: a build step that runs the tool is not part of Cabin yet, so a project runs its generator itself, between builds. cabin check checks only the selected packages’ own sources and builds no build dependency. Not yet supported:

  • system dependencies in the build context: system = true under [build-dependencies], and a workspace member built there that declares one, are rejected,
  • [features] entries that name a build dependency (gen/x, dep:gen),
  • publishing a package with build dependencies: cabin package refuses it, because package indexes do not carry them yet.

Lockfile behavior

The lockfile records resolved package versions; dependency-kind metadata is not duplicated there because the resolver re-runs from the manifest on every command and re-decides which kinds to include.

Workspace dependency inheritance

[workspace] roots may declare shared requirements per kind:

[workspace]
members = ["packages/*"]

[workspace.dependencies]
fmt = ">=10"

[workspace.dev-dependencies]
gtest = "^1.14"

[workspace.build-dependencies]
gen = "^1"

A member then opts into the workspace requirement with { workspace = true }:

[package]
name = "app"
version = "0.1.0"

[dependencies]
fmt = { workspace = true }       # looks up [workspace.dependencies]

[dev-dependencies]
gtest = { workspace = true }     # looks up [workspace.dev-dependencies]

The lookup is strictly kind-specific: a { workspace = true } under [dev-dependencies] does not fall back to [workspace.dependencies]. If the matching workspace table does not declare the dependency, Cabin reports an explicit error naming the section pair. system = true entries cannot use workspace = true; the two flags are mutually exclusive (the parser rejects the combination).

Command behavior

CommandBehavior
cabin addAdds an entry to [dependencies] (or [dev-dependencies] with --dev), preserving the manifest’s formatting and comments. Writes registry deps (<scope>/<name>@<req> - the scoped name and an explicit requirement are both required, because cabin add never queries the registry for names or versions) and local path deps (--path <dir>). --features / --no-default-features set those fields. Prints a note reminding you to add the dependency to a target’s deps to link it (declaring it here only makes it available - see Command behavior above).
cabin removeDeletes a named entry from [dependencies] (or [dev-dependencies] with --dev); removes the table when it becomes empty. Errors if the dependency is absent.
cabin metadataReports each Cabin package dep with its dependency_kind, plus a separate system_dependencies array.
cabin resolve / update / fetchWalks normal and build deps; excludes dev deps; never sees system deps.
cabin buildSame resolution as above. Only normal-kind edges link into ordinary C/C++ targets - dev and build deps cannot resolve through target.<X>.deps. Build deps build for the build machine (see Build dependencies).
cabin testWalks normal deps plus [dev-dependencies] of the selected primary packages, so test targets can depend on test-only packages. Dev-dep activation never propagates to transitive deps.
cabin packageIncludes per-kind dependency tables and system-dependencies in the canonical metadata document; refuses build deps.
cabin publish --dry-runValidates the same metadata; never touches the registry.
cabin publish --registry-dirPublishes the per-kind metadata into the local file registry.

Output ordering is deterministic in every command: dependency kinds iterate in canonical order (normal, dev, build), names sort ascending within each kind, and system deps sort by name.

Package and index metadata

cabin package emits a canonical per-version metadata document that round-trips dependency kinds. The on-disk shape is:

{
  "schema": 1,
  "name": "demo",
  "version": "0.1.0",
  "dependencies":      { "fmt":     ">=10 <11" },
  "dev-dependencies":  { "gtest":   "^1.14" },
  "system-dependencies": {
    "zlib": { "version": ">=1.2" }
  },
  "yanked":   false,
  "checksum": "sha256:...",
  "source":   { "type": "archive", "path": "...", "format": "zip" }
}

Empty kind tables are omitted, so manifests that only use [dependencies] produce the exact byte-for-byte metadata they always did.

The local file index and the sparse HTTP index carry the same dependency tables. They differ only in where the archive identity sits: an index version entry replaces the document’s top-level checksum / source with the per-revision map described in package-index.md.

Optional dependencies

Cabin package dependencies in [dependencies] may declare optional = true:

[dependencies]
openssl = { version = "^3", optional = true }

Optional dependencies only enter ordinary resolution / fetch / build when a feature enables them via dep:<name> or <name>/<feature> from [features]. Until then they appear in package / index metadata but never in the resolver’s selection or the lockfile. Per-edge features = [...] and default-features = false are also supported and are applied additively across all dependency edges that include the same package - see features.md for the full feature-resolution behavior.

optional = true is not supported on [dev-dependencies], [build-dependencies], or system = true entries. The manifest layer reports the violation as OptionalNotSupportedForKind (dev, build) or SystemConflictsWith (system).

Scope

  • Registry optional dependencies follow feature requests. Dependency resolution unifies the feature requests on every selected edge, local or registry, and enables a registry package’s optional dependencies exactly when those features do (see features.md).
  • System deps are primary-only and pkg-config-only. Cabin invokes pkg-config for active system = true entries declared by selected primary packages. It does not probe system declarations from local path or registry dependencies and does not invoke any other system package manager.

Examples

Library with a system dependency

[package]
name = "app"
version = "0.1.0"

[dependencies]
mylib = ">=2"
zlib = { version = ">=1.2", system = true }

zlib is the responsibility of whoever builds the package - it is not fetched through Cabin. At build time, Cabin probes it via pkg-config and merges the resulting cflags / ldflags into the compile commands; cabin metadata reports the declaration in a separate system-dependencies block alongside the regular dependencies array.