Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib, stdenv, fetchFromGitHub, fetchpatch
2, cmake, which, m4, python3, bison, flex, llvmPackages
3
4 # the default test target is sse4, but that is not supported by all Hydra agents
5, testedTargets ? [ "sse2" ]
6}:
7
8stdenv.mkDerivation rec {
9 pname = "ispc";
10 version = "unstable-2021-04-02";
11
12 src = fetchFromGitHub {
13 owner = pname;
14 repo = pname;
15 # ISPC release 1.15.0 doesn't build against LLVM 11.1, only against 11.0. So we
16 # use latest ISPC main branch for now, until they support an LLVM version we have.
17 # https://github.com/ispc/ispc/issues/2027#issuecomment-784470530
18 rev = "3e8313568265d2adfbf95bd6b6e1a4c70ef59bed";
19 sha256 = "sha256-gvr+VpoacmwQlP5gT4MnfmKdACZWJduVMIpR0YRzseg=";
20 };
21
22 patches = [
23 # Fix cmake error: `Failed to find clang++`
24 # https://github.com/ispc/ispc/pull/2055
25 (fetchpatch {
26 url = "https://github.com/erictapen/ispc/commit/338119b2f4e11fcf0b0852de296c320928e572a2.patch";
27 sha256 = "sha256-+RqDq1LMWomu/K4SgK0Nip47b1RwyM6W0cTSNGD4+m4=";
28 })
29 ];
30
31 nativeBuildInputs = [ cmake which m4 bison flex python3 llvmPackages.llvm.dev ];
32 buildInputs = with llvmPackages; [
33 llvm llvmPackages.libclang
34 ];
35
36 postPatch = ''
37 substituteInPlace CMakeLists.txt \
38 --replace curses ncurses
39 substituteInPlace cmake/GenerateBuiltins.cmake \
40 --replace 'bit 32 64' 'bit 64'
41 '';
42
43 inherit testedTargets;
44
45 # needs 'transcendentals' executable, which is only on linux
46 doCheck = stdenv.isLinux;
47
48 # the compiler enforces -Werror, and -fno-strict-overflow makes it mad.
49 # hilariously this is something of a double negative: 'disable' the
50 # 'strictoverflow' hardening protection actually means we *allow* the compiler
51 # to do strict overflow optimization. somewhat misleading...
52 hardeningDisable = [ "strictoverflow" ];
53
54 checkPhase = ''
55 export ISPC_HOME=$PWD/bin
56 for target in $testedTargets
57 do
58 echo "Testing target $target"
59 echo "================================"
60 echo
61 (cd ../
62 PATH=${llvmPackages.clang}/bin:$PATH python run_tests.py -t $target --non-interactive --verbose --file=test_output.log
63 fgrep -q "No new fails" test_output.log || exit 1)
64 done
65 '';
66
67 cmakeFlags = [
68 "-DLLVM_CONFIG_EXECUTABLE=${llvmPackages.llvm.dev}/bin/llvm-config"
69 "-DCLANG_EXECUTABLE=${llvmPackages.clang}/bin/clang"
70 "-DCLANGPP_EXECUTABLE=${llvmPackages.clang}/bin/clang++"
71 "-DISPC_INCLUDE_EXAMPLES=OFF"
72 "-DISPC_INCLUDE_UTILS=OFF"
73 "-DARM_ENABLED=FALSE"
74 ];
75
76 meta = with lib; {
77 homepage = "https://ispc.github.io/";
78 description = "Intel 'Single Program, Multiple Data' Compiler, a vectorised language";
79 license = licenses.bsd3;
80 platforms = [ "x86_64-linux" "x86_64-darwin" ]; # TODO: buildable on more platforms?
81 maintainers = with maintainers; [ aristid thoughtpolice ];
82 };
83}