1{ lib, stdenv, fetchFromGitHub, fetchpatch
2, cmake, which, m4, python3, bison, flex, llvmPackages, ncurses, xcode, tbb
3 # the default test target is sse4, but that is not supported by all Hydra agents
4, testedTargets ? if stdenv.isAarch64 || stdenv.isAarch32 then [ "neon-i32x4" ] else [ "sse2-i32x4" ]
5}:
6
7stdenv.mkDerivation rec {
8 pname = "ispc";
9 version = "1.22.0";
10
11 src = fetchFromGitHub {
12 owner = pname;
13 repo = pname;
14 rev = "v${version}";
15 sha256 = "sha256-NiBwQ7BzNgRdWLvjOi1fQni+vnYwn0nLHxqAVucmb2k=";
16 };
17
18 nativeBuildInputs = [ cmake which m4 bison flex python3 llvmPackages.libllvm.dev tbb ] ++ lib.lists.optionals stdenv.isDarwin [ xcode ];
19
20 buildInputs = with llvmPackages; [
21 libllvm libclang openmp ncurses
22 ];
23
24 postPatch = ''
25 substituteInPlace CMakeLists.txt \
26 --replace CURSES_CURSES_LIBRARY CURSES_NCURSES_LIBRARY
27 substituteInPlace cmake/GenerateBuiltins.cmake \
28 --replace 'bit 32 64' 'bit 64'
29 '';
30
31 inherit testedTargets;
32
33 doCheck = true;
34
35 # the compiler enforces -Werror, and -fno-strict-overflow makes it mad.
36 # hilariously this is something of a double negative: 'disable' the
37 # 'strictoverflow' hardening protection actually means we *allow* the compiler
38 # to do strict overflow optimization. somewhat misleading...
39 hardeningDisable = [ "strictoverflow" ];
40
41 checkPhase = ''
42 export ISPC_HOME=$PWD/bin
43 for target in $testedTargets
44 do
45 echo "Testing target $target"
46 echo "================================"
47 echo
48 (cd ../
49 PATH=${llvmPackages.clang}/bin:$PATH python run_tests.py -t $target --non-interactive --verbose --file=test_output.log
50 fgrep -q "No new fails" test_output.log || exit 1)
51 done
52 '';
53
54 cmakeFlags = [
55 "-DFILE_CHECK_EXECUTABLE=${llvmPackages.llvm}/bin/FileCheck"
56 "-DLLVM_AS_EXECUTABLE=${llvmPackages.llvm}/bin/llvm-as"
57 "-DLLVM_CONFIG_EXECUTABLE=${llvmPackages.llvm.dev}/bin/llvm-config"
58 "-DLLVM_DIS_EXECUTABLE=${llvmPackages.llvm}/bin/llvm-dis"
59 "-DCLANG_EXECUTABLE=${llvmPackages.clang}/bin/clang"
60 "-DCLANGPP_EXECUTABLE=${llvmPackages.clang}/bin/clang++"
61 "-DISPC_INCLUDE_EXAMPLES=OFF"
62 "-DISPC_INCLUDE_UTILS=OFF"
63 ("-DARM_ENABLED=" + (if stdenv.isAarch64 || stdenv.isAarch32 then "TRUE" else "FALSE"))
64 ("-DX86_ENABLED=" + (if stdenv.isx86_64 || stdenv.isx86_32 then "TRUE" else "FALSE"))
65 ] ++ lib.lists.optionals stdenv.isDarwin [
66 "-DISPC_MACOS_SDK_PATH=${xcode}/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
67 ];
68
69 meta = with lib; {
70 homepage = "https://ispc.github.io/";
71 description = "Intel 'Single Program, Multiple Data' Compiler, a vectorised language";
72 license = licenses.bsd3;
73 platforms = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; # TODO: buildable on more platforms?
74 maintainers = with maintainers; [ aristid thoughtpolice athas alexfmpe ];
75 };
76}