diff --git a/.cargo/config.toml b/.cargo/config.toml index b754c2e48ef..dbf3919a4c6 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -2,7 +2,8 @@ rustflags = ["--cfg", "tokio_unstable"] [target.x86_64-unknown-linux-gnu] -rustflags = ["-C", "link-arg=-fuse-ld=lld", "-C", "link-arg=-Wl,--compress-debug-sections=zlib", "--cfg", "tokio_unstable"] +linker = "clang" +rustflags = ["-C", "link-arg=-fuse-ld=mold", "-C", "link-arg=-Wl,--compress-debug-sections=zlib", "--cfg", "tokio_unstable"] # mold is currently broken on MacOS # [target.aarch64-apple-darwin] diff --git a/flake.nix b/flake.nix index 075f50370f3..74d2f7345d7 100644 --- a/flake.nix +++ b/flake.nix @@ -34,6 +34,32 @@ (final: prev: { cargo-udeps = pkgs-unstable.cargo-udeps; + # mold wrapper from https://discourse.nixos.org/t/using-mold-as-linker-prevents-libraries-from-being-found/18530/5 + mold = + let + bintools-wrapper = "${nixpkgs}/pkgs/build-support/bintools-wrapper"; + in + prev.symlinkJoin { + name = "mold"; + paths = [ prev.mold ]; + nativeBuildInputs = [ prev.makeWrapper ]; + suffixSalt = lib.replaceStrings [ "-" "." ] [ "_" "_" ] prev.targetPlatform.config; + postBuild = '' + for bin in ${prev.mold}/bin/*; do + rm $out/bin/"$(basename "$bin")" + + export prog="$bin" + substituteAll "${bintools-wrapper}/ld-wrapper.sh" $out/bin/"$(basename "$bin")" + chmod +x $out/bin/"$(basename "$bin")" + + mkdir -p $out/nix-support + substituteAll "${bintools-wrapper}/add-flags.sh" $out/nix-support/add-flags.sh + substituteAll "${bintools-wrapper}/add-hardening.sh" $out/nix-support/add-hardening.sh + substituteAll "${bintools-wrapper}/../wrapper-common/utils.bash" $out/nix-support/utils.bash + done + ''; + }; + # Note: we are using cargo-nextest from pkgs-unstable because it has some fixes we need # Note: shell script adding DYLD_FALLBACK_LIBRARY_PATH because of: https://github.com/nextest-rs/nextest/issues/962 cargo-nextest = pkgs.writeShellScriptBin "cargo-nextest" "exec env DYLD_FALLBACK_LIBRARY_PATH=\"$(dirname $(which rustc))/../lib\" ${pkgs-unstable.cargo-nextest}/bin/cargo-nextest \"$@\"";