Skip to content

Commit

Permalink
Align deps for zomes
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed May 28, 2024
1 parent a9f2b5f commit 0e595ec
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 123 deletions.
84 changes: 40 additions & 44 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -157,7 +153,7 @@

in pkgs.callPackage ./nix/zome.nix {
inherit deterministicCraneLib craneLib crateCargoToml
workspacePath zomeCargoDeps;
workspacePath zomeCargoArtifacts;
};
sweettest = { holochain, dna, workspacePath, crateCargoToml }:
let
Expand Down Expand Up @@ -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;
Expand Down
55 changes: 0 additions & 55 deletions nix/buildDepsOnlyWithArtifacts.nix

This file was deleted.

2 changes: 1 addition & 1 deletion nix/fixtures/module-repo/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 12 additions & 23 deletions nix/zome.nix
Original file line number Diff line number Diff line change
@@ -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"; };
Expand Down

0 comments on commit 0e595ec

Please sign in to comment.