2024-06-05 15:53:02 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
stdenv,
|
|
|
|
fetchFromGitHub,
|
|
|
|
substituteAll,
|
|
|
|
binutils,
|
|
|
|
asciidoctor,
|
|
|
|
cmake,
|
|
|
|
perl,
|
|
|
|
fmt,
|
|
|
|
hiredis,
|
|
|
|
xxHash,
|
|
|
|
zstd,
|
|
|
|
bashInteractive,
|
|
|
|
doctest,
|
|
|
|
xcodebuild,
|
|
|
|
makeWrapper,
|
|
|
|
nix-update-script,
|
2020-11-24 20:58:05 +00:00
|
|
|
}:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-03-15 16:39:30 +00:00
|
|
|
stdenv.mkDerivation (finalAttrs: {
|
2020-04-24 23:36:52 +00:00
|
|
|
pname = "ccache";
|
2024-06-05 15:53:02 +00:00
|
|
|
version = "4.10";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-07-18 16:06:22 +00:00
|
|
|
src = fetchFromGitHub {
|
2023-03-15 16:39:30 +00:00
|
|
|
owner = "ccache";
|
|
|
|
repo = "ccache";
|
|
|
|
rev = "refs/tags/v${finalAttrs.version}";
|
2024-06-05 15:53:02 +00:00
|
|
|
# `git archive` replaces `$Format:%H %D$` in cmake/CcacheVersion.cmake
|
|
|
|
# we need to replace it with something reproducible
|
|
|
|
# see https://github.com/NixOS/nixpkgs/pull/316524
|
|
|
|
postFetch = ''
|
|
|
|
sed -i -E \
|
|
|
|
's/version_info "([0-9a-f]{40}) .*(tag: v[^,]+).*"/version_info "\1 \2"/g w match' \
|
|
|
|
$out/cmake/CcacheVersion.cmake
|
|
|
|
if [ -s match ]; then
|
|
|
|
rm match
|
|
|
|
else # pattern didn't match
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
hash = "sha256-YHSr2pnk17QEdrIHInXX2eBFN9OGjdleaB41VLaqlnA=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
outputs = [
|
|
|
|
"out"
|
|
|
|
"man"
|
|
|
|
];
|
2021-04-12 18:23:04 +00:00
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
patches = [
|
2021-04-12 18:23:04 +00:00
|
|
|
# When building for Darwin, test/run uses dwarfdump, whereas on
|
|
|
|
# Linux it uses objdump. We don't have dwarfdump packaged for
|
|
|
|
# Darwin, so this patch updates the test to also use objdump on
|
|
|
|
# Darwin.
|
2023-08-04 22:07:22 +00:00
|
|
|
# Additionally, when cross compiling, the correct target prefix
|
|
|
|
# needs to be set.
|
2021-04-12 18:23:04 +00:00
|
|
|
(substituteAll {
|
2023-08-04 22:07:22 +00:00
|
|
|
src = ./fix-objdump-path.patch;
|
|
|
|
objdump = "${binutils.bintools}/bin/${binutils.targetPrefix}objdump";
|
2021-04-12 18:23:04 +00:00
|
|
|
})
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
strictDeps = true;
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
asciidoctor
|
|
|
|
cmake
|
|
|
|
perl
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
buildInputs = [
|
|
|
|
fmt
|
|
|
|
hiredis
|
|
|
|
xxHash
|
|
|
|
zstd
|
2021-08-25 08:27:29 +00:00
|
|
|
];
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
cmakeFlags = lib.optional (!finalAttrs.finalPackage.doCheck) "-DENABLE_TESTING=OFF";
|
|
|
|
|
2020-11-24 20:58:05 +00:00
|
|
|
doCheck = true;
|
2024-06-05 15:53:02 +00:00
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
nativeCheckInputs = [
|
2021-05-20 23:08:51 +00:00
|
|
|
# test/run requires the compgen function which is available in
|
|
|
|
# bashInteractive, but not bash.
|
|
|
|
bashInteractive
|
|
|
|
] ++ lib.optional stdenv.isDarwin xcodebuild;
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
checkInputs = [
|
|
|
|
doctest
|
|
|
|
];
|
|
|
|
|
2023-03-15 16:39:30 +00:00
|
|
|
checkPhase =
|
|
|
|
let
|
2024-06-05 15:53:02 +00:00
|
|
|
badTests =
|
|
|
|
[
|
|
|
|
"test.trim_dir" # flaky on hydra (possibly filesystem-specific?)
|
|
|
|
]
|
|
|
|
++ lib.optionals stdenv.isDarwin [
|
|
|
|
"test.basedir"
|
|
|
|
"test.fileclone" # flaky on hydra (possibly filesystem-specific?)
|
|
|
|
"test.multi_arch"
|
|
|
|
"test.nocpp2"
|
|
|
|
];
|
2023-03-15 16:39:30 +00:00
|
|
|
in
|
|
|
|
''
|
|
|
|
runHook preCheck
|
|
|
|
export HOME=$(mktemp -d)
|
|
|
|
ctest --output-on-failure -E '^(${lib.concatStringsSep "|" badTests})$'
|
|
|
|
runHook postCheck
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
passthru = {
|
|
|
|
# A derivation that provides gcc and g++ commands, but that
|
|
|
|
# will end up calling ccache for the given cacheDir
|
2024-06-05 15:53:02 +00:00
|
|
|
links =
|
|
|
|
{ unwrappedCC, extraConfig }:
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
pname = "ccache-links";
|
|
|
|
inherit (finalAttrs) version;
|
|
|
|
passthru = {
|
|
|
|
isClang = unwrappedCC.isClang or false;
|
|
|
|
isGNU = unwrappedCC.isGNU or false;
|
|
|
|
isCcache = true;
|
|
|
|
};
|
|
|
|
inherit (unwrappedCC) lib;
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
|
|
|
# Unwrapped clang does not have a targetPrefix because it is multi-target
|
|
|
|
# target is decided with argv0.
|
|
|
|
buildCommand =
|
|
|
|
let
|
|
|
|
targetPrefix =
|
|
|
|
if unwrappedCC.isClang or false then
|
|
|
|
""
|
|
|
|
else
|
|
|
|
(lib.optionalString (
|
|
|
|
unwrappedCC ? targetConfig && unwrappedCC.targetConfig != null && unwrappedCC.targetConfig != ""
|
|
|
|
) "${unwrappedCC.targetConfig}-");
|
|
|
|
in
|
|
|
|
''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
|
|
|
|
wrap() {
|
|
|
|
local cname="${targetPrefix}$1"
|
|
|
|
if [ -x "${unwrappedCC}/bin/$cname" ]; then
|
|
|
|
makeWrapper ${finalAttrs.finalPackage}/bin/ccache $out/bin/$cname \
|
|
|
|
--run ${lib.escapeShellArg extraConfig} \
|
|
|
|
--add-flags ${unwrappedCC}/bin/$cname
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
wrap cc
|
|
|
|
wrap c++
|
|
|
|
wrap gcc
|
|
|
|
wrap g++
|
|
|
|
wrap clang
|
|
|
|
wrap clang++
|
|
|
|
|
|
|
|
for executable in $(ls ${unwrappedCC}/bin); do
|
|
|
|
if [ ! -x "$out/bin/$executable" ]; then
|
|
|
|
ln -s ${unwrappedCC}/bin/$executable $out/bin/$executable
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
for file in $(ls ${unwrappedCC} | grep -vw bin); do
|
|
|
|
ln -s ${unwrappedCC}/$file $out/$file
|
|
|
|
done
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2023-03-15 16:39:30 +00:00
|
|
|
updateScript = nix-update-script { };
|
|
|
|
};
|
2021-12-06 16:07:01 +00:00
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Compiler cache for fast recompilation of C/C++ code";
|
2020-11-24 20:58:05 +00:00
|
|
|
homepage = "https://ccache.dev";
|
2020-07-18 16:06:22 +00:00
|
|
|
downloadPage = "https://ccache.dev/download.html";
|
2023-03-15 16:39:30 +00:00
|
|
|
changelog = "https://ccache.dev/releasenotes.html#_ccache_${
|
|
|
|
builtins.replaceStrings [ "." ] [ "_" ] finalAttrs.version
|
|
|
|
}";
|
2020-04-24 23:36:52 +00:00
|
|
|
license = licenses.gpl3Plus;
|
2023-10-19 13:55:26 +00:00
|
|
|
mainProgram = "ccache";
|
2024-06-05 15:53:02 +00:00
|
|
|
maintainers = with maintainers; [
|
|
|
|
kira-bruneau
|
|
|
|
r-burns
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
platforms = platforms.unix;
|
|
|
|
};
|
2023-03-15 16:39:30 +00:00
|
|
|
})
|