waf configure --bundled-clang=5.0.0 to use prebuilt clang+llvm 5.0.0, fixes #41

This commit is contained in:
Fangrui Song 2017-11-26 14:43:59 -08:00 committed by Jacob Dufault
parent c7ef44ad53
commit 3ca2d0f2ad

77
wscript
View File

@ -7,11 +7,12 @@ except ImportError:
from urllib.request import urlopen # Python 3 from urllib.request import urlopen # Python 3
import os.path import os.path
from subprocess import call import string
import subprocess
import sys import sys
VERSION='0.0.1' VERSION = '0.0.1'
APPNAME='indexer' APPNAME = 'cquery'
top = '.' top = '.'
out = 'build' out = 'build'
@ -21,41 +22,20 @@ out = 'build'
# http://releases.llvm.org/5.0.0/clang+llvm-5.0.0-linux-x86_64-ubuntu16.04.tar.xz # http://releases.llvm.org/5.0.0/clang+llvm-5.0.0-linux-x86_64-ubuntu16.04.tar.xz
# http://releases.llvm.org/5.0.0/clang+llvm-5.0.0-linux-x86_64-ubuntu14.04.tar.xz # http://releases.llvm.org/5.0.0/clang+llvm-5.0.0-linux-x86_64-ubuntu14.04.tar.xz
# http://releases.llvm.org/5.0.0/clang+llvm-5.0.0-x86_64-apple-darwin.tar.xz # http://releases.llvm.org/5.0.0/clang+llvm-5.0.0-x86_64-apple-darwin.tar.xz
# TODO: windows support (it's an exe!)
global CLANG_PLATFORM_NAME if sys.platform == 'darwin':
global CLANG_TARBALL_PLATFORM_NAME CLANG_TARBALL_NAME = 'clang+llvm-$version-x86_64-apple-darwin'
elif sys.platform.startswith('freebsd'):
if sys.platform == 'linux' or sys.platform == 'linux2': CLANG_TARBALL_NAME = 'clang+llvm-$version-amd64-unknown-freebsd10'
#CLANG_PLATFORM_NAME = 'linux-x86_64-ubuntu14.04' # It is either 'linux2' or 'linux3' before Python 3.3
CLANG_PLATFORM_NAME = 'x86_64-linux-gnu-ubuntu-14.04' elif sys.platform.startswith('linux'):
CLANG_TARBALL_PLATFORM_NAME = 'clang+llvm' # These executable depend on libtinfo.so.5
elif sys.platform == 'darwin': CLANG_TARBALL_NAME = 'clang+llvm-$version-linux-x86_64-ubuntu14.04'
CLANG_PLATFORM_NAME = 'x86_64-apple-darwin'
CLANG_TARBALL_PLATFORM_NAME = 'clang+llvm'
else: else:
# TODO: windows support (it's an exe!)
sys.stderr.write('ERROR: Unknown platform {0}\n'.format(sys.platform)) sys.stderr.write('ERROR: Unknown platform {0}\n'.format(sys.platform))
sys.exit(1) sys.exit(1)
# Version of clang to download and use.
#CLANG_VERSION = '5.0.0'
CLANG_VERSION = '4.0.0'
# Tarball name on clang servers that should be used.
CLANG_TARBALL_NAME = '{0}-{1}-{2}'.format(CLANG_TARBALL_PLATFORM_NAME, CLANG_VERSION, CLANG_PLATFORM_NAME)
# Directory clang has been extracted to.
CLANG_DIRECTORY = '{0}/{1}'.format(out, CLANG_TARBALL_NAME)
# URL of the tarball to download.
CLANG_TARBALL_URL = 'http://releases.llvm.org/{0}/{1}.tar.xz'.format(CLANG_VERSION, CLANG_TARBALL_NAME)
# Path to locally tarball.
CLANG_TARBALL_LOCAL_PATH = '{0}.tar.xz'.format(CLANG_DIRECTORY)
# Directory libcxx will be extracted to.
LIBCXX_DIRECTORY = '{0}/libcxx'.format(out)
# URL to download libcxx from.
LIBCXX_URL = 'http://releases.llvm.org/4.0.0/libcxx-4.0.0.src.tar.xz'
# Absolute path for where to download the URL.
LIBCXX_LOCAL_PATH = '{0}/libcxx-4.0.0.src.tar.xz'.format(out)
from waflib.Tools.compiler_cxx import cxx_compiler from waflib.Tools.compiler_cxx import cxx_compiler
cxx_compiler['linux'] = ['clang++', 'g++'] cxx_compiler['linux'] = ['clang++', 'g++']
@ -64,12 +44,15 @@ def options(opt):
grp = opt.add_option_group('Configuration options related to use of clang from the system (not recommended)') grp = opt.add_option_group('Configuration options related to use of clang from the system (not recommended)')
grp.add_option('--use-system-clang', dest='use_system_clang', default=False, action='store_true', grp.add_option('--use-system-clang', dest='use_system_clang', default=False, action='store_true',
help='enable use of clang from the system') help='enable use of clang from the system')
grp.add_option('--bundled-clang', dest='bundled_clang', default='4.0.0', choices=('4.0.0', '5.0.0'),
help='bundled clang version')
grp.add_option('--llvm-config', dest='llvm_config', default='llvm-config', grp.add_option('--llvm-config', dest='llvm_config', default='llvm-config',
help='specify path to llvm-config for automatic configuration [default: %default]') help='specify path to llvm-config for automatic configuration [default: %default]')
grp.add_option('--clang-prefix', dest='clang_prefix', default='', grp.add_option('--clang-prefix', dest='clang_prefix', default='',
help='enable fallback configuration method by specifying a clang installation prefix (e.g. /opt/llvm)') help='enable fallback configuration method by specifying a clang installation prefix (e.g. /opt/llvm)')
def download_and_extract(destdir, dest, url): def download_and_extract(destdir, url):
dest = destdir + '.tar.xz'
# Download and save the compressed tarball as |compressed_file_name|. # Download and save the compressed tarball as |compressed_file_name|.
if not os.path.isfile(dest): if not os.path.isfile(dest):
print('Downloading tarball') print('Downloading tarball')
@ -86,7 +69,7 @@ def download_and_extract(destdir, dest, url):
if not os.path.isdir(destdir): if not os.path.isdir(destdir):
print('Extracting') print('Extracting')
# TODO: make portable. # TODO: make portable.
call(['tar', 'xf', dest, '-C', out]) subprocess.call(['tar', '-x', '-C', out, '-f', dest])
else: else:
print('Found extracted at {0}'.format(destdir)) print('Found extracted at {0}'.format(destdir))
@ -125,8 +108,28 @@ def configure(conf):
conf.check_cxx(msg='Checking for library clang', lib='clang', uselib_store='clang', includes=includes, libpath=libpath) conf.check_cxx(msg='Checking for library clang', lib='clang', uselib_store='clang', includes=includes, libpath=libpath)
else: else:
global CLANG_TARBALL_NAME
# TODO Remove these after dropping clang 4 (after we figure out how to index Chrome)
if conf.options.bundled_clang[0] == '4':
if sys.platform == 'darwin':
CLANG_TARBALL_NAME = 'clang+llvm-$version-x86_64-apple-darwin'
elif sys.platform.startswith('linux'):
# These executable depend on libtinfo.so.5
CLANG_TARBALL_NAME = 'clang+llvm-$version-x86_64-linux-gnu-ubuntu-14.04'
else:
# TODO: windows support (it's an exe!)
sys.stderr.write('ERROR: Unknown platform {0}\n'.format(sys.platform))
sys.exit(1)
CLANG_TARBALL_NAME = string.Template(CLANG_TARBALL_NAME).substitute(version=conf.options.bundled_clang)
# Directory clang has been extracted to.
CLANG_DIRECTORY = '{0}/{1}'.format(out, CLANG_TARBALL_NAME)
# URL of the tarball to download.
CLANG_TARBALL_URL = 'http://releases.llvm.org/{0}/{1}.tar.xz'.format(conf.options.bundled_clang, CLANG_TARBALL_NAME)
print('Checking for clang') print('Checking for clang')
download_and_extract(CLANG_DIRECTORY, CLANG_TARBALL_LOCAL_PATH, CLANG_TARBALL_URL) download_and_extract(CLANG_DIRECTORY, CLANG_TARBALL_URL)
clang_node = conf.path.find_dir(CLANG_DIRECTORY) clang_node = conf.path.find_dir(CLANG_DIRECTORY)
conf.check_cxx(uselib_store='clang', conf.check_cxx(uselib_store='clang',
@ -165,7 +168,7 @@ def build(bld):
cc_files = bld.path.ant_glob(['src/*.cc']) cc_files = bld.path.ant_glob(['src/*.cc'])
lib = [] lib = []
if sys.platform == 'linux' or sys.platform == 'linux2': if sys.platform.startswith('linux'):
lib.append('rt') lib.append('rt')
lib.append('pthread') lib.append('pthread')
lib.append('dl') lib.append('dl')