[BUILD] Now downloading LLVM from web if system does not have llvm-config-11 (#142)

This commit is contained in:
Philippe Tillet
2021-07-28 01:02:31 -07:00
committed by GitHub
parent 1365e96330
commit 57c1fd3366
2 changed files with 28 additions and 1 deletions

View File

@@ -63,7 +63,7 @@ endif()
file(GLOB_RECURSE LIBTRITON_SRC lib/*.cc) file(GLOB_RECURSE LIBTRITON_SRC lib/*.cc)
add_library(triton SHARED ${LIBTRITON_SRC} ${PYTHON_SRC}) add_library(triton SHARED ${LIBTRITON_SRC} ${PYTHON_SRC})
target_link_options(triton PRIVATE ${LLVM_LDFLAGS}) target_link_options(triton PRIVATE ${LLVM_LDFLAGS})
target_link_libraries(triton ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS}) target_link_libraries(triton ${LLVM_LIBRARIES} z tinfo)
if(BUILD_PYTHON_MODULE) if(BUILD_PYTHON_MODULE)

View File

@@ -16,6 +16,31 @@ import distutils.spawn
import urllib.request import urllib.request
import tarfile import tarfile
def get_llvm():
# tries to find system LLVM
versions = ['-11.0', '-11', '-11-64']
supported = ['llvm-config{v}'.format(v=v) for v in versions]
paths = [distutils.spawn.find_executable(cfg) for cfg in supported]
paths = [p for p in paths if p is not None]
if paths:
return paths[0]
# download if nothing is installed
name = 'clang+llvm-11.0.1-x86_64-linux-gnu-ubuntu-16.04'
dir = '/tmp'
llvm_config = '{dir}/{name}/bin/llvm-config'.format(dir=dir, name=name)
if not os.path.exists(llvm_config):
try:
shutil.rmtree(os.path.join(dir, name))
except:
pass
url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.1/{name}.tar.xz".format(name=name)
print('downloading and extracting ' + url + '...')
ftpstream = urllib.request.urlopen(url)
file = tarfile.open(fileobj=ftpstream, mode="r|xz")
file.extractall(path=dir)
return llvm_config
class CMakeExtension(Extension): class CMakeExtension(Extension):
def __init__(self, name, path, sourcedir=""): def __init__(self, name, path, sourcedir=""):
Extension.__init__(self, name, sources=[]) Extension.__init__(self, name, sources=[])
@@ -51,6 +76,7 @@ class CMakeBuild(build_ext):
self.build_extension(ext) self.build_extension(ext)
def build_extension(self, ext): def build_extension(self, ext):
llvm_config = get_llvm()
# self.debug = True # self.debug = True
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.path))) extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.path)))
# create build directories # create build directories
@@ -67,6 +93,7 @@ class CMakeBuild(build_ext):
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir, "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir,
"-DBUILD_TUTORIALS=OFF", "-DBUILD_TUTORIALS=OFF",
"-DBUILD_PYTHON_MODULE=ON", "-DBUILD_PYTHON_MODULE=ON",
"-DLLVM_CONFIG=" + llvm_config,
#'-DPYTHON_EXECUTABLE=' + sys.executable, #'-DPYTHON_EXECUTABLE=' + sys.executable,
#'-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON', #'-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON',
"-DTRITON_LLVM_BUILD_DIR=" + llvm_build_dir, "-DTRITON_LLVM_BUILD_DIR=" + llvm_build_dir,