diff --git a/flake.nix b/flake.nix index d736e8e..d3f6b75 100644 --- a/flake.nix +++ b/flake.nix @@ -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 { @@ -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 diff --git a/nix/zome.nix b/nix/zome.nix index 69688d6..60c445e 100644 --- a/nix/zome.nix +++ b/nix/zome.nix @@ -3,19 +3,21 @@ 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"; @@ -23,11 +25,21 @@ let 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 + ''; + }