Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib
2, stdenv
3, fetchFromGitHub
4, substituteAll
5, binutils
6, asciidoctor
7, cmake
8, perl
9, zstd
10, bashInteractive
11, xcodebuild
12, makeWrapper
13, nix-update-script
14}:
15
16stdenv.mkDerivation (finalAttrs: {
17 pname = "ccache";
18 version = "4.8.1";
19
20 src = fetchFromGitHub {
21 owner = "ccache";
22 repo = "ccache";
23 rev = "refs/tags/v${finalAttrs.version}";
24 sha256 = "sha256-v0XYIaUKgdCYNSlwLNA3+oBEh6IDo8f5GPNsmYzzYRM=";
25 };
26
27 outputs = [ "out" "man" ];
28
29 patches = [
30 # When building for Darwin, test/run uses dwarfdump, whereas on
31 # Linux it uses objdump. We don't have dwarfdump packaged for
32 # Darwin, so this patch updates the test to also use objdump on
33 # Darwin.
34 (substituteAll {
35 src = ./force-objdump-on-darwin.patch;
36 objdump = "${binutils.bintools}/bin/objdump";
37 })
38 ];
39
40 nativeBuildInputs = [ asciidoctor cmake perl ];
41 buildInputs = [ zstd ];
42
43 cmakeFlags = [
44 # Build system does not autodetect redis library presence.
45 # Requires explicit flag.
46 "-DREDIS_STORAGE_BACKEND=OFF"
47 ];
48
49 doCheck = true;
50 nativeCheckInputs = [
51 # test/run requires the compgen function which is available in
52 # bashInteractive, but not bash.
53 bashInteractive
54 ] ++ lib.optional stdenv.isDarwin xcodebuild;
55
56 checkPhase =
57 let
58 badTests = [
59 "test.trim_dir" # flaky on hydra (possibly filesystem-specific?)
60 ] ++ lib.optionals stdenv.isDarwin [
61 "test.basedir"
62 "test.multi_arch"
63 "test.nocpp2"
64 ];
65 in
66 ''
67 runHook preCheck
68 export HOME=$(mktemp -d)
69 ctest --output-on-failure -E '^(${lib.concatStringsSep "|" badTests})$'
70 runHook postCheck
71 '';
72
73 passthru = {
74 # A derivation that provides gcc and g++ commands, but that
75 # will end up calling ccache for the given cacheDir
76 links = { unwrappedCC, extraConfig }: stdenv.mkDerivation {
77 pname = "ccache-links";
78 inherit (finalAttrs) version;
79 passthru = {
80 isClang = unwrappedCC.isClang or false;
81 isGNU = unwrappedCC.isGNU or false;
82 isCcache = true;
83 };
84 inherit (unwrappedCC) lib;
85 nativeBuildInputs = [ makeWrapper ];
86 buildCommand = ''
87 mkdir -p $out/bin
88
89 wrap() {
90 local cname="$1"
91 if [ -x "${unwrappedCC}/bin/$cname" ]; then
92 makeWrapper ${finalAttrs.finalPackage}/bin/ccache $out/bin/$cname \
93 --run ${lib.escapeShellArg extraConfig} \
94 --add-flags ${unwrappedCC}/bin/$cname
95 fi
96 }
97
98 wrap cc
99 wrap c++
100 wrap gcc
101 wrap g++
102 wrap clang
103 wrap clang++
104
105 for executable in $(ls ${unwrappedCC}/bin); do
106 if [ ! -x "$out/bin/$executable" ]; then
107 ln -s ${unwrappedCC}/bin/$executable $out/bin/$executable
108 fi
109 done
110 for file in $(ls ${unwrappedCC} | grep -vw bin); do
111 ln -s ${unwrappedCC}/$file $out/$file
112 done
113 '';
114 };
115
116 updateScript = nix-update-script { };
117 };
118
119 meta = with lib; {
120 description = "Compiler cache for fast recompilation of C/C++ code";
121 homepage = "https://ccache.dev";
122 downloadPage = "https://ccache.dev/download.html";
123 changelog = "https://ccache.dev/releasenotes.html#_ccache_${
124 builtins.replaceStrings [ "." ] [ "_" ] finalAttrs.version
125 }";
126 license = licenses.gpl3Plus;
127 maintainers = with maintainers; [ kira-bruneau r-burns ];
128 platforms = platforms.unix;
129 };
130})