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
|
2023-09-25 10:34:55 +00:00
|
|
|
, tbb
|
2022-09-04 11:33:19 +00:00
|
|
|
, zlib
|
2023-09-25 10:34:55 +00:00
|
|
|
, zstd
|
2023-09-24 12:45:09 +00:00
|
|
|
|
|
|
|
, buildPackages
|
2023-10-19 12:49:25 +00:00
|
|
|
, clangStdenv
|
|
|
|
, gccStdenv
|
2023-09-24 12:45:09 +00:00
|
|
|
, hello
|
2022-09-04 11:33:19 +00:00
|
|
|
, mold
|
2023-10-13 00:35:26 +00:00
|
|
|
, mold-wrapped
|
2023-09-24 12:45:09 +00:00
|
|
|
, runCommandCC
|
|
|
|
, testers
|
2023-10-13 00:35:26 +00:00
|
|
|
, useMoldLinker
|
2021-07-12 19:12:26 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "mold";
|
2023-11-30 08:20:56 +00:00
|
|
|
version = "2.4.0";
|
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}";
|
2023-11-30 08:20:56 +00:00
|
|
|
hash = "sha256-ufqTbY59AI1MrY/vrsDg5a4WEVz9IFTdgl1GHMw9HGc=";
|
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 = [
|
2023-09-25 10:34:55 +00:00
|
|
|
tbb
|
2023-01-08 08:51:50 +00:00
|
|
|
zlib
|
2023-09-25 10:34:55 +00:00
|
|
|
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"
|
2023-09-25 10:34:55 +00:00
|
|
|
"-DMOLD_USE_SYSTEM_TBB:BOOL=ON"
|
2023-01-08 08:51:50 +00:00
|
|
|
];
|
2022-09-04 11:33:19 +00:00
|
|
|
|
2023-02-20 15:36:06 +00:00
|
|
|
env.NIX_CFLAGS_COMPILE = toString (lib.optionals stdenv.isDarwin [
|
2023-01-08 08:51:50 +00:00
|
|
|
"-faligned-allocation"
|
2023-02-20 15:36:06 +00:00
|
|
|
]);
|
2022-09-04 11:33:19 +00:00
|
|
|
|
2023-07-26 21:04:26 +00:00
|
|
|
passthru = {
|
|
|
|
updateScript = nix-update-script { };
|
2023-10-13 00:35:26 +00:00
|
|
|
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; };
|
2023-10-19 12:49:25 +00:00
|
|
|
} // 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; }));
|
2023-10-13 00:35:26 +00:00
|
|
|
wrapped = helloTest "wrapped" (hello.overrideAttrs (previousAttrs: {
|
|
|
|
nativeBuildInputs = (previousAttrs.nativeBuildInputs or [ ]) ++ [ mold-wrapped ];
|
|
|
|
NIX_CFLAGS_LINK = toString (previousAttrs.NIX_CFLAGS_LINK or "") + " -fuse-ld=mold";
|
|
|
|
}));
|
|
|
|
};
|
2023-07-26 21:04:26 +00:00
|
|
|
};
|
2022-01-27 08:45:38 +00:00
|
|
|
|
2021-07-12 19:12:26 +00:00
|
|
|
meta = with lib; {
|
2023-09-24 22:15:45 +00:00
|
|
|
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}";
|
2023-07-26 21:05:35 +00:00
|
|
|
license = licenses.mit;
|
2022-03-22 17:59:05 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
}
|