JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
This page describes how to extend your CodeSonar-facing build so that your CodeSonar project includes:
This page describes how to extend your CodeSonar-facing build so that your CodeSonar project includes:
Incorporating Rust components follows the standard process for including a tier 3 component. The specializations to that process are summarized in the following table. For detailed instructions, see Including Rust Components In Your CodeSonar project, below. We also provide an example Makefile.
| Language Tools | You will need a Rust installation. |
|---|---|
| Third-Party Analyzer | clippy and clippy-sarif |
| Third-Party Analysis Step | You do not need to explicitly invoke clippy or clippy-sarif: they are invoked in the codesonar rust_scan.py subcommand. |
| Extend CodeSonar-facing Build | Invoke codesonar rust_scan.py on your Rust package. This will analyze the package source files with Clippy, use clippy-sarif to convert the Clippy results to SARIF format, then add the SARIF results and the source files to the CodeSonar project. |
Incorporating Rust components follows the standard process for including a tier 3 component.
The following diagram illustrates the extended software build described above, and its interactions with the CodeSonar build/analysis.
In this section (and throughout this manual), $CSONAR indicates the CodeSonar installation directory.
When a SARIF file is imported into a CodeSonar project, the SARIF importer determines an associated warning class for each rule object in the SARIF rules, creating this warning class if it does not already exist.
The SARIF importer has special handling for warning classes derived from SARIF produced by Rust Clippy via clippy-sarif. For more information, see Warning Classes Corresponding to Rust Clippy Rules.
To analyze Rust source files with Clippy and then add the source files and analysis results to a project, CodeSonar observes the execution of a command that incorporates one or more invocations of codesonar rust_scan.py.
where:
| cargo_projdir |
The path to the directory containing your Cargo project file
(Cargo.toml), relative to the
directory specified with -C/-directory.
|
|---|---|
| [-C rundir] [-directory rundir] |
Clippy will be run in rundir. If -C/-directory is not specified,
Clippy will be run in the current working directory.
The cargo_projdir argument is interpreted relative to rundir. For example:
Paths specified with -cargo, -cargo-clippy, and -clippy-sarif are also interpreted relative to rundir. |
| [-include-sources
file_pat] [-exclude-sources file_pat] |
By default, all Rust source files (.rs) in the directory tree rooted at
cargo_projdir will be imported into
the CodeSonar project. Use -include-sources and -exclude-sources to adjust this
imported set by adding or removing files.
file_pat is a recursive glob pattern representing a source file path. It matches all files whose file path matches file_pat. When a single codesonar rust_scan.py invocation contains a combination of -include-sources and -exclude-sources options, the set of imported files is determined by applying the corresponding inclusions and exclusions in the order in which they appear on the command line. Note:
|
| [-cargo cargo_path] | Specifies the path to your cargo executable. A relative value for
cargo_path will
be interpreted with respect to the directory specified with
-C/-directory. If -cargo cargo_path is not specified, CodeSonar will try to find cargo in your PATH. If it is unsuccessful, codesonar rust_scan.py will fail. |
| [-cargo-clippy clippy_path] | Specifies the path to your cargo-clippy executable. A relative value
for clippy_path
will be interpreted with respect to the directory specified with
-C/-directory. If -cargo-clippy clippy_path is not specified, CodeSonar will try to find cargo-clippy in your PATH. If it is unsuccessful, codesonar rust_scan.py will fail. |
| [-clippy-exit-ok clippy_code] |
Specifies that codesonar
rust_scan.py should ignore the clippy_code return
code from Clippy, rather than exiting with failure as it
otherwise would. In particular, you may wish to ignore return
code 101: Clippy typically
returns this code when it encounters rule violations.
You can specify this option multiple times to ignore multiple Clippy return codes. |
| [-clippy-sarif clippy_sarif_path] | Specifies the path to your clippy-sarif executable. A relative value
for clippy_sarif_path will be
interpreted with respect to the directory specified with -C/-directory. If -clippy-sarif clippy_sarif_path is not specified, CodeSonar will try to find clippy-sarif in your PATH. If it is unsuccessful, codesonar rust_scan.py will fail. |
| [-X+clippy_options_list] |
The +-separated
list of options and values in clippy_options_list are
passed to the Clippy invocation.
codesonar rust_scan.py -X+--+-W+missing-docs+--cap-lints+warn
[... remaining rust_scan.py options]
codesonar rust_scan.py -X+-- -X+-W+missing-docs
-X+--cap-lints+warn [... remaining rust_scan.py
options]
|
| [-sarif-output sarif_fname] |
Specifies that the SARIF output from Clippy should be written
to file sarif_fname. The primary use case for this option is in projects for which you wish to retain the SARIF results after the CodeSonar build/analysis has finished. If -sarif-output sarif_fname is not specified, codesonar rust_scan.py will use a temporary file for the SARIF output. |
| [-source-max-bytes num] | Specifies a maximum size of num bytes for imported
Rust source files: files larger than this maximum size will be
ignored by the importer. If -source-max-bytes is not specified, the importer will ignore files larger than 500KB. |
| [@infile] |
infile is a text file
containing a list of build option entries to be added to the
codesonar rust_scan.py
command line.
|
The codesonar rust_scan.py subcommand imports Rust source files into the CodeSonar project using the same mechanism as codesonar import_sarif.py, because CodeSonar does not have a full front end for Rust.
There are several consequences when files are directly imported with codesonar import_sarif.py.
An example Makefile for a Rust project is shown below. We also provide an example Makefile for a mixed-language project that has a Rust component: see Including Tier 3 Components in a CodeSonar Project: Example Makefile
RUST_PKG=$(SRCDIR)/rust_component .PHONY: all clean RustComponent csonar_facing all: RustComponent # The regular Rust build is managed by cargo. # In this example the package only has one source file, main.rs. # If there were other source files, they would be dependencies too. RustComponent: $(RUST_PKG)/src/main.rs $(RUST_PKG)/Cargo.toml cargo build --manifest-path $(RUST_PKG)/Cargo.toml # Invoke codesonar rust_scan.py to: # - Analyze our Rust source files (in this case, $(RUST_PKG)/src/main.rs) with Clippy. # - Convert the Clippy results to SARIF format with clippy-sarif. # - Import the SARIF and Rust source files into the CodeSonar project. csonar_facing: $(RUST_PKG)/src/main.rs "$(CSONAR)"/codesonar/bin/codesonar rust_scan.py $(RUST_PKG) clean: cd $(RUST_PKG) && cargo clean
We have provided a minimal sample project so you can experiment with the example Makefile.
SRCDIR=.
SRCDIR=.
CSONAR=path/to/your/codesonar/installation
# on Windows, typically CSONAR=C:\\Program Files\\CodeSecure\\CodeSonar
If you are interested, you can try building other targets in the example Makefile.
To report problems with this documentation, please visit https://support.codesecure.com/.