diff --git a/templates/rust/crate-lib/.editorconfig b/templates/rust/crate-lib/.editorconfig new file mode 100644 index 0000000..c1e2c64 --- /dev/null +++ b/templates/rust/crate-lib/.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/crate-lib/.envrc b/templates/rust/crate-lib/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/templates/rust/crate-lib/.envrc @@ -0,0 +1 @@ +use flake diff --git a/templates/rust/crate-lib/.gitignore b/templates/rust/crate-lib/.gitignore new file mode 100644 index 0000000..46b5d68 --- /dev/null +++ b/templates/rust/crate-lib/.gitignore @@ -0,0 +1,2 @@ +/target +.envrc diff --git a/templates/rust/crate-lib/Cargo.toml b/templates/rust/crate-lib/Cargo.toml new file mode 100644 index 0000000..e69de29 diff --git a/templates/rust/crate-lib/flake.nix b/templates/rust/crate-lib/flake.nix new file mode 100644 index 0000000..cd1a87d --- /dev/null +++ b/templates/rust/crate-lib/flake.nix @@ -0,0 +1,44 @@ +{ + description = "@project_description@"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + rust-overlay ={ + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { nixpkgs, rust-overlay, ... }: + let + system = "x86_64-linux"; + + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { + inherit system overlays; + }; + + rust = pkgs.rust-bin; + + rustToolchain = rust.fromRustupToolchainFile ./rust-toolchain.toml; + rustNightlyToolchain = rust.selectLatestNightlyWith(tc: tc.minimal.override { + extensions = [ "rustfmt" ]; + targets = [ "x86_64-unknown-linux-gnu" ]; + }) ; + + buildTools = [ + rustToolchain + rustNightlyToolchain + ]; + + devShell = pkgs.mkShell { + name = "@project_name@"; + buildInputs = buildTools; + packages = with pkgs; [ + rust-analyzer + ]; + }; + in { + devShells.${system}.default = devShell; + }; +} diff --git a/templates/rust/crate-lib/rust-toolchain.toml b/templates/rust/crate-lib/rust-toolchain.toml new file mode 100644 index 0000000..cc8f0d4 --- /dev/null +++ b/templates/rust/crate-lib/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/crate-lib/rustfmt.toml b/templates/rust/crate-lib/rustfmt.toml new file mode 100644 index 0000000..b99c2a4 --- /dev/null +++ b/templates/rust/crate-lib/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 diff --git a/templates/rust/crate-lib/src/lib.rs b/templates/rust/crate-lib/src/lib.rs new file mode 100644 index 0000000..e69de29