From 21b40d849a26c96d81e76ac9569e3682990006f4 Mon Sep 17 00:00:00 2001 From: ThetaSinner Date: Thu, 14 Mar 2024 19:24:48 +0000 Subject: [PATCH] Share workspace deps to reduce build overhead --- flake.nix | 9 +++++++++ nix/modules/scenario.nix | 26 +++----------------------- nix/modules/workspace.nix | 14 +++++++------- nix/modules/zome.nix | 8 ++++---- 4 files changed, 23 insertions(+), 34 deletions(-) diff --git a/flake.nix b/flake.nix index 95bc0b89..af8aebab 100644 --- a/flake.nix +++ b/flake.nix @@ -78,6 +78,15 @@ pkgs.statix ]; }; + + packages = { + default = config.workspace.workspace; + inherit (config.workspace) workspace; + }; + + checks = { + inherit (config.workspace) workspace_clippy; + }; }; }; } diff --git a/nix/modules/scenario.nix b/nix/modules/scenario.nix index 6aedb61b..ff59ce9a 100644 --- a/nix/modules/scenario.nix +++ b/nix/modules/scenario.nix @@ -5,35 +5,15 @@ let inherit (config.rustHelper) craneLib; - opensslStatic = - if system == "x86_64-darwin" - then pkgs.openssl # pkgsStatic is considered a cross build and this is not yet supported - else pkgs.pkgsStatic.openssl; - - mkPackage = { name }: craneLib.buildPackage { + mkPackage = { name }: craneLib.buildPackage (config.workspace.commonArgs // { pname = name; version = config.rustHelper.findCrateVersion ../../scenarios/${name}/Cargo.toml; - src = craneLib.cleanCargoSource (craneLib.path ./../..); - strictDeps = true; + inherit (config.workspace) cargoArtifacts; cargoExtraArgs = "-p ${name}"; SKIP_HAPP_BUILD = "1"; - - buildInputs = with pkgs; [ - # Some Holochain crates link against openssl - openssl - opensslStatic - ]; - - nativeBuildInputs = with pkgs; [ - # To build openssl-sys - perl - pkg-config - # Because the holochain_client depends on Kitsune/tx5 - go - ]; - }; + }); in { options.scenarioHelper = lib.mkOption { type = lib.types.raw; }; diff --git a/nix/modules/workspace.nix b/nix/modules/workspace.nix index 3ff54db2..82d4079c 100644 --- a/nix/modules/workspace.nix +++ b/nix/modules/workspace.nix @@ -15,6 +15,9 @@ src = craneLib.cleanCargoSource (craneLib.path ./../..); strictDeps = true; + cargoExtraArgs = "--locked --workspace"; + SKIP_HAPP_BUILD = "1"; + buildInputs = with pkgs; [ # Some Holochain crates link against openssl openssl @@ -38,19 +41,16 @@ inherit cargoArtifacts; }); - workspaceClippy = craneLib.cargoClippy (commonArgs // { + workspace_clippy = craneLib.cargoClippy (commonArgs // { inherit cargoArtifacts; cargoClippyExtraArgs = "--all-targets --all-features -- --deny warnings"; }); in { - packages = { - default = workspace; - inherit workspace; - }; + options.workspace = lib.mkOption { type = lib.types.raw; }; - checks = { - inherit workspaceClippy; + config.workspace = { + inherit commonArgs cargoArtifacts workspace workspace_clippy; }; }; } diff --git a/nix/modules/zome.nix b/nix/modules/zome.nix index b9facf9c..55fe7ef4 100644 --- a/nix/modules/zome.nix +++ b/nix/modules/zome.nix @@ -13,16 +13,16 @@ let packageName = if kind == "integrity" then "${name}_${kind}" else name; in - craneLib.buildPackage { + craneLib.buildPackage (config.workspace.commonArgs // { pname = "${name}_${kind}"; version = config.rustHelper.findCrateVersion ../../zomes/${name}/${kind}/Cargo.toml; - src = craneLib.cleanCargoSource (craneLib.path ./../..); - strictDeps = true; + inherit (config.workspace) cargoArtifacts; + doCheck = false; cargoExtraArgs = "-p ${packageName} --lib --target wasm32-unknown-unknown"; - }; + }); }; }; }