1{
2 lib,
3 stdenv,
4 llvm_meta,
5 release_version,
6 monorepoSrc ? null,
7 src ? null,
8 runCommand,
9 cmake,
10 ninja,
11 llvm,
12 targetLlvm,
13 lit,
14 clang-unwrapped,
15 perl,
16 pkg-config,
17 python3,
18 version,
19 devExtraCmakeFlags ? [ ],
20 ompdSupport ? true,
21 ompdGdbSupport ? ompdSupport,
22 getVersionFile,
23 fetchpatch,
24}:
25
26assert lib.assertMsg (ompdGdbSupport -> ompdSupport) "OMPD GDB support requires OMPD support!";
27
28stdenv.mkDerivation (finalAttrs: {
29 pname = "openmp";
30 inherit version;
31
32 src =
33 if monorepoSrc != null then
34 runCommand "openmp-src-${version}" { inherit (monorepoSrc) passthru; } (''
35 mkdir -p "$out"
36 cp -r ${monorepoSrc}/cmake "$out"
37 cp -r ${monorepoSrc}/openmp "$out"
38 '')
39 else
40 src;
41
42 sourceRoot = "${finalAttrs.src.name}/openmp";
43
44 outputs = [
45 "out"
46 "dev"
47 ];
48
49 # TODO: Remove on `staging`.
50 patchFlags = null;
51
52 patches =
53 lib.optional (lib.versionOlder release_version "19") (getVersionFile "openmp/fix-find-tool.patch")
54 ++ [
55 (getVersionFile "openmp/run-lit-directly.patch")
56 ];
57
58 nativeBuildInputs = [
59 cmake
60 python3.pythonOnBuildForHost
61 perl
62 ninja
63 pkg-config
64 lit
65 ];
66
67 buildInputs = [
68 (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm)
69 ]
70 ++ lib.optionals (ompdSupport && ompdGdbSupport) [
71 python3
72 ];
73
74 cmakeFlags = [
75 (lib.cmakeBool "LIBOMP_ENABLE_SHARED" (
76 !stdenv.hostPlatform.isStatic && stdenv.hostPlatform.hasSharedLibraries
77 ))
78 (lib.cmakeBool "LIBOMP_OMPD_SUPPORT" ompdSupport)
79 (lib.cmakeBool "LIBOMP_OMPD_GDB_SUPPORT" ompdGdbSupport)
80 (lib.cmakeFeature "CLANG_TOOL" "${clang-unwrapped}/bin/clang")
81 (lib.cmakeFeature "OPT_TOOL" "${llvm}/bin/opt")
82 (lib.cmakeFeature "LINK_TOOL" "${llvm}/bin/llvm-link")
83 ]
84 ++ devExtraCmakeFlags;
85
86 doCheck = false;
87
88 checkTarget = "check-openmp";
89
90 preCheck = ''
91 patchShebangs ../tools/archer/tests/deflake.bash
92 '';
93
94 meta = llvm_meta // {
95 homepage = "https://openmp.llvm.org/";
96 description = "Support for the OpenMP language";
97 longDescription = ''
98 The OpenMP subproject of LLVM contains the components required to build an
99 executable OpenMP program that are outside the compiler itself.
100 Contains the code for the runtime library against which code compiled by
101 "clang -fopenmp" must be linked before it can run and the library that
102 supports offload to target devices.
103 '';
104 # "All of the code is dual licensed under the MIT license and the UIUC
105 # License (a BSD-like license)":
106 license = with lib.licenses; [
107 mit
108 ncsa
109 ];
110 };
111})