Skip to content

Commit

Permalink
flake.nix, workflows: use Nix for clippy/fmt to start.
Browse files Browse the repository at this point in the history
Some of the clippy checks that fail with `--deny warnings` are likely
overzealous for our MSRV, but need to check.
  • Loading branch information
charlottia authored and kivikakk committed Nov 29, 2023
1 parent 840f14d commit 270c6ee
Show file tree
Hide file tree
Showing 4 changed files with 342 additions and 9 deletions.
17 changes: 8 additions & 9 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,16 @@ jobs:
run: cargo +stable build --locked --release --all-features
clippy_format:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
with:
submodules: true
- name: Obtain Rust
run: rustup override set ${{ matrix.rust }}
- uses: actions/checkout@v3
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4
- name: Run the Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v2
- name: Check clippy
run: rustup component add clippy && cargo clippy
run: nix build .#checks.x86_64-linux.comrak-clippy -L
- name: Check formatting
run: rustup component add rustfmt && cargo fmt -- --check
run: nix build .#checks.x86_64-linux.comrak-fmt -L
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ benches/cmark-gfm
benches/comrak-*
benches/pulldown-cmark
benches/markdown-it
/result*
198 changes: 198 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

135 changes: 135 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
description = "comrak";

inputs = {
nixpkgs.url = github:NixOS/nixpkgs/nixos-23.05;

crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};

fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-analyzer-src.follows = "";
};

flake-utils.url = "github:numtide/flake-utils";

advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
};

outputs = {
self,
nixpkgs,
crane,
fenix,
flake-utils,
advisory-db,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
};

inherit (pkgs) lib;

craneLib = crane.lib.${system};
src = craneLib.cleanCargoSource (craneLib.path ./.);

commonArgs = {
inherit src;

buildInputs =
[
]
++ lib.optionals pkgs.stdenv.isDarwin [
pkgs.libiconv
];
};

craneLibLLvmTools =
craneLib.overrideToolchain
(fenix.packages.${system}.complete.withComponents [
"cargo"
"llvm-tools"
"rustc"
]);

cargoArtifacts = craneLib.buildDepsOnly commonArgs;

comrak = craneLib.buildPackage (commonArgs
// {
inherit cargoArtifacts;

doCheck = false;
});
in {
checks =
{
inherit comrak;

comrak-clippy = craneLib.cargoClippy (commonArgs
// {
inherit cargoArtifacts;
# cargoClippyExtraArgs = "--lib --bins --examples --tests -- --deny warnings";
# XXX Not sure if we can fix all these and retain our current MSRV.
cargoClippyExtraArgs = "--lib --bins --examples --tests";
});

comrak-doc = craneLib.cargoDoc (commonArgs
// {
inherit cargoArtifacts;
});

comrak-fmt = craneLib.cargoFmt {
inherit src;
};

comrak-audit = craneLib.cargoAudit {
inherit src advisory-db;
};

comrak-nextest = craneLib.cargoNextest (commonArgs
// {
inherit cargoArtifacts;
partitions = 1;
partitionType = "count";
});
}
// lib.optionalAttrs (system == "x86_64-linux") {
comrak-coverage = craneLib.cargoTarpaulin (commonArgs
// {
inherit cargoArtifacts;
});
};

packages = {
default = comrak;
comrak-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs
// {
inherit cargoArtifacts;
});
};

apps.default = flake-utils.lib.mkApp {
drv = comrak;
};

formatter = pkgs.alejandra;

devShells.default = pkgs.mkShell {
inputsFrom = builtins.attrValues self.checks.${system};

nativeBuildInputs = with pkgs; [
cargo
rustc
];
};
});
}

0 comments on commit 270c6ee

Please sign in to comment.