index : rust-template
Feature rich rust template
about summary refs log tree commit diff
author Yousef Al-Harbi <yo2w86@gmail.com> 2026-11-21 20:36:20 +0300
committer Yousef Al-Harbi <yo2w86@gmail.com> 2026-11-21 20:36:20 +0300
commit 6d7381ec457decdc7dd63ce3f6c3166381272e37 [patch]
tree 30b5771e75a98d8ca203b84dd6d344207af3e913
download main.tar.gz

feat: initial Rust cargo-generate template HEAD main

Diffstat

-rw-r--r-- .gitignore 2
-rw-r--r-- CHANGELOG.md 4
-rw-r--r-- Cargo.toml 34
-rw-r--r-- README.md 18
-rw-r--r-- cargo-generate.toml 17
-rw-r--r-- cliff.toml 43
-rw-r--r-- clippy.toml 2
-rw-r--r-- justfile 60
-rw-r--r-- release.toml 16
-rw-r--r-- rustfmt.toml 2
-rw-r--r-- src/main.rs 11
-rw-r--r-- .github/workflows/ci.yml 35
-rw-r--r-- .github/workflows/release.yml 79
 13 files changed, 323 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1a4595e 100644
--- /dev/null
+++ b/.gitignore
@@ -1,0 +1,2 @@
/target
*.log
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..b9e5e0f 100644
--- /dev/null
+++ b/CHANGELOG.md
@@ -1,0 +1,4 @@
# Changelog
All notable changes to the `{{project-name}}` crate will be documented in this file.

## [Unreleased]
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..8ce2906 100644
--- /dev/null
+++ b/Cargo.toml
@@ -1,0 +1,34 @@
[package]
name = "{{project-name}}"
version = "0.1.0"
license = "{{license}}"
description = "{{description}}"
authors = ["Yousef Al-Harbi <yousefalharby416@gmail.com>"]
repository = "https://github.com/y2w8/{{project-name}}"
edition = "2024"
rust-version = "1.96.0"
readme = "README.md"
exclude = [
    ".github/",
    ".gitignore",
    "./assets/",
    "./release.toml",
    "./cliff.toml",
    "./justfile",
]

[dependencies]

[lints.rust]
unsafe_code = "forbid"

[lints.clippy]
all = { level = "warn", priority = -1 }
dbg_macro = "warn"
todo = "warn"
unwrap_used = "warn"

[profile.release]
lto = true
codegen-units = 1
strip = true
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..67fea7a 100644
--- /dev/null
+++ b/README.md
@@ -1,0 +1,18 @@
# {{project-name}}

{{description}}

## Development

Common tasks are automated via [`just`](https://github.com/casey/just):

```sh
just --list          # List all available recipes
just run             # Run locally
just ci              # Run rustfmt, clippy, and tests
just release patch   # Bump version, update CHANGELOG.md via git-cliff, tag & push
```

## License

Licensed under the [{{license}}](LICENSE) license.
diff --git a/cargo-generate.toml b/cargo-generate.toml
new file mode 100644
index 0000000..d78153d 100644
--- /dev/null
+++ b/cargo-generate.toml
@@ -1,0 +1,17 @@
[template]
cargo_generate_version = ">=0.18.0"
exclude = [
    "release.toml",
    ".github/workflows/ci.yml",
]

[placeholders.description]
type = "string"
prompt = "Crate description?"
default = "A fast application written in Rust."

[placeholders.license]
type = "string"
prompt = "License?"
choices = ["GPL-3.0", "MIT", "Apache-2.0"]
default = "GPL-3.0"
diff --git a/cliff.toml b/cliff.toml
new file mode 100644
index 0000000..a112d84 100644
--- /dev/null
+++ b/cliff.toml
@@ -1,0 +1,43 @@
[remote.github]
owner = "y2w8"
repo = "{{project-name}}"

[changelog]
header = """
# Changelog
All notable changes to the `{{project-name}}` crate will be documented in this file.

## [Unreleased]
"""
body = """
{% raw %}{% if version -%}
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% endif -%}
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | striptags | trim }}
{% for commit in commits -%}
- {{ commit.message | split(pat="\\n") | first | upper_first | trim }} \
([{{ commit.id | truncate(length=7, end="") }}](https://github.com/y2w8/{% endraw %}{{project-name}}{% raw %}/commit/{{ commit.id }})), \
by @{{ commit.remote.username | default(value=commit.author.name) }}
{% endfor %}
{% endfor -%}{% endraw %}
"""
trim = true

[git]
conventional_commits = true
filter_unconventional = false
split_commits = false
commit_parsers = [
  { message = "^feat", group = "<!-- 0 -->Added" },
  { message = "^fix", group = "<!-- 1 -->Fixed" },
  { message = "^refactor", group = "<!-- 2 -->Changed" },
  { message = "^perf", group = "<!-- 3 -->Performance" },
  { message = "^doc", group = "<!-- 4 -->Documentation" },
  { message = "^chore: release", skip = true },
  { message = "^chore\\(release\\)", skip = true },
  { message = ".*", group = "<!-- 5 -->Other" },
]
filter_commits = false
tag_pattern = "v[0-9].*"
sort_commits = "newest"
diff --git a/clippy.toml b/clippy.toml
new file mode 100644
index 0000000..fb9da76 100644
--- /dev/null
+++ b/clippy.toml
@@ -1,0 +1,2 @@
large-error-threshold = 256
too-many-arguments-threshold = 7
diff --git a/justfile b/justfile
new file mode 100644
index 0000000..6ec39a2 100644
--- /dev/null
+++ b/justfile
@@ -1,0 +1,60 @@
{% raw %}arm_target := "aarch64-unknown-linux-gnu"

default:
    @just --list

# Build debug binary
build *args:
    cargo build {{args}}

# Build optimized release binary (x86_64)
build-release:
    cargo build --release

# Cross-compile ARM64 release binary
build-arm:
    cargo build --release --target {{arm_target}}

# Run locally with arguments
run *args:
    cargo run -- {{args}}

# Fast type and borrow check
check:
    cargo check --all-targets --all-features

# Format all Rust code
fmt:
    cargo fmt --all

# Check formatting without modifying files
fmt-check:
    cargo fmt --all -- --check

# Run Clippy with all warnings denied
lint:
    cargo clippy --all-targets --all-features -- -D warnings

# Run all unit and integration tests
test *args:
    cargo test --all-targets --all-features {{args}}

# Run full CI quality gate locally (format check, clippy, tests)
ci: fmt-check lint test

# Preview changelog for unreleased commits
changelog-preview:
    git-cliff --unreleased

# Dry-run a version bump (patch, minor, major)
release-dry level="patch":
    cargo release {{level}}

# Execute a version bump, update CHANGELOG.md via git-cliff, tag, and push
release level="patch":
    cargo release {{level}} --execute

# Remove build artifacts
clean:
    cargo clean
{% endraw %}diff --git a/release.toml b/release.toml
new file mode 100644
index 0000000..e063c16 100644
--- /dev/null
+++ b/release.toml
@@ -1,0 +1,16 @@
push = true
publish = true
tag = true
sign-tag = false
pre-release-commit-message = "chore: release {{version}}"
tag-message = "Release {{version}}"

# Generate changelog entry with all commits and @author handles since last tag
pre-release-hook = [
  "git-cliff",
  "--tag",
  "{{version}}",
  "--unreleased",
  "--prepend",
  "CHANGELOG.md",
]
diff --git a/rustfmt.toml b/rustfmt.toml
new file mode 100644
index 0000000..d0324ff 100644
--- /dev/null
+++ b/rustfmt.toml
@@ -1,0 +1,2 @@
edition = "2024"
newline_style = "Unix"
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..5876304 100644
--- /dev/null
+++ b/src/main.rs
@@ -1,0 +1,11 @@
fn main() {
    println!("Hello from {{project-name}}!");
}

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        assert_eq!(2 + 2, 4);
    }
}
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..4f50659 100644
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -1,0 +1,35 @@
name: CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

env:
  CARGO_TERM_COLOR: always

jobs:
  ci:
    name: Check, Lint & Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - uses: Swatinem/rust-cache@v2

      - name: Check formatting
        run: cargo fmt --all -- --check

      - name: Lint with Clippy
        run: cargo clippy --all-targets --all-features -- -D warnings

      - name: Build
        run: cargo build --all-targets --verbose

      - name: Run tests
        run: cargo test --all-targets --all-features --verbose
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
new file mode 100644
index 0000000..3c01cfd 100644
--- /dev/null
+++ b/.github/workflows/release.yml
@@ -1,0 +1,79 @@
name: Release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write

jobs:
  build:
    name: Build {% raw %}${{ matrix.target }}{% endraw %}
    runs-on: {% raw %}${{ matrix.os }}{% endraw %}
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            binary: {{project-name}}
            asset: {{project-name}}-x86_64-linux
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            binary: {{project-name}}
            asset: {{project-name}}-aarch64-linux
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: {% raw %}${{ matrix.target }}{% endraw %}

      - uses: Swatinem/rust-cache@v2

      - name: Install cross
        run: cargo install cross --locked

      - name: Build release binary
        run: cross build --release --target {% raw %}${{ matrix.target }}{% endraw %}

      - name: Rename binary
        run: cp target/{% raw %}${{ matrix.target }}/release/${{ matrix.binary }} ${{ matrix.asset }}{% endraw %}

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: {% raw %}${{ matrix.asset }}{% endraw %}
          path: {% raw %}${{ matrix.asset }}{% endraw %}

  release:
    name: Create GitHub Release
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts
          merge-multiple: true

      - name: Extract changelog notes for tag
        id: changelog
        run: |
          {% raw %}VERSION=${GITHUB_REF#refs/tags/v}
          NOTES=$(awk "/## \[$VERSION\]/{flag=1; next} /## \[/{flag=0} flag" CHANGELOG.md)
          {
            echo "notes<<EOF"
            echo "$NOTES"
            echo "EOF"
          } >> "$GITHUB_OUTPUT"{% endraw %}

      - name: Publish GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          body: {% raw %}${{ steps.changelog.outputs.notes }}{% endraw %}
          files: artifacts/*