0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-19 16:40:32 +03:00
nixpkgs/pkgs/development/compilers/llvm/common/openmp/default.nix
Peter Waller 290ec4e775 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:50:52 +01:00

86 lines
2.3 KiB
Nix

{ lib
, stdenv
, llvm_meta
, release_version
, patches ? []
, monorepoSrc ? null
, src ? null
, runCommand
, cmake
, ninja
, llvm
, targetLlvm
, lit
, clang-unwrapped
, perl
, pkg-config
, version
, devExtraCmakeFlags ? []
}:
let
pname = "openmp";
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;
src = src';
sourceRoot =
if lib.versionOlder release_version "13" then null
else "${src.name}/${pname}";
outputs = [ "out" ]
++ lib.optionals (lib.versionAtLeast release_version "14") [ "dev" ];
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
];
buildInputs = [
(if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm)
];
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") [
"-DCLANG_TOOL=${clang-unwrapped}/bin/clang"
"-DOPT_TOOL=${llvm}/bin/opt"
"-DLINK_TOOL=${llvm}/bin/llvm-link"
] ++ devExtraCmakeFlags;
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 ];
};
} // (lib.optionalAttrs (lib.versionAtLeast release_version "14") {
doCheck = false;
checkTarget = "check-openmp";
preCheck = ''
patchShebangs ../tools/archer/tests/deflake.bash
'';
}))