Skip to content

Commit

Permalink
Merge pull request #21 from darksoil-studio/develop
Browse files Browse the repository at this point in the history
Speed up nix build of scaffold crates
  • Loading branch information
guillemcordoba authored Jul 21, 2024
2 parents 256ed3a + 0d70ad1 commit c451b5b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 37 deletions.
12 changes: 2 additions & 10 deletions .github/workflows/build-scaffold-holochain-runtime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,25 @@ jobs:
with:
name: darksoil-studio

- name: Build scaffold-holochain-runtime
env:
CACHIX_AUTH_TOKEN: "${{ secrets.DARKSOIL_CACHIX_AUTH_TOKEN }}"
run: |
nix build --accept-flake-config -L .#scaffold-holochain-runtime
cachix push darksoil-studio $(nix path-info --accept-flake-config .#scaffold-holochain-runtime)
- name: Test scaffold-holochain-runtime
run: |
cargo test -p scaffold-holochain-runtime
sh ./crates/scaffold-holochain-runtime/run_test.sh
- name: Cache scaffold-holochain-runtime
if: github.event_name == 'pull_request' && github.base_ref == 'main'
env:
CACHIX_AUTH_TOKEN: "${{ secrets.DARKSOIL_CACHIX_AUTH_TOKEN }}"
run: |
nix build --accept-flake-config -L .#scaffold-holochain-runtime
cachix watch-exec darksoil-studio -- nix build --accept-flake-config -L .#scaffold-holochain-runtime
cachix push darksoil-studio $(nix path-info --accept-flake-config .#scaffold-holochain-runtime)
- name: Pin scaffold-holochain-runtime
if: github.event_name != 'pull_request' && github.ref_name == 'main'
env:
CACHIX_AUTH_TOKEN: "${{ secrets.DARKSOIL_CACHIX_AUTH_TOKEN }}"
run: |
nix build --accept-flake-config -L .#scaffold-holochain-runtime
cachix watch-exec darksoil-studio -- nix build --accept-flake-config -L .#scaffold-holochain-runtime
cachix push darksoil-studio $(nix path-info --accept-flake-config .#scaffold-holochain-runtime)
cachix pin darksoil-studio scaffold-holochain-runtime $(nix path-info --accept-flake-config .#scaffold-holochain-runtime)
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ jobs:
with:
name: darksoil-studio

- name: Build scaffold-tauri-happ
env:
CACHIX_AUTH_TOKEN: "${{ secrets.DARKSOIL_CACHIX_AUTH_TOKEN }}"
run: |
nix build --accept-flake-config -L .#scaffold-tauri-happ
cachix push darksoil-studio $(nix path-info --accept-flake-config .#scaffold-tauri-happ)
- name: Test scaffold-tauri-happ
run: |
cargo test -p scaffold-tauri-happ
Expand All @@ -56,15 +49,15 @@ jobs:
env:
CACHIX_AUTH_TOKEN: "${{ secrets.DARKSOIL_CACHIX_AUTH_TOKEN }}"
run: |
nix build --accept-flake-config -L .#scaffold-tauri-happ
cachix watch-exec darksoil-studio -- nix build --accept-flake-config -L .#scaffold-tauri-happ
cachix push darksoil-studio $(nix path-info --accept-flake-config .#scaffold-tauri-happ)
- name: Pin scaffold-tauri-happ
if: github.event_name != 'pull_request' && github.ref_name == 'main'
env:
CACHIX_AUTH_TOKEN: "${{ secrets.DARKSOIL_CACHIX_AUTH_TOKEN }}"
run: |
nix build --accept-flake-config -L .#scaffold-tauri-happ
cachix watch-exec darksoil-studio -- nix build --accept-flake-config -L .#scaffold-tauri-happ
cachix push darksoil-studio $(nix path-info --accept-flake-config .#scaffold-tauri-happ)
cachix pin darksoil-studio scaffold-tauri-happ $(nix path-info --accept-flake-config .#scaffold-tauri-happ)
12 changes: 3 additions & 9 deletions crates/scaffold-holochain-runtime/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
crate = cargoToml.package.name;

commonArgs = {
src = craneLib.path ../../.;
src = (self.lib.cleanScaffoldingSource { inherit lib; })
(craneLib.path ../../.);
doCheck = false;
buildInputs = inputs.hc-infra.outputs.lib.holochainAppDeps.buildInputs {
inherit pkgs lib;
Expand All @@ -23,14 +24,7 @@
++ (inputs.hc-infra.outputs.lib.holochainAppDeps.nativeBuildInputs {
inherit pkgs lib;
});
# TODO: remove this if possible
postPatch = ''
mkdir -p "$TMPDIR/nix-vendor"
cp -Lr "$cargoVendorDir" -T "$TMPDIR/nix-vendor"
sed -i "s|$cargoVendorDir|$TMPDIR/nix-vendor/|g" "$TMPDIR/nix-vendor/config.toml"
chmod -R +w "$TMPDIR/nix-vendor"
cargoVendorDir="$TMPDIR/nix-vendor"
'';
cargoExtraArgs = "--locked --package scaffold-holochain-runtime";
};
in craneLib.buildPackage (commonArgs // {
pname = crate;
Expand Down
13 changes: 4 additions & 9 deletions crates/scaffold-tauri-happ/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

{
perSystem = { inputs', pkgs, system, lib, ... }: {

packages.scaffold-tauri-happ = let
craneLib = inputs.crane.mkLib pkgs;

Expand All @@ -12,7 +13,8 @@
crate = cargoToml.package.name;

commonArgs = {
src = craneLib.path ../../.;
src = (self.lib.cleanScaffoldingSource { inherit lib; })
(craneLib.path ../../.);
doCheck = false;
buildInputs = inputs.hc-infra.outputs.lib.holochainAppDeps.buildInputs {
inherit pkgs lib;
Expand All @@ -22,14 +24,7 @@
++ (inputs.hc-infra.outputs.lib.holochainAppDeps.nativeBuildInputs {
inherit pkgs lib;
});
# TODO: remove this if possible
postPatch = ''
mkdir -p "$TMPDIR/nix-vendor"
cp -Lr "$cargoVendorDir" -T "$TMPDIR/nix-vendor"
sed -i "s|$cargoVendorDir|$TMPDIR/nix-vendor/|g" "$TMPDIR/nix-vendor/config.toml"
chmod -R +w "$TMPDIR/nix-vendor"
cargoVendorDir="$TMPDIR/nix-vendor"
'';
cargoExtraArgs = "--locked --package scaffold-tauri-happ";
};
in craneLib.buildPackage (commonArgs // {
pname = crate;
Expand Down
32 changes: 32 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,38 @@

name = "tauri-workspace";
};
filterScaffoldingSources = { lib }:
orig_path: type:
let
path = (toString orig_path);
base = baseNameOf path;
parentDir = baseNameOf (dirOf path);

matchesSuffix = lib.any (suffix: lib.hasSuffix suffix base) [
# Keep rust sources
".rs"
# Keep all toml files as they are commonly used to configure other
# cargo-based tools
".toml"
# Keep templates
".hbs"
];

# Cargo.toml already captured above
isCargoFile = base == "Cargo.lock";

# .cargo/config.toml already captured above
isCargoConfig = parentDir == ".cargo" && base == "config";
in type == "directory" || matchesSuffix || isCargoFile
|| isCargoConfig;
cleanScaffoldingSource = { lib }:
src:
lib.cleanSourceWith {
src = lib.cleanSource src;
filter = filterScaffoldingSources { inherit lib; };

name = "scaffolding-workspace";
};

# TODO
# tauriApp = {pkgs,lib}: ;
Expand Down

0 comments on commit c451b5b

Please sign in to comment.