Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix installing of Clang with RPATH linking #2799

Merged
merged 14 commits into from
Nov 7, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions easybuild/easyblocks/c/clang.py
Original file line number Diff line number Diff line change
@@ -37,11 +37,11 @@
import glob
import os
import shutil
import copy
from distutils.version import LooseVersion

from easybuild.easyblocks.generic.cmakemake import CMakeMake
from easybuild.framework.easyconfig import CUSTOM
from easybuild.toolchains.compiler.clang import Clang
from easybuild.tools import run
from easybuild.tools.build_log import EasyBuildError, print_warning
from easybuild.tools.config import build_option
@@ -50,7 +50,7 @@
from easybuild.tools.run import run_cmd
from easybuild.tools.systemtools import AARCH32, AARCH64, POWER, X86_64
from easybuild.tools.systemtools import get_cpu_architecture, get_os_name, get_os_version, get_shared_lib_ext
from easybuild.tools.environment import setvar, restore_env, read_environment
from easybuild.tools.environment import setvar

# List of all possible build targets for Clang
CLANG_TARGETS = ["all", "AArch64", "AMDGPU", "ARM", "CppBackend", "Hexagon", "Mips",
@@ -408,15 +408,11 @@ def build_with_prev_stage(self, prev_obj, next_obj):
mkdir(next_obj)
change_dir(next_obj)

# Make sure the clang and clang++ compilers from previous stages are (temporarily) in PATH
orig_env = copy.deepcopy(os.environ)
prev_obj_path = os.path.join(prev_obj, 'bin')
current_path = read_environment({'path': 'PATH'})
setvar('PATH', current_path['path'] + ":" + prev_obj_path)
# keep track of original $PATH value, we need to restore it in case RPATH wrappers were put in place
orig_path = os.getenv('PATH')

# If building with rpath, create RPATH wrappers for the Clang compilers for stage 2 and 3
if build_option('rpath'):
from easybuild.toolchains.compiler.clang import Clang
my_clang_toolchain = Clang(name='Clang', version='1')
my_clang_toolchain.prepare_rpath_wrappers()
self.log.info("Prepared clang rpath wrappers")
@@ -433,29 +429,35 @@ def build_with_prev_stage(self, prev_obj, next_obj):
setvar('CFLAGS', "%s %s" % (cflags, '-Wno-unused-command-line-argument'))
setvar('CXXFLAGS', "%s %s" % (cxxflags, '-Wno-unused-command-line-argument'))

# determine full path to clang/clang++ (which may be wrapper scripts in case of RPATH linking)
clang = which('clang') or os.path.join(prev_obj, 'bin', 'clang')
clangxx = which('clang++') or os.path.join(prev_obj, 'bin', 'clang++')

# Configure.
options = "-DCMAKE_INSTALL_PREFIX=%s " % self.installdir
options += "-DCMAKE_C_COMPILER='clang' "
options += "-DCMAKE_CXX_COMPILER='clang++' "
options += self.cfg['configopts']
options += "-DCMAKE_BUILD_TYPE=%s " % self.build_type
options = [
"-DCMAKE_INSTALL_PREFIX=%s " % self.installdir,
"-DCMAKE_C_COMPILER='%s' " % clang,
"-DCMAKE_CXX_COMPILER='%s' " % clangxx,
self.cfg['configopts'],
"-DCMAKE_BUILD_TYPE=%s " % self.build_type,
]

# Cmake looks for llvm-link by default in the same directory as the compiler
# However, when compiling with rpath, the clang 'compiler' is not actually the compiler, but the wrapper
# Clearly, the wrapper directory won't llvm-link. Thus, we pass the linker to be used by full path.
# See https://github.com/easybuilders/easybuild-easyblocks/pull/2799#issuecomment-1275916186
if build_option('rpath'):
llvm_link = which('llvm-link')
options += "-DLIBOMPTARGET_NVPTX_BC_LINKER=%s" % llvm_link
options.append("-DLIBOMPTARGET_NVPTX_BC_LINKER=%s" % llvm_link)

self.log.info("Configuring")
run_cmd("cmake %s %s" % (options, self.llvm_src_dir), log_all=True)
run_cmd("cmake %s %s" % (' '.join(options), self.llvm_src_dir), log_all=True)

self.log.info("Building")
run_cmd("make %s VERBOSE=1" % self.make_parallel_opts, log_all=True)

# Restore environment (specifically: PATH)
restore_env(orig_env)
# restore $PATH
setvar('PATH', orig_path)

def run_clang_tests(self, obj_dir):
"""Run Clang tests in specified directory (unless disabled)."""