From c8271f76171197e744622f502c1abe7b7475e61c Mon Sep 17 00:00:00 2001 From: Austin Seipp Date: Fri, 14 Jul 2023 06:34:36 -0500 Subject: [PATCH] nix: use mold linker on Linux Summary: Pure QOL improvement, not that this was too awful as it stood. But this ultimately makes all builds faster, effectively for free; on my Linux machine, debug link time for jj-cli goes from 3s to 1s. This was originally submitted as part of #1864, and backed out as part of #1982, because the default `mold` package did not have the proper "wrapper script" that allowed it to find the right external libraries. Using the `mold-wrapped` package however fixes this. On top of that, let's go ahead and make `mold` the default linker in the Nix package/flake as well; this should improve the `nix build` speed since a lot of tests need to be linked. Signed-off-by: Austin Seipp --- flake.nix | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 9e1523a49..fba7b9b25 100644 --- a/flake.nix +++ b/flake.nix @@ -49,6 +49,16 @@ libiconv ]; + # NOTE (aseipp): on Linux, go ahead and use mold by default to improve + # link times a bit; mostly useful for debug build speed, but will help + # over time if we ever get more dependencies, too + useMoldLinker = pkgs.stdenv.isLinux; + + # these are needed in both devShell and buildInputs + linuxNativeDeps = with pkgs; lib.optionals stdenv.isLinux [ + mold-wrapped + ]; + in { packages = { @@ -72,13 +82,14 @@ installShellFiles makeWrapper pkg-config - ]; + ] ++ linuxNativeDeps; buildInputs = with pkgs; [ openssl zstd libgit2 libssh2 ] ++ darwinDeps; ZSTD_SYS_USE_PKG_CONFIG = "1"; LIBSSH2_SYS_USE_PKG_CONFIG = "1"; + RUSTFLAGS = pkgs.lib.optionalString useMoldLinker "-C link-arg=-fuse-ld=mold"; NIX_JJ_GIT_HASH = self.rev or ""; CARGO_INCREMENTAL = "0"; @@ -135,12 +146,14 @@ # For building the documentation website poetry - ] ++ darwinDeps; + ] ++ darwinDeps ++ linuxNativeDeps; shellHook = '' export RUST_BACKTRACE=1 export ZSTD_SYS_USE_PKG_CONFIG=1 export LIBSSH2_SYS_USE_PKG_CONFIG=1 + '' + pkgs.lib.optionalString useMoldLinker '' + export RUSTFLAGS="-C link-arg=-fuse-ld=mold $RUSTFLAGS" ''; }; }));