From bb400e412863d3de2584d87384dd0dc1ccc2e74c Mon Sep 17 00:00:00 2001 From: Kiran Shila Date: Fri, 5 Apr 2024 14:31:08 -0700 Subject: [PATCH] nixify, bump versions --- .envrc | 1 + .github/workflows/ci.yml | 121 +++++++++++++++++++-------------------- .gitignore | 1 + Cargo.toml | 9 ++- flake.lock | 85 +++++++++++++++++++++++++++ flake.nix | 51 +++++++++++++++++ 6 files changed, 201 insertions(+), 67 deletions(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..07fd338 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake . \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33ba0ab..b339383 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,75 +1,72 @@ -on: push -name: CI +name: Check and build the library using Nix +on: + push: + branches: + - main + tags: + - "v*.*.*" + pull_request: + branches: + - main + jobs: - lint: - name: Lint + check: + name: Check/Lint runs-on: ubuntu-latest - env: - RUSTFLAGS: -D warnings - CARGO_TERM_COLOR: always steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - # We need nightly for fmt - toolchain: nightly - override: true - components: rustfmt, clippy - - uses: Swatinem/rust-cache@v1 - - name: Lint (clippy) - uses: actions-rs/cargo@v1 + - name: git checkout + uses: actions/checkout@v3 + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + - name: Check Nixpkgs inputs + uses: DeterminateSystems/flake-checker-action@main with: - command: clippy - args: --all-targets --all-features - - name: Lint (rustfmt) - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all --check + fail-mode: true + + # Nix-specific logic begins here + - name: Check Rust formatting + run: | + nix develop --command cargo fmt --all --check + - name: Check Clippy lints + run: | + nix develop --command cargo clippy --all-targets + - name: Check spelling + run: | + nix develop --command \ + codespell \ + --skip target,.git \ + --ignore-words-list crate - build: - name: Build and test - # We don't need to build on windows, do we? + test_and_build: + name: Test and build library + needs: check runs-on: ubuntu-latest - strategy: - matrix: - rust-version: [stable, 1.57, nightly] - fail-fast: false - env: - RUSTFLAGS: -D warnings - CARGO_TERM_COLOR: always steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust-version }} - override: true - components: llvm-tools-preview - - uses: Swatinem/rust-cache@v1 - - name: Build all targets with all features - uses: actions-rs/cargo@v1 - with: - command: build - args: --all-targets --all-features - - name: Doctests - uses: actions-rs/cargo@v1 - with: - command: test - args: --doc --all-features - - name: Install latest nextest release - uses: taiki-e/install-action@nextest - - name: Test with latest nextest release - uses: actions-rs/cargo@v1 + - name: git checkout + uses: actions/checkout@v3 + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + - name: Set up Rust cache + uses: actions/cache@v3 with: - command: nextest - args: run --all-features - - name: Install cargo-llvm-cov - uses: taiki-e/install-action@cargo-llvm-cov + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: sigproc_filterbank-${{ hashFiles('**/Cargo.lock') }} + - name: Test library + run: | + nix develop --command cargo test + - name: Build library + run: | + nix develop --command cargo build - name: Generate code coverage - if: startsWith(matrix.rust-version, 'stable') - run: cargo llvm-cov nextest --all-features --workspace --lcov --output-path lcov.info + run: nix develop --command cargo llvm-cov --workspace --lcov --output-path lcov.info - name: Upload coverage to Codecov - if: startsWith(matrix.rust-version, 'stable') uses: codecov/codecov-action@v3 with: files: lcov.info diff --git a/.gitignore b/.gitignore index 4fffb2f..afecdba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target /Cargo.lock +.direnv \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 5f351b3..34041e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sigproc_filterbank" -version = "0.3.0" +version = "0.3.1" edition = "2021" rust-version = "1.57.0" license = "Apache-2.0 OR MIT" @@ -9,10 +9,9 @@ description = "A parser and serializer for SIGPROC pulsar filterbank files" homepage = "https://github.com/kiranshila/sigproc_filterbank" readme = "README.md" keywords = ["astronomy", "parser", "pulsars"] -categories = ["encoding","parser-implementations"] - +categories = ["encoding", "parser-implementations"] [dependencies] -nom = "7.1" -thiserror = "1.0" +nom = "7" +thiserror = "1" ux = "0.1" diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..948f076 --- /dev/null +++ b/flake.lock @@ -0,0 +1,85 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1712192574, + "narHash": "sha256-LbbVOliJKTF4Zl2b9salumvdMXuQBr2kuKP5+ZwbYq4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f480f9d09e4b4cf87ee6151eba068197125714de", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1712283118, + "narHash": "sha256-aZhKaT1qiwlRjdwd2rcPfcrYqpMMnOe9TMKoihEcw50=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "7790ac860cc3b2bad7f6f4759f4138c79bcb2988", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..1ef3c2f --- /dev/null +++ b/flake.nix @@ -0,0 +1,51 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; + }; + }; + + outputs = { + nixpkgs, + flake-utils, + rust-overlay, + ... + }: + flake-utils.lib.eachDefaultSystem (system: let + overlays = [(import rust-overlay)]; + pkgs = import nixpkgs {inherit system overlays;}; + + runCiLocally = pkgs.writeScriptBin "ci-local" '' + echo "Checking Rust formatting..." + cargo fmt --check + + echo "Checking clippy..." + cargo clippy --all-targets + + echo "Testing Rust code..." + cargo test + ''; + + nativeBuildInputs = with pkgs; []; + buildInputs = + [runCiLocally] + ++ (with pkgs; [ + # Rust stuff, some stuff dev-only + (rust-bin.nightly.latest.default.override { + extensions = ["rust-src" "rust-analyzer"]; + }) + + # Linting support + alejandra + ]); + in + with pkgs; { + devShells.default = mkShell {inherit buildInputs nativeBuildInputs;}; + }); +}