llvm: make targets a multivalued variant (#27735)

* llvm: make targets a multivalued variant

* Fix the targets variant values

1. Make them lowercase and add a mapping to cmake equivalent
2. auto -> all
2. Restore composability by using a multivalued variant, so that
   `targets=all` and `targets=x86` is combined to `targets=all,x86`
   which is then transformed into LLVM_TARGETS_TO_BUILD=all.

* use targets=x86 in iwyu

* Default to nvptx/amdgpu/host arch targets

* default to none

* Update var/spack/repos/builtin/packages/zig/package.py
This commit is contained in:
Harmen Stoppels 2022-01-05 22:11:05 +01:00 committed by GitHub
parent a4f0fbafbb
commit 071778b919
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 37 deletions

View File

@ -128,7 +128,7 @@ spack:
- libnrm - libnrm
- libquo - libquo
- libunwind - libunwind
- llvm +all_targets +clang +compiler-rt +libcxx +lld +lldb +llvm_dylib +flang ~cuda - llvm targets=amdgpu,nvptx +clang +compiler-rt +libcxx +lld +lldb +llvm_dylib +flang ~cuda
- loki - loki
- mercury - mercury
- metall - metall

View File

@ -139,7 +139,7 @@ spack:
- libnrm - libnrm
- libquo - libquo
- libunwind - libunwind
- llvm +all_targets +clang +compiler-rt +libcxx +lld +lldb +llvm_dylib +flang ~cuda - llvm targets=amdgpu,nvptx +clang +compiler-rt +libcxx +lld +lldb +llvm_dylib +flang ~cuda
- loki - loki
- mercury - mercury
- metall - metall

View File

@ -32,15 +32,8 @@ class Iwyu(CMakePackage):
depends_on('llvm+clang@8.0:8', when='@0.12') depends_on('llvm+clang@8.0:8', when='@0.12')
depends_on('llvm+clang@7.0:7', when='@0.11') depends_on('llvm+clang@7.0:7', when='@0.11')
# Non-X86 CPU use all_targets variants because iwyu use X86AsmParser # iwyu uses X86AsmParser
depends_on('llvm+all_targets', when='target=aarch64:') depends_on('llvm targets=x86')
depends_on('llvm+all_targets', when='target=arm:')
depends_on('llvm+all_targets', when='target=ppc:')
depends_on('llvm+all_targets', when='target=ppcle:')
depends_on('llvm+all_targets', when='target=ppc64:')
depends_on('llvm+all_targets', when='target=ppc64le:')
depends_on('llvm+all_targets', when='target=sparc:')
depends_on('llvm+all_targets', when='target=sparc64:')
@when('@0.14:') @when('@0.14:')
def cmake_args(self): def cmake_args(self):

View File

@ -138,10 +138,14 @@ class Llvm(CMakePackage, CudaPackage):
description="Link LLVM tools against the LLVM shared library", description="Link LLVM tools against the LLVM shared library",
) )
variant( variant(
"all_targets", "targets",
default=False, default="none",
description="Build all supported targets, default targets " description=("What targets to build. Spack's target family is always added "
"<current arch>,NVPTX,AMDGPU,CppBackend", "(e.g. X86 is automatically enabled when targeting znver2)."),
values=("all", "none", "aarch64", "amdgpu", "arm", "avr", "bpf", "cppbackend",
"hexagon", "lanai", "mips", "msp430", "nvptx", "powerpc", "riscv",
"sparc", "systemz", "webassembly", "x86", "xcore"),
multi=True
) )
variant( variant(
"build_type", "build_type",
@ -271,6 +275,11 @@ class Llvm(CMakePackage, CudaPackage):
# Fixed in upstream versions of both # Fixed in upstream versions of both
conflicts('^cmake@3.19.0', when='@6.0.0:11.0.0') conflicts('^cmake@3.19.0', when='@6.0.0:11.0.0')
# Starting in 3.9.0 CppBackend is no longer a target (see
# LLVM_ALL_TARGETS in llvm's top-level CMakeLists.txt for
# the complete list of targets)
conflicts("targets=cppbackend", when='@3.9.0:')
# Github issue #4986 # Github issue #4986
patch("llvm_gcc7.patch", when="@4.0.0:4.0.1+lldb %gcc@7.0:") patch("llvm_gcc7.patch", when="@4.0.0:4.0.1+lldb %gcc@7.0:")
@ -618,27 +627,9 @@ def cmake_args(self):
define('LIBCXX_ENABLE_STATIC_ABI_LIBRARY', True) define('LIBCXX_ENABLE_STATIC_ABI_LIBRARY', True)
]) ])
if "+all_targets" not in spec: # all is default on cmake cmake_args.append(define(
"LLVM_TARGETS_TO_BUILD",
targets = ["NVPTX", "AMDGPU"] get_llvm_targets_to_build(spec)))
if spec.version < Version("3.9.0"):
# Starting in 3.9.0 CppBackend is no longer a target (see
# LLVM_ALL_TARGETS in llvm's top-level CMakeLists.txt for
# the complete list of targets)
targets.append("CppBackend")
if spec.target.family in ("x86", "x86_64"):
targets.append("X86")
elif spec.target.family == "arm":
targets.append("ARM")
elif spec.target.family == "aarch64":
targets.append("AArch64")
elif spec.target.family in ("sparc", "sparc64"):
targets.append("Sparc")
elif spec.target.family in ("ppc64", "ppc64le", "ppc", "ppcle"):
targets.append("PowerPC")
cmake_args.append(define("LLVM_TARGETS_TO_BUILD", targets))
cmake_args.append(from_variant("LIBOMP_TSAN_SUPPORT", "omp_tsan")) cmake_args.append(from_variant("LIBOMP_TSAN_SUPPORT", "omp_tsan"))
@ -706,3 +697,51 @@ def post_install(self):
with working_dir(self.build_directory): with working_dir(self.build_directory):
install_tree("bin", join_path(self.prefix, "libexec", "llvm")) install_tree("bin", join_path(self.prefix, "libexec", "llvm"))
def get_llvm_targets_to_build(spec):
targets = spec.variants['targets'].value
# Build everything?
if 'all' in targets:
return 'all'
# Convert targets variant values to CMake LLVM_TARGETS_TO_BUILD array.
spack_to_cmake = {
"aarch64": "AArch64",
"amdgpu": "AMDGPU",
"arm": "ARM",
"avr": "AVR",
"bpf": "BPF",
"cppbackend": "CppBackend",
"hexagon": "Hexagon",
"lanai": "Lanai",
"mips": "Mips",
"msp430": "MSP430",
"nvptx": "NVPTX",
"powerpc": "PowerPC",
"riscv": "RISCV",
"sparc": "Sparc",
"systemz": "SystemZ",
"webassembly": "WebAssembly",
"x86": "X86",
"xcore": "XCore"
}
if 'none' in targets:
llvm_targets = set()
else:
llvm_targets = set(spack_to_cmake[target] for target in targets)
if spec.target.family in ("x86", "x86_64"):
llvm_targets.add("X86")
elif spec.target.family == "arm":
llvm_targets.add("ARM")
elif spec.target.family == "aarch64":
llvm_targets.add("AArch64")
elif spec.target.family in ("sparc", "sparc64"):
llvm_targets.add("Sparc")
elif spec.target.family in ("ppc64", "ppc64le", "ppc", "ppcle"):
llvm_targets.add("PowerPC")
return list(llvm_targets)

View File

@ -17,6 +17,6 @@ class Zig(CMakePackage):
default='Release', description='CMake build type' default='Release', description='CMake build type'
) )
depends_on('llvm@11.0.0: +all_targets') depends_on('llvm@11.0.0: targets=all')
provides('ziglang') provides('ziglang')