skip to content

When should a team publish its own ports in a custom vcpkg Git registry instead of overlay ports, and what must that registry contain?

level: seniorimportance: nice to knowfreq 20%

answer

  1. versioned ports for many repositories
  2. ports plus versions directories
  3. baseline.json and git-tree entries
  4. packages patterns pick the registry

basics

~20 s

Use a Git registry when private or patched ports must be shared, versioned and pinned across repositories. It needs ports/<name> directories and a versions database: versions/baseline.json plus versions/<letter>-/<name>.json entries holding each version's git-tree, maintained with vcpkg x-add-version.

solid answer

~40 s

Overlay ports suit one repository's short-lived fix; a **Git registry** suits a team publishing internal libraries or long-lived patches to many projects, because consumers get versions, a baseline and `version>=` exactly as with the curated registry. The repository holds `ports/<name>/` with `vcpkg.json` and `portfile.cmake`, and a **versions database**: `versions/baseline.json` mapping each port to its current version under a `default` object, and `versions/<first letter>-/<name>.json` listing every version with its `port-version` and the `git-tree` SHA of the port directory at that version. `vcpkg x-add-version` writes both, given `--x-builtin-ports-root` and `--x-builtin-registry-versions-dir`. Consumers add an entry to `registries` in `vcpkg-configuration.json` with `kind: git`, `repository`, a 40-character `baseline` commit and `packages` patterns. Name resolution then goes overlay first, then the best `packages` match (exact, then longest prefix, then first declared), then the default registry, without consulting the network.

code

json · 14 lines
json
{
  "default-registry": {
    "kind": "builtin",
    "baseline": "9eec002df1cd109f8f104cd966a763daf9751489"
  },
  "registries": [
    {
      "kind": "git",
      "repository": "https://git.example.com/tools/vcpkg-registry.git",
      "baseline": "768f6a3ad9f9b6c4c2ff390137690cf26e3c3453",
      "packages": [ "team-*", "zlib" ]
    }
  ]
}

go deeper

for a junior

Recall that vcpkg can use registries other than the curated one, configured in vcpkg-configuration.json.

for a middle

Explain the registry layout: ports, baseline.json and per-port versions files, and how packages patterns route names.

for a senior

Show how you publish with x-add-version, why git-tree enables history, and how name resolution order protects against dependency confusion.

for a principal

Decide whether a private registry is worth running: it needs owners, CI for each triplet and a baseline policy, against the cost of scattered overlays.

## Overlays versus registries Both mechanisms supply ports that the curated registry does not have, or replace ones it does. They differ in what consumers can do with them: | Need | Overlay ports | Git registry | |---|---|---| | Quick local fix in one repository | ideal | heavy | | Share ports across many repositories | copy per repo | one source | | Multiple versions with history | no (frozen copy) | yes, via git trees | | Consumers pin with a baseline | no | yes | | `version>=` and overrides | ignored | honoured | So a team publishing internal libraries, or carrying patches that will live for months, moves them into a registry; a one-off fix waiting for an upstream release stays an overlay. ## Registry layout The vcpkg docs define the structure every registry must follow: - `ports/<name>/`: each port's `vcpkg.json` and `portfile.cmake` (plus patches), the folder named after the port; - `versions/baseline.json`: one object, conventionally `default`, mapping each port name to `{ "baseline": "<version>", "port-version": <n> }`, the versions considered current; - `versions/<prefix>/<name>.json` with `<prefix>` the first letter and a hyphen, such as `versions/f-/foo.json`: a `versions` array listing every published version, each with its version field (`version`, `version-semver`, `version-date` or `version-string`, matching the port's manifest), `port-version`, and for Git registries the **`git-tree`** SHA of the port directory at that version. The `git-tree` is what lets vcpkg retrieve old versions: it asks git for that tree object from the registry's history. **Filesystem registries** use a `path` per version instead and suit testing or non-Git storage; the docs do not recommend them for large collections. ## Publishing a version 1. Change the port and set its version: bump `port-version`, or reset it to 0 when the upstream version changes. Never reuse a published version. 2. Stage the port directory with git. 3. Run `vcpkg x-add-version --x-builtin-ports-root=./ports --x-builtin-registry-versions-dir=./versions <name>`; it appends the new entry to the port's versions file and updates `baseline.json`. 4. Commit the port and the versions files together and push. ## Consuming the registry A project adds the registry in `vcpkg-configuration.json`: - `kind`: `git`; - `repository`: any URI git understands; access control is whatever the git host enforces; - `baseline`: a 40-character commit of the registry that holds `versions/baseline.json`; this is the floor for its ports, the counterpart of `builtin-baseline`; - `reference`: optional branch, defaulting to `HEAD`; - `packages`: the port names or prefix patterns (`team-*` style, a trailing `*` only) this registry serves. Package-name resolution is deterministic and local: 1. an overlay with that name wins; 2. otherwise the registry with the best `packages` match: exact name, then longest prefix pattern, then the first declared; 3. otherwise the default registry, unless `default-registry` is `null`, in which case resolution fails. Because the decision depends only on configuration, not on what a server happens to publish, the vcpkg docs present it as protection against dependency-confusion attacks. Duplicate patterns across registries produce a warning, and the later declarations are ignored. ## Operating a registry - Pin consumers to a baseline commit and move it deliberately, as with the curated registry. - Run CI on the registry that builds each changed port for the triplets you support before publishing. - Keep port names prefixed with the organisation's name, as the vcpkg naming guidance suggests, so patterns stay narrow. - If the team must control every port, set `default-registry` to a mirror of the curated registry, or to `null` with an explicit `*` pattern. ## Typical failure modes 1. **A version missing from the database**: a consumer's `version>=` names a version the registry never recorded, because the port changed but `x-add-version` was not run, or its output was not committed. 2. **A rewritten history**: changing a port's files without changing its version produces a new `git-tree` for the same version; `x-add-version` refuses to overwrite an existing version unless `--overwrite-version` is passed, an option meant for versions not yet published, and using it on a published one gives two different builds the same version label. 3. **A baseline the consumer cannot reach**: the consumer's `baseline` names a commit that is not on the registry's `reference` branch, or the build machine lacks credentials for the repository. 4. **A pattern that routes too much**: a broad pattern such as `b*` quietly moves curated ports into the team registry, where they may not exist. Each of these surfaces at install time, before any compilation, which is why registry CI that installs every port from a fresh consumer is cheap insurance.

  • Why does a Git registry store a git-tree SHA for each version?
    It identifies the exact contents of the port directory at that version, so vcpkg can extract it from the registry's history even after the port has moved on. This is the same mechanism the curated registry uses, and it is why vcpkg needs history, not a shallow clone.
  • Two registries both declare the pattern lib*. Which one serves libfoo?
    The first one declared in the `registries` array. Resolution prefers an exact name, then the longest pattern, then declaration order; vcpkg also warns that the pattern is duplicated and ignores the later declaration.

  • A registry is just a folder of ports; no versions database is needed.
  • vcpkg picks whichever registry offers the highest version of a port.
  • The git-tree field is the commit SHA where the version was added.
  • Overlay ports and registries offer the same versioning to consumers.
  • Republishing a version with changed port files is fine as long as you rerun x-add-version.