-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce development templates for easier project setup
- Loading branch information
1 parent
376e09e
commit a9e13b6
Showing
15 changed files
with
279 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,18 @@ | ||
rec { | ||
default = rust; | ||
rust = { | ||
path = ./rust; | ||
description = "Standard Rust development environment."; | ||
welcomeText = '' | ||
# Rust Project Template | ||
## Intended Usage | ||
Development and packaging of Rust programs and libraries. | ||
## Notes | ||
Do not forget to change the `Cargo.toml`'s `package.name` field! | ||
''; | ||
}; | ||
} |
This file contains 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,4 @@ | ||
# Doesn't work in the sandbox. | ||
[yanked] | ||
enabled = false # Don't warn for yanked crates in Cargo.lock. | ||
update_index = false # Don't auto-update the crates.io index. |
This file contains 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 @@ | ||
use flake |
This file contains 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,4 @@ | ||
.direnv | ||
|
||
result* | ||
target/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,7 @@ | ||
[package] | ||
name = "template" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license-file = "LICNESE" | ||
|
||
[dependencies] |
This file contains 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,23 @@ | ||
MIT License | ||
|
||
Copyright (c) 2025 Bastian Asmussen | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
|
This file contains 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,23 @@ | ||
# Rust Project Template | ||
|
||
This project is built using [Nix](https://nixos.org). | ||
|
||
## Usage | ||
|
||
### Building | ||
|
||
```sh | ||
nix build | ||
``` | ||
|
||
### Testing | ||
|
||
```sh | ||
nix flake check --all-systems | ||
``` | ||
|
||
### Running | ||
|
||
```sh | ||
nix run | ||
``` |
This file contains 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,2 @@ | ||
[licenses] | ||
allow = ["MIT"] |
This file contains 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,137 @@ | ||
{ | ||
inputs = { | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; | ||
crane.url = "github:ipetkov/crane"; | ||
fenix = { | ||
url = "github:nix-community/fenix"; | ||
inputs = { | ||
nixpkgs.follows = "nixpkgs"; | ||
rust-analyzer-src.follows = ""; | ||
}; | ||
}; | ||
|
||
advisory-db = { | ||
url = "github:rustsec/advisory-db"; | ||
flake = false; | ||
}; | ||
}; | ||
|
||
outputs = { self, nixpkgs, crane, fenix, flake-utils, advisory-db, ... }: | ||
flake-utils.lib.eachDefaultSystem (system: | ||
let | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
|
||
inherit (pkgs) lib; | ||
|
||
craneLib = crane.mkLib pkgs; | ||
src = ./.; | ||
|
||
# Common arguments can be set here to avoid repeating them later. | ||
commonArgs = { | ||
inherit src; | ||
|
||
strictDeps = true; | ||
buildInputs = [ | ||
# Additional build inputs. | ||
] ++ lib.optionals pkgs.stdenv.isDarwin (with pkgs; [ | ||
libiconv | ||
]); | ||
|
||
# Additional environment variables can be set directly. | ||
# RUST_BACKTRACE = "1"; | ||
}; | ||
|
||
craneLibLLvmTools = craneLib.overrideToolchain | ||
(fenix.packages.${system}.complete.withComponents [ | ||
"cargo" | ||
"llvm-tools" | ||
"rustc" | ||
]); | ||
|
||
# Build *just* the cargo dependencies, so we can reuse all of that work | ||
# (e.g. via cachix) when running in CI. | ||
cargoArtifacts = craneLib.buildDepsOnly commonArgs; | ||
|
||
# Build the actual crate itself, reusing the dependency artifacts from | ||
# above. | ||
crate = craneLib.buildPackage (commonArgs // { | ||
inherit cargoArtifacts; | ||
}); | ||
in | ||
{ | ||
checks = { | ||
# Build the crate as part of `nix flake check` for convenience. | ||
inherit crate; | ||
|
||
# Run clippy (and deny all warnings) on the crate source, again, | ||
# reusing the dependency artifacts from above. | ||
# | ||
# Note that this is done as a separate derivation so that we can block | ||
# the CI if there are issues here, but not prevent downstream | ||
# consumers from building our crate by itself. | ||
crate-clippy = craneLib.cargoClippy (commonArgs // { | ||
inherit cargoArtifacts; | ||
|
||
cargoClippyExtraArgs = "--all-targets -- --deny warnings"; | ||
}); | ||
|
||
crate-doc = craneLib.cargoDoc (commonArgs // { | ||
inherit cargoArtifacts; | ||
}); | ||
|
||
# Check formatting. | ||
crate-fmt = craneLib.cargoFmt { | ||
inherit src; | ||
}; | ||
|
||
crate-toml-fmt = craneLib.taploFmt { | ||
src = pkgs.lib.sources.sourceFilesBySuffices src [ ".toml" ]; | ||
}; | ||
|
||
# Audit dependencies. | ||
crate-audit = craneLib.cargoAudit { | ||
inherit src advisory-db; | ||
}; | ||
|
||
# Audit licenses. | ||
crate-deny = craneLib.cargoDeny { | ||
inherit src; | ||
}; | ||
|
||
# Run tests with `cargo-nextest`. | ||
crate-nextest = craneLib.cargoNextest (commonArgs // { | ||
inherit cargoArtifacts; | ||
|
||
partitions = 1; | ||
partitionType = "count"; | ||
cargoNextestPartitionsExtraArgs = "--no-tests=pass"; | ||
}); | ||
}; | ||
|
||
packages = { | ||
default = crate; | ||
} // lib.optionalAttrs (!pkgs.stdenv.isDarwin) { | ||
crate-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs // { | ||
inherit cargoArtifacts; | ||
}); | ||
}; | ||
|
||
apps.default = flake-utils.lib.mkApp { | ||
drv = crate; | ||
}; | ||
|
||
devShells.default = craneLib.devShell { | ||
# Inherit inputs from checks. | ||
checks = self.checks.${system}; | ||
|
||
# Additional dev-shell environment variables can be set here directly. | ||
# MY_CUSTOM_DEVELOPMENT_VAR = "something else"; | ||
|
||
# Extra inputs can be added here; cargo and rustc are provided by default. | ||
# packages = with pkgs; [ | ||
# bacon | ||
# ]; | ||
}; | ||
}); | ||
} |
This file contains 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,3 @@ | ||
fn main() { | ||
println!("Hello, World!"); | ||
} |
This file contains 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,9 @@ | ||
[formatting] | ||
reorder_keys = false | ||
|
||
[[rule]] | ||
include = ["**/Cargo.toml"] | ||
keys = ["dependencies"] | ||
|
||
[rule.formatting] | ||
reorder_keys = true |