From f3aa5f87af08bb3aeff5e344efd406a7154dffb3 Mon Sep 17 00:00:00 2001 From: Cyril Matthey-Doret Date: Wed, 19 Jun 2024 16:14:25 +0200 Subject: [PATCH] feat: tooling (#18) * feat: add rust tooling config * feat: add generic tooling * feat: add nix tooling * feat: justfile setup --- .editorconfig | 17 +++++++++ .envrc | 1 + .prettierrc | 9 +++++ justfile | 25 ++++++++++++ nix/flake.nix | 92 +++++++++++++++++++++++++++++++++++++++++++++ rust-toolchain.toml | 4 ++ rustfmt.toml | 3 ++ 7 files changed, 151 insertions(+) create mode 100644 .editorconfig create mode 100644 .envrc create mode 100644 .prettierrc create mode 100644 justfile create mode 100644 nix/flake.nix create mode 100644 rust-toolchain.toml create mode 100644 rustfmt.toml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..004129e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 + +[*.{json,yaml,yml}] +indent_size = 2 + +[*.nix] +indent_size = 2 diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..1e8b857 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake ./nix#default diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..e480fd5 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,9 @@ +{ + "printWidth": 80, + "tabWidth": 2, + "semi": false, + "singleQuote": false, + "overrides": [ + { "files": "*.md", "options": { "proseWrap": "always", "tabWidth": 2 } } + ] +} diff --git a/justfile b/justfile new file mode 100644 index 0000000..efc1813 --- /dev/null +++ b/justfile @@ -0,0 +1,25 @@ +set positional-arguments +set shell := ["bash", "-cue"] +comp_dir := justfile_directory() +root_dir := `git rev-parse --show-toplevel` + +# General Variables: +# You can chose either "podman" or "docker" +container_mgr := "podman" + +# Build the executable. +build *args: + cd "{{root_dir}}" && cargo build "${@:1}" + +# Watch source and continuously build the executable. +watch: + cd "{{root_dir}}" && cargo watch -x 'build' + +# Run the executable. +run: + cd "{{root_dir}}" && cargo run "${@:1}" + +format: + cd "{{root_dir}}" && \ + {{container_mgr}} run -v "{{root_dir}}:/repo" -v "$(pwd):/workspace" -w "/workspace" \ + instrumentisto/rust:nightly-alpine cargo fmt -- --config-path /repo diff --git a/nix/flake.nix b/nix/flake.nix new file mode 100644 index 0000000..48d20e0 --- /dev/null +++ b/nix/flake.nix @@ -0,0 +1,92 @@ +{ + description = "rdfpipe-rs"; + + nixConfig = { + substituters = [ + # Add here some other mirror if needed. + "https://cache.nixos.org/" + ]; + extra-substituters = [ + # Nix community's cache server + "https://nix-community.cachix.org" + ]; + extra-trusted-public-keys = [ + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + ]; + }; + + inputs = { + # Nixpkgs + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + # You can access packages and modules from different nixpkgs revs + # at the same time. Here's an working example: + nixpkgsStable.url = "github:nixos/nixpkgs/nixos-23.11"; + # Also see the 'stable-packages' overlay at 'overlays/default.nix'. + + flake-utils.url = "github:numtide/flake-utils"; + + # The Rust overlay to include the latest toolchain. + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; + }; + }; + + outputs = { + self, + nixpkgs, + nixpkgsStable, + flake-utils, + rust-overlay, + ... + } @ inputs: + flake-utils.lib.eachDefaultSystem + # Creates an attribute map `{ devShells..default = ...}` + # by calling this function: + ( + system: let + overlays = [(import rust-overlay)]; + + # Import nixpkgs and load it into pkgs. + pkgs = import nixpkgs { + inherit system overlays; + }; + + # Set the rust toolchain from the `rust-toolchain.toml`. + rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ../rust-toolchain.toml; + + # Things needed only at compile-time. + nativeBuildInputsBasic = with pkgs; [ + rustToolchain + cargo-watch + + just + parallel + podman + ]; + + # Things needed only at compile-time. + nativeBuildInputsDev = []; + + # Things needed at runtime. + buildInputs = []; + in + with pkgs; { + devShells = { + default = mkShell { + inherit buildInputs; + nativeBuildInputs = nativeBuildInputsBasic ++ nativeBuildInputsDev; + }; + + ci = mkShell { + inherit buildInputs; + nativeBuildInputs = nativeBuildInputsBasic; + }; + }; + } + ); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..782c141 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "nightly-2024-06-17" +components = [ "rustfmt", "rust-analyzer", "miri", "rust-docs", "clippy", "rust-src"] +profile = "default" diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..9aeb106 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,3 @@ +edition = "2021" +reorder_imports = true +imports_granularity = "Crate"