Skip to content

Commit

Permalink
Add some docs about JSON messages
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Oct 5, 2016
1 parent 1e15d0a commit b9ec2b1
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/doc/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ <h1>CARGO</h1>
<li><a href='pkgid-spec.html'>Package ID specs</a></li>
<li><a href='environment-variables.html'>Environment Variables</a></li>
<li><a href='source-replacement.html'>Source Replacement</a></li>
<li><a href='machine-readable-output.html'>Machine readable output</a></li>
<li><a href='policies.html'>Policies</a></li>
</ul>
</div>
Expand Down
78 changes: 78 additions & 0 deletions src/doc/machine-readable-output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
% Machine readable output.

Cargo can output information about project and build in JSON format.

# Information about project structure

You can use `cargo metadata` command to get information about project structure
and dependencies. The output of the command looks like this:

```
{
// Integer version number of the format.
"version": integer,
// List of packages for this workspace, including dependencies.
"packages": [
{
// Opaque package identifier.
"id": PackageId,
"name": string,
"version": string,
"source": SourceId,
// A list of declared dependencies, see `resolve` field for actual dependencies.
"dependencies": [ Dependency ],
"targets: [ Target ],
// Path to Cargo.toml
"manifest_path": string,
}
],
"workspace_members": [ PackageId ],
// Dependencies graph.
"resolve": {
"nodes": [
{
"id": PackageId,
"dependencies": [ PackageId ]
}
]
}
}
```


# Compiler errors

If you supply `--message-format json` to commands like `cargo build`, Cargo
reports compilation errors and warnings in JSON format. Messages go to the
standard output. Each message occupies exactly one line and does not contain
internal `\n` symbols, so it is possible to process messages one by one
without waiting for the whole build to finish.

The message format looks like this:

```
{
// Type of the message.
"reason": "compiler-message",
// Unique opaque identifier of compiled package.
"package_id": PackageId,
// Unique specification of a particular target within the package.
"target": Target,
// The error message from the compiler in JSON format.
"message": {...}
}
```

Package and target specification are the same that `cargo metadata` uses.

0 comments on commit b9ec2b1

Please sign in to comment.