Skip to content

Commit f251d74

Browse files
committed
flake.nix, workflows: use Nix for clippy/fmt to start.
Some of the clippy checks that fail with `--deny warnings` are likely overzealous for our MSRV, but need to check.
1 parent 72b5209 commit f251d74

File tree

4 files changed

+342
-9
lines changed

4 files changed

+342
-9
lines changed

.github/workflows/rust.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,16 @@ jobs:
7979
run: cargo +stable build --locked --release --all-features
8080
clippy_format:
8181
runs-on: ubuntu-latest
82-
strategy:
83-
matrix:
84-
rust:
85-
- stable
8682
steps:
87-
- uses: actions/checkout@v1
83+
- uses: actions/checkout@v3
8884
with:
8985
submodules: true
90-
- name: Obtain Rust
91-
run: rustup override set ${{ matrix.rust }}
86+
- uses: actions/checkout@v3
87+
- name: Install Nix
88+
uses: DeterminateSystems/nix-installer-action@v4
89+
- name: Run the Magic Nix Cache
90+
uses: DeterminateSystems/magic-nix-cache-action@v2
9291
- name: Check clippy
93-
run: rustup component add clippy && cargo clippy
92+
run: nix build .#checks.x86_64-linux.comrak-clippy -L
9493
- name: Check formatting
95-
run: rustup component add rustfmt && cargo fmt -- --check
94+
run: nix build .#checks.x86_64-linux.comrak-fmt -L

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ benches/cmark-gfm
88
benches/comrak-*
99
benches/pulldown-cmark
1010
benches/markdown-it
11+
/result*

flake.lock

Lines changed: 198 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
{
2+
description = "comrak";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
6+
7+
crane = {
8+
url = "github:ipetkov/crane";
9+
inputs.nixpkgs.follows = "nixpkgs";
10+
};
11+
12+
fenix = {
13+
url = "github:nix-community/fenix";
14+
inputs.nixpkgs.follows = "nixpkgs";
15+
inputs.rust-analyzer-src.follows = "";
16+
};
17+
18+
flake-utils.url = "github:numtide/flake-utils";
19+
20+
advisory-db = {
21+
url = "github:rustsec/advisory-db";
22+
flake = false;
23+
};
24+
};
25+
26+
outputs = {
27+
self,
28+
nixpkgs,
29+
crane,
30+
fenix,
31+
flake-utils,
32+
advisory-db,
33+
...
34+
}:
35+
flake-utils.lib.eachDefaultSystem (system: let
36+
pkgs = import nixpkgs {
37+
inherit system;
38+
};
39+
40+
inherit (pkgs) lib;
41+
42+
craneLib = crane.lib.${system};
43+
src = craneLib.cleanCargoSource (craneLib.path ./.);
44+
45+
commonArgs = {
46+
inherit src;
47+
48+
buildInputs =
49+
[
50+
]
51+
++ lib.optionals pkgs.stdenv.isDarwin [
52+
pkgs.libiconv
53+
];
54+
};
55+
56+
craneLibLLvmTools =
57+
craneLib.overrideToolchain
58+
(fenix.packages.${system}.complete.withComponents [
59+
"cargo"
60+
"llvm-tools"
61+
"rustc"
62+
]);
63+
64+
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
65+
66+
comrak = craneLib.buildPackage (commonArgs
67+
// {
68+
inherit cargoArtifacts;
69+
70+
doCheck = false;
71+
});
72+
in {
73+
checks =
74+
{
75+
inherit comrak;
76+
77+
comrak-clippy = craneLib.cargoClippy (commonArgs
78+
// {
79+
inherit cargoArtifacts;
80+
# cargoClippyExtraArgs = "--lib --bins --examples --tests -- --deny warnings";
81+
# XXX Not sure if we can fix all these and retain our current MSRV.
82+
cargoClippyExtraArgs = "--lib --bins --examples --tests";
83+
});
84+
85+
comrak-doc = craneLib.cargoDoc (commonArgs
86+
// {
87+
inherit cargoArtifacts;
88+
});
89+
90+
comrak-fmt = craneLib.cargoFmt {
91+
inherit src;
92+
};
93+
94+
comrak-audit = craneLib.cargoAudit {
95+
inherit src advisory-db;
96+
};
97+
98+
comrak-nextest = craneLib.cargoNextest (commonArgs
99+
// {
100+
inherit cargoArtifacts;
101+
partitions = 1;
102+
partitionType = "count";
103+
});
104+
}
105+
// lib.optionalAttrs (system == "x86_64-linux") {
106+
comrak-coverage = craneLib.cargoTarpaulin (commonArgs
107+
// {
108+
inherit cargoArtifacts;
109+
});
110+
};
111+
112+
packages = {
113+
default = comrak;
114+
comrak-llvm-coverage = craneLibLLvmTools.cargoLlvmCov (commonArgs
115+
// {
116+
inherit cargoArtifacts;
117+
});
118+
};
119+
120+
apps.default = flake-utils.lib.mkApp {
121+
drv = comrak;
122+
};
123+
124+
formatter = pkgs.alejandra;
125+
126+
devShells.default = pkgs.mkShell {
127+
inputsFrom = builtins.attrValues self.checks.${system};
128+
129+
nativeBuildInputs = with pkgs; [
130+
cargo
131+
rustc
132+
];
133+
};
134+
});
135+
}

0 commit comments

Comments
 (0)