2023-03-26 19:29:57 +02:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, llvm_meta
|
2024-03-28 11:28:13 -07:00
|
|
|
, release_version
|
|
|
|
, patches ? []
|
|
|
|
, monorepoSrc ? null
|
|
|
|
, src ? null
|
2023-03-26 19:29:57 +02:00
|
|
|
, runCommand
|
|
|
|
, cmake
|
|
|
|
, ninja
|
|
|
|
, llvm
|
|
|
|
, targetLlvm
|
|
|
|
, lit
|
|
|
|
, clang-unwrapped
|
|
|
|
, perl
|
|
|
|
, pkg-config
|
|
|
|
, version
|
llvmPackages.*: Add devExtraCmakeFlags parameter
cmake flags have a 'last flag wins' logic, so by appending to the end of
the flags it is possible to override any cmake flag.
It also ignores (and warns) if a flag is unused, so passing flags across
all packages should be safe if you want to target one package.
In combination with #320261, this PR allows consistently overriding all
packages within LLVM with additional cmake arguments. Consistency here
means for example 'if you override LLVM, then all dependencies on it are
also see the overridden LLVM in their input'. Consistency is hard to
achieve with the other obvious way of implementing this as a user: if
you use overrideAttrs then you have to write a big mess of override code
in order to override all dependents, and this can be very difficult in a
cross-compilation scenario using crossSystem and useLLVM, for example.
With this PR it is possible to write an overlay which overlays
`llvmPackages` with `llvmPackage.override { devExtraCmakeFlags = [ ... ]; }`,
and then the toolchain used with useLLVM in effect should respect
these flags.
This is useful in development for experimenting with the effect of
various flags, hence the chosen name `devCmakeFlags`.
This won't work out of the box without #341855 applied, which fixes
override passthrough.
See-Also: #320261, #341855
Signed-off-by: Peter Waller <p@pwaller.net>
2024-09-15 11:37:03 +01:00
|
|
|
, devExtraCmakeFlags ? []
|
2023-03-26 19:29:57 +02:00
|
|
|
}:
|
2024-03-28 11:28:13 -07:00
|
|
|
let
|
2023-03-26 19:29:57 +02:00
|
|
|
pname = "openmp";
|
2024-03-28 11:28:13 -07:00
|
|
|
src' =
|
|
|
|
if monorepoSrc != null then
|
|
|
|
runCommand "${pname}-src-${version}" {} ''
|
|
|
|
mkdir -p "$out"
|
|
|
|
cp -r ${monorepoSrc}/cmake "$out"
|
|
|
|
cp -r ${monorepoSrc}/${pname} "$out"
|
|
|
|
'' else src;
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation (rec {
|
|
|
|
inherit pname version patches;
|
2023-03-26 19:29:57 +02:00
|
|
|
|
2024-03-28 11:28:13 -07:00
|
|
|
src = src';
|
2023-03-26 19:29:57 +02:00
|
|
|
|
2024-03-28 11:28:13 -07:00
|
|
|
sourceRoot =
|
|
|
|
if lib.versionOlder release_version "13" then null
|
|
|
|
else "${src.name}/${pname}";
|
2023-03-26 19:29:57 +02:00
|
|
|
|
2024-03-28 11:28:13 -07:00
|
|
|
outputs = [ "out" ]
|
|
|
|
++ lib.optionals (lib.versionAtLeast release_version "14") [ "dev" ];
|
2023-03-26 19:29:57 +02:00
|
|
|
|
2024-03-28 11:28:13 -07:00
|
|
|
patchFlags =
|
|
|
|
if lib.versionOlder release_version "14" then [ "-p2" ]
|
|
|
|
else null;
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
cmake
|
|
|
|
] ++ lib.optionals (lib.versionAtLeast release_version "15") [
|
|
|
|
ninja
|
|
|
|
] ++ [ perl ] ++ lib.optionals (lib.versionAtLeast release_version "14") [
|
|
|
|
pkg-config lit
|
|
|
|
];
|
2023-03-26 19:29:57 +02:00
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
(if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm)
|
|
|
|
];
|
|
|
|
|
2024-03-28 11:28:13 -07:00
|
|
|
cmakeFlags = lib.optionals (lib.versions.major release_version == "13") [
|
|
|
|
"-DLIBOMPTARGET_BUILD_AMDGCN_BCLIB=OFF" # Building the AMDGCN device RTL fails
|
|
|
|
] ++ lib.optionals (lib.versionAtLeast release_version "14") [
|
2023-03-26 19:29:57 +02:00
|
|
|
"-DCLANG_TOOL=${clang-unwrapped}/bin/clang"
|
|
|
|
"-DOPT_TOOL=${llvm}/bin/opt"
|
|
|
|
"-DLINK_TOOL=${llvm}/bin/llvm-link"
|
llvmPackages.*: Add devExtraCmakeFlags parameter
cmake flags have a 'last flag wins' logic, so by appending to the end of
the flags it is possible to override any cmake flag.
It also ignores (and warns) if a flag is unused, so passing flags across
all packages should be safe if you want to target one package.
In combination with #320261, this PR allows consistently overriding all
packages within LLVM with additional cmake arguments. Consistency here
means for example 'if you override LLVM, then all dependencies on it are
also see the overridden LLVM in their input'. Consistency is hard to
achieve with the other obvious way of implementing this as a user: if
you use overrideAttrs then you have to write a big mess of override code
in order to override all dependents, and this can be very difficult in a
cross-compilation scenario using crossSystem and useLLVM, for example.
With this PR it is possible to write an overlay which overlays
`llvmPackages` with `llvmPackage.override { devExtraCmakeFlags = [ ... ]; }`,
and then the toolchain used with useLLVM in effect should respect
these flags.
This is useful in development for experimenting with the effect of
various flags, hence the chosen name `devCmakeFlags`.
This won't work out of the box without #341855 applied, which fixes
override passthrough.
See-Also: #320261, #341855
Signed-off-by: Peter Waller <p@pwaller.net>
2024-09-15 11:37:03 +01:00
|
|
|
] ++ devExtraCmakeFlags;
|
2023-03-26 19:29:57 +02:00
|
|
|
|
|
|
|
meta = llvm_meta // {
|
|
|
|
homepage = "https://openmp.llvm.org/";
|
|
|
|
description = "Support for the OpenMP language";
|
|
|
|
longDescription = ''
|
|
|
|
The OpenMP subproject of LLVM contains the components required to build an
|
|
|
|
executable OpenMP program that are outside the compiler itself.
|
|
|
|
Contains the code for the runtime library against which code compiled by
|
|
|
|
"clang -fopenmp" must be linked before it can run and the library that
|
|
|
|
supports offload to target devices.
|
|
|
|
'';
|
|
|
|
# "All of the code is dual licensed under the MIT license and the UIUC
|
|
|
|
# License (a BSD-like license)":
|
|
|
|
license = with lib.licenses; [ mit ncsa ];
|
|
|
|
};
|
2024-03-28 11:28:13 -07:00
|
|
|
} // (lib.optionalAttrs (lib.versionAtLeast release_version "14") {
|
|
|
|
doCheck = false;
|
|
|
|
checkTarget = "check-openmp";
|
|
|
|
preCheck = ''
|
|
|
|
patchShebangs ../tools/archer/tests/deflake.bash
|
|
|
|
'';
|
|
|
|
}))
|