commit f64c01ab6f08d63ac223ed3c3e45faddd0827d67 Author: Patrick Auernig Date: Wed Apr 24 16:53:15 2024 +0200 Add rust workspace template diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e07cc71 --- /dev/null +++ b/flake.nix @@ -0,0 +1,12 @@ +{ + description = "Various project templates"; + + outputs = { nixpkgs, ... }: { + templates = { + rust-workspace = { + path = ./templates/rust/workspace; + description = "Cargo based rust project using a virtual workspace"; + }; + }; + }; +} diff --git a/templates/rust/workspace/.editorconfig b/templates/rust/workspace/.editorconfig new file mode 100644 index 0000000..c1e2c64 --- /dev/null +++ b/templates/rust/workspace/.editorconfig @@ -0,0 +1,12 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/templates/rust/workspace/.envrc b/templates/rust/workspace/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/templates/rust/workspace/.envrc @@ -0,0 +1 @@ +use flake diff --git a/templates/rust/workspace/.gitignore b/templates/rust/workspace/.gitignore new file mode 100644 index 0000000..46b5d68 --- /dev/null +++ b/templates/rust/workspace/.gitignore @@ -0,0 +1,2 @@ +/target +.envrc diff --git a/templates/rust/workspace/Cargo.toml b/templates/rust/workspace/Cargo.toml new file mode 100644 index 0000000..06f17a7 --- /dev/null +++ b/templates/rust/workspace/Cargo.toml @@ -0,0 +1,15 @@ +[workspace] +resolver = "2" +members = [ + "./crates/mylib", +] + + +[workspace.package] +edition = "2021" +version = "0.1.0" +# license-file = "LICENSE" +# authors = [] + + +[workspace.dependencies] diff --git a/templates/rust/workspace/crates/mylib/Cargo.toml b/templates/rust/workspace/crates/mylib/Cargo.toml new file mode 100644 index 0000000..2300f61 --- /dev/null +++ b/templates/rust/workspace/crates/mylib/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "mylib" +version.workspace = true +edition.workspace = true +# license.workspace = true +# authors.workspace = true +publish = false + + +[features] +default = [] + + +[dependencies] diff --git a/templates/rust/workspace/crates/mylib/src/lib.rs b/templates/rust/workspace/crates/mylib/src/lib.rs new file mode 100644 index 0000000..e69de29 diff --git a/templates/rust/workspace/flake.nix b/templates/rust/workspace/flake.nix new file mode 100644 index 0000000..eeb52ab --- /dev/null +++ b/templates/rust/workspace/flake.nix @@ -0,0 +1,38 @@ +{ + description = "@project_description@"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + + outputs = { nixpkgs, rust-overlay, ... }: + let + system = "x86_64-linux"; + + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + + rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + rustNightlyToolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.minimal.override { + extensions = [ "rustfmt" ]; + targets = [ "x86_64-unknown-linux-gnu" ]; + }); + + + buildTools = with pkgs; [ + rustToolchain + rustNightlyToolchain + pkg-config + ]; + + devShell = pkgs.mkShell { + name = "@project_name@"; + buildInputs = buildTools; + }; + in { + devShells.${system}.default = devShell; + }; +} diff --git a/templates/rust/workspace/rust-toolchain.toml b/templates/rust/workspace/rust-toolchain.toml new file mode 100644 index 0000000..cc8f0d4 --- /dev/null +++ b/templates/rust/workspace/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "stable" +components = ["clippy", "rust-analyzer", "rust-src"] +targets = ["x86_64-unknown-linux-gnu"] +profile = "minimal" # includes rustc, cargo, and rust-std diff --git a/templates/rust/workspace/rustfmt.toml b/templates/rust/workspace/rustfmt.toml new file mode 100644 index 0000000..b99c2a4 --- /dev/null +++ b/templates/rust/workspace/rustfmt.toml @@ -0,0 +1,18 @@ +edition = "2021" + +# Just enforce it here as well instead of relying on editorconfig alone +hard_tabs = false +tab_spaces = 4 +newline_style = "Unix" + +imports_granularity = "Module" +group_imports = "StdExternalCrate" + +force_multiline_blocks = false +fn_single_line = false +comment_width = 100 +wrap_comments = true +hex_literal_case = "Upper" +blank_lines_upper_bound = 2 +overflow_delimited_expr = true +reorder_impl_items = true