ok/jj
1
0
Fork 0
forked from mirrors/jj

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 <aseipp@pobox.com>
This commit is contained in:
Austin Seipp 2023-07-14 06:34:36 -05:00
parent fc2b595098
commit c8271f7617

View file

@ -49,6 +49,16 @@
libiconv 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 in
{ {
packages = { packages = {
@ -72,13 +82,14 @@
installShellFiles installShellFiles
makeWrapper makeWrapper
pkg-config pkg-config
]; ] ++ linuxNativeDeps;
buildInputs = with pkgs; [ buildInputs = with pkgs; [
openssl zstd libgit2 libssh2 openssl zstd libgit2 libssh2
] ++ darwinDeps; ] ++ darwinDeps;
ZSTD_SYS_USE_PKG_CONFIG = "1"; ZSTD_SYS_USE_PKG_CONFIG = "1";
LIBSSH2_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 ""; NIX_JJ_GIT_HASH = self.rev or "";
CARGO_INCREMENTAL = "0"; CARGO_INCREMENTAL = "0";
@ -135,12 +146,14 @@
# For building the documentation website # For building the documentation website
poetry poetry
] ++ darwinDeps; ] ++ darwinDeps ++ linuxNativeDeps;
shellHook = '' shellHook = ''
export RUST_BACKTRACE=1 export RUST_BACKTRACE=1
export ZSTD_SYS_USE_PKG_CONFIG=1 export ZSTD_SYS_USE_PKG_CONFIG=1
export LIBSSH2_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"
''; '';
}; };
})); }));