Skip to content

Commit

Permalink
Extract common
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Jun 18, 2024
1 parent de4cdc1 commit 9bbc0bb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
18 changes: 18 additions & 0 deletions modules/common.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{}:
{
holochain = { lib, craneLib, holochain }:
let
# Crane filters out all non-cargo related files. Define include filter with files needed for build.
nonCargoBuildFiles = path: _type: builtins.match ".*(json|sql|wasm.gz)$" path != null;
includeFilesFilter = path: type:
(craneLib.filterCargoSources path type) || (nonCargoBuildFiles path type);
in
{
crateInfo = crate: craneLib.crateNameFromCargoToml { cargoToml = holochain + "/crates/${crate}/Cargo.toml"; };

src = lib.cleanSourceWith {
src = holochain;
filter = includeFilesFilter;
};
};
}
22 changes: 5 additions & 17 deletions modules/holochain-cross.nix
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
{
# Flake inputs
inputs

# The system that we are compiling on
, localSystem

# The crate to build, from the Holochain workspace. Must match the path to the Cargo.toml file.
, crate

# The name of the package to build, from the selected crate.
, package

#
# The remaining arguments are for configuring the cross-compile.
#

# The target system that we are cross-compiling for
, crossSystem
# The target that Rust should be configured to use
Expand All @@ -24,6 +16,8 @@
let
inherit (inputs) nixpkgs crane rust-overlay;

common = import ./common.nix { };

pkgs = import nixpkgs {
inherit crossSystem localSystem;
overlays = [ (import rust-overlay) ];
Expand Down Expand Up @@ -52,24 +46,18 @@ let
, stdenv
}:
let
# Crane filters out all non-cargo related files. Define include filter with files needed for build.
nonCargoBuildFiles = path: _type: builtins.match ".*(json|sql|wasm.gz)$" path != null;
includeFilesFilter = path: type:
(craneLib.filterCargoSources path type) || (nonCargoBuildFiles path type);
holochainCommon = common.holochain { inherit lib craneLib; holochain = inputs.holochain; };

# Crane doesn't know which version to select from a workspace, so we tell it where to look
crateInfo = craneLib.crateNameFromCargoToml { cargoToml = inputs.holochain + "/crates/${crate}/Cargo.toml"; };
crateInfo = holochainCommon.crateInfo crate;

commonArgs = {
# Just used for building the workspace, will be replaced when building a specific crate
pname = "default";
version = "0.0.0";

# Load source with a custom filter so we can include non-cargo files that get used during the build
src = lib.cleanSourceWith {
src = inputs.holochain;
filter = includeFilesFilter;
};
src = holochainCommon.src;

# We don't want to run tests
doCheck = false;
Expand Down
24 changes: 18 additions & 6 deletions modules/holochain-windows.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
{ inputs, localSystem, crate, package }:
{
# Flake inputs
inputs
# The system that we are compiling on
, localSystem
# The crate to build, from the Holochain workspace. Must match the path to the Cargo.toml file.
, crate
# The name of the package to build, from the selected crate.
, package
}:
let
inherit (inputs) nixpkgs crane fenix;

common = import ./common.nix { };

pkgs = nixpkgs.legacyPackages.${localSystem};

toolchain = with fenix.packages.${localSystem};
Expand All @@ -19,7 +30,9 @@ let
(craneLib.filterCargoSources path type) || (nonCargoBuildFiles path type);

# Crane doesn't know which version to select from a workspace, so we tell it where to look
crateInfo = craneLib.crateNameFromCargoToml { cargoToml = inputs.holochain + "/crates/${crate}/Cargo.toml"; };
crateInfo = holochainCommon.crateInfo crate;

holochainCommon = common.holochain { inherit craneLib; lib = pkgs.lib; holochain = inputs.holochain; };

libsodium = pkgs.stdenv.mkDerivation {
name = "libsodium";
Expand All @@ -38,10 +51,9 @@ in
craneLib.buildPackage {
pname = package;
version = crateInfo.version;
src = pkgs.lib.cleanSourceWith {
src = inputs.holochain;
filter = includeFilesFilter;
};

# Load source with a custom filter so we can include non-cargo files that get used during the build
src = holochainCommon.src;

strictDeps = true;
doCheck = false;
Expand Down

0 comments on commit 9bbc0bb

Please sign in to comment.