Skip to content

Commit 7ee44ee

Browse files
Desktop: Improve Nix build times with more caching
1 parent 1d03372 commit 7ee44ee

File tree

4 files changed

+103
-97
lines changed

4 files changed

+103
-97
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ jobs:
643643
run: sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache
644644

645645
- name: 📦 Build Nix package
646-
run: nix build .#graphite${{ inputs.debug && '-dev' || '' }} --no-link --print-out-paths
646+
run: nix build .#graphite${{ inputs.debug && '-dev' || '' }} --no-link --print-out-paths --print-build-logs
647647

648648
- name: 📤 Push to Nix cache
649649
env:
@@ -653,8 +653,16 @@ jobs:
653653
nix run nixpkgs#cachix -- authtoken $NIX_CACHE_AUTH_TOKEN
654654
nix build .#graphite${{ inputs.debug && '-dev' || '' }} --no-link --print-out-paths | nix run nixpkgs#cachix -- push $NIX_CACHE_NAME
655655
656+
- name: 📤 Push Dependencies to dev Nix cache
657+
env:
658+
NIX_CACHE_AUTH_TOKEN: ${{ secrets.NIX_CACHE_AUTH_TOKEN_DEV }}
659+
NIX_CACHE_NAME: graphite-dev
660+
run: |
661+
nix run nixpkgs#cachix -- authtoken $NIX_CACHE_AUTH_TOKEN
662+
nix build .#graphite${{ inputs.debug && '-dev' || '' }}.deps --no-link --print-out-paths | nix run nixpkgs#cachix -- push $NIX_CACHE_NAME
663+
656664
- name: 🏗 Build Linux bundle
657-
run: nix build .#graphite${{ inputs.debug && '-dev' || '' }}-bundle.tar.xz && cp ./result ./graphite-linux-bundle.tar.xz
665+
run: nix build .#graphite-bundle${{ inputs.debug && '-dev' || '' }}.tar.xz && cp ./result ./graphite-linux-bundle.tar.xz
658666

659667
- name: 📦 Upload Linux bundle
660668
uses: actions/upload-artifact@v6
@@ -692,7 +700,7 @@ jobs:
692700
693701
- name: 🏗 Build Flatpak
694702
run: |
695-
nix build .#graphite${{ inputs.debug && '-dev' || '' }}-flatpak-manifest
703+
nix build .#graphite-flatpak-manifest${{ inputs.debug && '-dev' || '' }}
696704
697705
rm -rf .flatpak
698706
mkdir -p .flatpak

.nix/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ in
6060
graphite-raster-nodes-shaders = lib.call ./pkgs/graphite-raster-nodes-shaders.nix;
6161
graphite-branding = lib.call ./pkgs/graphite-branding.nix;
6262
graphite-bundle = (lib.call ./pkgs/graphite-bundle.nix) { };
63-
graphite-dev-bundle = (lib.call ./pkgs/graphite-bundle.nix) { graphite = graphite-dev; };
63+
graphite-bundle-dev = (lib.call ./pkgs/graphite-bundle.nix) { graphite = graphite-dev; };
6464
graphite-flatpak-manifest = (lib.call ./pkgs/graphite-flatpak-manifest.nix) { };
65-
graphite-dev-flatpak-manifest = (lib.call ./pkgs/graphite-flatpak-manifest.nix) { graphite-bundle = graphite-dev-bundle; };
65+
graphite-flatpak-manifest-dev = (lib.call ./pkgs/graphite-flatpak-manifest.nix) { graphite-bundle = graphite-bundle-dev; };
6666

6767
# TODO: graphene-cli = lib.call ./pkgs/graphene-cli.nix;
6868

.nix/deps/crane.nix

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
{ pkgs, inputs, ... }:
22

33
{
4-
lib = inputs.crane.mkLib pkgs;
4+
lib = (inputs.crane.mkLib pkgs) // {
5+
combineArtifacts =
6+
name: artifacts:
7+
pkgs.runCommand name
8+
{
9+
nativeBuildInputs = [ pkgs.zstd ];
10+
}
11+
''
12+
mkdir -p $out target
13+
${pkgs.lib.concatMapStringsSep "\n" (a: "tar -xf ${a}/target.tar.zst -C target") artifacts}
14+
tar -cf $out/target.tar.zst -C target --use-compress-program "zstd -T0" .
15+
'';
16+
};
517
}

.nix/pkgs/graphite.nix

Lines changed: 77 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -14,125 +14,105 @@
1414

1515
let
1616
branding = self.packages.${system}.graphite-branding;
17-
cargoVendorDir = deps.crane.lib.vendorCargoDeps { inherit (info) src; };
18-
resourcesCommon = {
19-
pname = "${info.pname}-resources";
20-
inherit (info) version src;
21-
inherit cargoVendorDir;
22-
strictDeps = true;
23-
nativeBuildInputs = [
24-
pkgs.pkg-config
25-
pkgs.lld
26-
pkgs.nodejs
27-
pkgs.nodePackages.npm
28-
pkgs.binaryen
29-
pkgs.wasm-bindgen-cli_0_2_100
30-
pkgs.wasm-pack
31-
pkgs.cargo-about
32-
];
33-
buildInputs = [ pkgs.openssl ];
34-
env.CARGO_PROFILE = if dev then "dev" else "release";
35-
cargoExtraArgs = "--target wasm32-unknown-unknown -p graphite-wasm-wrapper --no-default-features --features native";
36-
doCheck = false;
37-
};
38-
resources = deps.crane.lib.buildPackage (
39-
resourcesCommon
40-
// {
41-
cargoArtifacts = deps.crane.lib.buildDepsOnly resourcesCommon;
42-
43-
npmDeps = pkgs.importNpmLock {
44-
npmRoot = "${info.src}/frontend";
45-
};
46-
47-
npmRoot = "frontend";
48-
npmConfigScript = "setup";
49-
makeCacheWritable = true;
50-
51-
nativeBuildInputs = [
52-
pkgs.importNpmLock.npmConfigHook
53-
pkgs.removeReferencesTo
54-
]
55-
++ resourcesCommon.nativeBuildInputs;
56-
57-
prePatch = ''
58-
mkdir branding
59-
cp -r ${branding}/* branding
60-
cp ${info.src}/.branding branding/.branding
61-
'';
62-
63-
buildPhase = ''
64-
export HOME="$TMPDIR"
65-
66-
pushd frontend
67-
npm run native:build-${if dev then "dev" else "production"}
68-
popd
69-
'';
70-
71-
installPhase = ''
72-
mkdir -p $out
73-
cp -r frontend/dist/* $out/
74-
'';
75-
76-
postFixup = ''
77-
find "$out" -type f -exec remove-references-to -t "${cargoVendorDir}" '{}' +
78-
'';
79-
}
80-
);
17+
profile = if dev then "dev" else "release";
8118
libs = [
8219
pkgs.wayland
8320
pkgs.vulkan-loader
8421
pkgs.libGL
8522
pkgs.openssl
8623
pkgs.libraw
87-
8824
# X11 Support
8925
pkgs.libxkbcommon
9026
pkgs.libXcursor
9127
pkgs.libxcb
9228
pkgs.libX11
9329
];
30+
9431
common = {
95-
inherit (info) pname version src;
96-
inherit cargoVendorDir;
97-
strictDeps = true;
32+
inherit (info) version src;
33+
cargoVendorDir = deps.crane.lib.vendorCargoDeps { inherit (info) src; };
9834
buildInputs = libs;
99-
nativeBuildInputs = [
100-
pkgs.pkg-config
101-
pkgs.cargo-about
102-
pkgs.removeReferencesTo
103-
];
104-
env = deps.cef.env // {
105-
CARGO_PROFILE = if dev then "dev" else "release";
106-
};
107-
cargoExtraArgs = "-p graphite-desktop";
35+
strictDeps = true;
10836
doCheck = false;
10937
};
38+
39+
wasmDeps = deps.crane.lib.buildDepsOnly (
40+
common
41+
// {
42+
pname = "${info.pname}-wasm";
43+
nativeBuildInputs = [
44+
pkgs.pkg-config
45+
pkgs.lld
46+
];
47+
buildInputs = [ pkgs.openssl ];
48+
env.CARGO_PROFILE = profile;
49+
cargoExtraArgs = "--target wasm32-unknown-unknown --no-default-features --features native";
50+
}
51+
);
52+
53+
nativeDeps = deps.crane.lib.buildDepsOnly (
54+
common
55+
// {
56+
pname = "${info.pname}-native";
57+
nativeBuildInputs = [ pkgs.pkg-config ];
58+
env = deps.cef.env // {
59+
CARGO_PROFILE = profile;
60+
};
61+
}
62+
);
63+
64+
depsCombined = deps.crane.lib.combineArtifacts "${info.pname}-deps-${info.version}" [
65+
wasmDeps
66+
nativeDeps
67+
];
11068
in
11169

11270
deps.crane.lib.buildPackage (
11371
common
11472
// {
115-
cargoArtifacts = deps.crane.lib.buildDepsOnly common;
73+
inherit (info) pname;
11674

117-
env = common.env // {
118-
RASTER_NODES_SHADER_PATH = self.packages.${system}.graphite-raster-nodes-shaders;
119-
EMBEDDED_RESOURCES = resources;
120-
GRAPHITE_GIT_COMMIT_HASH = self.rev or "unknown";
121-
GRAPHITE_GIT_COMMIT_DATE = self.lastModified or "unknown";
122-
};
75+
cargoArtifacts = depsCombined;
76+
77+
buildInputs = libs;
78+
nativeBuildInputs = [
79+
pkgs.pkg-config
80+
pkgs.lld
81+
pkgs.nodejs
82+
pkgs.nodePackages.npm
83+
pkgs.binaryen
84+
pkgs.wasm-bindgen-cli_0_2_100
85+
pkgs.wasm-pack
86+
pkgs.cargo-about
87+
pkgs.removeReferencesTo
88+
pkgs.importNpmLock.npmConfigHook
89+
];
12390

12491
npmDeps = pkgs.importNpmLock {
12592
npmRoot = "${info.src}/frontend";
12693
};
12794
npmRoot = "frontend";
128-
nativeBuildInputs = [
129-
pkgs.importNpmLock.npmConfigHook
130-
pkgs.nodePackages.npm
131-
]
132-
++ common.nativeBuildInputs;
95+
npmConfigScript = "setup";
96+
makeCacheWritable = true;
97+
98+
env = deps.cef.env // {
99+
CARGO_PROFILE = profile;
100+
RASTER_NODES_SHADER_PATH = self.packages.${system}.graphite-raster-nodes-shaders;
101+
GRAPHITE_GIT_COMMIT_HASH = self.rev or "unknown";
102+
GRAPHITE_GIT_COMMIT_DATE = self.lastModified or "unknown";
103+
};
104+
105+
postPatch = ''
106+
mkdir branding
107+
cp -r ${branding}/* branding
108+
cp ${info.src}/.branding branding/.branding
109+
'';
133110

134111
preBuild = ''
135-
${lib.getExe self.packages.${system}.tools.third-party-licenses}
112+
# Prevent `package-installer.js` from trying to update npm dependencies
113+
touch -r frontend/package-lock.json -d '+1 year' frontend/node_modules/.install-timestamp
114+
115+
export HOME="$TMPDIR"
136116
''
137117
+ (
138118
if self ? rev then
@@ -143,6 +123,10 @@ deps.crane.lib.buildPackage (
143123
""
144124
);
145125

126+
buildPhaseCargoCommand = "cargo run build desktop${if dev then " debug" else ""}";
127+
128+
doNotPostBuildInstallCargoBinaries = true;
129+
146130
installPhase = ''
147131
mkdir -p $out/bin
148132
cp target/${if dev then "debug" else "release"}/graphite $out/bin/graphite
@@ -161,12 +145,14 @@ deps.crane.lib.buildPackage (
161145
'';
162146

163147
postFixup = ''
164-
remove-references-to -t "${cargoVendorDir}" $out/bin/graphite
148+
remove-references-to -t "${common.cargoVendorDir}" $out/bin/graphite
165149
166150
patchelf \
167151
--set-rpath "${pkgs.lib.makeLibraryPath libs}:${deps.cef.env.CEF_PATH}" \
168152
--add-needed libGL.so \
169153
$out/bin/graphite
170154
'';
155+
156+
passthru.deps = depsCombined;
171157
}
172158
)

0 commit comments

Comments
 (0)