From 270c6eef1f46fa151a5bbbbf04096075763bb78d Mon Sep 17 00:00:00 2001 From: Charlotte Date: Tue, 29 Aug 2023 11:00:55 +1000 Subject: [PATCH] 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. --- .github/workflows/rust.yml | 17 ++-- .gitignore | 1 + flake.lock | 198 +++++++++++++++++++++++++++++++++++++ flake.nix | 135 +++++++++++++++++++++++++ 4 files changed, 342 insertions(+), 9 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4fe401ae..d0e090e4 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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 diff --git a/.gitignore b/.gitignore index 9c22735a..f1d6e272 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ benches/cmark-gfm benches/comrak-* benches/pulldown-cmark benches/markdown-it +/result* diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..3710f65f --- /dev/null +++ b/flake.lock @@ -0,0 +1,198 @@ +{ + "nodes": { + "advisory-db": { + "flake": false, + "locked": { + "lastModified": 1693237955, + "narHash": "sha256-O8bIGaqQmV7jI/fLAFtyCnUDG41qcUoY2TwvxAtcbt4=", + "owner": "rustsec", + "repo": "advisory-db", + "rev": "cbf97de9b780c3279e779ef40b7fa2789b2b9905", + "type": "github" + }, + "original": { + "owner": "rustsec", + "repo": "advisory-db", + "type": "github" + } + }, + "crane": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1693163878, + "narHash": "sha256-HXuyMUVaRSoIA602jfFuYGXt6AMZ+WUxuvLq8iJmYTA=", + "owner": "ipetkov", + "repo": "crane", + "rev": "43db881168bc65b568d36ceb614a0fc8b276191b", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": [] + }, + "locked": { + "lastModified": 1693203690, + "narHash": "sha256-qrgyFtRaduofcJF1T7TscNWM4HTx4qtFzpilD0K8M0o=", + "owner": "nix-community", + "repo": "fenix", + "rev": "8eb35c8c402edda73a7dde82e48bf279542640c7", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1692799911, + "narHash": "sha256-3eihraek4qL744EvQXsK1Ha6C3CR7nnT8X2qWap4RNk=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "f9e7cf818399d17d347f847525c5a5a8032e4e44", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1701053011, + "narHash": "sha256-8QQ7rFbKFqgKgLoaXVJRh7Ik5LtI3pyBBCfOnNOGkF0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5b528f99f73c4fad127118a8c1126b5e003b01a9", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "advisory-db": "advisory-db", + "crane": "crane", + "fenix": "fenix", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "crane", + "flake-utils" + ], + "nixpkgs": [ + "crane", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1691374719, + "narHash": "sha256-HCodqnx1Mi2vN4f3hjRPc7+lSQy18vRn8xWW68GeQOg=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "b520a3889b24aaf909e287d19d406862ced9ffc9", + "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" + } + }, + "systems_2": { + "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 00000000..ab2dd043 --- /dev/null +++ b/flake.nix @@ -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 + ]; + }; + }); +}