Skip to content

Commit

Permalink
feat: tooling (#18)
Browse files Browse the repository at this point in the history
* feat: add rust tooling config

* feat: add generic tooling

* feat: add nix tooling

* feat: justfile setup
  • Loading branch information
cmdoret authored Jun 19, 2024
1 parent 0863e1a commit f3aa5f8
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake ./nix#default
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"printWidth": 80,
"tabWidth": 2,
"semi": false,
"singleQuote": false,
"overrides": [
{ "files": "*.md", "options": { "proseWrap": "always", "tabWidth": 2 } }
]
}
25 changes: 25 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -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
92 changes: 92 additions & 0 deletions nix/flake.nix
Original file line number Diff line number Diff line change
@@ -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.<system>.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;
};
};
}
);
}
4 changes: 4 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
channel = "nightly-2024-06-17"
components = [ "rustfmt", "rust-analyzer", "miri", "rust-docs", "clippy", "rust-src"]
profile = "default"
3 changes: 3 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
edition = "2021"
reorder_imports = true
imports_granularity = "Crate"

0 comments on commit f3aa5f8

Please sign in to comment.