1{
2 lib,
3 stdenv,
4 fetchurl,
5 fetchpatch,
6 cmake,
7 makeWrapper,
8 llvm,
9 libclang,
10 flex,
11 zlib,
12 perlPackages,
13 util-linux,
14}:
15
16stdenv.mkDerivation rec {
17 pname = "creduce";
18 version = "2.10.0";
19
20 src = fetchurl {
21 url = "https://embed.cs.utah.edu/${pname}/${pname}-${version}.tar.gz";
22 sha256 = "2xwPEjln8k1iCwQM69UwAb89zwPkAPeFVqL/LhH+oGM=";
23 };
24
25 patches = [
26 # Port to LLVM 15
27 (fetchpatch {
28 url = "https://github.com/csmith-project/creduce/commit/e507cca4ccb32585c5692d49b8d907c1051c826c.patch";
29 hash = "sha256-jO5E85AvHcjlErbUhzuQDXwQkhQsXklcTMQfWBd09OU=";
30 })
31 (fetchpatch {
32 url = "https://github.com/csmith-project/creduce/commit/8d56bee3e1d2577fc8afd2ecc03b1323d6873404.patch";
33 hash = "sha256-dRaBaJAYkvMyxKvfriOcg4D+4i6+6orZ85zws1AFx/s=";
34 })
35 # Port to LLVM 16
36 (fetchpatch {
37 url = "https://github.com/csmith-project/creduce/commit/8ab9a69caf13ce24172737e8bfd09de51a1ecb6a.patch";
38 hash = "sha256-gPNXxYHnsyUvXmC0CGtsulH2Fu/EMnDE4GdOYc0UbiQ=";
39 })
40 ];
41
42 postPatch =
43 ''
44 substituteInPlace CMakeLists.txt \
45 --replace "-std=c++11" "-std=c++17"
46 ''
47 # On Linux, c-reduce's preferred way to reason about
48 # the cpu architecture/topology is to use 'lscpu',
49 # so let's make sure it knows where to find it:
50 + lib.optionalString stdenv.hostPlatform.isLinux ''
51 substituteInPlace creduce/creduce_utils.pm --replace \
52 lscpu ${util-linux}/bin/lscpu
53 '';
54
55 nativeBuildInputs = [
56 cmake
57 makeWrapper
58 llvm.dev
59 ];
60 buildInputs =
61 [
62 # Ensure stdenv's CC is on PATH before clang-unwrapped
63 stdenv.cc
64 # Actual deps:
65 llvm
66 libclang
67 flex
68 zlib
69 ]
70 ++ (with perlPackages; [
71 perl
72 ExporterLite
73 FileWhich
74 GetoptTabular
75 RegexpCommon
76 TermReadKey
77 ]);
78
79 postInstall = ''
80 wrapProgram $out/bin/creduce --prefix PERL5LIB : "$PERL5LIB"
81 '';
82
83 meta = with lib; {
84 description = "C program reducer";
85 mainProgram = "creduce";
86 homepage = "https://embed.cs.utah.edu/creduce";
87 # Officially, the license is: https://github.com/csmith-project/creduce/blob/master/COPYING
88 license = licenses.ncsa;
89 longDescription = ''
90 C-Reduce is a tool that takes a large C or C++ program that has a
91 property of interest (such as triggering a compiler bug) and
92 automatically produces a much smaller C/C++ program that has the same
93 property. It is intended for use by people who discover and report
94 bugs in compilers and other tools that process C/C++ code.
95 '';
96 maintainers = [ ];
97 platforms = platforms.all;
98 };
99}