-
Notifications
You must be signed in to change notification settings - Fork 1
Chores: makefile, tests #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
QuietSyscall
wants to merge
4
commits into
hypernetix:main
Choose a base branch
from
QuietSyscall:chores
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| # rclib Makefile | ||
| # Thorough code checking and development automation | ||
|
|
||
| CI := 1 | ||
|
|
||
| # -------- Utility macros -------- | ||
| define ensure_tool | ||
| @command -v $(1) >/dev/null || (echo "Installing $(1)..." && cargo install $(1)) | ||
| endef | ||
|
|
||
| # Show the help message with list of commands (default target) | ||
| help: | ||
| @echo "rclib Development Commands" | ||
| @echo "==========================" | ||
| @echo "" | ||
| @echo "Code Formatting:" | ||
| @echo " make fmt - Check code formatting" | ||
| @echo " make dev-fmt - Auto-fix code formatting" | ||
| @echo "" | ||
| @echo "Code Quality:" | ||
| @echo " make clippy - Run clippy linter" | ||
| @echo " make lint - Check for compile warnings" | ||
| @echo " make dev-clippy - Auto-fix clippy warnings" | ||
| @echo "" | ||
| @echo "Code Safety:" | ||
| @echo " make kani - Run Kani verifier for safety checks" | ||
| @echo " make geiger - Run Geiger scanner for unsafe code" | ||
| @echo " make safety - Run all code safety checks" | ||
| @echo "" | ||
| @echo "Security:" | ||
| @echo " make deny - Check licenses and dependencies" | ||
| @echo " make security - Run all security checks" | ||
| @echo "" | ||
| @echo "Tests:" | ||
| @echo " make test - Run all tests" | ||
| @echo " make test-lib - Run library tests only" | ||
| @echo " make test-int - Run integration tests only" | ||
| @echo "" | ||
| @echo "Coverage:" | ||
| @echo " make coverage - Generate code coverage report (HTML)" | ||
| @echo " make coverage-text - Generate code coverage report (text)" | ||
| @echo "" | ||
| @echo "Development:" | ||
| @echo " make dev - Auto-fix formatting and clippy, then test" | ||
| @echo " make dev-test - Run tests in development mode" | ||
| @echo "" | ||
| @echo "Build:" | ||
| @echo " make build - Make a release build" | ||
| @echo " make run - Run the dummyjson-cli example" | ||
| @echo "" | ||
| @echo "Main Targets:" | ||
| @echo " make check - Run all quality checks" | ||
| @echo " make ci - Run CI pipeline" | ||
| @echo " make all - Run all checks, tests, and build" | ||
|
|
||
| # -------- Code formatting -------- | ||
| .PHONY: fmt | ||
|
|
||
| # Check code formatting | ||
| fmt: | ||
| cargo fmt --all -- --check | ||
|
|
||
| # -------- Code quality -------- | ||
| .PHONY: clippy lint | ||
|
|
||
| # Run clippy linter | ||
| clippy: | ||
| cargo clippy --workspace --all-targets --all-features -- -D warnings -D clippy::perf | ||
|
|
||
| # Check there are no compile time warnings | ||
| lint: | ||
| RUSTFLAGS="-D warnings" cargo check --workspace --all-targets --all-features | ||
|
|
||
| # -------- Code safety checks -------- | ||
| .PHONY: kani geiger safety | ||
|
|
||
| # The Kani Rust Verifier for checking safety of the code | ||
| kani: | ||
| @command -v kani >/dev/null || \ | ||
| (echo "Installing Kani verifier..." && \ | ||
| cargo install --locked kani-verifier) | ||
| cargo kani --workspace --all-features | ||
|
|
||
| # Run Geiger scanner for unsafe code in dependencies | ||
| geiger: | ||
| $(call ensure_tool,cargo-geiger) | ||
| cargo geiger --all-features | ||
|
|
||
| # Run all code safety checks | ||
| safety: clippy lint | ||
| @echo "OK. Rust Safety Pipeline complete" | ||
|
|
||
| # -------- Code security checks -------- | ||
| .PHONY: deny security | ||
|
|
||
| # Check licenses and dependencies | ||
| deny: | ||
| $(call ensure_tool,cargo-deny) | ||
| cargo deny check | ||
|
|
||
| # Run all security checks | ||
| security: deny | ||
| @echo "OK. Rust Security Pipeline complete" | ||
|
|
||
| # -------- Development and auto fix -------- | ||
| .PHONY: dev dev-fmt dev-clippy dev-test | ||
|
|
||
| # Run tests in development mode | ||
| dev-test: | ||
| cargo test --workspace | ||
|
|
||
| # Auto-fix code formatting | ||
| dev-fmt: | ||
| cargo fmt --all | ||
|
|
||
| # Auto-fix clippy warnings | ||
| dev-clippy: | ||
| cargo clippy --workspace --all-targets --fix --allow-dirty | ||
|
|
||
| # Auto-fix formatting and clippy warnings | ||
| dev: dev-fmt dev-clippy dev-test | ||
|
|
||
| # -------- Tests -------- | ||
| .PHONY: test test-lib test-int | ||
|
|
||
| # Run all tests | ||
| test: | ||
| cargo test --workspace | ||
|
|
||
| # Run library tests only | ||
| test-lib: | ||
| cargo test -p rclib --lib | ||
|
|
||
| # Run integration tests only | ||
| test-int: | ||
| cargo test -p rclib --test integration_tests | ||
|
|
||
| # -------- Code coverage -------- | ||
| .PHONY: coverage coverage-text | ||
|
|
||
| # Generate code coverage report (HTML) | ||
| coverage: | ||
| @command -v cargo-llvm-cov >/dev/null || (echo "Installing cargo-llvm-cov..." && cargo install cargo-llvm-cov) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $(call ensure_tool,cargo-llvm-cov) |
||
| cargo llvm-cov --workspace --html | ||
| @echo "Coverage report generated at target/llvm-cov/html/index.html" | ||
|
|
||
| # Generate code coverage report (text) | ||
| coverage-text: | ||
| @command -v cargo-llvm-cov >/dev/null || (echo "Installing cargo-llvm-cov..." && cargo install cargo-llvm-cov) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $(call ensure_tool,cargo-llvm-cov) |
||
| cargo llvm-cov --workspace | ||
|
|
||
| # -------- Build -------- | ||
| .PHONY: build run | ||
|
|
||
| # Make a release build using stable toolchain | ||
| build: | ||
| cargo +stable build --release | ||
|
|
||
| # Run the dummyjson-cli example | ||
| run: | ||
| cargo run -p dummyjson-cli -- --help | ||
|
|
||
| # -------- Main targets -------- | ||
| .PHONY: check ci all | ||
|
|
||
| # Run all quality checks | ||
| check: fmt clippy lint test security | ||
|
|
||
| # Run CI pipeline | ||
| ci: check | ||
|
|
||
| # Run all necessary quality checks and tests and then build the release binary | ||
| all: check build | ||
| @echo "All checks passed and release binary built successfully" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$(call ensure_tool,cargo-geiger)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this approach.
When a tool is instructed to do something, it should do something rather than installing dependencies. Any 'check' is a read-only operation that should never modify the system's state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comment was not to open the discussion about that, it's to keep the same approach eveywhere:
https://github.com/hypernetix/rclib/pull/2/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52R8
We have a makefile function to install cargo tools, let's reuse that function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that another makefile does that, but this is not idiomatic. If you want two makefiles to be identical in their approach to silently installing tools just for the sake of consistency, I disagree. I would rather modify the Makefile in hyperspot to be idiomatic.