Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 110 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ resolver = "2"
# Common dependencies can be defined here
anyhow = "1"
clap = { version = "4.5", features = ["derive"] }
http = "1"
jsonpath_lib = "0.3"
openapiv3 = "1"
regex = "1"
Expand All @@ -21,3 +20,113 @@ once_cell = "1"
uuid = { version = "1.0", features = ["v4"] }
tokio = { version = "1" }
chrono = { version = "0.4", features = ["serde"] }

[workspace.lints.rust]
deprecated = "deny"
non_ascii_idents = "forbid"
unsafe_code = "forbid"
unused_mut = "warn"
noop_method_call = "warn"
unused_import_braces = "warn"

[workspace.lints.clippy]
# Workspace global rules
pedantic = { level = "warn", priority = -1 }
async_yields_async = "deny"
await_holding_lock = "deny"
await_holding_refcell_ref = "deny"
cast_possible_truncation = "warn"
cast_possible_wrap = "warn"
cast_precision_loss = "warn"
cast_sign_loss = "warn"
clone_on_copy = "deny"
cognitive_complexity = "warn"
dbg_macro = "deny"
debug_assert_with_mut_call = "deny"
default_trait_access = "warn"
doc_link_with_quotes = "warn"
doc_markdown = "warn"
elidable_lifetime_names = "deny"
empty_line_after_outer_attr = "warn"
empty_structs_with_brackets = "warn"
enum_glob_use = "deny"
expect_used = "warn"
explicit_iter_loop = "warn"
float_cmp = "warn"
float_cmp_const = "warn"
format_push_string = "warn"
if_not_else = "warn"
ignored_unit_patterns = "warn"
implicit_clone = "warn"
items_after_statements = "warn"
implicit_hasher = "warn"
inefficient_to_string = "warn"
integer_division = "warn"
lossy_float_literal = "warn"
manual_assert = "warn"
manual_let_else = "warn"
manual_string_new = "warn"
many_single_char_names = "warn"
map_clone = "warn"
map_unwrap_or = "warn"
match_same_arms = "warn"
match_wildcard_for_single_variants = "warn"
missing_errors_doc = "warn"
missing_fields_in_debug = "warn"
missing_panics_doc = "warn"
must_use_candidate = "warn"
mutex_atomic = "warn"
needless_borrow = "deny"
needless_lifetimes = "deny"
needless_pass_by_value = "warn"
no_effect_underscore_binding = "warn"
non_ascii_literal = "warn"
redundant_closure_for_method_calls = "warn"
redundant_else = "warn"
return_self_not_must_use = "warn"
semicolon_if_nothing_returned = "warn"
single_char_pattern = "warn"
similar_names = "warn"
single_match_else = "warn"
struct_excessive_bools = "warn"
suspicious_operation_groupings = "warn"
too_many_lines = "warn"
trivially_copy_pass_by_ref = "warn"
type_complexity = "warn"
uninlined_format_args = "warn"
unnecessary_wraps = "warn"
unnested_or_patterns = "warn"
unreadable_literal = "warn"
unused_async = "warn"
unused_self = "warn"
unwrap_used = "warn"
used_underscore_binding = "warn"
useless_let_if_seq = "warn"
wildcard_dependencies = "deny"
wildcard_imports = "deny"

# Catches redundant/inefficient patterns
redundant_clone = "deny"
redundant_pattern_matching = "warn"
redundant_pub_crate = "warn"
str_to_string = "warn"
manual_ok_or = "warn"
manual_map = "warn"
manual_filter_map = "warn"
manual_find_map = "warn"

# Prevents verbose/non-idiomatic code
match_bool = "warn"
needless_for_each = "warn"
needless_collect = "warn"
needless_late_init = "warn"
needless_option_as_deref = "warn"

# Memory efficiency and correctness
large_stack_arrays = "warn"
large_types_passed_by_value = "warn"
rc_buffer = "warn"
rc_mutex = "warn"
string_lit_as_bytes = "warn"
verbose_file_reads = "warn"

174 changes: 174 additions & 0 deletions Makefile
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 || \
Copy link

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)

Copy link
Author

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.

Copy link

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

Copy link
Author

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.

(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)
Copy link

Choose a reason for hiding this comment

The 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)
Copy link

Choose a reason for hiding this comment

The 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"
Loading