python312Packages.linear-operator: 0.5.3 -> 0.6
[NixPkgs.git] / pkgs / development / compilers / gcc / common / checksum.nix
blobc0e59563a515dc2836bcf9706ee28bab9582e966
2   lib,
3   stdenv,
4   nukeReferences,
5   langC,
6   langCC,
7   runtimeShell,
8 }:
10 let
11   enableChecksum =
12     (with stdenv; buildPlatform == hostPlatform && hostPlatform == targetPlatform)
13     && langC
14     && langCC
15     && !stdenv.hostPlatform.isDarwin;
18   pkg:
19   pkg.overrideAttrs (
20     previousAttrs:
21     lib.optionalAttrs enableChecksum {
22       outputs = previousAttrs.outputs ++ lib.optionals enableChecksum [ "checksum" ];
23       # This is a separate phase because gcc assembles its phase scripts
24       # in bash instead of nix (we should fix that).
25       preFixupPhases = (previousAttrs.preFixupPhases or [ ]) ++ [ "postInstallSaveChecksumPhase" ];
26       #
27       # gcc uses an auxiliary utility `genchecksum` to md5-hash (most of) its
28       # `.o` and `.a` files prior to linking (in case the linker is
29       # nondeterministic).  Since we want to compare across gccs built from two
30       # separate derivations, we wrap `genchecksum` with a `nuke-references`
31       # call.  We also stash copies of the inputs to `genchecksum` in
32       # `$checksum/inputs/` -- this is extremely helpful for debugging since
33       # it's hard to get Nix to not delete the $NIX_BUILD_TOP of a successful
34       # build.
35       #
36       postInstallSaveChecksumPhase = ''
37         mv gcc/build/genchecksum gcc/build/.genchecksum-wrapped
38         cat > gcc/build/genchecksum <<\EOF
39         #!${runtimeShell}
40         ${nukeReferences}/bin/nuke-refs $@
41         for INPUT in "$@"; do install -Dt $INPUT $checksum/inputs/; done
42         exec build/.genchecksum-wrapped $@
43         EOF
44         chmod +x gcc/build/genchecksum
45         rm gcc/*-checksum.*
46         make -C gcc cc1-checksum.o cc1plus-checksum.o
47         install -Dt $checksum/checksums/ gcc/cc*-checksum.o
48       '';
49     }
50   )