Compare commits

..
1 Commits
Author SHA1 Message Date
reed 25609ea025 feat(rust-esp32-c6): make the rust-esp32-c6 template 2026-06-04 20:20:48 -05:00
15 changed files with 69 additions and 165 deletions
-3
View File
@@ -1,8 +1,5 @@
name: "Flake.lock: update Nix dependencies for development environment only" name: "Flake.lock: update Nix dependencies for development environment only"
permissions:
contents: write
on: on:
workflow_dispatch: # allows manual triggering workflow_dispatch: # allows manual triggering
schedule: schedule:
-8
View File
@@ -1,8 +0,0 @@
[global]
disable = [
# line length limits
"MD013",
]
[MD057]
absolute-links = "relative_to_roots"
+2 -2
View File
@@ -155,8 +155,8 @@
}; };
# Formatter for nix files, available through 'nix fmt' # Formatter for nix files, available through 'nix fmt'
treefmt.programs = lib.mkIf cfg.formatter.enable { treefmt = lib.mkIf cfg.formatter.enable {
alejandra.enable = lib.mkIf cfg.formatter.nix true; programs.alejandra.enable = lib.mkIf cfg.formatter.nix true;
}; };
}; };
}); });
Generated
+18 -18
View File
@@ -95,11 +95,11 @@
}, },
"crane": { "crane": {
"locked": { "locked": {
"lastModified": 1790899423, "lastModified": 1777335812,
"narHash": "sha256-THGtz65UGJU+sonZidRboyCMk+9DclpMF7pwL4uDV4M=", "narHash": "sha256-bEg5xoAxAwsyfnGhkEX7RJViTIBIYPd8ISg4O1c0HFc=",
"owner": "ipetkov", "owner": "ipetkov",
"repo": "crane", "repo": "crane",
"rev": "47b6b27ed9a3a9181415e4367d0c30ab2a0e0250", "rev": "5e0fb2f64edff2822249f21293b8304dedaaf676",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -113,11 +113,11 @@
"nixpkgs-lib": "nixpkgs-lib" "nixpkgs-lib": "nixpkgs-lib"
}, },
"locked": { "locked": {
"lastModified": 1790898470, "lastModified": 1775087534,
"narHash": "sha256-zTwuwezD0w3hpga6a6P8emidzAZFyWqlNeRBlpWOOl8=", "narHash": "sha256-91qqW8lhL7TLwgQWijoGBbiD4t7/q75KTi8NxjVmSmA=",
"owner": "hercules-ci", "owner": "hercules-ci",
"repo": "flake-parts", "repo": "flake-parts",
"rev": "024633cd702b10285db5cb19b40ad48d2399ba60", "rev": "3107b77cd68437b9a76194f0f7f9c55f2329ca5b",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -162,11 +162,11 @@
}, },
"nixpkgs-lib": { "nixpkgs-lib": {
"locked": { "locked": {
"lastModified": 1790477367, "lastModified": 1774748309,
"narHash": "sha256-oujbxmVKDhci2E4EM3KyAbRUgp5/IsCoiA/LfEF7OOk=", "narHash": "sha256-+U7gF3qxzwD5TZuANzZPeJTZRHS29OFQgkQ2kiTJBIQ=",
"owner": "nix-community", "owner": "nix-community",
"repo": "nixpkgs.lib", "repo": "nixpkgs.lib",
"rev": "f7cd230690d9fc982d06129f9189b101fddcfa3b", "rev": "333c4e0545a6da976206c74db8773a1645b5870a",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -177,11 +177,11 @@
}, },
"nixpkgs_2": { "nixpkgs_2": {
"locked": { "locked": {
"lastModified": 1791260994, "lastModified": 1777268161,
"narHash": "sha256-Miqqk/ammqnTUxaoCyvtwoPeLbI1ksFyLxi/CazZpWY=", "narHash": "sha256-bxrdOn8SCOv8tN4JbTF/TXq7kjo9ag4M+C8yzzIRYbE=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "151fa4e8ddfdd8dd25d945ad94ed54a13de9f6e4", "rev": "1c3fe55ad329cbcb28471bb30f05c9827f724c76",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -273,11 +273,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1791276535, "lastModified": 1780197589,
"narHash": "sha256-iwqAmHTX1IgzTumJR3JayNAQAo5xEmmOuGzB6b2pT/Q=", "narHash": "sha256-FVCr2Ij/jKf59a4LW481eeOF6rJRreOBrVgW/aUBTrw=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "b962e5d0c8cd97196c6a882d659fe451b52ad989", "rev": "21632e942d89bf1cce4e5a63d7e58a215a0cbfcc",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -308,11 +308,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1791203292, "lastModified": 1775636079,
"narHash": "sha256-vuzVwvjeucSnwKwMBpyP8r5IzdrMKCHEdwTrRFwUN7I=", "narHash": "sha256-pc20NRoMdiar8oPQceQT47UUZMBTiMdUuWrYu2obUP0=",
"owner": "numtide", "owner": "numtide",
"repo": "treefmt-nix", "repo": "treefmt-nix",
"rev": "03d8ee1bcbc8f9638907bb79edb9673151d0e22b", "rev": "790751ff7fd3801feeaf96d7dc416a8d581265ba",
"type": "github" "type": "github"
}, },
"original": { "original": {
+1 -9
View File
@@ -36,7 +36,6 @@
./rust ./rust
./rust-esp32-c6 ./rust-esp32-c6
inputs.treefmt-nix.flakeModule
flake-parts.flakeModules.flakeModules flake-parts.flakeModules.flakeModules
# define the flake.templates option # define the flake.templates option
({lib, ...}: { ({lib, ...}: {
@@ -58,13 +57,6 @@
systems = ["aarch64-linux" "x86_64-linux" "aarch64-darwin"]; systems = ["aarch64-linux" "x86_64-linux" "aarch64-darwin"];
perSystem = {pkgs, ...}: { perSystem = {pkgs, ...}: {formatter = pkgs.alejandra;};
treefmt.programs = {
alejandra.enable = true; # nix
taplo.enable = true; # toml
rumdl-check.enable = true; # markdown
rumdl-format.enable = true; # markdown
};
};
}; };
} }
-8
View File
@@ -37,14 +37,6 @@
krantz.rust.devDeps = lib.mkOptionDefault (with pkgs; [ krantz.rust.devDeps = lib.mkOptionDefault (with pkgs; [
espflash espflash
]); ]);
krantz.rust.cargoArtifacts.extraAttrs = lib.mkOptionDefault {
doCheck = false;
};
krantz.rust.package.extraAttrs = lib.mkOptionDefault {
doCheck = false;
};
}; };
}); });
}; };
+2 -3
View File
@@ -2,14 +2,13 @@
runner = "espflash flash --monitor --chip esp32c6 --log-format defmt" runner = "espflash flash --monitor --chip esp32c6 --log-format defmt"
[env] [env]
DEFMT_LOG = "info" DEFMT_LOG="info"
[build] [build]
rustflags = [ rustflags = [
# Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.) # Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.)
# NOTE: May negatively impact performance of produced code # NOTE: May negatively impact performance of produced code
"-C", "-C", "force-frame-pointers",
"force-frame-pointers",
] ]
target = "riscv32imac-unknown-none-elf" target = "riscv32imac-unknown-none-elf"
-8
View File
@@ -1,8 +0,0 @@
[global]
disable = [
# line length limits
"MD013",
]
[MD057]
absolute-links = "relative_to_roots"
+9 -9
View File
@@ -1,8 +1,8 @@
[package] [package]
edition = "2024" edition = "2024"
name = "rust-esp32-c6" name = "rust-esp32-c6"
rust-version = "1.88" rust-version = "1.88"
version = "0.1.0" version = "0.1.0"
[[bin]] [[bin]]
name = "rust-esp32-c6" name = "rust-esp32-c6"
@@ -18,7 +18,7 @@ esp-rtos = { version = "0.3.0", features = [
"esp32c6", "esp32c6",
] } ] }
defmt = "1.0.1" defmt = "1.0.1"
esp-bootloader-esp-idf = { version = "0.5.0", features = ["defmt", "esp32c6"] } esp-bootloader-esp-idf = { version = "0.5.0", features = ["defmt", "esp32c6"] }
embassy-executor = { version = "0.10.0", features = ["defmt"] } embassy-executor = { version = "0.10.0", features = ["defmt"] }
@@ -32,7 +32,7 @@ esp-backtrace = { version = "0.19.0", features = [
esp-println = { version = "0.17.0", features = ["defmt-espflash", "esp32c6"] } esp-println = { version = "0.17.0", features = ["defmt-espflash", "esp32c6"] }
critical-section = "1.2.0" critical-section = "1.2.0"
static_cell = "2.1.1" static_cell = "2.1.1"
# For fine tuning these settings, please refer to https://doc.rust-lang.org/cargo/reference/profiles.html # For fine tuning these settings, please refer to https://doc.rust-lang.org/cargo/reference/profiles.html
@@ -42,7 +42,7 @@ static_cell = "2.1.1"
opt-level = "s" opt-level = "s"
[profile.release] [profile.release]
codegen-units = 1 # LLVM can perform better optimizations using a single thread codegen-units = 1 # LLVM can perform better optimizations using a single thread
debug = 2 # prefer slower builds but better debugging experience debug = 2 # prefer slower builds but better debugging experience
lto = 'fat' lto = 'fat'
opt-level = 's' opt-level = 's'
+1 -1
View File
@@ -7,7 +7,7 @@
flake-parts.url = "github:hercules-ci/flake-parts"; flake-parts.url = "github:hercules-ci/flake-parts";
project-templates = { project-templates = {
url = "git+https://git.krantz.one/reed/project-templates"; url = "git+file:///home/reed/code/project-templates";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-parts.follows = "flake-parts"; inputs.flake-parts.follows = "flake-parts";
}; };
+1 -1
View File
@@ -1,4 +1,4 @@
[toolchain] [toolchain]
channel = "stable" channel = "stable"
components = ["rust-src"] components = ["rust-src"]
targets = ["riscv32imac-unknown-none-elf"] targets = ["riscv32imac-unknown-none-elf"]
+33 -86
View File
@@ -25,54 +25,27 @@
}: let }: let
cfg = config.krantz.rust; cfg = config.krantz.rust;
manifest = (lib.importTOML "${cfg.srcFiltered}/Cargo.toml").package; src = cfg.srcFiltered;
manifest = (lib.importTOML "${src}/Cargo.toml").package;
craneLib = craneLib =
if hasToolchain if builtins.pathExists cfg.srcToolchain
then (inputs.crane.mkLib rustPkgs).overrideToolchain mkRustToolchain then
(inputs.crane.mkLib (pkgs.extend inputs.rust-overlay.overlays.default)).overrideToolchain (
p: p.rust-bin.fromRustupToolchainFile cfg.srcToolchain
)
else inputs.crane.mkLib pkgs; else inputs.crane.mkLib pkgs;
# Attrs to be included for all crane functions that build our crate buildInputs = cfg.runtimeDeps;
cargoBuildAttrs = let
# Include the standard library Cargo.lock if we have the "rust-src" component in our toolchain
cargoVendorDir =
lib.optionalAttrs (
hasToolchain
&& lib.pipe cfg.srcToolchain [
builtins.readFile
fromTOML
(t: t ? toolchain.components && builtins.elem "rust-src" t.toolchain.components)
]
) {
cargoVendorDir = craneLib.vendorMultipleCargoDeps {
inherit (craneLib.findCargoFiles cfg.srcFiltered) cargoConfigs;
cargoLockList = [
"${cfg.srcFiltered}/Cargo.lock"
"${(mkRustToolchain rustPkgs).passthru.availableComponents.rust-src}/lib/rustlib/src/rust/library/Cargo.lock"
];
};
};
in
rec {
src = cfg.srcFiltered;
buildInputs = cfg.runtimeDeps; # build dependencies
nativeBuildInputs = cfg.buildDeps;
nativeBuildInputs = cfg.buildDeps; # Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
# Build *just* the cargo dependencies, so we can reuse cargoArtifacts = craneLib.buildDepsOnly {
# all of that work (e.g. via cachix) when running in CI inherit src buildInputs nativeBuildInputs;
cargoArtifacts = craneLib.buildDepsOnly ({ };
inherit src buildInputs nativeBuildInputs;
}
// cargoVendorDir
// cfg.cargoArtifacts.extraAttrs);
}
// cargoVendorDir;
hasToolchain = cfg.srcToolchain != null && builtins.pathExists cfg.srcToolchain;
rustPkgs = pkgs.extend inputs.rust-overlay.overlays.default;
mkRustToolchain = p: p.rust-bin.fromRustupToolchainFile cfg.srcToolchain;
in { in {
options.krantz.rust = { options.krantz.rust = {
enable = lib.mkEnableOption "building a cargo project with crane"; enable = lib.mkEnableOption "building a cargo project with crane";
@@ -87,26 +60,14 @@
description = "A path to the filtered directory of the root of the crate."; description = "A path to the filtered directory of the root of the crate.";
type = lib.types.path; type = lib.types.path;
default = craneLib.cleanCargoSource cfg.src; default = craneLib.cleanCargoSource cfg.src;
defaultText = lib.literalExpression "config.krantz.rust.craneLib.cleanCargoSource cfg.src"; defaultText = lib.literalExpression "config.krantz.rust.craneLib cfg.src";
example = lib.literalExpression "./."; example = lib.literalExpression "./.";
}; };
srcToolchain = lib.mkOption { srcToolchain = lib.mkOption {
description = "A path to the rust-toolchain(.toml) file for the repo. Will use the toolchain from nixpkgs if the file does not exist."; description = "A path to the rust-toolchain(.toml) file for the repo. Will use the toolchain from nixpkgs if the file does not exist.";
type = lib.types.nullOr lib.types.path; type = lib.types.path;
default = default = "${if cfg.src != null then cfg.src else "/dev/null"}/rust-toolchain.toml";
if cfg.src != null defaultText = lib.literalExpression "cfg.src + \"/rust-toolchain.toml\"";
then cfg.src + "/rust-toolchain.toml"
else null;
defaultText =
lib.literalExpression
/*
nix
*/
''
if cfg.src != null
then cfg.src + "/rust-toolchain.toml"
else null;
'';
example = lib.literalExpression "./rust-toolchain"; example = lib.literalExpression "./rust-toolchain";
}; };
@@ -135,17 +96,6 @@
]; ];
}; };
cargoArtifacts = {
extraAttrs = lib.mkOption {
description = "Extra attributes to merge into buildDepsOnly. See https://crane.dev/API.html#cranelibbuilddepsonly";
type = lib.types.attrs;
default = {};
example = {
doCheck = false;
};
};
};
devShell = { devShell = {
enable = lib.mkEnableOption "a rust development environment" // {default = true;}; enable = lib.mkEnableOption "a rust development environment" // {default = true;};
@@ -193,8 +143,6 @@
nix = lib.mkEnableOption "formatting for nix files" // {default = true;}; nix = lib.mkEnableOption "formatting for nix files" // {default = true;};
rust = lib.mkEnableOption "formatting for rust files" // {default = true;}; rust = lib.mkEnableOption "formatting for rust files" // {default = true;};
toml = lib.mkEnableOption "formatting for toml files" // {default = true;};
markdown = lib.mkEnableOption "formatting for toml files" // {default = true;};
}; };
checks = { checks = {
@@ -216,7 +164,8 @@
# Available through 'nix develop' # Available through 'nix develop'
# Also can be activated automatically if direnv is installed on the system with 'direnv allow' # Also can be activated automatically if direnv is installed on the system with 'direnv allow'
devShells = lib.mkIf cfg.devShell.enable { devShells = lib.mkIf cfg.devShell.enable {
${cfg.devShell.name} = craneLib.devShell ({ ${cfg.devShell.name} =
craneLib.devShell {
inherit (self') checks; inherit (self') checks;
# extra tooling dependencies # extra tooling dependencies
@@ -224,35 +173,33 @@
inputsFrom = [self'.packages.${cfg.package.name}]; inputsFrom = [self'.packages.${cfg.package.name}];
} }
// cfg.devShell.extraAttrs); // cfg.devShell.extraAttrs;
}; };
# Your custom packages # Your custom packages
# Accessible through 'nix build', 'nix shell', 'nix run', etc # Accessible through 'nix build', 'nix shell', 'nix run', etc
packages = lib.mkIf cfg.package.enable { packages = lib.mkIf cfg.package.enable {
${cfg.package.name} = craneLib.buildPackage ({ ${cfg.package.name} =
craneLib.buildPackage {
inherit src buildInputs nativeBuildInputs cargoArtifacts;
} }
// cargoBuildAttrs // cfg.package.extraAttrs;
// cfg.package.extraAttrs);
}; };
# Formatter for nix files, available through 'nix fmt' # Formatter for nix files, available through 'nix fmt'
treefmt.programs = lib.mkIf cfg.formatter.enable { treefmt = lib.mkIf cfg.formatter.enable {
alejandra.enable = lib.mkIf cfg.formatter.nix true; programs.alejandra.enable = lib.mkIf cfg.formatter.nix true;
rustfmt = lib.mkIf cfg.formatter.rust { programs.rustfmt = lib.mkIf cfg.formatter.rust {
enable = true; enable = true;
edition = manifest.edition; edition = manifest.edition;
}; };
taplo.enable = lib.mkIf cfg.formatter.toml true;
rumdl-check.enable = lib.mkIf cfg.formatter.markdown true;
rumdl-format.enable = lib.mkIf cfg.formatter.markdown true;
}; };
checks = lib.mkIf cfg.checks.enable { checks = lib.mkIf cfg.checks.enable {
clippy = lib.mkIf cfg.checks.linter (craneLib.cargoClippy ({ clippy = lib.mkIf cfg.checks.linter (craneLib.cargoClippy {
cargoClippyExtraArgs = "-- --deny warnings"; inherit src buildInputs nativeBuildInputs cargoArtifacts;
} cargoClippyExtraArgs = "-- --deny warnings";
// cargoBuildAttrs)); });
}; };
}; };
}); });
-8
View File
@@ -1,8 +0,0 @@
[global]
disable = [
# line length limits
"MD013",
]
[MD057]
absolute-links = "relative_to_roots"
+1
View File
@@ -15,3 +15,4 @@ tracing-subscriber = "*"
clap = { version = "*", features = ["derive"] } clap = { version = "*", features = ["derive"] }
figment = { version = "*", features = ["toml", "env", "json"] } figment = { version = "*", features = ["toml", "env", "json"] }