Skip to content

Commit

Permalink
The third revision (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
habedi authored Feb 18, 2025
1 parent 93649aa commit 048133e
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@
*.out filter=lfs diff=lfs merge=lfs -text
*.a filter=lfs diff=lfs merge=lfs -text
*.o filter=lfs diff=lfs merge=lfs -text

# Exclude files from language stats (GitHub Linguist)
*.ipynb linguist-vendored
43 changes: 38 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "template-rust-project"
version = "0.2.3"
version = "0.2.4"
description = "A template for Rust projects"
repository = "https://github.com/habedi/template-rust-project"
license = "MIT OR Apache-2.0"
Expand All @@ -9,8 +9,24 @@ keywords = ["project-template", "rust", "library", "application"]
authors = ["Hassan Abedi <[email protected]>"]
homepage = "https://github.com/habedi/template-rust-project"
documentation = "https://docs.rs/template-rust-project"
#categories = ["development-tools"]
categories = ["development-tools"]
edition = "2021"
rust-version = "1.83"

[workspace]
members = []

resolver = "2"

include = [
"assets/**/*",
"docs/**/*",
"src/**/*",
"Cargo.toml",
"README.md",
"LICENSE-MIT",
"LICENSE-APACHE"
]

[lib]
name = "template_rust_project"
Expand All @@ -20,9 +36,26 @@ path = "src/lib.rs"
name = "template-rust-project"
path = "src/main.rs"

[features]
default = [] # No features enabled by default
binaries = []

[dependencies]
clap = "4.5.27"
log = "0.4.25"
ctor = "0.2.9"
tracing = "0.1.41"
tracing-subscriber = "0.3.19"

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }

[[bench]]
name = "project_benchmarks"
harness = false

[profile.release]
strip = "symbols"
codegen-units = 1
lto = true

[dev-dependencies]
[profile.bench]
debug = true
24 changes: 18 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PKG = github.com/habedi/template-rust-project
BINARY_NAME = $(or $(PROJ_BINARY), $(notdir $(PKG)))
BINARY = target/release/$(BINARY_NAME)
PATH := /snap/bin:$(PATH)
DEBUG_PROJ = 1

# Default target
.DEFAULT_GOAL := help
Expand All @@ -19,22 +20,22 @@ format: ## Format Rust files
.PHONY: test
test: format ## Run tests
@echo "Running tests..."
cargo test -- --nocapture
DEBUG_PROJ=$(DEBUG_PROJ) cargo test -- --nocapture

.PHONY: coverage
coverage: format ## Generate test coverage report
@echo "Generating test coverage report..."
cargo tarpaulin --out Xml --out Html
DEBUG_PROJ=$(DEBUG_PROJ) cargo tarpaulin --out Xml --out Html

.PHONY: build
build: format ## Build the binary for the current platform
@echo "Building the project..."
cargo build --release
DEBUG_PROJ=$(DEBUG_PROJ) cargo build --release

.PHONY: run
run: build ## Build and run the binary
@echo "Running the $(BINARY) binary..."
./$(BINARY)
DEBUG_PROJ=$(DEBUG_PROJ) ./$(BINARY)

.PHONY: clean
clean: ## Remove generated and temporary files
Expand All @@ -54,13 +55,24 @@ install-deps: install-snap ## Install development dependencies
@echo "Installing dependencies..."
rustup component add rustfmt clippy
cargo install cargo-tarpaulin
cargo install cargo-audit

.PHONY: lint
lint: format ## Run linters on Rust files
@echo "Linting Rust files..."
cargo clippy -- -D warnings
DEBUG_PROJ=$(DEBUG_PROJ) cargo clippy -- -D warnings

.PHONY: publish
publish: ## Publish the package to crates.io (requires CARGO_REGISTRY_TOKEN to be set)
@echo "Publishing the package to Cargo registry..."
cargo publish --token $(CARGO_REGISTRY_TOKEN)
cargo publish --token $(CARGO_REGISTRY_TOKEN)

.PHONY: bench
bench: ## Run benchmarks
@echo "Running benchmarks..."
DEBUG_PROJ=$(DEBUG_PROJ) cargo bench

.PHONY: audit
audit: ## Run security audit on Rust dependencies
@echo "Running security audit..."
cargo audit
8 changes: 8 additions & 0 deletions benches/project_benchmarks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use criterion::{criterion_group, criterion_main, Criterion};

fn benchmark_fun(_c: &mut Criterion) {
// Your benchmarking code here
}

criterion_group!(benches, benchmark_fun,);
criterion_main!(benches);
2 changes: 2 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::ffi::OsString;
use tracing::error;

pub fn run(args: impl IntoIterator<Item = OsString>) -> Result<(), i32> {
let _args: Vec<OsString> = args.into_iter().collect();
// Your implementation here
// Expecting at least 2 arguments
if _args.len() < 2 {
error!("Expecting at least 2 arguments");
return Err(1);
}
Ok(())
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod cli;
pub mod logging;
17 changes: 17 additions & 0 deletions src/logging.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use ctor::ctor;
use tracing::Level;
use tracing_subscriber;

#[ctor]
fn set_debug_level() {
// If DEBUG_PROJ is not set or set to false, disable logging. Otherwise, enable logging
if std::env::var("DEBUG_PROJ").map_or(true, |v| v == "0" || v == "false" || v.is_empty()) {
// Disable logging
} else {
tracing_subscriber::fmt()
.with_max_level(Level::DEBUG)
.init();
}

//println!("DEBUG_PROJ: {:?}", std::env::var("DEBUG_PROJ"));
}
Empty file removed tests/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit 048133e

Please sign in to comment.