A registry is an index of published packages and their versions. cx reads registries over HTTPS, over HTTP, or from a local directory.
Configuring registries
Registries are named in the configuration files, so a project can commit which registries it uses:
# .cx/config.toml
[registries]
default = "https://registry.example.com/index"
internal = "https://cx.corp.example/index"
Environment variables override the files:
export CX_REGISTRY=https://registry.example.com/index # the default registry
export CX_REGISTRY_INTERNAL=https://cx.corp.example/index # a registry named "internal"
[dependencies]
fmt = "^11" # the default registry
tools = { version = "^2", registry = "internal" } # the registry named "internal"
URLs can be https://, http://, file:// or a plain directory path.
A private registry needs a token: store it with cx login --registry
internal, or set CX_TOKEN_INTERNAL. See Credentials.
Caching and offline use
- Caching: index files and archives are cached in ~/.cache/cx, or $CX_HOME. Index files are revalidated with conditional requests (ETag / Last-Modified), at most once per cx run.
- Locked packages: packages pinned in cx.lock are answered from the cache, so a fully locked build needs no network.
- Unreachable registry: cx uses the cache and prints a warning.
- --offline, CX_OFFLINE=1 or net.offline = true: cx never uses the network, including git. Anything that isn't cached is an error that tells you so.
- Retries: a request that fails to connect, or gets a 5xx or 429 answer, is retried net.retries times (default 2) with a short backoff.
- Parallel fetching: index files and archives are fetched in parallel.
Security
- Archives: every archive is checked against the sha256: checksum in the index before it is unpacked, and checked again whenever a cached copy is unpacked.
- TLS certificates: always verified. To use a different CA bundle, set SSL_CERT_FILE.
- Signed indexes, auditing, dependency confusion: see Security.
Hosting a registry
A registry is just static files, so any web server, GitHub Pages or an object store can host one:
index/
├── config.toml dl = "archives/{name}-{version}.tar.gz"
├── fm/t/fmt one file per package (see below for the path)
├── 3/z/zlb
└── archives/
└── fmt-11.1.4.tar.gz
config.toml sets dl, the archive URL template. {name} and {version} are filled in. A relative template is resolved against the index URL. An optional api URL makes it an API registry that accepts cx publish over HTTP (see Publishing). `cx-registry` serves such a registry.
Package files live at a path derived from the lower-cased name, as on crates.io:
| Name length | Path |
| 1 | 1/<name> |
| 2 | 2/<name> |
| 3 | 3/<first letter>/<name> |
| 4 or more | <first two>/<next two>/<name> |
Each package file is TOML, with one [[version]] table per published version. Publishing a version (cx publish) appends a block:
[[version]]
version = "11.1.4"
build = "cmake" # "cx" if the archive has a cx.toml
checksum = "sha256:…" # of the archive
targets = ["fmt::fmt"] # CMake targets to link (plain CMake packages)
yanked = false # true: only used when cx.lock already pins it
build-script = false # true: building it runs [[generate]] or build.cmake
language = "c++" # with standard: what its cx.toml asks for (cx packages)
standard = 20
[version.dependencies]
some-dep = "^1.0"
optional-dep = { version = "^2", optional = true, features = ["x"], default-features = false }
windows-dep = { version = "^1", target = "cfg(windows)" } # only on matching platforms
codegen = { version = "^1", build = true } # a build-dependency (a tool)
[version.features] # cx packages only
default = ["std"]
std = []
Archives are .tar.gz files with a single top-level directory (for example fmt-11.1.4/). A cx package's archive contains its cx.toml.
The index lists dependencies itself, so cx never downloads source code just to find out what a package depends on.