Initial template
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
end_of_line = lf
|
||||||
|
|
||||||
|
[*.{c,h,cpp,hpp,cc,hh,cxx,hxx}]
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
[*.{java,scala,cs,fs,rs,go,py}]
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
[*.go]
|
||||||
|
indent_style = tab
|
||||||
|
|
||||||
|
[Makefile]
|
||||||
|
indent_style = tab
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
# Rust build artifacts
|
||||||
|
/target/
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# Nix
|
||||||
|
result
|
||||||
|
.direnv/
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v4.4.0
|
||||||
|
hooks:
|
||||||
|
- id: trailing-whitespace
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: check-yaml
|
||||||
|
- id: check-added-large-files
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
Thank you for considering contributing!
|
||||||
|
|
||||||
|
- Please follow the project coding style and directory structure.
|
||||||
|
- Submit issues or pull requests for bugs, features, or improvements.
|
||||||
|
- Add tests for new features where possible.
|
||||||
|
- Ensure your code builds and passes tests before submitting.
|
||||||
|
- Contributions are licensed under CC BY-SA 4.0.
|
||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "sample-rust-app"
|
||||||
|
version = "0.1.0"
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "sample-rust-app"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
Creative Commons Attribution-ShareAlike 4.0 International
|
||||||
|
|
||||||
|
<https://creativecommons.org/licenses/by-sa/4.0/>
|
||||||
|
|
||||||
|
You are free to:
|
||||||
|
|
||||||
|
- Share — copy and redistribute the material in any medium or format
|
||||||
|
- Adapt — remix, transform, and build upon the material for any purpose, even commercially.
|
||||||
|
|
||||||
|
Under the following terms:
|
||||||
|
|
||||||
|
- Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made.
|
||||||
|
- ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
|
||||||
|
|
||||||
|
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
|
||||||
|
|
||||||
|
See the full license at the link above.
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
build:
|
||||||
|
cargo build
|
||||||
|
|
||||||
|
run:
|
||||||
|
cargo run
|
||||||
|
|
||||||
|
test:
|
||||||
|
cargo test
|
||||||
|
|
||||||
|
clean:
|
||||||
|
cargo clean
|
||||||
|
|
||||||
|
.PHONY: build run test clean
|
||||||
|
|
||||||
|
|
||||||
|
# Flatpak build target
|
||||||
|
.PHONY:
|
||||||
|
# Standardized code quality targets
|
||||||
|
fmt format:
|
||||||
|
cargo fmt
|
||||||
|
|
||||||
|
lint:
|
||||||
|
cargo clippy -- -D warnings 2>/dev/null || true
|
||||||
|
|
||||||
|
check: fmt lint
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# Coding Agent Instructions
|
||||||
|
|
||||||
|
This project is intended for educational purposes. To support this, please adhere to the following guidelines:
|
||||||
|
|
||||||
|
## Allowed Actions
|
||||||
|
- **Environment Maintenance:** Feel free to update Nix flakes, shell configurations, or other environment-related setup.
|
||||||
|
- **Project Housekeeping:** Maintain a standard project layout, keep `README.md` up-to-date, and clean up temporary or build-related files.
|
||||||
|
- **Documentation:** Add comments, manage project documentation, and add links to relevant external resources.
|
||||||
|
|
||||||
|
## Restricted Actions
|
||||||
|
- **Source Code Editing:** You are NOT allowed to edit the executable source code (`src/` directory) except to improve documentation..
|
||||||
|
- **Code Generation:** Do not provide example code unless explicitly asked by the user.
|
||||||
|
|
||||||
|
## Communication Guidelines
|
||||||
|
- **Educational Focus:** When asked about code, prioritize explaining the concepts and providing advice over writing code.
|
||||||
|
- **Documentation Links:** Always include links to official language or library documentation for references.
|
||||||
+27
@@ -0,0 +1,27 @@
|
|||||||
|
{pkgs}: let
|
||||||
|
inherit (pkgs) lib;
|
||||||
|
templateName = builtins.baseNameOf (toString ./.);
|
||||||
|
in {
|
||||||
|
${templateName} = pkgs.stdenvNoCC.mkDerivation {
|
||||||
|
pname = templateName;
|
||||||
|
version = "0.1.0";
|
||||||
|
src = ./.;
|
||||||
|
dontBuild = true;
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/share/${templateName}
|
||||||
|
if [ -d src ]; then
|
||||||
|
cp -r src $out/share/${templateName}/
|
||||||
|
fi
|
||||||
|
for f in README.md project.toml flake.nix default.nix shell.nix Makefile .editorconfig .gitignore; do
|
||||||
|
if [ -f "$f" ]; then
|
||||||
|
cp "$f" $out/share/${templateName}/
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
meta = with lib; {
|
||||||
|
description = "Template project: ${templateName}";
|
||||||
|
license = licenses.unfreeRedistributable;
|
||||||
|
platforms = platforms.all;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
{
|
||||||
|
description = "A Nix-flake-based Rust development environment";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
fenix = {
|
||||||
|
url = "github:nix-community/fenix";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = inputs @ {self, ...}: let
|
||||||
|
supportedSystems = [
|
||||||
|
"x86_64-linux"
|
||||||
|
"aarch64-linux"
|
||||||
|
"aarch64-darwin"
|
||||||
|
];
|
||||||
|
forEachSupportedSystem = f:
|
||||||
|
inputs.nixpkgs.lib.genAttrs supportedSystems (
|
||||||
|
system:
|
||||||
|
f {
|
||||||
|
pkgs = import inputs.nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
overlays = [
|
||||||
|
inputs.self.overlays.default
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
in {
|
||||||
|
formatter = forEachSupportedSystem ({pkgs}: pkgs.rustfmt);
|
||||||
|
|
||||||
|
templates = {
|
||||||
|
default = {
|
||||||
|
path = ./.;
|
||||||
|
description = "Rust dev environment using fenix; includes a skeletal Cargo project and packaged helper app";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
overlays.default = _final: prev: {
|
||||||
|
rustToolchain = with inputs.fenix.packages.${prev.stdenv.hostPlatform.system};
|
||||||
|
combine (
|
||||||
|
with stable; [
|
||||||
|
clippy
|
||||||
|
rustc
|
||||||
|
cargo
|
||||||
|
rustfmt
|
||||||
|
rust-src
|
||||||
|
]
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
devShells = forEachSupportedSystem (
|
||||||
|
{pkgs}: {
|
||||||
|
default = pkgs.mkShell {
|
||||||
|
packages = with pkgs; [
|
||||||
|
rustToolchain
|
||||||
|
git
|
||||||
|
gnumake
|
||||||
|
alejandra
|
||||||
|
statix
|
||||||
|
deadnix
|
||||||
|
editorconfig-checker
|
||||||
|
openssl
|
||||||
|
pkg-config
|
||||||
|
cargo-deny
|
||||||
|
cargo-edit
|
||||||
|
cargo-watch
|
||||||
|
cargo-generate
|
||||||
|
rust-analyzer
|
||||||
|
rustup
|
||||||
|
# Embedded Rust tooling
|
||||||
|
probe-rs-tools
|
||||||
|
espflash
|
||||||
|
openocd
|
||||||
|
minicom
|
||||||
|
# RP2040 UF2 workflows
|
||||||
|
elf2uf2-rs
|
||||||
|
picotool
|
||||||
|
avrdude
|
||||||
|
pkgsCross.avr.buildPackages.libc
|
||||||
|
pkgsCross.avr.buildPackages.gcc
|
||||||
|
ravedude
|
||||||
|
pre-commit
|
||||||
|
];
|
||||||
|
|
||||||
|
env = {
|
||||||
|
# Required by rust-analyzer
|
||||||
|
RUST_SRC_PATH = "${pkgs.rustToolchain}/lib/rustlib/src/rust/library";
|
||||||
|
};
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
# Initialize git repository if not already present
|
||||||
|
if [ ! -d .git ]; then
|
||||||
|
git init
|
||||||
|
echo "✓ Initialized git repository"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ensure user's Cargo-installed binaries are available
|
||||||
|
export PATH="$HOME/.cargo/bin:$PATH"
|
||||||
|
|
||||||
|
if command -v rustup >/dev/null 2>&1; then
|
||||||
|
echo "Ensuring common embedded Rust targets are available (idempotent)..."
|
||||||
|
rustup target add thumbv6m-none-eabi >/dev/null 2>&1 || true # Cortex-M0/M0+ (RP2040)
|
||||||
|
rustup target add thumbv7em-none-eabihf >/dev/null 2>&1 || true # Cortex-M4F/M7F (many STM32/nRF52)
|
||||||
|
rustup target add riscv32imc-unknown-none-elf >/dev/null 2>&1 || true
|
||||||
|
rustup target add riscv32imac-unknown-none-elf >/dev/null 2>&1 || true # ESP32-C3 class
|
||||||
|
echo "Note: ESP32 Xtensa targets require espup/custom toolchains (see esp-rs)."
|
||||||
|
fi
|
||||||
|
echo "[rust-template] Welcome to the Rust dev shell!"
|
||||||
|
echo "Tools: cargo, rustc, clippy, rustfmt, rust-analyzer, probe-rs, espflash, openocd, minicom, elf2uf2-rs, picotool, avrdude, ravedude"
|
||||||
|
echo "Run 'cargo build' to build, or 'nix run .#dev-helper' for a tool summary."
|
||||||
|
echo "See README.md for usage."
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
packages = forEachSupportedSystem (
|
||||||
|
{pkgs}: {
|
||||||
|
# Build the skeletal Cargo project
|
||||||
|
default = pkgs.rustPlatform.buildRustPackage {
|
||||||
|
pname = "sample-rust-app";
|
||||||
|
version = "0.1.0";
|
||||||
|
src = ./.;
|
||||||
|
cargoLock.lockFile = ./Cargo.lock;
|
||||||
|
};
|
||||||
|
|
||||||
|
devHelper = pkgs.writeShellScriptBin "dev-helper" ''
|
||||||
|
echo "Rust toolchain available:"
|
||||||
|
command -v cargo >/dev/null 2>&1 && cargo --version || true
|
||||||
|
command -v rustc >/dev/null 2>&1 && rustc --version || true
|
||||||
|
echo "This binary is built by Nix (packages.default)."
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
apps = forEachSupportedSystem (
|
||||||
|
{pkgs}: {
|
||||||
|
default = {
|
||||||
|
type = "app";
|
||||||
|
program = pkgs.lib.getExe self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
||||||
|
};
|
||||||
|
dev-helper = {
|
||||||
|
type = "app";
|
||||||
|
program = pkgs.lib.getExe self.packages.${pkgs.stdenv.hostPlatform.system}.devHelper;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"app-id": "org.example.rustdevshell",
|
||||||
|
"runtime": "org.freedesktop.Platform",
|
||||||
|
"runtime-version": "23.08",
|
||||||
|
"sdk": "org.freedesktop.Sdk",
|
||||||
|
"command": "rustdevshell-app",
|
||||||
|
"modules": [
|
||||||
|
{
|
||||||
|
"name": "rustdevshell-app",
|
||||||
|
"buildsystem": "simple",
|
||||||
|
"build-commands": [
|
||||||
|
"cargo build --release"
|
||||||
|
],
|
||||||
|
"sources": [
|
||||||
|
{
|
||||||
|
"type": "dir",
|
||||||
|
"path": ".."
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[project]
|
||||||
|
name = "rust-template"
|
||||||
|
description = "A reusable Nix flake template for Rust development."
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["gooba42 <your@email>"]
|
||||||
|
license = "MIT"
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{pkgs ? import <nixpkgs> {}}:
|
||||||
|
pkgs.mkShell {
|
||||||
|
buildInputs = [
|
||||||
|
pkgs.rustc
|
||||||
|
pkgs.cargo
|
||||||
|
pkgs.rustfmt
|
||||||
|
pkgs.clippy
|
||||||
|
pkgs.rust-analyzer
|
||||||
|
];
|
||||||
|
shellHook = ''
|
||||||
|
echo "[shell.nix] Legacy shell for Rust dev. Use 'nix develop' for full flake support."
|
||||||
|
'';
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("Hello from Rust skeletal app. Edit src/main.rs to get started!");
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
#[test]
|
||||||
|
fn test_sample() {
|
||||||
|
assert_eq!(1, 1);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user