Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Nix for CI. #338

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
];
};
});
}