Skip to content

Commit

Permalink
refactor(libmake): 🎨 template optimisations and dependencies upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed May 12, 2024
1 parent 34ba474 commit 3432538
Show file tree
Hide file tree
Showing 11 changed files with 589 additions and 32 deletions.
35 changes: 33 additions & 2 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,54 @@ pub fn generate_files(params: FileGenerationParams) -> io::Result<()> {

// Copying the template files to the new library directory
let templates = [
// --- #Start GitHub Actions workflows ---
// Add audit GitHub Actions workflows template
("github/workflows/audit.tpl", ".github/workflows/audit.yml"),
// Add check GitHub Actions workflows template
("github/workflows/check.tpl", ".github/workflows/check.yml"),
// Add coverage GitHub Actions workflows template
("github/workflows/coverage.tpl", ".github/workflows/coverage.yml"),
// Add document GitHub Actions workflows template
("github/workflows/document.tpl", ".github/workflows/document.yml"),
// Add lint GitHub Actions workflows template
("github/workflows/lint.tpl", ".github/workflows/lint.yml"),
// Add release GitHub Actions workflows template
("github/workflows/release.tpl", ".github/workflows/release.yml"),
// Add test GitHub Actions workflows template
("github/workflows/test.tpl", ".github/workflows/test.yml"),
// --- #End GitHub Actions workflows ---
// Add Authors template
("AUTHORS.tpl", "AUTHORS.md"),
// Add build template
("build.tpl", "build.rs"),
// Add Cargo template
("Cargo.tpl", "Cargo.toml"),
("ci.tpl", ".github/workflows/ci.yml"),
// Add Contributing template
("CONTRIBUTING.tpl", "CONTRIBUTING.md"),
// Add Criterion template
("criterion.tpl", "benches/criterion.rs"),
// Add Deepsource template
("deepsource.tpl", ".deepsource.toml"),
// Add Deny template
("deny.tpl", "deny.toml"),
// Add Example template
("example.tpl", "examples/example.rs"),
// Add Gitignore template
("gitignore.tpl", ".gitignore"),
// Add Lib template
("lib.tpl", "src/lib.rs"),
// Add Macros template
("macros.tpl", "src/macros.rs"),
// Add Main template
("main.tpl", "src/main.rs"),
// Add Readme template
("README.tpl", "README.md"),
// Add Rustfmt template
("rustfmt.tpl", "rustfmt.toml"),
// Add Template template
("TEMPLATE.tpl", "TEMPLATE.md"),
("test.tpl", "tests/test.rs"),
// Add Test template
("test_test.tpl", "tests/test_test.rs"),
];

for (template, target) in templates {
Expand Down
84 changes: 56 additions & 28 deletions template/Cargo.tpl
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
[package]
authors = [{author}]
build = {build}
categories = {categories}
description = {description}
documentation = {documentation}
edition = {edition}
# Metadata about the package.
authors = "{author}"
build = "{build}"
categories = [{categories}]
description = "{description}"
documentation = "{documentation}"
edition = "{edition}"
exclude = ["/.git/*", "/.github/*", "/.gitignore", "/.vscode/*"]
homepage = {homepage}
keywords = {keywords}
license = {license}
homepage = "{homepage}"
keywords = [{keywords}]
license = "{license}"
name = "{name}"
readme = {readme}
readme = "{readme}"
repository = "{repository}"
rust-version = {rustversion}
version = {version}
rust-version = "{rustversion}"
version = "{version}"
include = [
"/CONTRIBUTING.md",
"/LICENSE-APACHE",
Expand All @@ -28,6 +29,7 @@ include = [
]

[[bench]]
# Benchmarking configuration.
name = "benchmark"
harness = false
path = "benches/criterion.rs"
Expand All @@ -36,58 +38,77 @@ path = "benches/criterion.rs"
debug = true

[dependencies]
anyhow = "1.0.81"
dtt = "0.0.5"
# The dependencies of the package.
anyhow = "1.0.83"
dtt = "0.0.6"
env_logger = "0.11.3"
rlg = "0.0.3"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"
serde_yml = "0.0.4"
rlg = "0.0.4"
serde = { version = "1.0.201", features = ["derive"] }
serde_json = "1.0.117"
serde_yml = "0.0.5"
toml = "0.8.12"
vrd = "0.0.6"
vrd = "0.0.7"

[dev-dependencies]
# The development dependencies of the package.
criterion = "0.5.1"

[lib]
# The library configuration.
crate-type = ["lib"]
name = "{name}"
path = "src/lib.rs"

[features]
# The features of the package.
default = []

[package.metadata.docs.rs]
all-features = true
# Configuration for docs.rs.
targets = ["x86_64-unknown-linux-gnu"]
rustdoc-args = ["--generate-link-to-definition"]

# Linting config
[lints.rust]

## Warn
missing_copy_implementations = "warn"
missing_docs = "warn"
unstable_features = "warn"
unused_extern_crates = "warn"
unused_results = "warn"

## Allow
bare_trait_objects = "allow"
elided_lifetimes_in_paths = "allow"
non_camel_case_types = "allow"
non_upper_case_globals = "allow"
trivial_bounds = "allow"
unsafe_code = "allow"

## Forbid
missing_debug_implementations = "forbid"
missing_docs = "warn"
non_ascii_idents = "forbid"
unreachable_pub = "forbid"
unsafe_code = "forbid"

## Deny
dead_code = "deny"
deprecated_in_future = "deny"
ellipsis_inclusive_range_patterns = "deny"
explicit_outlives_requirements = "deny"
future_incompatible = "deny"
future_incompatible = { level = "deny", priority = -1 }
keyword_idents = "deny"
macro_use_extern_crate = "deny"
meta_variable_misuse = "deny"
missing_fragment_specifier = "deny"
noop_method_call = "deny"
pointer_structural_match = "deny"
rust_2018_idioms = "deny"
rust_2021_compatibility = "deny"
rust_2018_idioms = { level = "deny", priority = -1 }
rust_2021_compatibility = { level = "deny", priority = -1 }
single_use_lifetimes = "deny"
trivial_casts = "deny"
trivial_numeric_casts = "deny"
unused = "deny"
unused = { level = "deny", priority = -1 }
unused_features = "deny"
unused_import_braces = "deny"
unused_labels = "deny"
Expand All @@ -96,7 +117,12 @@ unused_macro_rules = "deny"
unused_qualifications = "deny"
variant_size_differences = "deny"

[package.metadata.clippy]
# Clippy configuration.
warn-lints = ["clippy::all", "clippy::pedantic", "clippy::cargo", "clippy::nursery"]

[profile.dev]
# Development profile configuration.
codegen-units = 256
debug = true
debug-assertions = true
Expand All @@ -109,18 +135,20 @@ rpath = false
strip = false

[profile.release]
# Release profile configuration.
codegen-units = 1
debug = false
debug-assertions = false
incremental = false
lto = true
opt-level = "s"
overflow-checks = false
panic = "abort"
panic = 'abort'
rpath = false
strip = "symbols"
strip = 'symbols'

[profile.test]
# Test profile configuration.
codegen-units = 256
debug = true
debug-assertions = true
Expand Down
4 changes: 2 additions & 2 deletions template/ci.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ on:
pull_request:
branches:
- main
- 'feat/*'
- feat/{name}
push:
branches:
- main
- 'feat/*'
- feat/{name}

jobs:
# This job checks a local package and all of its dependencies for
Expand Down
28 changes: 28 additions & 0 deletions template/github/workflows/audit.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: 🧪 Audit

on:
push:
branches:
- main
- feat/{name}
pull_request:
branches:
- feat/{name}
release:
types: [created]

jobs:
dependencies:
name: Audit dependencies
runs-on: ubuntu-latest
steps:
- uses: hecrj/setup-rust-action@v2
- name: Install cargo-audit
run: cargo install cargo-audit

- uses: actions/checkout@v4
- name: Resolve dependencies
run: cargo update

- name: Audit vulnerabilities
run: cargo audit
24 changes: 24 additions & 0 deletions template/github/workflows/check.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 🧪 Check

on:
push:
branches:
- main
- feat/{name}
pull_request:
branches:
- feat/{name}
release:
types: [created]

jobs:
all:
name: Check
runs-on: ubuntu-latest
steps:
- uses: hecrj/setup-rust-action@v2
with:
components: clippy
- uses: actions/checkout@v4
- name: Check lints
run: cargo check --all-targets --workspace --all-features
61 changes: 61 additions & 0 deletions template/github/workflows/coverage.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: 📶 Coverage

on:
push:
branches:
- main
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
coverage:
name: Code Coverage
runs-on: ubuntu-latest
env:
CARGO_INCREMENTAL: "0"
RUSTFLAGS: "-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests"
RUSTDOCFLAGS: "-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Cpanic=abort -Zpanic_abort_tests"

steps:
# Checkout the repository
- name: Checkout repository
uses: actions/checkout@v4

# Setup Rust nightly
- name: Install Rust
uses: actions-rs/toolchain@v1
id: toolchain
with:
toolchain: nightly
override: true

# Configure cache for Cargo
- name: Cache Cargo registry, index
uses: actions/cache@v4
id: cache-cargo
with:
path: |
~/.cargo/registry
~/.cargo/bin
~/.cargo/git
key: linux-${{ steps.toolchain.outputs.rustc_hash }}-rust-cov-${{ hashFiles('**/Cargo.lock') }}

# Run tests with all features
- name: Test (cargo test)
uses: actions-rs/cargo@v1
with:
command: test
args: "--workspace"

# Install grcov
- uses: actions-rs/[email protected]
id: coverage

# Upload to Codecov.io
- name: Upload to Codecov.io
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ${{ steps.coverage.outputs.report }}
Loading

0 comments on commit 3432538

Please sign in to comment.