Ported to rust #59
Replies: 3 comments 2 replies
-
Initial benchmarks using hyperfine:
Looks like my efforts are fruitful here (about 1 second faster than pure python). I expect that the rust port would scale better when the test case is a much more complex scenario (like a 5000 line file full of clang-tidy and clang-format violations). The above scenario was just using the this repo's root folder. |
Beta Was this translation helpful? Give feedback.
-
I'm impressed with how quickly you ported to rust (previous is dart). I have a stupid question does the port to rust benefit from any other improvements except a second speed faster (I apologize if missed something you already mentioned), it's already pretty good by the time you're done refactoring the pure python cpp-linter. Rust is a language worth trying, and if clang-format, or even clang-tidy (especially existing build issue of clang-tidy on Linux and MacOSX)., were rewritten with rust, go, or dart maybe, this would be a big thing for the open source community. |
Beta Was this translation helpful? Give feedback.
-
Release Candidate 1 lives! 🎉I just published v2.0.0-rc1 to test-pypi (as a trusted publisher with attestations) and crates.io. Take a peek at lib.rs for package info at a glance (dependencies used, download frequency, etc). I finally got the feature parity up to par with the python codebase (plus async HTTP requests). How to installWe have some more options for installing cpp-linter v2.x: Using crates.ioNote These options skip installing from pre-releases by default. Using
|
Beta Was this translation helpful? Give feedback.
-
I did it again... I ported the pure python cpp-linter package to the rust language.
This repo is essentially a cargo virtual workspace (cargo is the package manager for rust). It has 3 separate packages:
cpp-linter-lib
: The main codebase as a library. This is used as the executables' backend.cpp-linter-cli
: This package wraps thecpp-linter-lib
package into a native executable binary. The built binary does not require python nor rust installed to run.cpp-linter-py
: This package wraps thecpp-linter-lib
package into a pip-installable python package. See below for more detail.cpp-linter-py
We can still deploy this port to pypi because there is a python package/binding located in cpp-linter-py directory. The python binding only exposes the
run::main()
function and is specified as an entry point script in pyproject.toml. There is no other rust API exposed in python.How to build/run the python package?
maturin
(similar to thesetuptools
build backend)--features openssl-vendored
(which should build openssl from source)cpp-linter-lib
Differences vs pure python package
Most of the functionality from the pure python codebase has been accurately ported over to rust. There is 1 difference that I plan on back-porting to the pure python pkg:
The
--verbosity
argument only accepts the valuesinfo
ordebug
. Normally, this arg's default value isinfo
, but if the user re-runs a cpp-linter step in CI with debugging logs enabled, then the arg's value changes todebug
.Testing and code coverage
The testing is not complete (yet), but I got code coverage up to 59%. Rust separates unit tests from integration tests:
Code coverage in rust seems to have been an afterthought. It does not seem well matured when compared to python's testing capabilities (no way to easily parametrize in rust).
cpp-linter-cli
Note
UPDATE: The cpp-linter-cli crate was consolidated into the cpp-linter-lib crate as a standalone binary executable for the cpp-linter-lib.
I have setup the CI to build (& deploy as release assets) several supported platforms:
https://github.com/cpp-linter/cpp_linter_rs/blob/33a22b5c78c8df4bfa1324870776b3f34ce08689/.github/workflows/binary-builds.yml#L174-L183
This should cover most use cases for CI workflows. It even covers ARM64 platforms on Linux (GNU C lib only) and Apple.
Other toolchains are supported by the rustc compiler, but cross-compiling them in CI is rather painful since openssl is required for the libgit2 rust binding (package named git2). I have to devise a better CI workflow that can make use of different docker images specifically tailored to cross-compiling rust and openssl.
How to build/run the native binary exe?
From the repo root, simply run
This will build the exe in debug mode. To make compiler optimize the code, add
--release
after therun
command.The
-- -h
means anything after the--
is passed to the built executable. So, you should see the help menu.To only build the exe, use the
build
command instead:And you'll find the binary located at
target/debug/cpp-linter-cli
.Installing binary exe from release assets
There are a few ways to download the built binary executable from release assets.
Note
None of these ways will take advantage of dependabot updates though.
This simplest way would be with
cargo-binstall
(acargo
aftermarket sub-command). Butcargo-binstall
uses Github's REST API (implying rate limits) and requires ourcpp-linter-cli
andcpp-linter-lib
packages be published to crates.io.Another way would be using the same method we get static clang-tools binaries from GitHub release assets (in clang-tools-pip).
We could also just use
cargo install
, but this will compile the binary from source every time.Beta Was this translation helpful? Give feedback.
All reactions