From 303f955de45e5a0ac77212c1f5080912a3876c6a Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sun, 27 Aug 2023 01:46:20 -0400 Subject: [PATCH] Upgrade flake build process The previous build process was MASSIVELY inefficient in multiple ways. This is a massive improvement. --- flake.nix | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/flake.nix b/flake.nix index 806d1b2..c7a5f70 100644 --- a/flake.nix +++ b/flake.nix @@ -14,21 +14,39 @@ flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; }; craneLib = crane.lib.${system}; + + commonArgs = { + version = "0.1.0"; + src = craneLib.path ./.; + cargoBuildFlags = "-p cli"; + buildInputs = [ pkgs.openssl ]; + nativeBuildInputs = [ pkgs.pkg-config ]; + }; + + # Cargo build dependencies/artifacts only + # This derivation exists so that multiple builds can reuse + # the same build artifacts + cargoArtifacts = craneLib.buildDepsOnly (commonArgs // { + pname = "ggelo-deps"; + }); + + # Run clippy (and deny all warnings) on the crate source + runClippy = craneLib.cargoClippy (commonArgs // { + pname = "ggelo-clippy-check"; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + inherit cargoArtifacts; + }); + + ggelo = craneLib.buildPackage (commonArgs // { + pname = "ggelo"; + inherit cargoArtifacts; + }); in { - packages.ggelo = craneLib.buildPackage { - pname = "ggelo"; - version = "0.1.0"; - src = ./.; - cargoBuildFlags = "-p cli"; + packages.ggelo = ggelo; + packages.default = ggelo; - nativeBuildInputs = [ pkgs.pkg-config ]; - PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; - - doCheck = true; - }; - - packages.default = self.packages.${system}.ggelo; - checks.default = self.packages.${system}.ggelo; + checks.build = ggelo; + checks.runClippy = runClippy; devShells.default = pkgs.mkShell { packages = with pkgs; [ rustc cargo pkg-config rust-analyzer ];