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

Run cx help <command> or cx <command> --help for the same information in the terminal.

Options for every command

Option Meaning
-q, --quiet don't print status messages
-v, --verbose print the commands cx runs, its HTTP requests, and full CMake output
--color <WHEN> auto (default), always or never
--offline never use the network; use cached registry data and git clones
-h, --help print help
-V, --version print the version (before the command name)

Feature and workspace options

These apply to build, run, test, bench, tree and generate:

Option Meaning
-F, --features <LIST> features to enable, comma-separated or repeated
--no-default-features don't enable the default feature
--all-features enable every feature
-p, --package <NAME> in a workspace: only this member
--workspace in a workspace: every member, even inside a member's directory
--message-format <FMT> human (default) or json: JSON lines on stdout

cx update also takes -p and --workspace.

cx new / cx init

cx new [OPTIONS] <PATH>
cx init [OPTIONS] [PATH]

new creates a package in a new directory. init creates one in an existing directory (default: .) and never overwrites files.

Option Meaning
--lib / --bin create a library / a binary (the default)
--c create a C package instead of C++
--std <N> language standard (default: C++23 / C17)
--name <NAME> package name (default: the directory name)
--vcs <VCS> git (default) or none
--author-from <SOURCE> where package.authors comes from: auto (default: git's author, if git knows one), git (an error if it doesn't) or none
--from <FILE> init only: draft cx.toml from an existing CMakeLists.txt or vcpkg.json; repeat it to read both. See Importing an existing project
--dry-run with --from: print the cx.toml instead of writing it

cx build

cx build [OPTIONS]

Compiles the package and its dependencies.

Option Meaning
-r, --release build with optimizations (the release profile)
--profile <NAME> build with a profile (default: debug); output goes to target/<NAME>/
--target <TRIPLE> cross-compile with [target.<TRIPLE>] (see Toolchains); output goes to target/<TRIPLE>/<profile>/. Also on run, test, bench, lint, metadata and clean
-j, --jobs <N> parallel jobs (default: build.jobs from the configuration, else the number of CPUs)
--locked fail if cx.lock needs to change
--bins build the binaries (they're always built)
--tests also build the test programs
--examples also build the examples
--example <NAME> also build this example (repeatable); without NAME, lists the examples
--benches also build the benchmarks
--all-targets also build tests, examples and benchmarks

cx run

cx run [OPTIONS] [-- <ARGS>...]

Builds the package and runs one of its binaries with ARGS. Accepts --release, --profile, --jobs and --locked. The exit code is the program's.

Option Meaning
--bin <NAME> the binary to run (default: the only one, or package.default-run)
--example <NAME> build and run an example from examples/ instead; only that example is built

As in Cargo, --bin or --example without a name lists the binaries or examples (and exits with an error), and so does a name that doesn't exist. With several binaries and neither --bin nor default-run, cx run fails and lists them.

$ cx run --example
error: `--example` takes the name of an example; available examples: wc
$ cx run --example wc -- --verbose

cx test

cx test [OPTIONS] [-- <ARGS>...]

Builds and runs the test programs in tests/ through ctest. ARGS go to ctest. Accepts --release, --profile, --jobs and --locked.

cx bench

cx bench [OPTIONS] [-- <ARGS>...]

Builds the benchmarks in benches/ with the release profile (or --profile), then runs each one with ARGS. cx doesn't prescribe a benchmark framework: a benchmark is a program. The exit code is the first non-zero one.

Option Meaning
--bench <NAME> only run this benchmark

cx fmt

cx fmt [--check] [-p <NAME>] [--workspace]

Formats the package's own files with clang-format. --check only lists the files that need formatting and fails if there are any. See Formatting, linting and docs.

cx lint

cx lint [OPTIONS]

Builds, then runs clang-tidy on every source file of the package, and fails if it reports anything. --fix applies its fixes. Takes the options of cx build.

cx doc

cx doc [--open] [--no-deps] [--document-private-items] [FEATURES] [--locked] [-p <NAME>] [--workspace]

Generates the API reference of the package and of every cx package it depends on with Doxygen, like cargo doc: target/doc/<name>/index.html for each, linked to each other, and target/doc/index.html listing them. See Formatting, linting and documentation.

Option Meaning
--open open the package's page (or the index, for several) in the browser
--no-deps don't document the dependencies
--document-private-items also document src/ and private members
-F, --features, --all-features, --no-default-features the features whose #ifdefs are documented
--locked fail instead of changing cx.lock

cx add

cx add [OPTIONS] <NAME[@REQ]>

Adds a dependency to cx.toml and resolves. With no source option, it adds a registry dependency. Without a requirement, it writes "^<resolved version>".

Option Meaning
--git <URL> with --tag / --branch / --rev git dependency
--path <PATH> path dependency
--system with --package <NAME>, --component <NAME> system dependency
--vcpkg with --package <NAME>, --component <NAME> vcpkg dependency: the port NAME (vcpkg = true)
--build-system <SYSTEM> with --git/--path: cmake, configure or scons
--lib <NAME> a library a configure or SCons project builds (repeatable; libs)
--registry <NAME> registry to use (default: the default registry)
--version <VERSION> requirement (registry), exact provided version (plain CMake git/path), or minimum (system, vcpkg)
--target <TARGET> CMake target to link (repeatable)
--option <KEY=VALUE> CMake option for the dependency (repeatable)
--dev add to [dev-dependencies]
--optional only include it when a feature enables it
-F, --features <LIST> features of the dependency to enable
--no-default-features don't enable the dependency's default feature
--public part of the library's interface: users get its headers too (public = true)
--platform <COND> only on these platforms: add to [target.<COND>.dependencies], where COND is cfg(...) or a triple
--build add to [build-dependencies]: a tool whose binaries [[generate]] runs

Adding a dependency that already exists replaces its entry. A dependency declared in another section (say, a platform's) must be removed first.

cx remove

cx remove [OPTIONS] <NAME>

Removes a dependency (--dev for a dev-dependency) and resolves again. A platform-specific dependency is removed from its [target.*] section.

cx update

cx update [OPTIONS] [PACKAGES]...

Resolves again, ignoring the locked versions of PACKAGES (default: all of them), and writes cx.lock.

Option Meaning
--resolution <STRATEGY> prefer highest (default) or lowest allowed versions

cx tree

cx tree [OPTIONS]

Shows the dependency tree with versions, sources and enabled features. Accepts --locked. Packages already shown are marked (*). --target <TRIPLE> shows the platform-specific dependencies of that target instead of the host's.

cx generate

cx generate [OPTIONS]

Resolves, writes the generated CMake project, and prints the path of its CMakeLists.txt. Use it for IDEs.

cx clean

cx clean [OPTIONS]

Deletes target/. Use --release, --debug or --profile <NAME> to delete only one profile. --gc only deletes stale directories: profiles no longer in cx.toml, and --target triples not built for 90 days.

cx cache

cx cache info
cx cache gc [--max-age <AGE>] [--max-size <SIZE>] [--kind <KIND>]... [--dry-run]
cx cache clean [--kind <KIND>]... [--dry-run]

Shows or cleans up cx's cache (see Build caches).

Option Meaning
--max-age <AGE> gc: remove what wasn't used for this long, e.g. 30d, 12h, 2w (default 90d)
--max-size <SIZE> gc: then remove the least recently used until this much is left, e.g. 10GiB
--kind <KIND> only registry, index, git, artifacts, tools or install (repeatable)
--dry-run show what would be removed

cx check

cx check [OPTIONS]

Compiles the package's sources for errors only (-fsyntax-only, MSVC /Zs), without generating code or linking. Accepts the options of cx build (--release, --profile, --target, --jobs, --locked, features, -p). --all-targets also checks tests, examples and benches. See cx check.

cx metadata

cx metadata [OPTIONS]

Resolves without building and prints the packages, their targets and the build directories as one JSON document. See Build output and JSON. Accepts --profile, --release, --locked, the feature options, -p and --workspace.

cx audit

cx audit [--db <URL>] [--deny warnings]

Checks cx.lock against an advisory database (--db, audit.database or CX_AUDIT_DB). Fails on vulnerabilities, and with --deny warnings on informational advisories too. See Security.

cx verify

cx verify

Downloads every locked registry archive again (ignoring the cache) and checks it against cx.lock and the index; checks that locked git commits and tags are unchanged. See Security.

cx index

cx index keygen --out <FILE>
cx index sign --key <FILE> [DIR | FILE]
cx index pubkey --key <FILE>

Signs a static registry index: keygen writes a new secret key and prints its public key, sign signs every index file in DIR (or just FILE, such as a release's cx-release.toml), pubkey prints the public key of a secret key. See Security.

cx install / cx uninstall

cx install [OPTIONS] [NAME[@REQ]]
cx uninstall [--root <DIR>] <NAME>

install builds a package (the current one, NAME[@REQ] from a registry, --git <URL> with --tag/--branch/--rev, or --path <DIR>) in release mode and installs its binaries. uninstall removes what install installed. See Installing and CMake export.

Option Meaning
--root <DIR> the prefix (default: CX_INSTALL_ROOT, else ~/.local)
--lib also install the library, its headers and a CMake package config
--registry <NAME> the registry for NAME[@REQ]
--debug, --profile <NAME> install another profile's build
-p <NAME> the workspace member to install

cx vendor

cx vendor [--dir <DIR>] [--locked]

Copies the sources of every locked registry and git dependency into DIR (default: vendor/ next to cx.lock) and prints the [source] setting that makes builds use them. See Vendoring.

cx package

cx package [OPTIONS]

Writes target/package/<name>-<version>.tar.gz and builds the unpacked archive to check it. See Publishing.

Option Meaning
--list print the files that would be packaged, and stop
--no-verify don't build the unpacked archive

cx publish

cx publish [OPTIONS]

Packages the package and publishes it: into a local static index, or through the registry's API.

Option Meaning
--registry <NAME> registry to publish to (default: the default registry)
--index <DIR> publish into this local index directory (a checkout of a static registry)
--dry-run do everything except publishing
--no-verify don't build the unpacked archive
--sign-key <FILE> sign the changed index file (static registries)

cx yank

cx yank [OPTIONS] <NAME@VERSION>

Marks a published version as yanked, so new resolutions skip it.

Option Meaning
--undo un-yank the version
--registry <NAME> registry (default: the default registry)
--index <DIR> yank in this local index directory
--sign-key <FILE> sign the changed index file

cx config

cx config list
cx config get <KEY>
cx config set <KEY> <VALUE> [--project]
cx config unset <KEY> [--project]

Shows or changes settings in the configuration files. list shows every setting with where it came from. set and unset edit ~/.config/cx/config.toml, or with --project the project's .cx/config.toml. Keys: registries.<name>, net.offline, net.retries, build.jobs, term.color, tools.<name>, tools.mirror, and the others in Configuration.

cx tools

cx tools list
cx tools install [TOOL]

Shows or downloads the external tools cx runs: cmake, ninja, clang-format, clang-tidy, doxygen, python, scons, vcpkg, make and autoreconf.

  • list prints, for each tool, its version, the program cx runs and why (from PATH, managed by cx, or set by tools.<name>), on stdout. It never downloads anything.
  • install downloads and unpacks the pinned release of TOOL, or of CMake, Ninja, clang-format, clang-tidy and Doxygen, unless it's in the cache already. python and scons are only installed when named. vcpkg, make and autoreconf have no download.

cx self

cx self update [VERSION] [--dry-run]
cx self version

Updates cx itself, like uv self update. See Updating cx.

  • update installs the latest release, or VERSION (0.1.0 or v0.1.0, also older than this cx), from https://github.com/AKJ7/cortex/releases (or CX_SELF_UPDATE_URL). It replaces the running cx and the cx-registry next to it, after checking the archive's SHA-256, the release's signature (once releases are signed) and that the new cx runs. It refuses to replace a cx installed by Homebrew, Nix or the system's package manager.
  • version prints this cx's version, platform and path on stdout: cx 0.1.0 (linux-x86_64, /home/me/.local/bin/cx).
Option Meaning
--dry-run update: show what would be installed, and change nothing

cx login / cx logout

cx login [--registry <NAME>]
cx logout [--registry <NAME>]

login reads a token from standard input and stores it for the registry (default: the default registry) with the registry's first credential provider: by default in ~/.config/cx/credentials.toml (mode 0600). logout removes it.

cx-registry

cx-registry init <ROOT> [--url <URL>] [--signing-key <FILE>]
cx-registry serve <ROOT> [--listen <HOST:PORT>] [--tokens <FILE>] [--signing-key <FILE>] [--max-upload <MIB>]
cx-registry token add <ROOT> --name <NAME> [--scope <SCOPE>]... [--package <GLOB>]... [--tokens <FILE>]
cx-registry token list <ROOT> [--tokens <FILE>]
cx-registry token remove <ROOT> <NAME> [--tokens <FILE>]

A separate program, installed next to cx: a small registry server. See Running a registry.

Option Meaning
--url <URL> init: write an absolute api URL (default: api, relative to the index)
--signing-key <FILE> sign config.toml (init) and every changed index file (serve)
--listen <HOST:PORT> where to listen (default 127.0.0.1:8080; port 0 picks a free one)
--tokens <FILE> the tokens file (default <ROOT>/.cx-registry/tokens.toml)
--max-upload <MIB> the largest accepted upload (default 64)
--name <NAME> the new token's name
--scope <SCOPE> publish or yank (repeatable; default both)
--package <GLOB> only for matching packages (repeatable; default all)