Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
guillemcordoba committed Feb 22, 2024
1 parent 8a39f5f commit 31c40e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{
flake = {
lib = {
rustZome = { src, crate, holochain, excludedCrates ? [] }:
rustZome = { src, crate, holochain, workspacePath, optimizeWasm ? true, excludedCrates ? [] }:
let
system = holochain.devShells.holonix.system;
pkgs = import inputs.nixpkgs {
Expand All @@ -44,7 +44,7 @@

in
pkgs.callPackage ./nix/zome.nix {
inherit src craneLib crate excludedCrates;
inherit src craneLib crate excludedCrates workspacePath optimizeWasm;
};
dna = { holochain, dnaManifest, zomes }:
let
Expand Down
36 changes: 24 additions & 12 deletions nix/zome.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,43 @@
stdenv,
binaryen,
craneLib,
src,
excludedCrates ? []
workspacePath,
excludedCrates,
optimizeWasm
}:

let
cargoExtraArgs = "--workspace ${if excludedCrates != null then builtins.concatStringsSep " " (builtins.map (excludedCrate: ''--exclude ${excludedCrate}'') excludedCrates) else ''''}";
wasmDeps = craneLib.buildDepsOnly {
inherit src cargoExtraArgs;
inherit cargoExtraArgs;
src = craneLib.cleanCargoSource (craneLib.path workspacePath);
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
doCheck = false;
};
wasm = craneLib.buildPackage {
inherit src;
src = craneLib.cleanCargoSource (craneLib.path workspacePath);
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
cargoArtifacts = wasmDeps;
cargoExtraArgs = "-p ${crate} --locked";
pname = crate;
doCheck = false;
};
in
stdenv.mkDerivation {
name = crate;
buildInputs = [ wasm binaryen ];
phases = [ "buildPhase" ];
buildPhase = ''
wasm-opt --strip-debug -Oz -o $out ${wasm}/lib/${crate}.wasm
'';
}
if optimizeWasm then
stdenv.mkDerivation {
name = crate;
buildInputs = [ wasm binaryen ];
phases = [ "buildPhase" ];
buildPhase = ''
wasm-opt --strip-debug -Oz -o $out ${wasm}/lib/${crate}.wasm
'';
}
else
stdenv.mkDerivation {
name = crate;
buildInputs = [ wasm ];
phases = [ "buildPhase" ];
buildPhase = ''
cp ${wasm}/lib/${crate}.wasm $out
'';
}

0 comments on commit 31c40e5

Please sign in to comment.