Skip to content

Commit a6da88f

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

File tree

4 files changed

+104
-97
lines changed

4 files changed

+104
-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: 78 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -14,125 +14,106 @@
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 -p graphite-wasm-wrapper --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+
cargoExtraArgs = "-p graphite-desktop-platform-linux";
62+
}
63+
);
64+
65+
depsCombined = deps.crane.lib.combineArtifacts "${info.pname}-deps-${info.version}" [
66+
wasmDeps
67+
nativeDeps
68+
];
11069
in
11170

11271
deps.crane.lib.buildPackage (
11372
common
11473
// {
115-
cargoArtifacts = deps.crane.lib.buildDepsOnly common;
74+
inherit (info) pname;
11675

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-
};
76+
cargoArtifacts = depsCombined;
77+
78+
buildInputs = libs;
79+
nativeBuildInputs = [
80+
pkgs.pkg-config
81+
pkgs.lld
82+
pkgs.nodejs
83+
pkgs.nodePackages.npm
84+
pkgs.binaryen
85+
pkgs.wasm-bindgen-cli_0_2_100
86+
pkgs.wasm-pack
87+
pkgs.cargo-about
88+
pkgs.removeReferencesTo
89+
pkgs.importNpmLock.npmConfigHook
90+
];
12391

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

134112
preBuild = ''
135-
${lib.getExe self.packages.${system}.tools.third-party-licenses}
113+
# Prevent `package-installer.js` from trying to update npm dependencies
114+
touch -r frontend/package-lock.json -d '+1 year' frontend/node_modules/.install-timestamp
115+
116+
export HOME="$TMPDIR"
136117
''
137118
+ (
138119
if self ? rev then
@@ -143,6 +124,10 @@ deps.crane.lib.buildPackage (
143124
""
144125
);
145126

127+
buildPhaseCargoCommand = "cargo run build desktop${if dev then " debug" else ""}";
128+
129+
doNotPostBuildInstallCargoBinaries = true;
130+
146131
installPhase = ''
147132
mkdir -p $out/bin
148133
cp target/${if dev then "debug" else "release"}/graphite $out/bin/graphite
@@ -161,12 +146,14 @@ deps.crane.lib.buildPackage (
161146
'';
162147

163148
postFixup = ''
164-
remove-references-to -t "${cargoVendorDir}" $out/bin/graphite
149+
remove-references-to -t "${common.cargoVendorDir}" $out/bin/graphite
165150
166151
patchelf \
167152
--set-rpath "${pkgs.lib.makeLibraryPath libs}:${deps.cef.env.CEF_PATH}" \
168153
--add-needed libGL.so \
169154
$out/bin/graphite
170155
'';
156+
157+
passthru.deps = depsCombined;
171158
}
172159
)

0 commit comments

Comments
 (0)