Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix: use -ld_new on macOS #3880

Merged
merged 2 commits into from
Jun 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,25 @@
libiconv
];

# work around https://github.com/nextest-rs/nextest/issues/267
# this needs to exist in both the devShell and preCheck phase!
darwinNextestHack = pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
export DYLD_FALLBACK_LIBRARY_PATH=$(${ourRustVersion}/bin/rustc --print sysroot)/lib
'';

# 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
];

# on macOS and Linux, use faster parallel linkers that are much more
# efficient than the defaults. these noticeably improve link time even for
# medium sized rust projects like jj
rustLinkerFlags =
if pkgs.stdenv.isLinux then
[ "-fuse-ld=mold" "-Wl,--compress-debug-sections=zstd" ]
else if pkgs.stdenv.isDarwin then
[ "-fuse-ld=/usr/bin/ld" "-ld_new" ]
else
[ ];

rustLinkFlagsString = pkgs.lib.concatStringsSep " " (pkgs.lib.concatMap (x:
[ "-C" "link-arg=${x}" ]
) rustLinkerFlags);
in
{
packages = {
Expand Down Expand Up @@ -98,13 +101,13 @@

ZSTD_SYS_USE_PKG_CONFIG = "1";
LIBSSH2_SYS_USE_PKG_CONFIG = "1";
RUSTFLAGS = pkgs.lib.optionalString useMoldLinker "-C link-arg=-fuse-ld=mold";
RUSTFLAGS = pkgs.lib.optionalString pkgs.stdenv.isLinux "-C link-arg=-fuse-ld=mold";
NIX_JJ_GIT_HASH = self.rev or "";
CARGO_INCREMENTAL = "0";

preCheck = ''
export RUST_BACKTRACE=1
'' + darwinNextestHack;
'';

postInstall = ''
$out/bin/jj util mangen > ./jj.1
Expand Down Expand Up @@ -175,10 +178,8 @@
export ZSTD_SYS_USE_PKG_CONFIG=1
export LIBSSH2_SYS_USE_PKG_CONFIG=1

export RUSTFLAGS="-Zthreads=0"
'' + pkgs.lib.optionalString useMoldLinker ''
export RUSTFLAGS+=" -C link-arg=-fuse-ld=mold -C link-arg=-Wl,--compress-debug-sections=zstd"
'' + darwinNextestHack;
export RUSTFLAGS="-Zthreads=0 ${rustLinkFlagsString}"
'';
};
}));
}