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

The progress display

When stderr is a terminal, cx build (and run, test, bench) shows one progress line instead of the build tool's output:

Compiling app v0.1.0 (/home/me/app)
Building [=========> ] 42/97: parser.cpp
  • Warnings and errors appear as they arrive, above the progress line, in the compiler's own format and colors.
  • A summary at the end counts warnings per package: "warning: `app` generated 3 warnings".
  • Build-system chatter ("Built target ...", "Entering directory ...") is dropped.
  • With Ninja the line shows finished/total steps; with Make, a percentage.

The output passes through unchanged when stderr isn't a terminal (CI logs, a pipe), with --verbose, with --quiet, or with TERM=dumb.

--message-format json

build, run, test, bench, tree and generate take --message-format json. cx then writes one JSON object per line to stdout, for editors, IDEs and CI. Status lines and the build's own output stay on stderr, so cx build --message-format json | jq works.

{"reason":"resolved","format_version":1,"packages":[{"name":"fmt","version":"11.1.4","source":"registry+https://...","kind":"cx","source_dir":"...","features":["std"],"dependencies":[]}]}
{"reason":"compiler-message","format_version":1,"package":"app","level":"warning","file":"/home/me/app/src/main.cpp","line":3,"column":9,"message":"unused variable 'x' [-Wunused-variable]"}
{"reason":"artifact","format_version":1,"package":"app","kind":"bin","name":"app","path":"/home/me/app/target/debug/app"}
{"reason":"build-finished","format_version":1,"success":true}
reason When Fields
resolved after resolving (tree prints only this) packages: name, version, source (as in cx.lock), kind (cx, cmake, system), source_dir, features, dependencies
compiler-message for each compiler diagnostic package (or null if the file isn't in a package), level (warning, error, fatal error, note), file (with / separators, also on Windows), line, column (0 if unknown), message
artifact for each file the build produced package, kind (lib, bin, example, bench), name, path
build-finished at the end of a build success
generated cx generate path of the generated CMakeLists.txt
  • Stability: every message has "format_version": 1. Within a format version, fields are only added, never removed or changed.
  • Diagnostics are read from the compilers' normal text output (file:line:column: level: message for GCC and Clang, file(line,column): level code: message for MSVC), so they work with every compiler version cx supports.
  • cx run: the program's own output also goes to stdout, after the build's JSON lines. cx test sends ctest's output to stderr in JSON mode.

cx metadata

cx metadata resolves without building and prints one JSON document, for IDE integration:

{
"format_version": 1,
"workspace_root": "/home/me/app",
"target_directory": "/home/me/app/target",
"profile": "debug",
"output_directory": "/home/me/app/target/debug",
"build_directory": "/home/me/app/target/debug/build",
"compile_commands": "/home/me/app/target/debug/build/compile_commands.json",
"members": ["app"],
"packages": [
{"name": "app", "version": "0.1.0", "authors": [{"name": "Ada Lovelace", "email": "ada@example.com"}],
"source": "path+.", "kind": "cx", "features": [],
"dependencies": ["fmt"], "dev_dependencies": [],
"targets": [{"kind": "bin", "name": "app", "sources": ["/home/me/app/src/main.cpp"], "required_features": []}]}
]
}

(It prints on one line; shown formatted here.) The packages are the ones the resolution uses, with the same fields as in resolved, plus targets and authors for cx packages (lib with its sources, and every binary, example, bench and test; authors as in cx.toml, each with name and/or email). --profile or --release change the directories. In a workspace, members lists the members, and the workspace's root is the root.