summaryrefslogtreecommitdiff
path: root/var/spack/repos/builtin/packages/llvm/package.py
diff options
context:
space:
mode:
Diffstat (limited to 'var/spack/repos/builtin/packages/llvm/package.py')
-rw-r--r--var/spack/repos/builtin/packages/llvm/package.py138
1 files changed, 100 insertions, 38 deletions
diff --git a/var/spack/repos/builtin/packages/llvm/package.py b/var/spack/repos/builtin/packages/llvm/package.py
index c5a88cd9fb..8d353b071b 100644
--- a/var/spack/repos/builtin/packages/llvm/package.py
+++ b/var/spack/repos/builtin/packages/llvm/package.py
@@ -2,12 +2,14 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+import os
import os.path
import re
import sys
import llnl.util.tty as tty
+import spack.build_environment
import spack.util.executable
@@ -23,10 +25,12 @@ class Llvm(CMakePackage, CudaPackage):
url = "https://github.com/llvm/llvm-project/archive/llvmorg-7.1.0.tar.gz"
list_url = "https://releases.llvm.org/download.html"
git = "https://github.com/llvm/llvm-project"
- maintainers = ['trws', 'naromero77']
+ maintainers = ['trws', 'haampie']
tags = ['e4s']
+ generator = 'Ninja'
+
family = "compiler" # Used by lmod
# fmt: off
@@ -129,6 +133,11 @@ class Llvm(CMakePackage, CudaPackage):
"components in a single shared library",
)
variant(
+ "link_llvm_dylib",
+ default=False,
+ description="Link LLVM tools against the LLVM shared library",
+ )
+ variant(
"all_targets",
default=False,
description="Build all supported targets, default targets "
@@ -154,10 +163,15 @@ class Llvm(CMakePackage, CudaPackage):
description="Enable code-signing on macOS")
variant("python", default=False, description="Install python bindings")
+ variant('version_suffix', default='none', description="Add a symbol suffix")
+ variant('z3', default=False, description='Use Z3 for the clang static analyzer')
+
extends("python", when="+python")
# Build dependency
depends_on("cmake@3.4.3:", type="build")
+ depends_on('cmake@3.13.4:', type='build', when='@12:')
+ depends_on("ninja", type="build")
depends_on("python@2.7:2.8", when="@:4 ~python", type="build")
depends_on("python", when="@5: ~python", type="build")
depends_on("pkgconfig", type="build")
@@ -165,7 +179,7 @@ class Llvm(CMakePackage, CudaPackage):
# Universal dependency
depends_on("python@2.7:2.8", when="@:4+python")
depends_on("python", when="@5:+python")
- depends_on("z3", when="@9:")
+ depends_on('z3', when='@8:+clang+z3')
# openmp dependencies
depends_on("perl-data-dumper", type=("build"))
@@ -189,6 +203,7 @@ class Llvm(CMakePackage, CudaPackage):
depends_on("isl", when="@:3.6 +polly")
conflicts("+llvm_dylib", when="+shared_libs")
+ conflicts("+link_llvm_dylib", when="~llvm_dylib")
conflicts("+lldb", when="~clang")
conflicts("+libcxx", when="~clang")
conflicts("+internal_unwind", when="~clang")
@@ -197,11 +212,16 @@ class Llvm(CMakePackage, CudaPackage):
# Introduced in version 11 as a part of LLVM and not a separate package.
conflicts("+flang", when="@:10")
+ conflicts('~mlir', when='+flang', msg='Flang requires MLIR')
+
# Older LLVM do not build with newer compilers, and vice versa
- conflicts("%gcc@11:", when="@:7")
conflicts("%gcc@8:", when="@:5")
conflicts("%gcc@:5.0", when="@8:")
- conflicts("%apple-clang@13:", when="@:9")
+ # clang/lib: a lambda parameter cannot shadow an explicitly captured entity
+ conflicts("%clang@8:", when="@:4")
+
+ # When these versions are concretized, but not explicitly with +libcxx, these
+ # conflicts will enable clingo to set ~libcxx, making the build successful:
# libc++ of LLVM13, see https://libcxx.llvm.org/#platform-and-compiler-support
# @13 does not support %gcc@:10 https://bugs.llvm.org/show_bug.cgi?id=51359#c1
@@ -210,7 +230,15 @@ class Llvm(CMakePackage, CudaPackage):
# AppleClang 12 - latest stable release per Xcode release page
conflicts("%gcc@:10", when="@13:+libcxx")
conflicts("%clang@:10", when="@13:+libcxx")
- conflicts("%apple_clang@:11", when="@13:+libcxx")
+ conflicts("%apple-clang@:11", when="@13:+libcxx")
+
+ # libcxx-4 and compiler-rt-4 fail to build with "newer" clang and gcc versions:
+ conflicts('%gcc@7:', when='@:4+libcxx')
+ conflicts('%clang@6:', when='@:4+libcxx')
+ conflicts('%apple-clang@6:', when='@:4+libcxx')
+ conflicts('%gcc@7:', when='@:4+compiler-rt')
+ conflicts('%clang@6:', when='@:4+compiler-rt')
+ conflicts('%apple-clang@6:', when='@:4+compiler-rt')
# OMP TSAN exists in > 5.x
conflicts("+omp_tsan", when="@:5")
@@ -246,10 +274,22 @@ class Llvm(CMakePackage, CudaPackage):
# Github issue #4986
patch("llvm_gcc7.patch", when="@4.0.0:4.0.1+lldb %gcc@7.0:")
- # https://github.com/spack/spack/issues/24270
- patch('https://src.fedoraproject.org/rpms/llvm10/raw/7ce7ebd066955ea95ba2b491c41fbc6e4ee0643a/f/llvm10-gcc11.patch',
- sha256='958c64838c9d469be514eef195eca0f8c3ab069bc4b64a48fad59991c626bab8',
- when='@8:11 %gcc@11:')
+ # sys/ustat.h has been removed in favour of statfs from glibc-2.28. Use fixed sizes:
+ patch('llvm5-sanitizer-ustat.patch', when="@4:6+compiler-rt")
+
+ # Fix lld templates: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=230463
+ patch('llvm4-lld-ELF-Symbols.patch', when="@4+lld%clang@6:")
+ patch('llvm5-lld-ELF-Symbols.patch', when="@5+lld%clang@7:")
+
+ # Fix missing std:size_t in 'llvm@4:5' when built with '%clang@7:'
+ patch('xray_buffer_queue-cstddef.patch', when="@4:5+compiler-rt%clang@7:")
+
+ # https://github.com/llvm/llvm-project/commit/947f9692440836dcb8d88b74b69dd379d85974ce
+ patch('sanitizer-ipc_perm_mode.patch', when="@5:7+compiler-rt%clang@11:")
+ patch('sanitizer-ipc_perm_mode.patch', when="@5:9+compiler-rt%gcc@9:")
+
+ # github.com/spack/spack/issues/24270: MicrosoftDemangle for %gcc@10: and %clang@13:
+ patch('missing-includes.patch', when='@8:9')
# Backport from llvm master + additional fix
# see https://bugs.llvm.org/show_bug.cgi?id=39696
@@ -276,6 +316,11 @@ class Llvm(CMakePackage, CudaPackage):
# Workaround for issue https://github.com/spack/spack/issues/18197
patch('llvm7_intel.patch', when='@7 %intel@18.0.2,19.0.4')
+ # Remove cyclades support to build against newer kernel headers
+ # https://reviews.llvm.org/D102059
+ patch('no_cyclades.patch', when='@10:12.0.0')
+ patch('no_cyclades9.patch', when='@6:9')
+
# The functions and attributes below implement external package
# detection for LLVM. See:
#
@@ -439,6 +484,17 @@ class Llvm(CMakePackage, CudaPackage):
return(None, flags, None)
return(flags, None, None)
+ def setup_build_environment(self, env):
+ """When using %clang, add only its ld.lld-$ver and/or ld.lld to our PATH"""
+ if self.compiler.name in ['clang', 'apple-clang']:
+ for lld in 'ld.lld-{0}'.format(self.compiler.version.version[0]), 'ld.lld':
+ bin = os.path.join(os.path.dirname(self.compiler.cc), lld)
+ sym = os.path.join(self.stage.path, 'ld.lld')
+ if os.path.exists(bin) and not os.path.exists(sym):
+ mkdirp(self.stage.path)
+ os.symlink(bin, sym)
+ env.prepend_path('PATH', self.stage.path)
+
def setup_run_environment(self, env):
if "+clang" in self.spec:
env.set("CC", join_path(self.spec.prefix.bin, "clang"))
@@ -465,6 +521,10 @@ class Llvm(CMakePackage, CudaPackage):
define("LIBOMP_HWLOC_INSTALL_DIR", spec["hwloc"].prefix),
]
+ version_suffix = spec.variants['version_suffix'].value
+ if version_suffix != 'none':
+ cmake_args.append(define('LLVM_VERSION_SUFFIX', version_suffix))
+
if python.version >= Version("3"):
cmake_args.append(define("Python3_EXECUTABLE", python.command.path))
else:
@@ -521,6 +581,13 @@ class Llvm(CMakePackage, CudaPackage):
else:
projects.append("openmp")
+ if self.spec.satisfies("@8"):
+ cmake_args.append(define('CLANG_ANALYZER_ENABLE_Z3_SOLVER',
+ self.spec.satisfies('@8+z3')))
+ if self.spec.satisfies("@9:"):
+ cmake_args.append(define('LLVM_ENABLE_Z3_SOLVER',
+ self.spec.satisfies('@9:+z3')))
+
if "+flang" in spec:
projects.append("flang")
if "+lldb" in spec:
@@ -540,9 +607,16 @@ class Llvm(CMakePackage, CudaPackage):
projects.append("polly")
cmake_args.append(define("LINK_POLLY_INTO_TOOLS", True))
- cmake_args.append(from_variant("BUILD_SHARED_LIBS", "shared_libs"))
- cmake_args.append(from_variant("LLVM_BUILD_LLVM_DYLIB", "llvm_dylib"))
- cmake_args.append(from_variant("LLVM_USE_SPLIT_DWARF", "split_dwarf"))
+ cmake_args.extend([
+ from_variant("BUILD_SHARED_LIBS", "shared_libs"),
+ from_variant("LLVM_BUILD_LLVM_DYLIB", "llvm_dylib"),
+ from_variant("LLVM_LINK_LLVM_DYLIB", "link_llvm_dylib"),
+ from_variant("LLVM_USE_SPLIT_DWARF", "split_dwarf"),
+ # By default on Linux, libc++.so is a ldscript. CMake fails to add
+ # CMAKE_INSTALL_RPATH to it, which fails. Statically link libc++abi.a
+ # into libc++.so, linking with -lc++ or -stdlib=libc++ is enough.
+ define('LIBCXX_ENABLE_STATIC_ABI_LIBRARY', True)
+ ])
if "+all_targets" not in spec: # all is default on cmake
@@ -581,12 +655,6 @@ class Llvm(CMakePackage, CudaPackage):
break
cmake_args.append(define("GCC_INSTALL_PREFIX", gcc_prefix))
- if spec.satisfies("@4.0.0:"):
- if spec.satisfies("platform=cray") or spec.satisfies(
- "platform=linux"
- ):
- cmake_args.append(define("CMAKE_BUILD_WITH_INSTALL_RPATH", "1"))
-
if self.spec.satisfies("~code_signing platform=darwin"):
cmake_args.append(define('LLDB_USE_SYSTEM_DEBUGSERVER', True))
@@ -599,43 +667,37 @@ class Llvm(CMakePackage, CudaPackage):
return cmake_args
- @run_before("build")
- def pre_install(self):
- with working_dir(self.build_directory):
- # When building shared libraries these need to be installed first
- make("install-LLVMTableGen")
- if self.spec.version >= Version("4.0.0"):
- # LLVMDemangle target was added in 4.0.0
- make("install-LLVMDemangle")
- make("install-LLVMSupport")
-
@run_after("install")
def post_install(self):
spec = self.spec
define = CMakePackage.define
# unnecessary if we build openmp via LLVM_ENABLE_RUNTIMES
- if "+cuda" in self.spec and "+omp_as_runtime" not in self.spec:
+ if "+cuda ~omp_as_runtime" in self.spec:
ompdir = "build-bootstrapped-omp"
+ prefix_paths = spack.build_environment.get_cmake_prefix_path(self)
+ prefix_paths.append(str(spec.prefix))
# rebuild libomptarget to get bytecode runtime library files
with working_dir(ompdir, create=True):
cmake_args = [
- self.stage.source_path + "/openmp",
+ '-G', 'Ninja',
+ define('CMAKE_BUILD_TYPE', spec.variants['build_type'].value),
define("CMAKE_C_COMPILER", spec.prefix.bin + "/clang"),
define("CMAKE_CXX_COMPILER", spec.prefix.bin + "/clang++"),
define("CMAKE_INSTALL_PREFIX", spec.prefix),
+ define('CMAKE_PREFIX_PATH', prefix_paths)
]
cmake_args.extend(self.cmake_args())
- cmake_args.append(define("LIBOMPTARGET_NVPTX_ENABLE_BCLIB",
- True))
-
- # work around bad libelf detection in libomptarget
- cmake_args.append(define("LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIR",
- spec["libelf"].prefix.include))
+ cmake_args.extend([
+ define("LIBOMPTARGET_NVPTX_ENABLE_BCLIB", True),
+ define("LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIR",
+ spec["libelf"].prefix.include),
+ self.stage.source_path + "/openmp",
+ ])
cmake(*cmake_args)
- make()
- make("install")
+ ninja()
+ ninja("install")
if "+python" in self.spec:
install_tree("llvm/bindings/python", site_packages_dir)