From aa666c548734723250d2ef4e8e50330492cf8da1 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Thu, 12 Jun 2025 08:31:24 -0400 Subject: [PATCH] Initial commit. --- .envrc | 1 + .forgejo/workflows/test.yml | 28 +++++++++++++++++ .gitignore | 2 ++ .pre-commit-config.yaml | 10 ++++++ Cargo.toml | 6 ++++ flake.lock | 61 +++++++++++++++++++++++++++++++++++++ flake.nix | 38 +++++++++++++++++++++++ src/lib.rs | 14 +++++++++ 8 files changed, 160 insertions(+) create mode 100644 .envrc create mode 100644 .forgejo/workflows/test.yml create mode 100644 .gitignore create mode 100644 .pre-commit-config.yaml create mode 100644 Cargo.toml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 src/lib.rs diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.forgejo/workflows/test.yml b/.forgejo/workflows/test.yml new file mode 100644 index 0000000..3f92221 --- /dev/null +++ b/.forgejo/workflows/test.yml @@ -0,0 +1,28 @@ +name: Test + +on: + pull_request: + push: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: ~/.cache/pre-commit + key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Install Nix + uses: https://github.com/cachix/install-nix-action@v31 + - name: Test + run: nix develop --command pre-commit run -a diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0e71e34 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +.direnv/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..020b494 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +fail_fast: true +repos: + - repo: https://github.com/doublify/pre-commit-rust + rev: v1.0 + hooks: + - id: fmt + args: [--, --check] + - id: cargo-check + args: [--bins, --examples] + - id: clippy diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..fa83b94 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "supermetal_assignment" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4f8a8c0 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1749619289, + "narHash": "sha256-qX6gXVjaCXXbcn6A9eSLUf8Fm07MgPGe5ir3++y2O1Q=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f72be405a10668b8b00937b452f2145244103ebc", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..66aff5f --- /dev/null +++ b/flake.nix @@ -0,0 +1,38 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + utils, + }: + utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + devShell = + with pkgs; + mkShell.override { stdenv = pkgs.clangStdenv; } { + nativeBuildInputs = [ + pre-commit + cargo + cargo-watch + rustc + rustfmt + rustPackages.clippy + llvmPackages.bintools + ]; + shellHook = '' + pre-commit install + ''; + RUST_SRC_PATH = rustPlatform.rustLibSrc; + }; + } + ); +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..b93cf3f --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,14 @@ +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +}