nixpkgs/pkgs/development/tools/mold/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

120 lines
3.3 KiB
Nix
Raw Normal View History

2022-09-04 11:33:19 +00:00
{ lib
, stdenv
2021-07-12 19:12:26 +00:00
, fetchFromGitHub
2023-09-24 12:45:09 +00:00
, nix-update-script
2021-07-12 19:12:26 +00:00
, cmake
2022-09-04 11:33:19 +00:00
, mimalloc
, ninja
, tbb
2022-09-04 11:33:19 +00:00
, zlib
, zstd
2023-09-24 12:45:09 +00:00
, buildPackages
, clangStdenv
, gccStdenv
2023-09-24 12:45:09 +00:00
, hello
2022-09-04 11:33:19 +00:00
, mold
, mold-wrapped
2023-09-24 12:45:09 +00:00
, runCommandCC
, testers
, useMoldLinker
2021-07-12 19:12:26 +00:00
}:
stdenv.mkDerivation rec {
pname = "mold";
2024-03-01 14:48:11 +00:00
version = "2.4.1";
2021-07-12 19:12:26 +00:00
src = fetchFromGitHub {
owner = "rui314";
2023-09-24 12:45:09 +00:00
repo = "mold";
rev = "v${version}";
2024-03-01 14:48:11 +00:00
hash = "sha256-wwlpYAWP8sAsEkTq0w3s2jAWGayW3v9QcaVRKWHTlGE=";
2021-07-12 19:12:26 +00:00
};
2023-01-08 08:51:50 +00:00
nativeBuildInputs = [
cmake
ninja
];
2021-07-12 19:12:26 +00:00
2023-01-08 08:51:50 +00:00
buildInputs = [
tbb
2023-01-08 08:51:50 +00:00
zlib
zstd
2023-01-08 08:51:50 +00:00
] ++ lib.optionals (!stdenv.isDarwin) [
mimalloc
];
2021-07-12 19:12:26 +00:00
2023-01-08 08:51:50 +00:00
cmakeFlags = [
"-DMOLD_USE_SYSTEM_MIMALLOC:BOOL=ON"
"-DMOLD_USE_SYSTEM_TBB:BOOL=ON"
2023-01-08 08:51:50 +00:00
];
2022-09-04 11:33:19 +00:00
env.NIX_CFLAGS_COMPILE = toString (lib.optionals stdenv.isDarwin [
2023-01-08 08:51:50 +00:00
"-faligned-allocation"
]);
2022-09-04 11:33:19 +00:00
passthru = {
updateScript = nix-update-script { };
tests =
let
helloTest = name: helloMold:
let
command = "$READELF -p .comment ${lib.getExe helloMold}";
emulator = stdenv.hostPlatform.emulator buildPackages;
in
runCommandCC "mold-${name}-test" { passthru = { inherit helloMold; }; }
''
echo "Testing running the 'hello' binary which should be linked with 'mold'" >&2
${emulator} ${lib.getExe helloMold}
echo "Checking for mold in the '.comment' section" >&2
if output=$(${command} 2>&1); then
if grep -Fw -- "mold" - <<< "$output"; then
touch $out
else
echo "No mention of 'mold' detected in the '.comment' section" >&2
echo "The command was:" >&2
echo "${command}" >&2
echo "The output was:" >&2
echo "$output" >&2
exit 1
fi
else
echo -n "${command}" >&2
echo " returned a non-zero exit code." >&2
echo "$output" >&2
exit 1
fi
''
;
in
{
version = testers.testVersion { package = mold; };
} // lib.optionalAttrs stdenv.isLinux {
adapter-gcc = helloTest "adapter-gcc" (hello.override (old: { stdenv = useMoldLinker gccStdenv; }));
adapter-llvm = helloTest "adapter-llvm" (hello.override (old: { stdenv = useMoldLinker clangStdenv; }));
wrapped = helloTest "wrapped" (hello.overrideAttrs (previousAttrs: {
nativeBuildInputs = (previousAttrs.nativeBuildInputs or [ ]) ++ [ mold-wrapped ];
NIX_CFLAGS_LINK = toString (previousAttrs.NIX_CFLAGS_LINK or "") + " -fuse-ld=mold";
}));
};
};
2022-01-27 08:45:38 +00:00
2021-07-12 19:12:26 +00:00
meta = with lib; {
description = "A faster drop-in replacement for existing Unix linkers (unwrapped)";
2022-09-04 11:33:19 +00:00
longDescription = ''
mold is a faster drop-in replacement for existing Unix linkers. It is
several times faster than the LLVM lld linker. mold is designed to
increase developer productivity by reducing build time, especially in
rapid debug-edit-rebuild cycles.
'';
2021-07-12 19:12:26 +00:00
homepage = "https://github.com/rui314/mold";
2023-01-08 08:51:50 +00:00
changelog = "https://github.com/rui314/mold/releases/tag/v${version}";
license = licenses.mit;
platforms = platforms.unix;
2023-09-24 12:45:09 +00:00
mainProgram = "mold";
2023-12-10 23:50:25 +00:00
maintainers = with maintainers; [ azahi paveloom ];
2021-07-12 19:12:26 +00:00
};
}