nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
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 (
29 finalAttrs:
30 {
31 pname = "openmp";
32 inherit version;
33
34 src =
35 if monorepoSrc != null then
36 runCommand "openmp-src-${version}" { inherit (monorepoSrc) passthru; } (
37 ''
38 mkdir -p "$out"
39 ''
40 + lib.optionalString (lib.versionAtLeast release_version "14") ''
41 cp -r ${monorepoSrc}/cmake "$out"
42 ''
43 + ''
44 cp -r ${monorepoSrc}/openmp "$out"
45 ''
46 )
47 else
48 src;
49
50 sourceRoot = "${finalAttrs.src.name}/openmp";
51
52 outputs = [ "out" ] ++ lib.optionals (lib.versionAtLeast release_version "14") [ "dev" ];
53
54 patchFlags = if lib.versionOlder release_version "14" then [ "-p2" ] else null;
55
56 patches =
57 lib.optional (lib.versionAtLeast release_version "15" && lib.versionOlder release_version "19") (
58 getVersionFile "openmp/fix-find-tool.patch"
59 )
60 ++ lib.optional (lib.versionAtLeast release_version "14" && lib.versionOlder release_version "18") (
61 getVersionFile "openmp/gnu-install-dirs.patch"
62 )
63 ++ lib.optional (lib.versionAtLeast release_version "14") (
64 getVersionFile "openmp/run-lit-directly.patch"
65 )
66 ++
67 lib.optional (lib.versionOlder release_version "14")
68 # Fix cross.
69 (
70 fetchpatch {
71 url = "https://github.com/llvm/llvm-project/commit/5e2358c781b85a18d1463fd924d2741d4ae5e42e.patch";
72 hash = "sha256-UxIlAifXnexF/MaraPW0Ut6q+sf3e7y1fMdEv1q103A=";
73 }
74 );
75
76 nativeBuildInputs = [
77 cmake
78 python3.pythonOnBuildForHost
79 perl
80 ]
81 ++ lib.optionals (lib.versionAtLeast release_version "15") [
82 ninja
83 ]
84 ++ lib.optionals (lib.versionAtLeast release_version "14") [
85 pkg-config
86 lit
87 ];
88
89 buildInputs = [
90 (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm)
91 ]
92 ++ lib.optionals (ompdSupport && ompdGdbSupport) [
93 python3
94 ];
95
96 cmakeFlags = [
97 (lib.cmakeBool "LIBOMP_ENABLE_SHARED" (
98 !stdenv.hostPlatform.isStatic && stdenv.hostPlatform.hasSharedLibraries
99 ))
100 (lib.cmakeBool "LIBOMP_OMPD_SUPPORT" ompdSupport)
101 (lib.cmakeBool "LIBOMP_OMPD_GDB_SUPPORT" ompdGdbSupport)
102 ]
103 ++ lib.optionals (lib.versions.major release_version == "13") [
104 (lib.cmakeBool "LIBOMPTARGET_BUILD_AMDGCN_BCLIB" false) # Building the AMDGCN device RTL fails
105 ]
106 ++ lib.optionals (lib.versionAtLeast release_version "14") [
107 (lib.cmakeFeature "CLANG_TOOL" "${clang-unwrapped}/bin/clang")
108 (lib.cmakeFeature "OPT_TOOL" "${llvm}/bin/opt")
109 (lib.cmakeFeature "LINK_TOOL" "${llvm}/bin/llvm-link")
110 ]
111 ++ devExtraCmakeFlags;
112
113 meta = llvm_meta // {
114 homepage = "https://openmp.llvm.org/";
115 description = "Support for the OpenMP language";
116 longDescription = ''
117 The OpenMP subproject of LLVM contains the components required to build an
118 executable OpenMP program that are outside the compiler itself.
119 Contains the code for the runtime library against which code compiled by
120 "clang -fopenmp" must be linked before it can run and the library that
121 supports offload to target devices.
122 '';
123 # "All of the code is dual licensed under the MIT license and the UIUC
124 # License (a BSD-like license)":
125 license = with lib.licenses; [
126 mit
127 ncsa
128 ];
129 };
130 }
131 // (lib.optionalAttrs (lib.versionAtLeast release_version "14") {
132 doCheck = false;
133 checkTarget = "check-openmp";
134 preCheck = ''
135 patchShebangs ../tools/archer/tests/deflake.bash
136 '';
137 })
138)