diff --git a/flake.nix b/flake.nix index d6dc6d7..bbe57ba 100644 --- a/flake.nix +++ b/flake.nix @@ -92,24 +92,20 @@ (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain; in craneLib; - zomeCargoDeps = { craneLib, debug ? false }: + zomeCargoArtifacts = { craneLib, src, debug ? false }: let commonArgs = { doCheck = false; - src = craneLib.cleanCargoSource - (craneLib.path ./nix/reference-happ); + inherit src; CARGO_BUILD_TARGET = "wasm32-unknown-unknown"; CARGO_PROFILE = if debug then "debug" else "release"; }; - - cargoVendorDir = craneLib.vendorCargoDeps commonArgs; cargoArtifacts = craneLib.buildDepsOnly (commonArgs // { - inherit cargoVendorDir; pname = "zome"; version = "for-holochain-0_3_rc"; }); - in { inherit cargoArtifacts cargoVendorDir; }; + in cargoArtifacts; holochainCargoDeps = { pkgs, lib, craneLib, debug ? false }: let @@ -157,7 +153,7 @@ in pkgs.callPackage ./nix/zome.nix { inherit deterministicCraneLib craneLib crateCargoToml - workspacePath zomeCargoDeps; + workspacePath zomeCargoArtifacts; }; sweettest = { holochain, dna, workspacePath, crateCargoToml }: let @@ -244,42 +240,42 @@ ''; }; - devShells.zomeDev = let - configureCargoVendoredDepsHook = - pkgs.writeShellScriptBin "configureCargoVendoredDeps" - (builtins.readFile ./nix/configureCargoVendoredDepsHook.sh); - inheritCargoArtifacts = - pkgs.writeShellScriptBin "inheritCargoArtifacts" - (builtins.readFile ./nix/inheritCargoArtifacts.sh); - craneLib = flake.lib.holochainCraneLib { inherit system; }; - zomeDeps = flake.lib.zomeCargoDeps { inherit craneLib; }; - in pkgs.mkShell { - packages = [ configureCargoVendoredDepsHook inheritCargoArtifacts ]; - - shellHook = '' - cargoVendorDir=${zomeDeps.cargoVendorDir} configureCargoVendoredDeps - cargoArtifacts=${zomeDeps.cargoArtifacts} inheritCargoArtifacts - ''; - }; - - devShells.sweettestDev = let - configureCargoVendoredDepsHook = - pkgs.writeShellScriptBin "configureCargoVendoredDeps" - (builtins.readFile ./nix/configureCargoVendoredDepsHook.sh); - inheritCargoArtifacts = - pkgs.writeShellScriptBin "inheritCargoArtifacts" - (builtins.readFile ./nix/inheritCargoArtifacts.sh); - craneLib = flake.lib.holochainCraneLib { inherit system; }; - holochainDeps = - pkgs.callPackage flake.lib.holochainCargoDeps { inherit craneLib; }; - in pkgs.mkShell { - packages = [ configureCargoVendoredDepsHook inheritCargoArtifacts ]; - - shellHook = '' - cargoVendorDir=${holochainDeps.cargoVendorDir} configureCargoVendoredDeps - cargoArtifacts=${holochainDeps.cargoArtifacts} inheritCargoArtifacts - ''; - }; + # devShells.zomeDev = let + # configureCargoVendoredDepsHook = + # pkgs.writeShellScriptBin "configureCargoVendoredDeps" + # (builtins.readFile ./nix/configureCargoVendoredDepsHook.sh); + # inheritCargoArtifacts = + # pkgs.writeShellScriptBin "inheritCargoArtifacts" + # (builtins.readFile ./nix/inheritCargoArtifacts.sh); + # craneLib = flake.lib.holochainCraneLib { inherit system; }; + # zomeDeps = flake.lib.zomeCargoDeps { inherit craneLib; }; + # in pkgs.mkShell { + # packages = [ configureCargoVendoredDepsHook inheritCargoArtifacts ]; + + # shellHook = '' + # cargoVendorDir=${zomeDeps.cargoVendorDir} configureCargoVendoredDeps + # cargoArtifacts=${zomeDeps.cargoArtifacts} inheritCargoArtifacts + # ''; + # }; + + # devShells.sweettestDev = let + # configureCargoVendoredDepsHook = + # pkgs.writeShellScriptBin "configureCargoVendoredDeps" + # (builtins.readFile ./nix/configureCargoVendoredDepsHook.sh); + # inheritCargoArtifacts = + # pkgs.writeShellScriptBin "inheritCargoArtifacts" + # (builtins.readFile ./nix/inheritCargoArtifacts.sh); + # craneLib = flake.lib.holochainCraneLib { inherit system; }; + # holochainDeps = + # pkgs.callPackage flake.lib.holochainCargoDeps { inherit craneLib; }; + # in pkgs.mkShell { + # packages = [ configureCargoVendoredDepsHook inheritCargoArtifacts ]; + + # shellHook = '' + # cargoVendorDir=${holochainDeps.cargoVendorDir} configureCargoVendoredDeps + # cargoArtifacts=${holochainDeps.cargoArtifacts} inheritCargoArtifacts + # ''; + # }; packages.sync-npm-git-dependencies-with-nix = let craneLib = inputs.crane.mkLib pkgs; diff --git a/nix/buildDepsOnlyWithArtifacts.nix b/nix/buildDepsOnlyWithArtifacts.nix deleted file mode 100644 index 45cf3df..0000000 --- a/nix/buildDepsOnlyWithArtifacts.nix +++ /dev/null @@ -1,55 +0,0 @@ -{ crateNameFromCargoToml, lib, mkCargoDerivation, mkDummySrc, vendorCargoDeps }: - -{ cargoBuildCommand ? "cargoWithProfile build" -, cargoCheckCommand ? "cargoWithProfile check", cargoExtraArgs ? "--locked" -, cargoTestCommand ? "cargoWithProfile test", cargoTestExtraArgs ? "--no-run" -, ... }@args: -let - crateName = crateNameFromCargoToml args; - cleanedArgs = builtins.removeAttrs args [ - "cargoBuildCommand" - "cargoCheckCommand" - "cargoCheckExtraArgs" - "cargoExtraArgs" - "cargoTestCommand" - "cargoTestExtraArgs" - "outputHashes" - "dummySrc" - "outputs" - ]; - - # Run tests by default to ensure we cache any dev-dependencies - doCheck = args.doCheck or true; - - cargoCheckExtraArgs = - args.cargoCheckExtraArgs or (if doCheck then "--all-targets" else ""); - - dummySrc = if args ? dummySrc then - lib.warnIf (args ? src && args.src != null) - "buildDepsOnly will ignore `src` when `dummySrc` is specified" args.dummySrc - else - mkDummySrc args; -in mkCargoDerivation (cleanedArgs // { - inherit doCheck; - - src = dummySrc; - pnameSuffix = "-deps"; - pname = args.pname or crateName.pname; - version = args.version or crateName.version; - - cargoVendorDir = args.cargoVendorDir or (vendorCargoDeps args); - - # First we run `cargo check` to cache cargo's internal artifacts, fingerprints, etc. for all deps. - # Then we run `cargo build` to actually compile the deps and cache the results - buildPhaseCargoCommand = args.buildPhaseCargoCommand or '' - ${cargoCheckCommand} ${cargoExtraArgs} ${cargoCheckExtraArgs} - ${cargoBuildCommand} ${cargoExtraArgs} - ''; - - checkPhaseCargoCommand = args.checkPhaseCargoCommand or '' - ${cargoTestCommand} ${cargoExtraArgs} ${cargoTestExtraArgs} - ''; - - # No point in building this if not for the cargo artifacts - doInstallCargoArtifacts = true; -}) diff --git a/nix/fixtures/module-repo/flake.lock b/nix/fixtures/module-repo/flake.lock index c26cd09..0acbd90 100644 --- a/nix/fixtures/module-repo/flake.lock +++ b/nix/fixtures/module-repo/flake.lock @@ -643,7 +643,7 @@ }, "locked": { "lastModified": 0, - "narHash": "sha256-mFO/OpOKOrRK7SLVRSEJkXwPgSIMid5S/j+/9UHaZXE=", + "narHash": "sha256-dtwK71cA2uFbCqnREAcZzSiJTHq7QWsQRL71eKtw2P0=", "path": "../../..", "type": "path" }, diff --git a/nix/zome.nix b/nix/zome.nix index 4483727..4b1e4b3 100644 --- a/nix/zome.nix +++ b/nix/zome.nix @@ -1,43 +1,32 @@ -{ pkgs, runCommandLocal, runCommandNoCC, binaryen, deterministicCraneLib -, craneLib, workspacePath, crateCargoToml, zomeCargoDeps }: +{ zomeCargoArtifacts, pkgs, runCommandLocal, runCommandNoCC, binaryen +, deterministicCraneLib, craneLib, workspacePath, crateCargoToml }: let cargoToml = builtins.fromTOML (builtins.readFile crateCargoToml); crate = cargoToml.package.name; + src = craneLib.cleanCargoSource (craneLib.path workspacePath); commonArgs = { - strictDeps = true; doCheck = false; - src = craneLib.cleanCargoSource (craneLib.path workspacePath); + inherit src; CARGO_BUILD_TARGET = "wasm32-unknown-unknown"; - cargoLock = workspacePath + /Cargo.lock; - }; - - cargoArtifacts = (craneLib.callPackage ./buildDepsOnlyWithArtifacts.nix { }) - (commonArgs // { - pname = crate; - version = "deps"; - - # cargoVendorDir = (zomeCargoDeps { inherit craneLib; }).cargoVendorDir; - cargoArtifacts = (zomeCargoDeps { inherit craneLib; }).cargoArtifacts; - }); - - buildPackageCommonArgs = commonArgs // { cargoExtraArgs = "-p ${crate} --locked"; pname = crate; version = cargoToml.package.version; cargoToml = crateCargoToml; + cargoLock = workspacePath + /Cargo.lock; }; - wasm = craneLib.buildPackage - (buildPackageCommonArgs // { inherit cargoArtifacts; }); + wasm = craneLib.buildPackage (commonArgs // { + cargoArtifacts = zomeCargoArtifacts { inherit craneLib src; }; + }); deterministicWasm = let wasm = deterministicCraneLib.buildPackage (commonArgs // { - cargoArtifacts = - (zomeCargoDeps { craneLib = deterministicCraneLib; }).cargoArtifacts; - cargoVendorDir = - (zomeCargoDeps { craneLib = deterministicCraneLib; }).cargoVendorDir; + cargoArtifacts = zomeCargoArtifacts { + inherit src; + craneLib = deterministicCraneLib; + }; }); in runCommandLocal "${crate}-deterministic" { meta = { holochainPackageType = "zome"; };