The cx Book 1.0.0
cx: a package manager and build tool for C and C++
Loading...
Searching...
No Matches
Vendoring

Some builds can't reach a registry or a git host at all: air-gapped networks, hermetic CI, distribution packaging. --offline only helps when the cache was filled earlier on the same machine. Vendoring puts the dependency sources in a directory you can commit or copy around instead.

$ cx vendor # every locked dependency into vendor/
$ cx vendor --dir third_party/cx
Vendoring fmt v11.1.4
Vendoring spdlog v1.15.0
Vendored 2 packages into `/home/me/app/vendor`
To build with the vendored sources, add this to `.cx/config.toml`:
[source]
vendor = "vendor"

With [source] vendor set (in .cx/config.toml, relative to the project, or with CX_VENDOR=<dir>):

  • Resolution: registry and git dependencies come only from the vendor directory. cx.lock doesn't change: the packages keep their registry and git sources.
  • Network and cache: none are needed, and none are used. The registry doesn't even have to be configured: the vendor directory records the registry URLs the lockfile refers to.
  • Integrity: every vendored package has a .cx-checksum.toml with the SHA-256 of each of its files, checked on every build. An edited, missing or extra file is an error that names the file.
  • Path and system dependencies are not vendored: they're already local.

What cx vendor writes

vendor/
├── config.toml the registries the packages came from
├── index/ index files for exactly the vendored versions
├── fmt-11.1.4/ a registry package, unpacked
│ └── .cx-checksum.toml
└── greeter-0a1b2c3d4e5f/ a git package at its locked commit, without .git
  • All features: cx vendor resolves as if every feature were enabled, so every build cx.lock allows can use the vendored sources.
  • Re-vendoring: run cx vendor again after cx update or cx add. It replaces a directory it wrote itself, and refuses to touch any other directory.
  • Changes: a vendored build can't add dependencies or update git dependencies, because that needs the network. A dependency that isn't vendored is an error that says to run cx vendor again.

To patch a vendored dependency on purpose, don't edit vendor/. Point the dependency at a local copy with a path dependency in your cx.toml, which overrides the registry (see Dependencies).