cppmake
cppmake is a Visual Studio Code extension for inspecting C and C++ compiler
diagnostics in SARIF format. It recursively reads SARIF files from the
workspace, presents errors, warnings, notes, and related locations as a tree,
and opens the corresponding source location when an item is selected.
Make
Building requires Node.js, npm, and vsce:
npm install --global @vscode/vsce
node make.js --build
The resulting extension package is written to .build/cpptheme.vsix. To
install the generated package locally, ensure that the code command is
available and run:
node make.js --install
Usage
Writing SARIF
GCC
Recent GCC releases can add a SARIF output while retaining normal terminal
diagnostics:
mkdir -p .cppmake
g++ -std=c++23 -Wall -Wextra -fdiagnostics-add-output=sarif:file=.cppmake/main.sarif -c main.cpp -o main.o
SARIF 2.1 can be selected explicitly:
g++ -fdiagnostics-add-output=sarif:version=2.1,file=.cppmake/main.sarif -c main.cpp -o main.o
On GCC releases without additional diagnostic outputs, use:
g++ -fdiagnostics-format=sarif-file -c main.cpp -o main.o
This form replaces the normal text diagnostics and lets GCC derive the SARIF
file name from the input file. Available options depend on the GCC release and
can be inspected with g++ --help=common.
Clang
Clang writes SARIF diagnostics to standard error, so the stream must be
redirected to a file:
mkdir -p .cppmake
clang++ -std=c++23 -Wall -Wextra -fdiagnostics-format=sarif -Wno-sarif-format-unstable -fno-caret-diagnostics -c main.cpp -o main.o 2> .cppmake/main.sarif
-Wno-sarif-format-unstable suppresses Clang's warning that its SARIF format
is not yet stable. -fno-caret-diagnostics prevents terminal-oriented source
snippets from being appended to the JSON output.
Reading SARIF
For example, the error produced by this program is accompanied by its template
instantiation context:
template <class T>
void consume(T value) {
value.missing();
}
int main() {
consume(1);
}
The compiler reports the invalid member access as the primary error and the
instantiation of consume<int> as its context. Instantiation points, rejected
candidates, constraint failures, and similar notes are attached to the primary
diagnostic. cppmake preserves this nesting and displays a tree such as:
main
error: member reference base type 'int' is not a structure or union
note: in instantiation of function template specialization 'consume<int>'
The exact structure depends on the compiler and version. Related locations
without a nesting level are displayed directly below the primary result.
For the file format and data model, see the
SARIF 2.1.0 specification.
Searching SARIF
By default, the extension recursively scans the .make directory in each
workspace folder. The directory can be changed in the workspace settings:
{
"cppmake.sarifDirectory": ".make"
}
Open the Build view in the Activity Bar after compilation. Selecting a result
or related location opens its physical source location. The view rescans the
directory whenever it becomes visible.
Each compiler process should write to a separate SARIF file. This is especially
important for parallel builds; use the target or source file name as part of
the output file name.
License
This project is distributed under the GNU General Public License version 3.
See license.txt for the full license text.