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

Install a release with the install script, or build cx from source with CMake.

Installing a release

On Linux and macOS:

curl -LsSf https://github.com/AKJ7/cortex/releases/latest/download/install.sh | sh

On Windows (PowerShell):

powershell -ExecutionPolicy Bypass -c "irm https://github.com/AKJ7/cortex/releases/latest/download/install.ps1 | iex"
  • Where it goes: cx and cx-registry go into ~/.local/bin (on Windows USERPROFILE%\.local\bin, which the script adds to your PATH). Set CX_INSTALL_DIR to choose another directory. On Windows, CX_NO_MODIFY_PATH=1 leaves PATH alone.
  • Which version: the latest release, or CX_INSTALL_VERSION=1.0.0.
  • What's checked: the script checks the archive against the SHA-256 in the release's cx-release.toml.
  • Platforms: Linux (x86-64 and aarch64), macOS 13.3 or newer (Intel and Apple silicon) and Windows (x86-64). The Linux build is a static binary that runs on any distribution. The Windows build needs no Visual C++ redistributable.

You can also download an archive from the releases page and put its programs anywhere. Each release lists the archives' checksums in SHA256SUMS, and has GitHub build provenance (gh attestation verify <file> --repo AKJ7/cortex).

Updating cx

cx self update # the latest release
cx self update 1.0.0 # a specific version (also an older one)
cx self update --dry-run # only show what would be installed
cx self version # this cx's version, platform and path

cx self update replaces the running cx, and the cx-registry next to it, with a release's build:

  • Checks before replacing anything: the archive must match the SHA-256 in cx-release.toml, and once releases are signed, cx-release.toml.sig must be valid for cx's built-in release key. The new cx must run and report the expected version.
  • Package managers: a cx installed by Homebrew, Nix or the system's package manager (/usr/bin) is left to that package manager.
  • Permissions: cx must be able to write to its own directory.
  • Network: it needs the network (--offline makes it fail). A proxy or mirror with the same layout as GitHub's releases works with CX_SELF_UPDATE_URL; see Environment variables.

Building from source

Requirements

  • To build cx: CMake 3.28 or newer, a C++23 compiler (GCC 14+, Clang 19+, or MSVC from Visual Studio 2022; Clang 18 only with libc++, since libstdc++ hides std::expected from it), and network access the first time you configure.
  • To use cx:

    • a C and C++ compiler
    • git, for git dependencies

    cx unpacks .tar.gz and .zip archives itself, so it doesn't need tar.

  • Installed for you: CMake (3.25 or newer), Ninja, clang-format and clang-tidy. cx uses the ones in PATH, and downloads a pinned release of any that is missing the first time it's needed. Ninja is the exception on Windows. See External tools.

Building

git clone https://github.com/AKJ7/cortex.git
cd cortex
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j
cmake --install build # installs `cx` (add --prefix ~/.local for a user install)

The first configure downloads and builds cx's dependencies, libcurl and, on Linux and macOS, mbedTLS, which cx uses for HTTPS registries. On Windows, libcurl uses Schannel, Windows' own TLS, with the system certificate store. The dependencies are pinned to release archives by SHA-256 in cmake/Dependencies.cmake. This takes a minute or two, once.

Windows

Build cx from a "Developer PowerShell for VS 2022" (or any shell where cl.exe is set up), so that CMake finds MSVC:

cmake -S . -B build
cmake --build build --config Release
  • Generators: cx uses Ninja when it's installed. Otherwise CMake picks the Visual Studio generator, and cx passes --config to it. cx doesn't download Ninja automatically on Windows, because Ninja with MSVC needs a developer prompt. Set tools.ninja = "managed" to download it anyway (see External tools).
  • Paths: cx's cache is in LOCALAPPDATA%\cx, and its configuration in APPDATA%\cx.
  • Programs: cx runs programs directly, never through a shell, so a tool that is only a .bat or .cmd file can't be used as cmake or git.
  • Status: Windows support is new. CI builds cx with MSVC and runs the unit tests; the end-to-end tests run under Git Bash. MinGW may work, but isn't tested.

Building cx with cx

cortex is also a cx package: the repository's cx.toml describes it. Once you have a cx, it can build and test itself:

cx build --release # target/release/cx
cx test # the unit tests (tests/unit/, one test program)
  • The CMake build stays the primary build: it needs no cx, so it's how cx is bootstrapped, and it also runs the end-to-end tests.
  • The same dependencies: cx.toml depends on cmake/deps, a small CMake project that includes cmake/Dependencies.cmake, so both builds fetch the same pinned libcurl, mbedTLS and Monocypher.
  • One version: package.version in cx.toml. The CMake build reads it from there and checks that the CX_VERSION define in [build] agrees.
  • Windows: building cx with cx is only supported on Linux and macOS for now, because the MSVC-only flags of the CMake build (/utf-8) can't be expressed in cx.toml yet.

Checking the installation

$ cx --version
cx 1.0.0

To run cx's own test suite:

ctest --test-dir build --output-on-failure

The end-to-end tests run fully offline. They use local git repositories and a local registry served on 127.0.0.1.