{ pkgs, myLib, myPkgs }: let inherit (pkgs) lib; onlyDrvs = lib.filterAttrs (_: lib.isDerivation); in onlyDrvs (lib.makeScope myLib.newScope (self: let callPackage = self.newScope { }; myLibLlvmTools = myLib.overrideToolchain (pkgs.rust-bin.stable.latest.minimal.override { extensions = [ "llvm-tools" ]; }); x64Linux = pkgs.hostPlatform.system == "x86_64-linux"; in { cleanCargoTomlTests = callPackage ./cleanCargoTomlTests { }; clippy = callPackage ./clippy { }; cargoFmt = myLib.cargoFmt { src = ./simple; }; # https://github.com/ipetkov/crane/issues/6 cargoClippyThenBuild = myLib.buildPackage { src = ./simple; cargoArtifacts = myLib.cargoClippy { cargoArtifacts = null; src = ./simple; }; }; # https://github.com/ipetkov/crane/issues/6 cargoFmtThenClippy = myLib.cargoClippy { src = ./simple; cargoArtifacts = self.cargoFmt; }; cargoAuditTests = callPackage ./cargoAudit.nix { }; cargoLlvmCov = myLibLlvmTools.cargoLlvmCov { src = ./simple; cargoArtifacts = myLib.buildDepsOnly { src = ./simple; }; }; cargoLlvmCovNextest = myLibLlvmTools.cargoLlvmCov { src = ./simple; cargoLlvmCovCommand = "nextest"; cargoArtifacts = myLib.buildDepsOnly { src = ./simple; }; nativeBuildInputs = [ pkgs.cargo-nextest ]; }; # NB: explicitly using a github release (not crates.io release) # which lacks a Cargo.lock file, so we can test adding our own cargoLockOverride = let cargoLock = ./testCargoLockOverride.lock; cargoLockContents = builtins.readFile cargoLock; cargoLockParsed = builtins.fromTOML cargoLockContents; in pkgs.linkFarmFromDrvs "cargoLockOverride-tests" (map (args: myLib.buildPackage (args // rec { pname = "cargo-llvm-cov"; version = "0.4.14"; src = pkgs.fetchFromGitHub { owner = "taiki-e"; repo = pname; rev = "v${version}"; sha256 = "sha256-sNwizxYVUNyv5InR8HS+CyUsroA79h/FpouS+fMWJUI="; }; doCheck = false; # Tests need llvm-tools installed })) [ { inherit cargoLock; } { inherit cargoLockContents; } { inherit cargoLockParsed; } ] ); cargoTarpaulin = lib.optionalAttrs x64Linux (myLib.cargoTarpaulin { src = ./simple; cargoArtifacts = myLib.buildDepsOnly { src = ./simple; }; }); compilesFresh = callPackage ./compilesFresh.nix { }; compilesFreshSimple = self.compilesFresh "simple" (myLib.cargoBuild) { src = ./simple; }; compilesFreshSimpleBuildPackage = self.compilesFresh "simple" (myLib.buildPackage) { src = ./simple; }; compilesFreshOverlappingTargets = self.compilesFresh (builtins.concatStringsSep "\n" [ "bar" "baz" "foo" "overlapping-targets" ]) myLib.cargoBuild { src = ./overlapping-targets; }; compilesFreshWithBuildScript = self.compilesFresh { check = (builtins.concatStringsSep "\n" [ "build-script-build" "with-build-script" ]); build = (builtins.concatStringsSep "\n" [ "with-build-script" ]); test = (builtins.concatStringsSep "\n" [ "with-build-script" ]); } myLib.cargoBuild { src = ./with-build-script; }; compilesFreshWithBuildScriptCustom = self.compilesFresh { check = (builtins.concatStringsSep "\n" [ "build-script-mycustomscript" "with-build-script-custom" ]); build = (builtins.concatStringsSep "\n" [ "with-build-script-custom" ]); test = (builtins.concatStringsSep "\n" [ "with-build-script-custom" ]); } myLib.cargoBuild { src = ./with-build-script-custom; }; customCargoTargetDirectory = let simple = self.simple.overrideAttrs (_old: { pname = "customCargoTargetDirectory"; doInstallCargoArtifacts = false; CARGO_TARGET_DIR = "some/nested/custom-cargo-dir"; }); in pkgs.runCommand "smoke-simple" { } '' # does it run? ${simple}/bin/simple touch $out ''; # https://github.com/ipetkov/crane/pull/234 nonJsonCargoBuildLog = let nonJson = '' db_id attr "field_id" Attribute { pound_token: Pound, style: Outer, bracket_token: Bracket, path: Path { leading_colon: None, segments: [PathSegment { ident: Ident { ident: "db_id", span: #0 bytes(8250..8255) }, arguments: None }] }, tokens: TokenStream [] } ''; in myLib.buildPackage { src = myLib.cleanCargoSource ./simple; buildPhaseCargoCommand = '' cargoBuildLog=$(mktemp cargoBuildLogXXXX.json) cargoWithProfile build --message-format json-render-diagnostics >"$cargoBuildLog" echo "${nonJson}" >>"$cargoBuildLog" ''; }; # https://github.com/ipetkov/crane/discussions/203 dependencyBuildScriptPerms = myLib.cargoClippy { src = ./dependencyBuildScriptPerms; cargoExtraArgs = "--all-features --all"; cargoClippyExtraArgs = "-- --deny warnings"; cargoArtifacts = myLib.buildDepsOnly { src = ./dependencyBuildScriptPerms; # NB: explicitly build this with no feature flags }; }; docs = myLib.cargoDoc { src = ./simple; cargoArtifacts = myLib.buildDepsOnly { src = ./simple; }; }; docsFresh = self.compilesFresh "simple" (myLib.cargoDoc) { src = ./simple; cargoArtifacts = myLib.buildDepsOnly { src = ./simple; }; }; # https://github.com/ipetkov/crane/issues/188 depsOnlySourceName = myLib.buildPackage { src = ./highs-sys-test; stdenv = pkgs.clangStdenv; LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; nativeBuildInputs = with pkgs; [ cmake ]; }; depsOnlyVariousTargets = myLib.buildDepsOnly { src = ./various-targets; }; features = callPackage ./features { }; flakePackages = let pkgDrvs = builtins.attrValues myPkgs; extraChecks = lib.flatten (map builtins.attrValues (map (p: onlyDrvs (p.passthru.checks or { })) pkgDrvs) ); in pkgs.linkFarmFromDrvs "flake-packages" (pkgDrvs ++ extraChecks); gitOverlappingRepo = myLib.buildPackage { src = ./git-overlapping; }; gitRevNoRef = myLib.buildPackage { src = ./gitRevNoRef; }; illegalBin = myLib.buildPackage { pname = "illegalBin"; version = "0.0.1"; src = ./illegal-bin; }; manyLibs = myLib.buildPackage { src = ./with-libs; pname = "my-libs"; version = "0.0.1"; cargoArtifacts = null; }; manyLibsInstalledAsExpected = pkgs.runCommand "manyLibsInstalledAsExpected" { } '' cat >expected <