diff --git a/flake.lock b/flake.lock index cd0647be..80e86485 100644 --- a/flake.lock +++ b/flake.lock @@ -25,11 +25,11 @@ "crane": { "flake": false, "locked": { - "lastModified": 1654444508, - "narHash": "sha256-4OBvQ4V7jyt7afs6iKUvRzJ1u/9eYnKzVQbeQdiamuY=", + "lastModified": 1661875961, + "narHash": "sha256-f1h/2c6Teeu1ofAHWzrS8TwBPcnN+EEu+z1sRVmMQTk=", "owner": "ipetkov", "repo": "crane", - "rev": "db5482bf225acc3160899124a1df5a617cfa27b5", + "rev": "d9f394e4e20e97c2a60c3ad82c2b6ef99be19e24", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index d4f6377e..f511a13d 100644 --- a/flake.nix +++ b/flake.nix @@ -100,12 +100,12 @@ "lib/mkCargoDerivation.nix" "lib/mkDummySrc.nix" "lib/writeTOML.nix" + "pkgs/cargoHelperFunctions.sh" "pkgs/configureCargoCommonVarsHook.sh" "pkgs/configureCargoVendoredDepsHook.sh" "pkgs/installFromCargoBuildLogHook.sh" "pkgs/inheritCargoArtifactsHook.sh" "pkgs/installCargoArtifactsHook.sh" - "pkgs/remapSourcePathPrefixHook.sh" "LICENSE" ]; }; diff --git a/src/default.nix b/src/default.nix index 29abcfe4..b33bd707 100644 --- a/src/default.nix +++ b/src/default.nix @@ -136,9 +136,9 @@ in let }: rec { otherHooks = genHooks [ + "cargoHelperFunctions" "configureCargoCommonVarsHook" "configureCargoVendoredDepsHook" - "remapSourcePathPrefixHook" ] {}; installHooks = @@ -174,12 +174,21 @@ in let inherit writeTOML cleanCargoToml findCargoFiles; }; - mkCargoDerivation = importLibFile "mkCargoDerivation" ({ - cargo = cargoHostTarget; - inherit (pkgs) stdenv lib; - } - // installHooks - // otherHooks); + mkCargoDerivation = importLibFile "mkCargoDerivation" { + cargo = cargoHostTarget; + inherit (pkgs) stdenv lib; + inherit + (installHooks) + inheritCargoArtifactsHook + installCargoArtifactsHook + ; + inherit + (otherHooks) + configureCargoCommonVarsHook + configureCargoVendoredDepsHook + ; + cargoHelperFunctionsHook = otherHooks.cargoHelperFunctions; + }; buildDepsOnly = importLibFile "buildDepsOnly" { inherit mkCargoDerivation @@ -197,7 +206,7 @@ in let ; }; buildPackage = importLibFile "buildPackage" { - inherit (pkgs) lib; + inherit (pkgs) removeReferencesTo lib; inherit (installLogHook) installFromCargoBuildLogHook; inherit cargoBuild; }; diff --git a/src/subsystems/rust/builders/build-rust-package/default.nix b/src/subsystems/rust/builders/build-rust-package/default.nix index 7ad90c89..4ef2b32c 100644 --- a/src/subsystems/rust/builders/build-rust-package/default.nix +++ b/src/subsystems/rust/builders/build-rust-package/default.nix @@ -31,7 +31,6 @@ buildPackage = pname: version: let src = utils.getRootSource pname version; - vendorDir = vendoring.vendoredDependencies; replacePaths = utils.replaceRelativePathsWithAbsolute subsystemAttrs.relPathReplacements.${pname}.${version}; @@ -48,7 +47,7 @@ cargoVendorDir = "../nix-vendor"; postUnpack = '' - ln -s ${vendorDir} ./nix-vendor + ${vendoring.copyVendorDir "./nix-vendor"} export CARGO_HOME=$(pwd)/.cargo_home ''; diff --git a/src/subsystems/rust/builders/crane/default.nix b/src/subsystems/rust/builders/crane/default.nix index a708c84c..7810b002 100644 --- a/src/subsystems/rust/builders/crane/default.nix +++ b/src/subsystems/rust/builders/crane/default.nix @@ -52,15 +52,25 @@ # common args we use for both buildDepsOnly and buildPackage common = { inherit pname version; + src = utils.getRootSource pname version; - cargoVendorDir = vendoring.vendoredDependencies; + cargoVendorDir = "./nix-vendor"; + + # this is needed because remove-references-to doesn't work on non nix-store paths + doNotRemoveReferencesToVendorDir = true; + postUnpack = '' + ${vendoring.copyVendorDir "./nix-vendor"} export CARGO_HOME=$(pwd)/.cargo_home ''; preConfigure = '' ${writeGitVendorEntries} ${replacePaths} ''; + + # Make sure cargo only builds & tests the package we want + cargoBuildCommand = "cargo build --release --package ${pname}"; + cargoTestCommand = "cargo test --release --package ${pname}"; }; # The deps-only derivation will use this as a prefix to the `pname` @@ -72,6 +82,8 @@ # so that crane's mkDummySrc adds it to the dummy source inherit (utils) cargoLock; pnameSuffix = depsNameSuffix; + # Make sure cargo only checks the package we want + cargoCheckCommand = "cargo check --release --package ${pname}"; }; deps = produceDerivation @@ -82,9 +94,6 @@ common // { cargoArtifacts = deps; - # Make sure cargo only builds & tests the package we want - cargoBuildCommand = "cargo build --release --package ${pname}"; - cargoTestCommand = "cargo test --release --package ${pname}"; # write our cargo lock # note: we don't do this in buildDepsOnly since # that uses a cargoLock argument instead diff --git a/src/subsystems/rust/builders/vendor.nix b/src/subsystems/rust/builders/vendor.nix index b96b2eb3..10e2e80e 100644 --- a/src/subsystems/rust/builders/vendor.nix +++ b/src/subsystems/rust/builders/vendor.nix @@ -97,4 +97,6 @@ in rec { # All dependencies in the Cargo.lock file, vendored vendoredDependencies = vendorDependencies allDependencies; + + copyVendorDir = path: ''cp -r --no-preserve=mode,ownership ${vendoredDependencies} ${path}''; } diff --git a/src/subsystems/rust/translators/cargo-lock/default.nix b/src/subsystems/rust/translators/cargo-lock/default.nix index 697b4a2b..965bb388 100644 --- a/src/subsystems/rust/translators/cargo-lock/default.nix +++ b/src/subsystems/rust/translators/cargo-lock/default.nix @@ -21,14 +21,13 @@ in { translate = {translatorName, ...}: { project, tree, - packageName, ... - } @ args: let + }: let # get the root source and project source rootTree = tree; + projectTree = rootTree.getNodeFromPath project.relPath; rootSource = rootTree.fullPath; projectSource = dlib.sanitizePath "${rootSource}/${project.relPath}"; - projectTree = rootTree.getNodeFromPath project.relPath; subsystemInfo = project.subsystemInfo; # Get the root toml @@ -84,12 +83,6 @@ in { # Get a "main" package toml packageToml = l.elemAt cargoPackages 0; - # Figure out a package name - packageName = - if args.packageName == "{automatic}" - then packageToml.value.package.name - else args.packageName; - # Parse Cargo.lock and extract dependencies parsedLock = projectTree.files."Cargo.lock".tomlContent; parsedDeps = parsedLock.package; @@ -186,7 +179,7 @@ in { }; in dlib.simpleTranslate2.translate - ({...}: rec { + ({...}: { inherit translatorName; # relative path of the project within the source tree. @@ -198,7 +191,7 @@ in { # Extract subsystem specific attributes. # The structure of this should be defined in: # ./src/specifications/{subsystem} - subsystemAttrs = rec { + subsystemAttrs = { relPathReplacements = let # function to find path replacements for one package findReplacements = package: let @@ -237,8 +230,7 @@ in { filtered = l.filterAttrs ( - n: v: - (l.removeSuffix "/" (l.removePrefix "./" n)) != v + n: v: ! l.pathExists (dlib.sanitizePath "${projectSource}/${v}") ) replacements; in @@ -314,7 +306,7 @@ in { workspaceCrates = l.map ( - pkg: rec { + pkg: { inherit (pkg.value.package) name version; inherit (pkg) relPath; } @@ -382,12 +374,5 @@ in { # - string argument (type = "argument") # - boolean flag (type = "flag") # String arguments contain a default value and examples. Flags do not. - extraArgs = { - packageName = { - description = "name of the package you want to build"; - default = "{automatic}"; - examples = ["rand"]; - type = "argument"; - }; - }; + extraArgs = {}; }