How stable is cargo's message-format=json?

Specifically, I'm interested in the stdout of cargo test --no-run --message-format=json.

I'm interested in extracting the list of test binaries without linking against cargo or scraping the human output. The "compiler errors and warnings, produced artifacts, [and] results of the build scripts" that the json message format provides contains the information that I want, but what about the format can I expect to remain the same? (Conversely, what about the output is free to change in the future?)

It is stable. We most likely will add new fields to the json object, and will add new types of json messages though. In the unlikely event that we'll have for some reason to make a backwards-incompatible change, we'll probably add --message-format=json-v2.

FWIW, these events are used by IntelliJ Rust when launching debugger:

https://github.com/intellij-rust/intellij-rust/blob/91e70cfaa0ed3a7f5a4ea23ab48199a7d7868628/debugger/src/main/kotlin/org/rust/debugger/runconfig/RsDebugRunner.kt#L138

Beware of kind and crate_types fields from Target: they are super confusing at the moment precisely because of backwards compatibility :slight_smile:

https://github.com/rust-lang/cargo/blob/489f570d47dea88d8f9a1205173d3e779e1a78e2/src/cargo/core/manifest.rs#L239-L244

3 Likes