Skip to content

Commit

Permalink
meta.debug again
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Sep 23, 2024
1 parent 1c003ec commit 316e12a
Show file tree
Hide file tree
Showing 7 changed files with 459 additions and 461 deletions.
104 changes: 39 additions & 65 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,48 +39,15 @@ rec {

]);

filterByHolochainPackageType = holochainPackageType: packages:
inputs.nixpkgs.lib.filterAttrs (key: value:
(builtins.hasAttr "meta" value)
&& (builtins.hasAttr "holochainPackageType" value.meta)
&& value.meta.holochainPackageType == holochainPackageType)
packages;

filterZomes = filterByHolochainPackageType "zome";
filterDnas = filterByHolochainPackageType "dna";
filterHapps = filterByHolochainPackageType "happ";
filterNpmPackages = filterByHolochainPackageType "npm";

holochainPkgs = { system }:
let
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import inputs.rust-overlay) ];
};
in pkgs;

holochainRustToolchain = { system }:
let
pkgs = holochainPkgs { inherit system; };

rustToolchain = pkgs.rust-bin.stable."1.77.2".minimal.override {
# Set the build targets supported by the toolchain,
# wasm32-unknown-unknown is required for trunk.
targets = [ "wasm32-unknown-unknown" ];
};
in rustToolchain;
zomeCargoArtifacts = { system, craneLib ? (let

holochainCraneLib = { system }:
let
pkgs = holochainPkgs { inherit system; };
rustToolchain = holochainRustToolchain { inherit system; };
craneLib =
(inputs.crane.mkLib pkgs).overrideToolchain rustToolchain;
in craneLib;

zomeCargoArtifacts = { system
, craneLib ? (holochainCraneLib { inherit system; }), debug ? false
}:
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import inputs.rust-overlay) ];
};
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain
inputs.holonix.outputs.packages.${system}.rust;
in craneLib), debug ? false }:
let
src =
craneLib.cleanCargoSource (craneLib.path ./nix/reference-happ);
Expand All @@ -98,8 +65,12 @@ rec {

holochainCargoArtifacts = { system }:
let
pkgs = holochainPkgs { inherit system; };
craneLib = holochainCraneLib { inherit system; };
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import inputs.rust-overlay) ];
};
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain
inputs.holonix.outputs.packages.${system}.rust;

buildInputs = holochainDeps {
inherit pkgs;
Expand All @@ -122,40 +93,37 @@ rec {
in cargoArtifacts;

rustZome = { crateCargoToml, system, workspacePath
, nonWasmCrates ? [ ], cargoArtifacts ? null
, matchingZomeHash ? null }:
, cargoArtifacts ? null, matchingZomeHash ? null }:
let
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import inputs.rust-overlay) ];
};

deterministicCraneLib = let
pkgs = import inputs.nixpkgs {
system = "x86_64-linux";
overlays = [ (import inputs.rust-overlay) ];
};

rustToolchain = pkgs.rust-bin.stable."1.77.2".minimal.override {
# Set the build targets supported by the toolchain,
# wasm32-unknown-unknown is required for trunk.
targets = [ "wasm32-unknown-unknown" ];
};
rustToolchain =
inputs.holonix.outputs.packages."x86_64-linux".rust;
in (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain;

pkgs = holochainPkgs { inherit system; };
craneLib = holochainCraneLib { inherit system; };

craneLib = (inputs.crane.mkLib pkgs).overrideToolchain
inputs.holonix.outputs.packages.${system}.rust;
zome-wasm-hash =
(outputs inputs).packages.${system}.zome-wasm-hash;

in pkgs.callPackage ./nix/zome.nix {
inherit deterministicCraneLib craneLib crateCargoToml
cargoArtifacts nonWasmCrates workspacePath matchingZomeHash
zome-wasm-hash;
referenceZomeCargoArtifacts = flake.lib.zomeCargoArtifacts;
cargoArtifacts workspacePath matchingZomeHash zome-wasm-hash;
};
sweettest = { system, dna, workspacePath, crateCargoToml
, buildInputs ? [ ], nativeBuildInputs ? [ ], cargoArtifacts ? null
}:
let
pkgs = holochainPkgs { inherit system; };
craneLib = holochainCraneLib { inherit system; };
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import inputs.rust-overlay) ];
};
craneLib = (inputs.crane.mkLib pkgs).overrideToolchain
inputs.holonix.outputs.packages.${system}.rust;
in pkgs.callPackage ./nix/sweettest.nix {
inherit dna craneLib crateCargoToml cargoArtifacts workspacePath;
buildInputs = buildInputs ++ holochainDeps {
Expand All @@ -165,7 +133,10 @@ rec {
};
dna = { system, dnaManifest, zomes, matchingIntegrityDna ? null }:
let
pkgs = holochainPkgs { inherit system; };
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import inputs.rust-overlay) ];
};
compare-dnas-integrity =
(outputs inputs).packages.${system}.compare-dnas-integrity;
holochain = inputs.holonix.outputs.packages.${system}.holochain;
Expand All @@ -176,7 +147,10 @@ rec {
};
happ = { system, happManifest, dnas }:
let
pkgs = holochainPkgs { inherit system; };
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import inputs.rust-overlay) ];
};
holochain = inputs.holonix.outputs.packages.${system}.holochain;
in pkgs.callPackage ./nix/happ.nix {
inherit dnas holochain happManifest;
Expand Down
64 changes: 32 additions & 32 deletions nix/dna.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,51 +21,34 @@ let
dnaManifestJson = writeText "dna.json" (builtins.toJSON manifest');
dnaManifestYaml = runCommandLocal "json-to-yaml" { }
" ${json2yaml}/bin/json2yaml ${dnaManifestJson} $out\n"; # Recurse over the zomes, and add the correct bundled zome package by name
release = runCommandLocal manifest.name {
srcs = builtins.map (zome: zome.meta.release) zomeSrcs;
meta = { holochainPackageType = "dna"; };
} ''
mkdir workdir
cp ${dnaManifestYaml} workdir/dna.yaml
# Debug package

debug = runCommandLocal manifest.name {
srcs = builtins.map (zome: zome.meta.debug) zomeSrcs;
} ''
mkdir workdir
cp ${dnaManifestYaml} workdir/dna.yaml
${
builtins.toString (builtins.map (zome: ''
cp ${zomes.${zome.name}.meta.release} ./workdir/${zome.name}.wasm
cp ${zomes.${zome.name}.meta.debug} ./workdir/${zome.name}.wasm
'') manifest'.integrity.zomes)
}
${
builtins.toString (builtins.map (zome: ''
cp ${zomes.${zome.name}.meta.release} ./workdir/${zome.name}.wasm
cp ${zomes.${zome.name}.meta.debug} ./workdir/${zome.name}.wasm
'') manifest'.coordinator.zomes)
}
${holochain}/bin/hc dna pack workdir
mv workdir/${manifest.name}.dna $out
'';

guardedRelease = if matchingIntegrityDna != null then
runCommandLocal "check-match-dna-${manifest.name}-integrity" {
srcs = [ release matchingIntegrityDna.meta.release ];
buildInputs = [ compare-dnas-integrity ];
} ''
${compare-dnas-integrity}/bin/compare-dnas-integrity ${matchingIntegrityDna.meta.release} ${release}
cp ${release} $out
''
else
release;
release = runCommandLocal "${manifest.name}-release" { srcs = zomeSrcs; } ''
mkdir workdir
cp ${dnaManifestYaml} workdir/dna.yaml
# Debug package
debug = runCommandLocal manifest.name {
srcs = zomeSrcs;
meta = {
release = guardedRelease;
holochainPackageType = "dna";
};
} ''
mkdir workdir
cp ${dnaManifestYaml} workdir/dna.yaml
${
builtins.toString (builtins.map (zome: ''
cp ${zomes.${zome.name}} ./workdir/${zome.name}.wasm
Expand All @@ -76,8 +59,25 @@ let
cp ${zomes.${zome.name}} ./workdir/${zome.name}.wasm
'') manifest'.coordinator.zomes)
}
${holochain}/bin/hc dna pack workdir
mv workdir/${manifest.name}.dna $out
'';
in debug

guardedRelease = if matchingIntegrityDna != null then
runCommandLocal "check-match-dna-${manifest.name}-integrity" {
srcs = [ release matchingIntegrityDna ];
buildInputs = [ compare-dnas-integrity ];
} ''
${compare-dnas-integrity}/bin/compare-dnas-integrity ${matchingIntegrityDna} ${release}
cp ${release} $out
''
else
release;

in runCommandLocal manifest.name {
meta = { inherit debug; };
outputs = [ "out" ];
} ''
cp ${guardedRelease} $out
''
Loading

0 comments on commit 316e12a

Please sign in to comment.