improve rust template

This commit is contained in:
ulic-youthlic 2025-05-25 15:38:17 +08:00
parent 69c6e41eff
commit dc5dfddf74
Signed by: youthlic
GPG key ID: 63E86C3C14A0D721
2 changed files with 18 additions and 14 deletions

View file

@ -50,26 +50,29 @@
}; };
basicArgs = { basicArgs = {
inherit src; inherit src;
pname = "rust-demo";
strictDeps = true; strictDeps = true;
}; };
cargoArtifacts = craneLib.buildDepsOnly basicArgs; nativeBuildInputs = with pkgs; [];
buildInputs =
(with pkgs; [])
++ lib.optional pkgs.stdenv.buildPlatform.isDarwin (with pkgs; [
darwin.apple_sdk.frameworks.Security
]);
cargoArtifacts = craneLib.buildDepsOnly (basicArgs
// {
inherit buildInputs nativeBuildInputs;
});
commonArgs = commonArgs =
basicArgs basicArgs
// { // {
inherit cargoArtifacts; inherit cargoArtifacts buildInputs nativeBuildInputs;
nativeBuildInputs = with pkgs; [];
buildInputs =
(with pkgs; [])
++ lib.optional pkgs.stdenv.buildPlatform.isDarwin (with pkgs; [
darwin.apple_sdk.frameworks.Security
]);
env = {};
}; };
in { in {
formatter = pkgs.alejandra; formatter = pkgs.alejandra;
checks = { checks = {
inherit (self.packages.${system}) default; package = self.packages.${system}.default.overrideAttrs {
doCheck = true;
};
clippy = craneLib.cargoClippy (commonArgs clippy = craneLib.cargoClippy (commonArgs
// { // {
cargoClippyExtraArgs = "--all-targets -- --deny warnings"; cargoClippyExtraArgs = "--all-targets -- --deny warnings";
@ -84,7 +87,6 @@
// { // {
partitions = 1; partitions = 1;
partitionType = "count"; partitionType = "count";
nativeBuildInputs = [];
cargoNextestExtraArgs = "--no-tests pass"; cargoNextestExtraArgs = "--no-tests pass";
env = { env = {
CARGO_PROFILE = "dev"; CARGO_PROFILE = "dev";
@ -98,10 +100,10 @@
(craneLib.crateNameFromCargoToml { (craneLib.crateNameFromCargoToml {
cargoToml = "${toString src}/Cargo.toml"; cargoToml = "${toString src}/Cargo.toml";
}) })
pname
version
; ;
doCheck = false; doCheck = false;
nativeBuildInputs = [];
buildInputs = [];
}); });
default = rust-demo; default = rust-demo;
}; };
@ -109,6 +111,7 @@
drv = self.packages."${system}".default; drv = self.packages."${system}".default;
}; };
devShells.default = craneLib.devShell { devShells.default = craneLib.devShell {
checks = self.checks.${system};
packages = with pkgs; [ packages = with pkgs; [
rust-analyzer rust-analyzer
cargo-audit cargo-audit

View file

@ -1,3 +1,4 @@
[toolchain] [toolchain]
channel = "stable" channel = "stable"
profile = "default" profile = "default"
components = ["rust-src"]