Skip to content

Commit 1a7e170

Browse files
committed
Use mold for linking when supported
1 parent f5ec8c5 commit 1a7e170

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

flake.nix

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@
3434
rust' = (rust-bin.fromRustupToolchainFile ./rust-toolchain.toml);
3535
# Setup rust nix packaging
3636
craneLib = (crane.mkLib pkgs).overrideToolchain (_: rust');
37+
stdenvSelector = p: if p.stdenv.hostPlatform.isElf then p.stdenvAdapters.useMoldLinker p.stdenv else p.stdenv;
3738
commonArgs = {
3839
src = craneLib.cleanCargoSource ./.;
3940
strictDeps = true;
4041

4142
buildInputs = with pkgs; [ openssl ];
4243
nativeBuildInputs = with pkgs; [ pkg-config ];
44+
45+
# Use mold linker for faster builds on ELF platforms
46+
stdenv = stdenvSelector;
4347
};
4448
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
4549
commonArgsWithDeps = commonArgs // {
@@ -94,7 +98,11 @@
9498
}
9599
);
96100
};
97-
devShells.default = craneLib.devShell {
101+
devShells.default = craneLib.devShell.override {
102+
mkShell = pkgs.mkShell.override {
103+
stdenv = stdenvSelector pkgs;
104+
};
105+
} {
98106
# Add all build-time dependencies to the environment
99107
packages =
100108
cranePackage.buildInputs

0 commit comments

Comments
 (0)