2016-07-14 19:16:42 +03:00
|
|
|
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
2016-03-24 02:36:23 +03:00
|
|
|
# vim: set filetype=python:
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2018-05-31 04:16:10 +03:00
|
|
|
imply_option('--enable-release', mozilla_official)
|
|
|
|
imply_option('--enable-release', depends_if('MOZ_AUTOMATION')(lambda x: True))
|
|
|
|
|
|
|
|
js_option('--enable-release',
|
2018-06-06 10:13:09 +03:00
|
|
|
default=milestone.is_release_or_beta,
|
2018-05-31 04:16:10 +03:00
|
|
|
help='Build with more conservative, release engineering-oriented '
|
|
|
|
'options. This may slow down builds.')
|
|
|
|
|
|
|
|
|
|
|
|
@depends('--enable-release')
|
|
|
|
def developer_options(value):
|
|
|
|
if not value:
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
add_old_configure_assignment('DEVELOPER_OPTIONS', developer_options)
|
|
|
|
set_config('DEVELOPER_OPTIONS', developer_options)
|
|
|
|
|
2016-08-05 10:38:39 +03:00
|
|
|
# PGO
|
|
|
|
# ==============================================================
|
2017-11-10 20:23:27 +03:00
|
|
|
js_option(env='MOZ_PGO', help='Build with profile guided optimizations')
|
2016-08-05 10:38:39 +03:00
|
|
|
|
|
|
|
set_config('MOZ_PGO', depends('MOZ_PGO')(lambda x: bool(x)))
|
|
|
|
add_old_configure_assignment('MOZ_PGO', depends('MOZ_PGO')(lambda x: bool(x)))
|
|
|
|
|
2017-10-25 05:54:48 +03:00
|
|
|
# Code optimization
|
|
|
|
# ==============================================================
|
|
|
|
|
|
|
|
js_option('--enable-optimize',
|
|
|
|
nargs='?',
|
|
|
|
default=True,
|
|
|
|
help='Enable optimizations via compiler flags')
|
|
|
|
|
2017-10-25 20:57:51 +03:00
|
|
|
|
2017-10-25 05:54:48 +03:00
|
|
|
@depends('--enable-optimize')
|
|
|
|
def moz_optimize(option):
|
|
|
|
flags = None
|
|
|
|
|
|
|
|
if len(option):
|
|
|
|
val = '2'
|
|
|
|
flags = option[0]
|
|
|
|
elif option:
|
|
|
|
val = '1'
|
|
|
|
else:
|
|
|
|
val = None
|
|
|
|
|
|
|
|
return namespace(
|
|
|
|
optimize=val,
|
|
|
|
flags=flags,
|
|
|
|
)
|
|
|
|
|
2017-10-25 20:57:51 +03:00
|
|
|
|
2017-10-25 05:54:48 +03:00
|
|
|
set_config('MOZ_OPTIMIZE', moz_optimize.optimize)
|
|
|
|
add_old_configure_assignment('MOZ_OPTIMIZE', moz_optimize.optimize)
|
|
|
|
add_old_configure_assignment('MOZ_CONFIGURE_OPTIMIZE_FLAGS', moz_optimize.flags)
|
|
|
|
|
2016-03-24 02:36:23 +03:00
|
|
|
# yasm detection
|
|
|
|
# ==============================================================
|
|
|
|
yasm = check_prog('YASM', ['yasm'], allow_missing=True)
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-03-24 09:26:32 +03:00
|
|
|
@depends_if(yasm)
|
2016-03-24 02:36:23 +03:00
|
|
|
@checking('yasm version')
|
|
|
|
def yasm_version(yasm):
|
2016-05-18 00:40:03 +03:00
|
|
|
version = check_cmd_output(
|
|
|
|
yasm, '--version',
|
|
|
|
onerror=lambda: die('Failed to get yasm version.')
|
|
|
|
).splitlines()[0].split()[1]
|
2016-06-09 09:27:59 +03:00
|
|
|
return Version(version)
|
2016-03-24 02:36:23 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-11-06 21:07:26 +03:00
|
|
|
@depends_if(yasm_version)
|
2017-10-31 21:42:27 +03:00
|
|
|
def yasm_major_version(yasm_version):
|
|
|
|
return str(yasm_version.major)
|
|
|
|
|
|
|
|
|
2017-11-06 21:07:26 +03:00
|
|
|
@depends_if(yasm_version)
|
2017-10-31 21:42:27 +03:00
|
|
|
def yasm_minor_version(yasm_version):
|
|
|
|
return str(yasm_version.minor)
|
|
|
|
|
|
|
|
|
|
|
|
set_config('YASM_MAJOR_VERSION', yasm_major_version)
|
|
|
|
set_config('YASM_MINOR_VERSION', yasm_minor_version)
|
2016-03-24 02:36:23 +03:00
|
|
|
# Until we move all the yasm consumers out of old-configure.
|
|
|
|
# bug 1257904
|
|
|
|
add_old_configure_assignment('_YASM_MAJOR_VERSION',
|
2017-05-17 10:13:34 +03:00
|
|
|
yasm_version.major)
|
2016-03-24 02:36:23 +03:00
|
|
|
add_old_configure_assignment('_YASM_MINOR_VERSION',
|
2017-05-17 10:13:34 +03:00
|
|
|
yasm_version.minor)
|
2016-03-24 02:36:23 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-03-24 02:36:23 +03:00
|
|
|
@depends(yasm, target)
|
|
|
|
def yasm_asflags(yasm, target):
|
|
|
|
if yasm:
|
|
|
|
asflags = {
|
2017-11-14 21:38:17 +03:00
|
|
|
('OSX', 'x86'): ['-f', 'macho32'],
|
|
|
|
('OSX', 'x86_64'): ['-f', 'macho64'],
|
|
|
|
('WINNT', 'x86'): ['-f', 'win32'],
|
|
|
|
('WINNT', 'x86_64'): ['-f', 'x64'],
|
2016-03-24 02:36:23 +03:00
|
|
|
}.get((target.os, target.cpu), None)
|
|
|
|
if asflags is None:
|
|
|
|
# We're assuming every x86 platform we support that's
|
|
|
|
# not Windows or Mac is ELF.
|
|
|
|
if target.cpu == 'x86':
|
2017-11-14 21:38:17 +03:00
|
|
|
asflags = ['-f', 'elf32']
|
2016-03-24 02:36:23 +03:00
|
|
|
elif target.cpu == 'x86_64':
|
2017-11-14 21:38:17 +03:00
|
|
|
asflags = ['-f', 'elf64']
|
2016-03-24 02:36:23 +03:00
|
|
|
if asflags:
|
2017-11-14 21:38:17 +03:00
|
|
|
asflags += ['-rnasm', '-pnasm']
|
2016-03-24 02:36:23 +03:00
|
|
|
return asflags
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-03-24 02:36:23 +03:00
|
|
|
set_config('YASM_ASFLAGS', yasm_asflags)
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-03-24 02:36:23 +03:00
|
|
|
@depends(yasm_asflags)
|
|
|
|
def have_yasm(value):
|
|
|
|
if value:
|
|
|
|
return True
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-03-24 02:36:23 +03:00
|
|
|
set_config('HAVE_YASM', have_yasm)
|
|
|
|
# Until the YASM variable is not necessary in old-configure.
|
|
|
|
add_old_configure_assignment('YASM', have_yasm)
|
2016-03-25 15:14:59 +03:00
|
|
|
|
2016-04-02 05:23:40 +03:00
|
|
|
# Android NDK
|
|
|
|
# ==============================================================
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-07-21 07:48:10 +03:00
|
|
|
@depends('--disable-compile-environment', build_project, '--help')
|
|
|
|
def compiling_android(compile_env, build_project, _):
|
|
|
|
return compile_env and build_project in ('mobile/android', 'js')
|
2016-04-02 05:23:40 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-10-13 11:15:24 +03:00
|
|
|
include('android-ndk.configure', when=compiling_android)
|
2016-04-02 05:23:40 +03:00
|
|
|
|
2016-04-21 02:11:32 +03:00
|
|
|
# MacOS deployment target version
|
|
|
|
# ==============================================================
|
|
|
|
# This needs to happen before any compilation test is done.
|
|
|
|
|
|
|
|
option('--enable-macos-target', env='MACOSX_DEPLOYMENT_TARGET', nargs=1,
|
2018-05-10 12:41:13 +03:00
|
|
|
default='10.9', help='Set the minimum MacOS version needed at runtime')
|
2016-04-21 02:11:32 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-04-21 02:11:32 +03:00
|
|
|
@depends('--enable-macos-target', target)
|
|
|
|
@imports(_from='os', _import='environ')
|
|
|
|
def macos_target(value, target):
|
|
|
|
if value and target.os == 'OSX':
|
|
|
|
# Ensure every compiler process we spawn uses this value.
|
|
|
|
environ['MACOSX_DEPLOYMENT_TARGET'] = value[0]
|
|
|
|
return value[0]
|
|
|
|
if value and value.origin != 'default':
|
|
|
|
die('--enable-macos-target cannot be used when targeting %s',
|
|
|
|
target.os)
|
|
|
|
|
|
|
|
|
|
|
|
set_config('MACOSX_DEPLOYMENT_TARGET', macos_target)
|
|
|
|
add_old_configure_assignment('MACOSX_DEPLOYMENT_TARGET', macos_target)
|
|
|
|
|
2017-09-26 20:56:38 +03:00
|
|
|
# Xcode state
|
|
|
|
# ===========
|
|
|
|
|
2017-09-28 18:46:30 +03:00
|
|
|
js_option('--disable-xcode-checks',
|
2017-10-12 16:22:59 +03:00
|
|
|
help='Do not check that Xcode is installed and properly configured')
|
|
|
|
|
2017-09-26 20:56:38 +03:00
|
|
|
|
|
|
|
@depends(host, '--disable-xcode-checks')
|
|
|
|
def xcode_path(host, xcode_checks):
|
|
|
|
if host.kernel != 'Darwin' or not xcode_checks:
|
|
|
|
return
|
|
|
|
|
|
|
|
# xcode-select -p prints the path to the installed Xcode. It
|
|
|
|
# should exit 0 and return non-empty result if Xcode is installed.
|
|
|
|
|
|
|
|
def bad_xcode_select():
|
|
|
|
die('Could not find installed Xcode; install Xcode from the App '
|
|
|
|
'Store, run it once to perform initial configuration, and then '
|
|
|
|
'try again; in the rare case you wish to build without Xcode '
|
|
|
|
'installed, add the --disable-xcode-checks configure flag')
|
|
|
|
|
|
|
|
xcode_path = check_cmd_output('xcode-select', '--print-path',
|
|
|
|
onerror=bad_xcode_select).strip()
|
|
|
|
|
|
|
|
if not xcode_path:
|
|
|
|
bad_xcode_select()
|
|
|
|
|
|
|
|
# Now look for the Command Line Tools.
|
|
|
|
def no_cltools():
|
|
|
|
die('Could not find installed Xcode Command Line Tools; '
|
|
|
|
'run `xcode-select --install` and follow the instructions '
|
|
|
|
'to install them then try again; if you wish to build without '
|
|
|
|
'Xcode Command Line Tools installed, '
|
|
|
|
'add the --disable-xcode-checks configure flag')
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
check_cmd_output('pkgutil', '--pkg-info',
|
|
|
|
'com.apple.pkg.CLTools_Executables',
|
|
|
|
onerror=no_cltools)
|
2017-09-26 20:56:38 +03:00
|
|
|
|
|
|
|
return xcode_path
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-09-26 20:56:38 +03:00
|
|
|
set_config('XCODE_PATH', xcode_path)
|
|
|
|
|
2016-04-21 02:11:32 +03:00
|
|
|
|
2016-03-25 15:14:59 +03:00
|
|
|
# Compiler wrappers
|
|
|
|
# ==============================================================
|
2016-04-05 04:56:42 +03:00
|
|
|
# Normally, we'd use js_option and automatically have those variables
|
|
|
|
# propagated to js/src, but things are complicated by possible additional
|
|
|
|
# wrappers in CC/CXX, and by other subconfigures that do not handle those
|
|
|
|
# options and do need CC/CXX altered.
|
|
|
|
option('--with-compiler-wrapper', env='COMPILER_WRAPPER', nargs=1,
|
|
|
|
help='Enable compiling with wrappers such as distcc and ccache')
|
2016-03-25 15:14:59 +03:00
|
|
|
|
2018-09-14 19:12:34 +03:00
|
|
|
js_option('--with-ccache', env='CCACHE', nargs='?',
|
|
|
|
help='Enable compiling with ccache')
|
2016-03-25 15:14:59 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-03-25 15:14:59 +03:00
|
|
|
@depends_if('--with-ccache')
|
|
|
|
def ccache(value):
|
|
|
|
if len(value):
|
|
|
|
return value
|
|
|
|
# If --with-ccache was given without an explicit value, we default to
|
|
|
|
# 'ccache'.
|
|
|
|
return 'ccache'
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-03-25 15:14:59 +03:00
|
|
|
ccache = check_prog('CCACHE', progs=(), input=ccache)
|
|
|
|
|
2016-08-26 01:39:57 +03:00
|
|
|
# Distinguish ccache from sccache.
|
2017-10-12 16:22:59 +03:00
|
|
|
|
|
|
|
|
2016-03-25 15:14:59 +03:00
|
|
|
@depends_if(ccache)
|
2016-08-26 01:39:57 +03:00
|
|
|
def ccache_is_sccache(ccache):
|
|
|
|
return check_cmd_output(ccache, '--version').startswith('sccache')
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-08-26 01:39:57 +03:00
|
|
|
@depends(ccache, ccache_is_sccache)
|
|
|
|
def using_ccache(ccache, ccache_is_sccache):
|
|
|
|
return ccache and not ccache_is_sccache
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-08-26 01:39:57 +03:00
|
|
|
@depends_if(ccache, ccache_is_sccache)
|
|
|
|
def using_sccache(ccache, ccache_is_sccache):
|
2017-06-16 17:34:09 +03:00
|
|
|
return ccache and ccache_is_sccache
|
2016-03-25 15:14:59 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-03-25 15:14:59 +03:00
|
|
|
set_config('MOZ_USING_CCACHE', using_ccache)
|
2016-08-26 01:39:57 +03:00
|
|
|
set_config('MOZ_USING_SCCACHE', using_sccache)
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
option(env='SCCACHE_VERBOSE_STATS',
|
|
|
|
help='Print verbose sccache stats after build')
|
|
|
|
|
2016-08-26 01:39:57 +03:00
|
|
|
|
|
|
|
@depends(using_sccache, 'SCCACHE_VERBOSE_STATS')
|
|
|
|
def sccache_verbose_stats(using_sccache, verbose_stats):
|
|
|
|
return using_sccache and bool(verbose_stats)
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-08-26 01:39:57 +03:00
|
|
|
set_config('SCCACHE_VERBOSE_STATS', sccache_verbose_stats)
|
2016-03-25 15:14:59 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-03-25 15:14:59 +03:00
|
|
|
@depends('--with-compiler-wrapper', ccache)
|
2016-03-27 05:40:13 +03:00
|
|
|
@imports(_from='mozbuild.shellutil', _import='split', _as='shell_split')
|
2016-03-25 15:14:59 +03:00
|
|
|
def compiler_wrapper(wrapper, ccache):
|
2016-04-05 08:05:59 +03:00
|
|
|
if wrapper:
|
|
|
|
raw_wrapper = wrapper[0]
|
|
|
|
wrapper = shell_split(raw_wrapper)
|
|
|
|
wrapper_program = find_program(wrapper[0])
|
|
|
|
if not wrapper_program:
|
|
|
|
die('Cannot find `%s` from the given compiler wrapper `%s`',
|
|
|
|
wrapper[0], raw_wrapper)
|
|
|
|
wrapper[0] = wrapper_program
|
|
|
|
|
2016-03-25 15:14:59 +03:00
|
|
|
if ccache:
|
|
|
|
if wrapper:
|
2016-04-05 08:05:59 +03:00
|
|
|
return tuple([ccache] + wrapper)
|
2016-03-25 15:14:59 +03:00
|
|
|
else:
|
|
|
|
return (ccache,)
|
|
|
|
elif wrapper:
|
2016-04-05 08:05:59 +03:00
|
|
|
return tuple(wrapper)
|
2016-03-25 15:14:59 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-03-25 15:14:59 +03:00
|
|
|
add_old_configure_assignment('COMPILER_WRAPPER', compiler_wrapper)
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-03-25 15:14:59 +03:00
|
|
|
@depends_if(compiler_wrapper)
|
|
|
|
def using_compiler_wrapper(compiler_wrapper):
|
|
|
|
return True
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-03-25 15:14:59 +03:00
|
|
|
set_config('MOZ_USING_COMPILER_WRAPPER', using_compiler_wrapper)
|
2016-03-30 08:47:13 +03:00
|
|
|
|
|
|
|
|
2017-05-27 20:51:40 +03:00
|
|
|
# GC rooting and hazard analysis.
|
|
|
|
# ==============================================================
|
|
|
|
option(env='MOZ_HAZARD', help='Build for the GC rooting hazard analysis')
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-05-27 20:51:40 +03:00
|
|
|
@depends('MOZ_HAZARD')
|
|
|
|
def hazard_analysis(value):
|
|
|
|
if value:
|
|
|
|
return True
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-05-27 20:51:40 +03:00
|
|
|
set_config('MOZ_HAZARD', hazard_analysis)
|
|
|
|
|
|
|
|
|
2016-03-30 08:47:13 +03:00
|
|
|
# Cross-compilation related things.
|
|
|
|
# ==============================================================
|
|
|
|
js_option('--with-toolchain-prefix', env='TOOLCHAIN_PREFIX', nargs=1,
|
|
|
|
help='Prefix for the target toolchain')
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-11-11 06:52:37 +03:00
|
|
|
@depends('--with-toolchain-prefix', target, cross_compiling)
|
|
|
|
def toolchain_prefix(value, target, cross_compiling):
|
2016-03-30 08:47:13 +03:00
|
|
|
if value:
|
2016-10-21 01:50:40 +03:00
|
|
|
return tuple(value)
|
|
|
|
if cross_compiling:
|
|
|
|
return ('%s-' % target.toolchain, '%s-' % target.alias)
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-10-21 01:50:40 +03:00
|
|
|
@depends(toolchain_prefix, target)
|
|
|
|
def first_toolchain_prefix(toolchain_prefix, target):
|
|
|
|
# Pass TOOLCHAIN_PREFIX down to the build system if it was given from the
|
|
|
|
# command line/environment (in which case there's only one value in the tuple),
|
|
|
|
# or when cross-compiling for Android.
|
|
|
|
if toolchain_prefix and (target.os == 'Android' or len(toolchain_prefix) == 1):
|
|
|
|
return toolchain_prefix[0]
|
2016-03-30 08:47:13 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-10-21 01:50:40 +03:00
|
|
|
set_config('TOOLCHAIN_PREFIX', first_toolchain_prefix)
|
|
|
|
add_old_configure_assignment('TOOLCHAIN_PREFIX', first_toolchain_prefix)
|
2016-04-05 04:56:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
# Compilers
|
|
|
|
# ==============================================================
|
2016-08-04 09:51:47 +03:00
|
|
|
include('compilers-util.configure')
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-04-06 05:32:03 +03:00
|
|
|
def try_preprocess(compiler, language, source):
|
2016-07-27 01:27:19 +03:00
|
|
|
return try_invoke_compiler(compiler, language, source, ['-E'])
|
2016-04-05 04:56:42 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-04-06 05:32:03 +03:00
|
|
|
@imports(_from='mozbuild.configure.constants', _import='CompilerType')
|
2016-04-22 09:08:55 +03:00
|
|
|
@imports(_from='mozbuild.configure.constants',
|
|
|
|
_import='CPU_preprocessor_checks')
|
2016-04-26 09:38:45 +03:00
|
|
|
@imports(_from='mozbuild.configure.constants',
|
|
|
|
_import='kernel_preprocessor_checks')
|
2018-09-13 19:09:26 +03:00
|
|
|
@imports(_from='mozbuild.configure.constants',
|
|
|
|
_import='OS_preprocessor_checks')
|
2016-04-06 05:32:03 +03:00
|
|
|
@imports(_from='textwrap', _import='dedent')
|
2016-04-06 11:18:07 +03:00
|
|
|
def get_compiler_info(compiler, language):
|
|
|
|
'''Returns information about the given `compiler` (command line in the
|
|
|
|
form of a list or tuple), in the given `language`.
|
|
|
|
|
|
|
|
The returned information includes:
|
|
|
|
- the compiler type (msvc, clang-cl, clang or gcc)
|
|
|
|
- the compiler version
|
|
|
|
- the compiler supported language
|
|
|
|
- the compiler supported language version
|
|
|
|
'''
|
|
|
|
# Note: MSVC doesn't expose __STDC_VERSION__. It does expose __STDC__,
|
|
|
|
# but only when given the -Za option, which disables compiler
|
|
|
|
# extensions.
|
2016-04-19 09:09:10 +03:00
|
|
|
# Note: We'd normally do a version check for clang, but versions of clang
|
|
|
|
# in Xcode have a completely different versioning scheme despite exposing
|
|
|
|
# the version with the same defines.
|
|
|
|
# So instead, we make things such that the version is missing when the
|
2018-09-10 20:59:07 +03:00
|
|
|
# clang used is below the minimum supported version (currently clang 3.9).
|
2016-04-19 09:09:10 +03:00
|
|
|
# We then only include the version information when the C++ compiler
|
|
|
|
# matches the feature check, so that an unsupported version of clang would
|
|
|
|
# have no version number.
|
2016-04-06 05:32:03 +03:00
|
|
|
check = dedent('''\
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#if defined(__clang__)
|
2016-09-08 01:27:56 +03:00
|
|
|
%COMPILER "clang-cl"
|
2016-04-19 09:55:36 +03:00
|
|
|
%VERSION _MSC_FULL_VER
|
2016-04-06 05:32:03 +03:00
|
|
|
#else
|
2016-09-08 01:27:56 +03:00
|
|
|
%COMPILER "msvc"
|
2016-04-06 11:18:07 +03:00
|
|
|
%VERSION _MSC_FULL_VER
|
2016-04-06 05:32:03 +03:00
|
|
|
#endif
|
|
|
|
#elif defined(__clang__)
|
2016-09-08 01:27:56 +03:00
|
|
|
%COMPILER "clang"
|
2018-09-10 20:59:07 +03:00
|
|
|
# if !__cplusplus || __has_builtin(__builtin_bitreverse8)
|
2016-04-06 11:18:07 +03:00
|
|
|
%VERSION __clang_major__.__clang_minor__.__clang_patchlevel__
|
2016-04-19 09:09:10 +03:00
|
|
|
# endif
|
2016-04-06 05:32:03 +03:00
|
|
|
#elif defined(__GNUC__)
|
2016-09-08 01:27:56 +03:00
|
|
|
%COMPILER "gcc"
|
2016-04-06 11:18:07 +03:00
|
|
|
%VERSION __GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __cplusplus
|
|
|
|
%cplusplus __cplusplus
|
|
|
|
#elif __STDC_VERSION__
|
|
|
|
%STDC_VERSION __STDC_VERSION__
|
|
|
|
#elif __STDC__
|
|
|
|
%STDC_VERSION 198900L
|
2016-04-06 05:32:03 +03:00
|
|
|
#endif
|
|
|
|
''')
|
|
|
|
|
2016-04-22 09:08:55 +03:00
|
|
|
# While we're doing some preprocessing, we might as well do some more
|
|
|
|
# preprocessor-based tests at the same time, to check the toolchain
|
|
|
|
# matches what we want.
|
2016-04-26 09:38:45 +03:00
|
|
|
for name, preprocessor_checks in (
|
|
|
|
('CPU', CPU_preprocessor_checks),
|
|
|
|
('KERNEL', kernel_preprocessor_checks),
|
2018-09-13 19:09:26 +03:00
|
|
|
('OS', OS_preprocessor_checks),
|
2016-04-26 09:38:45 +03:00
|
|
|
):
|
|
|
|
for n, (value, condition) in enumerate(preprocessor_checks.iteritems()):
|
|
|
|
check += dedent('''\
|
|
|
|
#%(if)s %(condition)s
|
2016-09-08 01:27:56 +03:00
|
|
|
%%%(name)s "%(value)s"
|
2016-04-26 09:38:45 +03:00
|
|
|
''' % {
|
|
|
|
'if': 'elif' if n else 'if',
|
|
|
|
'condition': condition,
|
|
|
|
'name': name,
|
|
|
|
'value': value,
|
|
|
|
})
|
|
|
|
check += '#endif\n'
|
2016-04-22 09:08:55 +03:00
|
|
|
|
2016-07-21 02:24:45 +03:00
|
|
|
# Also check for endianness. The advantage of living in modern times is
|
|
|
|
# that all the modern compilers we support now have __BYTE_ORDER__ defined
|
|
|
|
# by the preprocessor, except MSVC, which only supports little endian.
|
|
|
|
check += dedent('''\
|
|
|
|
#if _MSC_VER || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
2016-09-08 01:27:56 +03:00
|
|
|
%ENDIANNESS "little"
|
2016-07-21 02:24:45 +03:00
|
|
|
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
2016-09-08 01:27:56 +03:00
|
|
|
%ENDIANNESS "big"
|
2016-07-21 02:24:45 +03:00
|
|
|
#endif
|
|
|
|
''')
|
|
|
|
|
2016-04-06 05:32:03 +03:00
|
|
|
result = try_preprocess(compiler, language, check)
|
|
|
|
|
2016-04-06 11:18:07 +03:00
|
|
|
if not result:
|
|
|
|
raise FatalCheckError(
|
|
|
|
'Unknown compiler or compiler not supported.')
|
|
|
|
|
2016-08-30 12:47:28 +03:00
|
|
|
# Metadata emitted by preprocessors such as GCC with LANG=ja_JP.utf-8 may
|
|
|
|
# have non-ASCII characters. Treat the output as bytearray.
|
2016-04-06 11:18:07 +03:00
|
|
|
data = {}
|
|
|
|
for line in result.splitlines():
|
2016-08-30 12:47:28 +03:00
|
|
|
if line.startswith(b'%'):
|
2016-04-06 11:18:07 +03:00
|
|
|
k, _, v = line.partition(' ')
|
|
|
|
k = k.lstrip('%')
|
2016-09-08 01:27:56 +03:00
|
|
|
data[k] = v.replace(' ', '').lstrip('"').rstrip('"')
|
2016-04-06 11:18:07 +03:00
|
|
|
log.debug('%s = %s', k, data[k])
|
|
|
|
|
2016-04-19 10:03:07 +03:00
|
|
|
try:
|
|
|
|
type = CompilerType(data['COMPILER'])
|
2018-01-31 22:32:08 +03:00
|
|
|
except Exception:
|
2016-04-06 11:18:07 +03:00
|
|
|
raise FatalCheckError(
|
|
|
|
'Unknown compiler or compiler not supported.')
|
|
|
|
|
|
|
|
cplusplus = int(data.get('cplusplus', '0L').rstrip('L'))
|
|
|
|
stdc_version = int(data.get('STDC_VERSION', '0L').rstrip('L'))
|
|
|
|
|
2016-04-19 10:03:07 +03:00
|
|
|
version = data.get('VERSION')
|
|
|
|
if version and type in ('msvc', 'clang-cl'):
|
|
|
|
msc_ver = version
|
|
|
|
version = msc_ver[0:2]
|
|
|
|
if len(msc_ver) > 2:
|
|
|
|
version += '.' + msc_ver[2:4]
|
|
|
|
if len(msc_ver) > 4:
|
|
|
|
version += '.' + msc_ver[4:]
|
|
|
|
|
|
|
|
if version:
|
|
|
|
version = Version(version)
|
|
|
|
|
2016-04-06 11:18:07 +03:00
|
|
|
return namespace(
|
2016-04-19 10:03:07 +03:00
|
|
|
type=type,
|
|
|
|
version=version,
|
2016-04-22 09:08:55 +03:00
|
|
|
cpu=data.get('CPU'),
|
2016-04-26 09:38:45 +03:00
|
|
|
kernel=data.get('KERNEL'),
|
2016-07-21 02:24:45 +03:00
|
|
|
endianness=data.get('ENDIANNESS'),
|
2018-09-13 19:09:26 +03:00
|
|
|
os=data.get('OS'),
|
2016-04-06 11:18:07 +03:00
|
|
|
language='C++' if cplusplus else 'C',
|
|
|
|
language_version=cplusplus if cplusplus else stdc_version,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-09-14 20:40:52 +03:00
|
|
|
def same_arch_different_bits():
|
|
|
|
return (
|
|
|
|
('x86', 'x86_64'),
|
|
|
|
('ppc', 'ppc64'),
|
|
|
|
('sparc', 'sparc64'),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2016-04-06 11:18:07 +03:00
|
|
|
@imports(_from='mozbuild.shellutil', _import='quote')
|
2018-09-13 19:09:26 +03:00
|
|
|
@imports(_from='mozbuild.configure.constants',
|
|
|
|
_import='OS_preprocessor_checks')
|
2016-04-22 09:08:55 +03:00
|
|
|
def check_compiler(compiler, language, target):
|
2016-04-06 11:18:07 +03:00
|
|
|
info = get_compiler_info(compiler, language)
|
|
|
|
|
|
|
|
flags = []
|
|
|
|
|
|
|
|
def append_flag(flag):
|
|
|
|
if flag not in flags:
|
|
|
|
if info.type == 'clang-cl':
|
|
|
|
flags.append('-Xclang')
|
|
|
|
flags.append(flag)
|
|
|
|
|
|
|
|
# Check language standards
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
if language != info.language:
|
|
|
|
raise FatalCheckError(
|
|
|
|
'`%s` is not a %s compiler.' % (quote(*compiler), language))
|
|
|
|
|
|
|
|
# Note: We do a strict version check because there sometimes are backwards
|
|
|
|
# incompatible changes in the standard, and not all code that compiles as
|
|
|
|
# C99 compiles as e.g. C11 (as of writing, this is true of libnestegg, for
|
|
|
|
# example)
|
|
|
|
if info.language == 'C' and info.language_version != 199901:
|
|
|
|
if info.type in ('clang-cl', 'clang', 'gcc'):
|
|
|
|
append_flag('-std=gnu99')
|
|
|
|
|
2017-11-15 21:53:16 +03:00
|
|
|
# Note: MSVC, while supporting C++14, still reports 199711L for __cplusplus.
|
2016-04-06 11:18:07 +03:00
|
|
|
# Note: this is a strict version check because we used to always add
|
2017-11-15 21:53:16 +03:00
|
|
|
# -std=gnu++14.
|
2017-09-22 20:26:42 +03:00
|
|
|
cxx14_version = 201402
|
2016-10-04 23:34:04 +03:00
|
|
|
if info.language == 'C++':
|
2017-11-15 21:53:16 +03:00
|
|
|
if info.type == 'clang' and info.language_version != cxx14_version:
|
|
|
|
append_flag('-std=gnu++14')
|
2018-05-10 00:26:31 +03:00
|
|
|
# MSVC headers include C++14 features, but don't guard them
|
2017-11-15 21:53:16 +03:00
|
|
|
# with appropriate checks.
|
|
|
|
elif info.type == 'clang-cl' and info.language_version != cxx14_version:
|
|
|
|
append_flag('-std=c++14')
|
2016-04-06 11:18:07 +03:00
|
|
|
|
2018-09-07 01:15:19 +03:00
|
|
|
# We force clang-cl to emulate Visual C++ 2017 version 15.8.4
|
|
|
|
msvc_version = '19.15.26726'
|
2018-03-13 02:24:44 +03:00
|
|
|
if info.type == 'clang-cl' and info.version != msvc_version:
|
2016-12-21 14:56:48 +03:00
|
|
|
# This flag is a direct clang-cl flag that doesn't need -Xclang,
|
|
|
|
# add it directly.
|
2018-03-13 02:24:44 +03:00
|
|
|
flags.append('-fms-compatibility-version=%s' % msvc_version)
|
2016-04-19 09:55:36 +03:00
|
|
|
|
2016-04-22 09:08:55 +03:00
|
|
|
# Check compiler target
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
if not info.cpu or info.cpu != target.cpu:
|
|
|
|
if info.type == 'clang':
|
|
|
|
append_flag('--target=%s' % target.toolchain)
|
2018-01-10 20:17:32 +03:00
|
|
|
elif info.type == 'clang-cl':
|
|
|
|
# Ideally this would share the 'clang' branch above, but on Windows
|
|
|
|
# the --target needs additional data like ms-compatibility-version.
|
|
|
|
if (info.cpu, target.cpu) == ('x86_64', 'x86'):
|
|
|
|
# -m32 does not use -Xclang, so add it directly.
|
|
|
|
flags.append('-m32')
|
2016-04-22 09:08:55 +03:00
|
|
|
elif info.type == 'gcc':
|
2018-09-14 20:40:52 +03:00
|
|
|
same_arch = same_arch_different_bits()
|
|
|
|
if (target.cpu, info.cpu) in same_arch:
|
2016-04-22 09:08:55 +03:00
|
|
|
append_flag('-m32')
|
2018-09-14 20:40:52 +03:00
|
|
|
elif (info.cpu, target.cpu) in same_arch:
|
2016-04-22 09:08:55 +03:00
|
|
|
append_flag('-m64')
|
|
|
|
|
2016-04-26 09:38:45 +03:00
|
|
|
if not info.kernel or info.kernel != target.kernel:
|
|
|
|
if info.type == 'clang':
|
|
|
|
append_flag('--target=%s' % target.toolchain)
|
|
|
|
|
2016-07-21 02:24:45 +03:00
|
|
|
if not info.endianness or info.endianness != target.endianness:
|
|
|
|
if info.type == 'clang':
|
|
|
|
append_flag('--target=%s' % target.toolchain)
|
|
|
|
|
2018-09-13 19:09:26 +03:00
|
|
|
# Add target flag when there is an OS mismatch (e.g. building for Android on
|
|
|
|
# Linux). However, only do this if the target OS is in our whitelist, to
|
|
|
|
# keep things the same on other platforms.
|
|
|
|
if target.os in OS_preprocessor_checks and (
|
|
|
|
not info.os or info.os != target.os):
|
|
|
|
if info.type == 'clang':
|
|
|
|
append_flag('--target=%s' % target.toolchain)
|
|
|
|
|
2016-04-22 03:24:32 +03:00
|
|
|
return namespace(
|
|
|
|
type=info.type,
|
|
|
|
version=info.version,
|
2016-04-22 09:08:55 +03:00
|
|
|
target_cpu=info.cpu,
|
2016-04-26 09:38:45 +03:00
|
|
|
target_kernel=info.kernel,
|
2016-07-21 02:24:45 +03:00
|
|
|
target_endianness=info.endianness,
|
2018-09-13 19:09:26 +03:00
|
|
|
target_os=info.os,
|
2016-04-22 03:24:32 +03:00
|
|
|
flags=flags,
|
|
|
|
)
|
2016-04-06 05:32:03 +03:00
|
|
|
|
|
|
|
|
2017-04-26 22:18:48 +03:00
|
|
|
@imports(_from='__builtin__', _import='open')
|
|
|
|
@imports('json')
|
|
|
|
@imports('subprocess')
|
2017-05-08 09:31:44 +03:00
|
|
|
@imports('sys')
|
2017-04-26 22:18:48 +03:00
|
|
|
def get_vc_paths(topsrcdir):
|
|
|
|
def vswhere(args):
|
2017-05-08 09:31:44 +03:00
|
|
|
encoding = 'mbcs' if sys.platform == 'win32' else 'utf-8'
|
2017-10-12 16:22:59 +03:00
|
|
|
return json.loads(
|
|
|
|
subprocess.check_output([
|
|
|
|
os.path.join(topsrcdir, 'build/win32/vswhere.exe'),
|
|
|
|
'-format',
|
|
|
|
'json'
|
|
|
|
] + args).decode(encoding, 'replace'))
|
2017-04-26 22:18:48 +03:00
|
|
|
|
|
|
|
for install in vswhere(['-requires', 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64']):
|
|
|
|
path = install['installationPath']
|
2017-10-12 16:22:59 +03:00
|
|
|
tools_version = open(os.path.join(
|
|
|
|
path, r'VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt'), 'rb').read().strip()
|
|
|
|
tools_path = os.path.join(
|
|
|
|
path, r'VC\Tools\MSVC', tools_version, r'bin\HostX64')
|
2017-04-26 22:18:48 +03:00
|
|
|
yield (Version(install['installationVersion']), {
|
|
|
|
'x64': [os.path.join(tools_path, 'x64')],
|
|
|
|
# The x64->x86 cross toolchain requires DLLs from the native x64 toolchain.
|
|
|
|
'x86': [os.path.join(tools_path, 'x86'), os.path.join(tools_path, 'x64')],
|
2018-08-03 04:40:40 +03:00
|
|
|
'arm64': [os.path.join(tools_path, 'x64')],
|
2017-04-26 22:18:48 +03:00
|
|
|
})
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-10-09 19:16:00 +03:00
|
|
|
js_option('--with-visual-studio-version', nargs=1,
|
2018-05-10 00:26:31 +03:00
|
|
|
choices=('2017',),
|
2017-10-09 19:16:00 +03:00
|
|
|
help='Select a specific Visual Studio version to use')
|
2017-04-26 22:18:48 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-04-20 19:43:44 +03:00
|
|
|
@depends('--with-visual-studio-version')
|
|
|
|
def vs_major_version(value):
|
|
|
|
if value:
|
2018-05-10 00:26:31 +03:00
|
|
|
return {'2017': 15}[value[0]]
|
2017-04-20 19:43:44 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-04-20 19:43:44 +03:00
|
|
|
@depends(host, target, vs_major_version, check_build_environment, '--with-visual-studio-version')
|
2016-07-22 09:51:34 +03:00
|
|
|
@imports(_from='__builtin__', _import='sorted')
|
2017-04-26 22:18:48 +03:00
|
|
|
@imports(_from='operator', _import='itemgetter')
|
2016-07-22 09:51:34 +03:00
|
|
|
@imports('platform')
|
2017-04-20 19:43:44 +03:00
|
|
|
def vc_compiler_path(host, target, vs_major_version, env, vs_release_name):
|
2016-07-22 09:51:34 +03:00
|
|
|
if host.kernel != 'WINNT':
|
|
|
|
return
|
|
|
|
vc_target = {
|
|
|
|
'x86': 'x86',
|
|
|
|
'x86_64': 'x64',
|
|
|
|
'arm': 'arm',
|
2018-08-03 04:40:40 +03:00
|
|
|
'aarch64': 'arm64'
|
2017-04-26 22:18:48 +03:00
|
|
|
}.get(target.cpu)
|
2016-07-22 09:51:34 +03:00
|
|
|
if vc_target is None:
|
|
|
|
return
|
|
|
|
|
2017-04-26 22:18:48 +03:00
|
|
|
all_versions = sorted(get_vc_paths(env.topsrcdir), key=itemgetter(0))
|
|
|
|
if not all_versions:
|
2017-04-25 23:38:36 +03:00
|
|
|
return
|
2017-04-20 19:43:44 +03:00
|
|
|
if vs_major_version:
|
2017-10-12 16:22:59 +03:00
|
|
|
versions = [d for (v, d) in all_versions if v.major ==
|
|
|
|
vs_major_version]
|
2017-04-20 19:43:44 +03:00
|
|
|
if not versions:
|
|
|
|
die('Visual Studio %s could not be found!' % vs_release_name)
|
|
|
|
data = versions[0]
|
|
|
|
else:
|
|
|
|
# Choose the newest version.
|
|
|
|
data = all_versions[-1][1]
|
2017-04-26 22:18:48 +03:00
|
|
|
paths = data.get(vc_target)
|
|
|
|
if not paths:
|
2016-07-22 09:51:34 +03:00
|
|
|
return
|
2017-04-26 22:18:48 +03:00
|
|
|
return paths
|
2016-07-22 09:51:34 +03:00
|
|
|
|
|
|
|
|
|
|
|
@depends(vc_compiler_path)
|
|
|
|
@imports('os')
|
2018-06-07 03:57:36 +03:00
|
|
|
@imports(_from='os', _import='environ')
|
2016-07-22 09:51:34 +03:00
|
|
|
def toolchain_search_path(vc_compiler_path):
|
2018-06-07 03:57:36 +03:00
|
|
|
result = [environ.get('PATH')]
|
|
|
|
|
2016-07-22 09:51:34 +03:00
|
|
|
if vc_compiler_path:
|
|
|
|
result.extend(vc_compiler_path)
|
2018-02-28 04:13:16 +03:00
|
|
|
|
2018-06-07 03:57:36 +03:00
|
|
|
# Also add in the location to which `mach bootstrap` or
|
|
|
|
# `mach artifact toolchain` installs clang.
|
|
|
|
mozbuild_state_dir = environ.get('MOZBUILD_STATE_PATH',
|
|
|
|
os.path.expanduser(os.path.join('~', '.mozbuild')))
|
|
|
|
bootstrap_clang_path = os.path.join(mozbuild_state_dir, 'clang', 'bin')
|
|
|
|
result.append(bootstrap_clang_path)
|
2018-02-28 04:13:16 +03:00
|
|
|
|
2018-08-17 19:43:06 +03:00
|
|
|
bootstrap_cbindgen_path = os.path.join(mozbuild_state_dir, 'cbindgen')
|
|
|
|
result.append(bootstrap_cbindgen_path)
|
|
|
|
|
2018-06-07 03:57:36 +03:00
|
|
|
if vc_compiler_path:
|
2016-07-26 09:15:08 +03:00
|
|
|
# We're going to alter PATH for good in windows.configure, but we also
|
2018-06-07 03:57:36 +03:00
|
|
|
# need to do it for the valid_compiler() check below. This is only needed
|
|
|
|
# on Windows, where MSVC needs PATH set to find dlls.
|
|
|
|
environ['PATH'] = os.pathsep.join(result)
|
|
|
|
|
|
|
|
return result
|
2016-07-22 09:51:34 +03:00
|
|
|
|
|
|
|
|
2016-04-05 04:56:42 +03:00
|
|
|
@template
|
2018-09-14 20:40:52 +03:00
|
|
|
def default_c_compilers(host_or_target, other_c_compiler=None):
|
2016-04-05 04:56:42 +03:00
|
|
|
'''Template defining the set of default C compilers for the host and
|
|
|
|
target platforms.
|
|
|
|
`host_or_target` is either `host` or `target` (the @depends functions
|
|
|
|
from init.configure.
|
2018-09-14 20:40:52 +03:00
|
|
|
`other_c_compiler` is the `target` C compiler when `host_or_target` is `host`.
|
2016-04-05 04:56:42 +03:00
|
|
|
'''
|
|
|
|
assert host_or_target in (host, target)
|
|
|
|
|
2018-09-14 20:40:52 +03:00
|
|
|
other_c_compiler = () if other_c_compiler is None else (other_c_compiler,)
|
|
|
|
|
2018-05-31 04:16:10 +03:00
|
|
|
@depends(host_or_target, target, toolchain_prefix, android_clang_compiler,
|
2018-09-14 21:01:23 +03:00
|
|
|
*other_c_compiler)
|
2018-05-31 04:16:10 +03:00
|
|
|
def default_c_compilers(host_or_target, target, toolchain_prefix,
|
2018-09-14 21:01:23 +03:00
|
|
|
android_clang_compiler, *other_c_compiler):
|
2018-09-14 20:40:52 +03:00
|
|
|
if host_or_target.kernel == 'WINNT':
|
|
|
|
supported = types = ('clang-cl', 'msvc', 'gcc', 'clang')
|
|
|
|
elif host_or_target.kernel == 'Darwin':
|
|
|
|
types = ('clang',)
|
|
|
|
supported = ('clang', 'gcc')
|
|
|
|
else:
|
2018-09-14 21:01:23 +03:00
|
|
|
supported = types = ('clang', 'gcc')
|
2018-09-14 20:40:52 +03:00
|
|
|
|
|
|
|
info = other_c_compiler[0] if other_c_compiler else None
|
|
|
|
if info and info.type in supported:
|
|
|
|
# When getting default C compilers for the host, we prioritize the
|
|
|
|
# same compiler as the target C compiler.
|
|
|
|
prioritized = info.compiler
|
|
|
|
if info.type == 'gcc':
|
|
|
|
same_arch = same_arch_different_bits()
|
|
|
|
if (target.cpu != host_or_target.cpu and
|
|
|
|
(target.cpu, host_or_target.cpu) not in same_arch and
|
|
|
|
(host_or_target.cpu, target.cpu) not in same_arch):
|
2018-09-15 04:14:29 +03:00
|
|
|
# If the target C compiler is GCC, and it can't be used with
|
2018-09-14 20:40:52 +03:00
|
|
|
# -m32/-m64 for the host, it's probably toolchain-prefixed,
|
|
|
|
# so we prioritize a raw 'gcc' instead.
|
|
|
|
prioritized = info.type
|
|
|
|
elif info.type == 'clang' and android_clang_compiler:
|
|
|
|
# Android NDK clangs do not function as host compiler, so
|
|
|
|
# prioritize a raw 'clang' instead.
|
|
|
|
prioritized = info.type
|
|
|
|
|
|
|
|
types = [prioritized] + [t for t in types if t != info.type]
|
|
|
|
|
2016-10-21 01:50:40 +03:00
|
|
|
gcc = ('gcc',)
|
|
|
|
if toolchain_prefix and host_or_target is target:
|
|
|
|
gcc = tuple('%sgcc' % p for p in toolchain_prefix) + gcc
|
|
|
|
|
2018-09-14 20:40:52 +03:00
|
|
|
result = []
|
|
|
|
for type in types:
|
|
|
|
# Android sets toolchain_prefix and android_clang_compiler, but
|
|
|
|
# we want the latter to take precedence, because the latter can
|
|
|
|
# point at clang, which is what we want to use.
|
|
|
|
if type == 'clang' and android_clang_compiler and host_or_target is target:
|
|
|
|
result.append(android_clang_compiler)
|
|
|
|
elif type == 'gcc':
|
|
|
|
result.extend(gcc)
|
|
|
|
elif type == 'msvc':
|
|
|
|
result.append('cl')
|
|
|
|
else:
|
|
|
|
result.append(type)
|
|
|
|
|
|
|
|
return tuple(result)
|
2016-04-05 04:56:42 +03:00
|
|
|
|
|
|
|
return default_c_compilers
|
|
|
|
|
|
|
|
|
|
|
|
@template
|
2018-09-14 20:40:52 +03:00
|
|
|
def default_cxx_compilers(c_compiler, other_c_compiler=None, other_cxx_compiler=None):
|
2016-04-05 04:56:42 +03:00
|
|
|
'''Template defining the set of default C++ compilers for the host and
|
|
|
|
target platforms.
|
|
|
|
`c_compiler` is the @depends function returning a Compiler instance for
|
|
|
|
the desired platform.
|
|
|
|
|
|
|
|
Because the build system expects the C and C++ compilers to be from the
|
|
|
|
same compiler suite, we derive the default C++ compilers from the C
|
|
|
|
compiler that was found if none was provided.
|
2018-09-14 20:40:52 +03:00
|
|
|
|
2018-09-15 04:14:29 +03:00
|
|
|
We also factor in the target C++ compiler when getting the default host
|
|
|
|
C++ compiler, using the target C++ compiler if the host and target C
|
|
|
|
compilers are the same.
|
2016-04-05 04:56:42 +03:00
|
|
|
'''
|
|
|
|
|
2018-09-14 20:40:52 +03:00
|
|
|
assert (other_c_compiler is None) == (other_cxx_compiler is None)
|
|
|
|
if other_c_compiler is not None:
|
|
|
|
other_compilers = (other_c_compiler, other_cxx_compiler)
|
|
|
|
else:
|
|
|
|
other_compilers = ()
|
|
|
|
|
|
|
|
@depends(c_compiler, *other_compilers)
|
|
|
|
def default_cxx_compilers(c_compiler, *other_compilers):
|
|
|
|
if other_compilers:
|
|
|
|
other_c_compiler, other_cxx_compiler = other_compilers
|
|
|
|
if other_c_compiler.compiler == c_compiler.compiler:
|
|
|
|
return (other_cxx_compiler.compiler,)
|
|
|
|
|
2016-04-05 04:56:42 +03:00
|
|
|
dir = os.path.dirname(c_compiler.compiler)
|
|
|
|
file = os.path.basename(c_compiler.compiler)
|
|
|
|
|
|
|
|
if c_compiler.type == 'gcc':
|
|
|
|
return (os.path.join(dir, file.replace('gcc', 'g++')),)
|
|
|
|
|
|
|
|
if c_compiler.type == 'clang':
|
|
|
|
return (os.path.join(dir, file.replace('clang', 'clang++')),)
|
|
|
|
|
|
|
|
return (c_compiler.compiler,)
|
|
|
|
|
|
|
|
return default_cxx_compilers
|
|
|
|
|
|
|
|
|
|
|
|
@template
|
2016-04-22 02:00:11 +03:00
|
|
|
def compiler(language, host_or_target, c_compiler=None, other_compiler=None,
|
|
|
|
other_c_compiler=None):
|
2016-04-05 04:56:42 +03:00
|
|
|
'''Template handling the generic base checks for the compiler for the
|
|
|
|
given `language` on the given platform (`host_or_target`).
|
|
|
|
`host_or_target` is either `host` or `target` (the @depends functions
|
|
|
|
from init.configure.
|
2016-04-22 02:00:11 +03:00
|
|
|
When the language is 'C++', `c_compiler` is the result of the `compiler`
|
2016-04-05 04:56:42 +03:00
|
|
|
template for the language 'C' for the same `host_or_target`.
|
|
|
|
When `host_or_target` is `host`, `other_compiler` is the result of the
|
|
|
|
`compiler` template for the same `language` for `target`.
|
2016-04-22 02:00:11 +03:00
|
|
|
When `host_or_target` is `host` and the language is 'C++',
|
|
|
|
`other_c_compiler` is the result of the `compiler` template for the
|
|
|
|
language 'C' for `target`.
|
2016-04-05 04:56:42 +03:00
|
|
|
'''
|
|
|
|
assert host_or_target in (host, target)
|
|
|
|
assert language in ('C', 'C++')
|
2017-05-10 05:35:22 +03:00
|
|
|
assert language == 'C' or c_compiler is not None
|
|
|
|
assert host_or_target == target or other_compiler is not None
|
|
|
|
assert language == 'C' or host_or_target == target or \
|
|
|
|
other_c_compiler is not None
|
2016-04-05 04:56:42 +03:00
|
|
|
|
|
|
|
host_or_target_str = {
|
|
|
|
host: 'host',
|
|
|
|
target: 'target',
|
|
|
|
}[host_or_target]
|
|
|
|
|
|
|
|
var = {
|
|
|
|
('C', target): 'CC',
|
|
|
|
('C++', target): 'CXX',
|
|
|
|
('C', host): 'HOST_CC',
|
|
|
|
('C++', host): 'HOST_CXX',
|
|
|
|
}[language, host_or_target]
|
|
|
|
|
|
|
|
default_compilers = {
|
2018-09-14 20:40:52 +03:00
|
|
|
'C': lambda: default_c_compilers(host_or_target, other_compiler),
|
|
|
|
'C++': lambda: default_cxx_compilers(c_compiler, other_c_compiler, other_compiler),
|
2016-04-05 04:56:42 +03:00
|
|
|
}[language]()
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
what = 'the %s %s compiler' % (host_or_target_str, language)
|
2016-04-05 04:56:42 +03:00
|
|
|
|
|
|
|
option(env=var, nargs=1, help='Path to %s' % what)
|
|
|
|
|
|
|
|
# Handle the compiler given by the user through one of the CC/CXX/HOST_CC/
|
|
|
|
# HOST_CXX variables.
|
|
|
|
@depends_if(var)
|
|
|
|
@imports(_from='itertools', _import='takewhile')
|
|
|
|
@imports(_from='mozbuild.shellutil', _import='split', _as='shell_split')
|
|
|
|
def provided_compiler(cmd):
|
|
|
|
# Historically, the compiler variables have contained more than the
|
|
|
|
# path to the compiler itself. So for backwards compatibility, try to
|
|
|
|
# find what is what in there, assuming the first dash-prefixed item is
|
|
|
|
# a compiler option, the item before that is the compiler, and anything
|
|
|
|
# before that is a compiler wrapper.
|
|
|
|
cmd = shell_split(cmd[0])
|
|
|
|
|
|
|
|
without_flags = list(takewhile(lambda x: not x.startswith('-'), cmd))
|
|
|
|
|
|
|
|
return namespace(
|
|
|
|
wrapper=without_flags[:-1],
|
|
|
|
compiler=without_flags[-1],
|
|
|
|
flags=cmd[len(without_flags):],
|
|
|
|
)
|
|
|
|
|
|
|
|
# Normally, we'd use `var` instead of `_var`, but the interaction with
|
|
|
|
# old-configure complicates things, and for now, we a) can't take the plain
|
|
|
|
# result from check_prog as CC/CXX/HOST_CC/HOST_CXX and b) have to let
|
|
|
|
# old-configure AC_SUBST it (because it's autoconf doing it, not us)
|
|
|
|
compiler = check_prog('_%s' % var, what=what, progs=default_compilers,
|
2017-05-17 10:13:34 +03:00
|
|
|
input=provided_compiler.compiler,
|
2016-07-22 09:51:34 +03:00
|
|
|
paths=toolchain_search_path)
|
2016-04-05 04:56:42 +03:00
|
|
|
|
2017-11-16 17:53:34 +03:00
|
|
|
@depends(compiler, provided_compiler, compiler_wrapper, host_or_target)
|
2016-04-06 11:18:07 +03:00
|
|
|
@checking('whether %s can be used' % what, lambda x: bool(x))
|
2016-04-05 04:56:42 +03:00
|
|
|
@imports(_from='mozbuild.shellutil', _import='quote')
|
2016-04-22 09:08:55 +03:00
|
|
|
def valid_compiler(compiler, provided_compiler, compiler_wrapper,
|
2017-11-16 17:53:34 +03:00
|
|
|
host_or_target):
|
2016-04-05 04:56:42 +03:00
|
|
|
wrapper = list(compiler_wrapper or ())
|
|
|
|
if provided_compiler:
|
|
|
|
provided_wrapper = list(provided_compiler.wrapper)
|
|
|
|
# When doing a subconfigure, the compiler is set by old-configure
|
|
|
|
# and it contains the wrappers from --with-compiler-wrapper and
|
|
|
|
# --with-ccache.
|
|
|
|
if provided_wrapper[:len(wrapper)] == wrapper:
|
|
|
|
provided_wrapper = provided_wrapper[len(wrapper):]
|
|
|
|
wrapper.extend(provided_wrapper)
|
|
|
|
flags = provided_compiler.flags
|
|
|
|
else:
|
|
|
|
flags = []
|
|
|
|
|
|
|
|
# Ideally, we'd always use the absolute path, but unfortunately, on
|
|
|
|
# Windows, the compiler is very often in a directory containing spaces.
|
|
|
|
# Unfortunately, due to the way autoconf does its compiler tests with
|
|
|
|
# eval, that doesn't work out. So in that case, check that the
|
|
|
|
# compiler can still be found in $PATH, and use the file name instead
|
|
|
|
# of the full path.
|
|
|
|
if quote(compiler) != compiler:
|
|
|
|
full_path = os.path.abspath(compiler)
|
|
|
|
compiler = os.path.basename(compiler)
|
|
|
|
found_compiler = find_program(compiler)
|
|
|
|
if not found_compiler:
|
|
|
|
die('%s is not in your $PATH'
|
|
|
|
% quote(os.path.dirname(full_path)))
|
|
|
|
if os.path.normcase(find_program(compiler)) != os.path.normcase(
|
|
|
|
full_path):
|
|
|
|
die('Found `%s` before `%s` in your $PATH. '
|
|
|
|
'Please reorder your $PATH.',
|
|
|
|
quote(os.path.dirname(found_compiler)),
|
|
|
|
quote(os.path.dirname(full_path)))
|
|
|
|
|
2017-11-16 17:53:34 +03:00
|
|
|
info = check_compiler(wrapper + [compiler] + flags, language,
|
|
|
|
host_or_target)
|
2016-04-19 08:48:19 +03:00
|
|
|
|
|
|
|
# Check that the additional flags we got are enough to not require any
|
2017-09-21 20:40:02 +03:00
|
|
|
# more flags. If we get an exception, just ignore it; it's liable to be
|
|
|
|
# invalid command-line flags, which means the compiler we're checking
|
|
|
|
# doesn't support those command-line flags and will fail one or more of
|
|
|
|
# the checks below.
|
|
|
|
try:
|
|
|
|
if info.flags:
|
|
|
|
flags += info.flags
|
2017-11-16 17:53:34 +03:00
|
|
|
info = check_compiler(wrapper + [compiler] + flags, language,
|
|
|
|
host_or_target)
|
2017-09-21 20:40:02 +03:00
|
|
|
except FatalCheckError:
|
|
|
|
pass
|
2016-04-22 09:08:55 +03:00
|
|
|
|
|
|
|
if not info.target_cpu or info.target_cpu != host_or_target.cpu:
|
|
|
|
raise FatalCheckError(
|
|
|
|
'%s %s compiler target CPU (%s) does not match --%s CPU (%s)'
|
|
|
|
% (host_or_target_str.capitalize(), language,
|
|
|
|
info.target_cpu or 'unknown', host_or_target_str,
|
|
|
|
host_or_target.raw_cpu))
|
2016-04-19 08:48:19 +03:00
|
|
|
|
2016-04-26 09:38:45 +03:00
|
|
|
if not info.target_kernel or (info.target_kernel !=
|
|
|
|
host_or_target.kernel):
|
|
|
|
raise FatalCheckError(
|
|
|
|
'%s %s compiler target kernel (%s) does not match --%s kernel (%s)'
|
|
|
|
% (host_or_target_str.capitalize(), language,
|
|
|
|
info.target_kernel or 'unknown', host_or_target_str,
|
|
|
|
host_or_target.kernel))
|
|
|
|
|
2016-07-21 02:24:45 +03:00
|
|
|
if not info.target_endianness or (info.target_endianness !=
|
|
|
|
host_or_target.endianness):
|
|
|
|
raise FatalCheckError(
|
|
|
|
'%s %s compiler target endianness (%s) does not match --%s '
|
|
|
|
'endianness (%s)'
|
|
|
|
% (host_or_target_str.capitalize(), language,
|
|
|
|
info.target_endianness or 'unknown', host_or_target_str,
|
|
|
|
host_or_target.endianness))
|
|
|
|
|
2016-04-19 09:09:10 +03:00
|
|
|
# Compiler version checks
|
|
|
|
# ===================================================
|
|
|
|
# Check the compiler version here instead of in `compiler_version` so
|
|
|
|
# that the `checking` message doesn't pretend the compiler can be used
|
|
|
|
# to then bail out one line later.
|
2018-03-23 01:48:52 +03:00
|
|
|
if info.type == 'gcc':
|
|
|
|
if host_or_target.os == 'Android':
|
|
|
|
raise FatalCheckError('GCC is not supported on Android.\n'
|
|
|
|
'Please use clang from the Android NDK instead.')
|
|
|
|
if info.version < '6.1.0':
|
|
|
|
raise FatalCheckError(
|
|
|
|
'Only GCC 6.1 or newer is supported (found version %s).'
|
|
|
|
% info.version)
|
2017-10-29 00:38:59 +03:00
|
|
|
|
2016-04-19 09:09:10 +03:00
|
|
|
# If you want to bump the version check here search for
|
2018-09-10 20:59:07 +03:00
|
|
|
# builtin_bitreverse8 above, and see the associated comment.
|
2016-04-22 03:24:32 +03:00
|
|
|
if info.type == 'clang' and not info.version:
|
2016-04-19 09:09:10 +03:00
|
|
|
raise FatalCheckError(
|
2018-09-10 20:59:07 +03:00
|
|
|
'Only clang/llvm 3.9 or newer is supported.')
|
2016-04-19 09:09:10 +03:00
|
|
|
|
2016-04-22 03:24:32 +03:00
|
|
|
if info.type == 'msvc':
|
2018-09-16 16:22:31 +03:00
|
|
|
if info.version < '19.15.26726':
|
2016-04-19 09:09:10 +03:00
|
|
|
raise FatalCheckError(
|
|
|
|
'This version (%s) of the MSVC compiler is not '
|
|
|
|
'supported.\n'
|
2018-09-16 16:22:31 +03:00
|
|
|
'You must install Visual C++ 2017 Update 8 or '
|
|
|
|
'later in order to build.\n'
|
2016-04-19 09:09:10 +03:00
|
|
|
'See https://developer.mozilla.org/en/'
|
2016-04-22 03:24:32 +03:00
|
|
|
'Windows_Build_Prerequisites' % info.version)
|
2017-09-27 12:28:37 +03:00
|
|
|
|
2017-09-21 20:40:02 +03:00
|
|
|
if info.flags:
|
|
|
|
raise FatalCheckError(
|
|
|
|
'Unknown compiler or compiler not supported.')
|
|
|
|
|
2016-04-06 11:18:07 +03:00
|
|
|
return namespace(
|
|
|
|
wrapper=wrapper,
|
|
|
|
compiler=compiler,
|
2016-04-19 08:48:19 +03:00
|
|
|
flags=flags,
|
2016-04-22 03:24:32 +03:00
|
|
|
type=info.type,
|
|
|
|
version=info.version,
|
2016-08-04 10:24:29 +03:00
|
|
|
language=language,
|
2016-04-06 11:18:07 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
@depends(valid_compiler)
|
|
|
|
@checking('%s version' % what)
|
|
|
|
def compiler_version(compiler):
|
|
|
|
return compiler.version
|
2016-04-05 04:56:42 +03:00
|
|
|
|
|
|
|
if language == 'C++':
|
|
|
|
@depends(valid_compiler, c_compiler)
|
2016-04-20 07:56:55 +03:00
|
|
|
def valid_compiler(compiler, c_compiler):
|
2016-04-05 04:56:42 +03:00
|
|
|
if compiler.type != c_compiler.type:
|
|
|
|
die('The %s C compiler is %s, while the %s C++ compiler is '
|
|
|
|
'%s. Need to use the same compiler suite.',
|
|
|
|
host_or_target_str, c_compiler.type,
|
|
|
|
host_or_target_str, compiler.type)
|
|
|
|
|
|
|
|
if compiler.version != c_compiler.version:
|
|
|
|
die('The %s C compiler is version %s, while the %s C++ '
|
|
|
|
'compiler is version %s. Need to use the same compiler '
|
|
|
|
'version.',
|
|
|
|
host_or_target_str, c_compiler.version,
|
|
|
|
host_or_target_str, compiler.version)
|
2016-04-20 07:56:55 +03:00
|
|
|
return compiler
|
2016-04-05 04:56:42 +03:00
|
|
|
|
|
|
|
# Set CC/CXX/HOST_CC/HOST_CXX for old-configure, which needs the wrapper
|
|
|
|
# and the flags that were part of the user input for those variables to
|
|
|
|
# be provided.
|
|
|
|
add_old_configure_assignment(var, depends_if(valid_compiler)(
|
|
|
|
lambda x: list(x.wrapper) + [x.compiler] + list(x.flags)))
|
|
|
|
|
|
|
|
# Set CC_TYPE/CC_VERSION/HOST_CC_TYPE/HOST_CC_VERSION to allow
|
|
|
|
# old-configure to do some of its still existing checks.
|
|
|
|
if language == 'C':
|
2017-02-08 18:36:04 +03:00
|
|
|
set_config(
|
2017-05-17 10:13:34 +03:00
|
|
|
'%s_TYPE' % var, valid_compiler.type)
|
2016-04-05 04:56:42 +03:00
|
|
|
add_old_configure_assignment(
|
2017-05-17 10:13:34 +03:00
|
|
|
'%s_TYPE' % var, valid_compiler.type)
|
2016-04-05 04:56:42 +03:00
|
|
|
add_old_configure_assignment(
|
2017-05-17 10:13:34 +03:00
|
|
|
'%s_VERSION' % var, valid_compiler.version)
|
2016-04-05 04:56:42 +03:00
|
|
|
|
2017-08-18 19:05:05 +03:00
|
|
|
valid_compiler = compiler_class(valid_compiler, host_or_target)
|
2016-08-04 09:51:47 +03:00
|
|
|
|
|
|
|
def compiler_error():
|
|
|
|
raise FatalCheckError('Failed compiling a simple %s source with %s'
|
|
|
|
% (language, what))
|
|
|
|
|
|
|
|
valid_compiler.try_compile(check_msg='%s works' % what,
|
|
|
|
onerror=compiler_error)
|
|
|
|
|
2016-09-06 02:22:36 +03:00
|
|
|
# Set CPP/CXXCPP for both the build system and old-configure. We don't
|
|
|
|
# need to check this works for preprocessing, because we already relied
|
|
|
|
# on $CC -E/$CXX -E doing preprocessing work to validate the compiler
|
|
|
|
# in the first place.
|
|
|
|
if host_or_target == target:
|
|
|
|
pp_var = {
|
|
|
|
'C': 'CPP',
|
|
|
|
'C++': 'CXXCPP',
|
|
|
|
}[language]
|
|
|
|
|
|
|
|
preprocessor = depends_if(valid_compiler)(
|
2017-10-12 16:22:59 +03:00
|
|
|
lambda x: list(x.wrapper) + [x.compiler, '-E'] + list(x.flags))
|
2016-09-06 02:22:36 +03:00
|
|
|
|
|
|
|
set_config(pp_var, preprocessor)
|
|
|
|
add_old_configure_assignment(pp_var, preprocessor)
|
|
|
|
|
2016-11-24 09:07:01 +03:00
|
|
|
if language == 'C':
|
|
|
|
linker_var = {
|
|
|
|
target: 'LD',
|
|
|
|
host: 'HOST_LD',
|
|
|
|
}[host_or_target]
|
|
|
|
|
|
|
|
@deprecated_option(env=linker_var, nargs=1)
|
|
|
|
def linker(value):
|
|
|
|
if value:
|
|
|
|
return value[0]
|
|
|
|
|
|
|
|
@depends(valid_compiler, linker)
|
|
|
|
def unused_linker(compiler, linker):
|
|
|
|
if linker and compiler.type != 'msvc':
|
|
|
|
log.warning('The value of %s is not used by this build system.'
|
|
|
|
% linker_var)
|
|
|
|
|
|
|
|
if host_or_target == target:
|
|
|
|
@depends(valid_compiler)
|
|
|
|
def is_msvc(compiler):
|
|
|
|
return compiler.type == 'msvc'
|
|
|
|
|
2017-12-20 17:07:46 +03:00
|
|
|
imply_option('LINKER', linker, reason='LD', when=is_msvc)
|
2016-11-24 09:07:01 +03:00
|
|
|
|
2016-04-05 04:56:42 +03:00
|
|
|
return valid_compiler
|
|
|
|
|
|
|
|
|
|
|
|
c_compiler = compiler('C', target)
|
|
|
|
cxx_compiler = compiler('C++', target, c_compiler=c_compiler)
|
|
|
|
host_c_compiler = compiler('C', host, other_compiler=c_compiler)
|
|
|
|
host_cxx_compiler = compiler('C++', host, c_compiler=host_c_compiler,
|
2016-04-22 02:00:11 +03:00
|
|
|
other_compiler=cxx_compiler,
|
|
|
|
other_c_compiler=c_compiler)
|
2016-06-21 02:02:01 +03:00
|
|
|
|
2016-09-21 22:04:08 +03:00
|
|
|
# Generic compiler-based conditions.
|
|
|
|
non_msvc_compiler = depends(c_compiler)(lambda info: info.type != 'msvc')
|
|
|
|
building_with_gcc = depends(c_compiler)(lambda info: info.type == 'gcc')
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-06-15 02:52:55 +03:00
|
|
|
@depends(c_compiler)
|
|
|
|
def msvs_version(info):
|
|
|
|
# clang-cl emulates the same version scheme as cl. And MSVS_VERSION needs to
|
|
|
|
# be set for GYP on Windows.
|
|
|
|
if info.type in ('clang-cl', 'msvc'):
|
|
|
|
if info.version >= '19.10':
|
|
|
|
return '2017'
|
|
|
|
|
|
|
|
return ''
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-06-15 02:52:55 +03:00
|
|
|
set_config('MSVS_VERSION', msvs_version)
|
|
|
|
|
2016-08-09 02:25:35 +03:00
|
|
|
include('compile-checks.configure')
|
2016-07-27 01:27:19 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-08-10 05:39:16 +03:00
|
|
|
@depends(have_64_bit,
|
|
|
|
try_compile(body='static_assert(sizeof(void *) == 8, "")',
|
|
|
|
check_msg='for 64-bit OS'))
|
|
|
|
def check_have_64_bit(have_64_bit, compiler_have_64_bit):
|
|
|
|
if have_64_bit != compiler_have_64_bit:
|
|
|
|
configure_error('The target compiler does not agree with configure '
|
|
|
|
'about the target bitness.')
|
2016-08-10 03:00:23 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2018-09-25 16:31:22 +03:00
|
|
|
js_option(env='BINDGEN_CFLAGS',
|
|
|
|
nargs=1,
|
|
|
|
default=bindgen_cflags_defaults,
|
|
|
|
help='Options bindgen should pass to the C/C++ parser')
|
2017-07-06 21:34:03 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-07-06 21:34:03 +03:00
|
|
|
@depends('BINDGEN_CFLAGS')
|
2017-11-10 18:05:36 +03:00
|
|
|
@checking('bindgen cflags', lambda s: s if s else 'no')
|
2017-07-06 21:34:03 +03:00
|
|
|
def bindgen_cflags(value):
|
|
|
|
if value and len(value):
|
2017-11-10 18:05:36 +03:00
|
|
|
return value[0].split()
|
2017-07-06 21:34:03 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-11-10 18:05:36 +03:00
|
|
|
add_old_configure_assignment('_BINDGEN_CFLAGS', bindgen_cflags)
|
2016-08-10 03:00:23 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-06-21 02:02:01 +03:00
|
|
|
@depends(c_compiler)
|
|
|
|
def default_debug_flags(compiler_info):
|
|
|
|
# Debug info is ON by default.
|
2016-08-30 17:17:21 +03:00
|
|
|
if compiler_info.type in ('msvc', 'clang-cl'):
|
2016-06-21 02:02:01 +03:00
|
|
|
return '-Zi'
|
|
|
|
return '-g'
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-06-21 02:02:01 +03:00
|
|
|
option(env='MOZ_DEBUG_FLAGS',
|
|
|
|
nargs=1,
|
|
|
|
help='Debug compiler flags')
|
|
|
|
|
|
|
|
imply_option('--enable-debug-symbols',
|
|
|
|
depends_if('--enable-debug')(lambda v: v))
|
|
|
|
|
|
|
|
js_option('--enable-debug-symbols',
|
|
|
|
nargs='?',
|
|
|
|
default=True,
|
|
|
|
help='Enable debug symbols using the given compiler flags')
|
|
|
|
|
|
|
|
set_config('MOZ_DEBUG_SYMBOLS',
|
|
|
|
depends_if('--enable-debug-symbols')(lambda _: True))
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-06-21 02:02:01 +03:00
|
|
|
@depends('MOZ_DEBUG_FLAGS', '--enable-debug-symbols', default_debug_flags)
|
|
|
|
def debug_flags(env_debug_flags, enable_debug_flags, default_debug_flags):
|
|
|
|
# If MOZ_DEBUG_FLAGS is set, and --enable-debug-symbols is set to a value,
|
|
|
|
# --enable-debug-symbols takes precedence. Note, the value of
|
|
|
|
# --enable-debug-symbols may be implied by --enable-debug.
|
|
|
|
if len(enable_debug_flags):
|
|
|
|
return enable_debug_flags[0]
|
|
|
|
if env_debug_flags:
|
|
|
|
return env_debug_flags[0]
|
|
|
|
return default_debug_flags
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-06-21 02:02:01 +03:00
|
|
|
set_config('MOZ_DEBUG_FLAGS', debug_flags)
|
|
|
|
add_old_configure_assignment('MOZ_DEBUG_FLAGS', debug_flags)
|
2016-05-16 22:27:37 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-11-10 01:01:24 +03:00
|
|
|
@depends(c_compiler)
|
|
|
|
def color_cflags(info):
|
|
|
|
# We could test compiling with flags. By why incur the overhead when
|
|
|
|
# color support should always be present in a specific toolchain
|
|
|
|
# version?
|
|
|
|
|
|
|
|
# Code for auto-adding this flag to compiler invocations needs to
|
|
|
|
# determine if an existing flag isn't already present. That is likely
|
|
|
|
# using exact string matching on the returned value. So if the return
|
|
|
|
# value changes to e.g. "<x>=always", exact string match may fail and
|
|
|
|
# multiple color flags could be added. So examine downstream consumers
|
|
|
|
# before adding flags to return values.
|
2018-03-23 01:48:52 +03:00
|
|
|
if info.type == 'gcc':
|
2016-11-10 01:01:24 +03:00
|
|
|
return '-fdiagnostics-color'
|
|
|
|
elif info.type == 'clang':
|
|
|
|
return '-fcolor-diagnostics'
|
|
|
|
else:
|
|
|
|
return ''
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-11-10 01:01:24 +03:00
|
|
|
set_config('COLOR_CFLAGS', color_cflags)
|
|
|
|
|
2016-07-06 22:30:22 +03:00
|
|
|
# Some standard library headers (notably bionic on Android) declare standard
|
|
|
|
# functions (e.g. getchar()) and also #define macros for those standard
|
|
|
|
# functions. libc++ deals with this by doing something like the following
|
|
|
|
# (explanatory comments added):
|
|
|
|
#
|
|
|
|
# #ifdef FUNC
|
|
|
|
# // Capture the definition of FUNC.
|
|
|
|
# inline _LIBCPP_INLINE_VISIBILITY int __libcpp_FUNC(...) { return FUNC(...); }
|
|
|
|
# #undef FUNC
|
|
|
|
# // Use a real inline definition.
|
|
|
|
# inline _LIBCPP_INLINE_VISIBILITY int FUNC(...) { return _libcpp_FUNC(...); }
|
|
|
|
# #endif
|
|
|
|
#
|
|
|
|
# _LIBCPP_INLINE_VISIBILITY is typically defined as:
|
|
|
|
#
|
|
|
|
# __attribute__((__visibility__("hidden"), __always_inline__))
|
|
|
|
#
|
|
|
|
# Unfortunately, this interacts badly with our system header wrappers, as the:
|
|
|
|
#
|
|
|
|
# #pragma GCC visibility push(default)
|
|
|
|
#
|
|
|
|
# that they do prior to including the actual system header is treated by the
|
|
|
|
# compiler as an explicit declaration of visibility on every function declared
|
|
|
|
# in the header. Therefore, when the libc++ code above is encountered, it is
|
|
|
|
# as though the compiler has effectively seen:
|
|
|
|
#
|
|
|
|
# int FUNC(...) __attribute__((__visibility__("default")));
|
|
|
|
# int FUNC(...) __attribute__((__visibility__("hidden")));
|
|
|
|
#
|
|
|
|
# and the compiler complains about the mismatched visibility declarations.
|
|
|
|
#
|
|
|
|
# However, libc++ will only define _LIBCPP_INLINE_VISIBILITY if there is no
|
|
|
|
# existing definition. We can therefore define it to the empty string (since
|
|
|
|
# we are properly managing visibility ourselves) and avoid this whole mess.
|
|
|
|
# Note that we don't need to do this with gcc, as libc++ detects gcc and
|
|
|
|
# effectively does the same thing we are doing here.
|
2017-07-05 16:32:29 +03:00
|
|
|
#
|
|
|
|
# _LIBCPP_ALWAYS_INLINE needs similar workarounds, since it too declares
|
|
|
|
# hidden visibility.
|
2017-10-12 16:22:59 +03:00
|
|
|
|
|
|
|
|
2016-07-06 22:30:22 +03:00
|
|
|
@depends(c_compiler, target)
|
2017-07-05 16:32:29 +03:00
|
|
|
def libcxx_override_visibility(c_compiler, target):
|
2016-07-06 22:30:22 +03:00
|
|
|
if c_compiler.type == 'clang' and target.os == 'Android':
|
|
|
|
return ''
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-07-05 16:32:29 +03:00
|
|
|
set_define('_LIBCPP_INLINE_VISIBILITY', libcxx_override_visibility)
|
2017-10-12 16:22:59 +03:00
|
|
|
set_define('_LIBCPP_INLINE_VISIBILITY_EXCEPT_GCC49',
|
|
|
|
libcxx_override_visibility)
|
2017-07-05 16:32:29 +03:00
|
|
|
set_define('_LIBCPP_ALWAYS_INLINE', libcxx_override_visibility)
|
|
|
|
set_define('_LIBCPP_ALWAYS_INLINE_EXCEPT_GCC49', libcxx_override_visibility)
|
2016-07-06 22:30:22 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-11-11 06:52:37 +03:00
|
|
|
@depends(target, check_build_environment)
|
|
|
|
def visibility_flags(target, env):
|
2016-10-04 21:48:21 +03:00
|
|
|
if target.os != 'WINNT':
|
|
|
|
if target.kernel == 'Darwin':
|
|
|
|
return ('-fvisibility=hidden', '-fvisibility-inlines-hidden')
|
|
|
|
return ('-I%s/system_wrappers' % os.path.join(env.dist),
|
|
|
|
'-include',
|
|
|
|
'%s/config/gcc_hidden.h' % env.topsrcdir)
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-10-04 21:48:21 +03:00
|
|
|
@depends(target, visibility_flags)
|
|
|
|
def wrap_system_includes(target, visibility_flags):
|
|
|
|
if visibility_flags and target.kernel != 'Darwin':
|
|
|
|
return True
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-10-04 21:48:21 +03:00
|
|
|
set_define('HAVE_VISIBILITY_HIDDEN_ATTRIBUTE',
|
|
|
|
depends(visibility_flags)(lambda v: bool(v) or None))
|
|
|
|
set_define('HAVE_VISIBILITY_ATTRIBUTE',
|
|
|
|
depends(visibility_flags)(lambda v: bool(v) or None))
|
|
|
|
set_config('WRAP_SYSTEM_INCLUDES', wrap_system_includes)
|
|
|
|
set_config('VISIBILITY_FLAGS', visibility_flags)
|
|
|
|
|
2017-11-01 17:03:08 +03:00
|
|
|
|
2018-09-14 19:12:34 +03:00
|
|
|
@depends(c_compiler, using_sccache)
|
|
|
|
def depend_cflags(info, using_sccache):
|
|
|
|
if info.type not in ('clang-cl', 'msvc'):
|
|
|
|
return ['-MD', '-MP', '-MF $(MDDEPDIR)/$(@F).pp']
|
|
|
|
elif info.type == 'clang-cl':
|
|
|
|
# clang-cl doesn't accept the normal -MD -MP -MF options that clang
|
|
|
|
# does, but the underlying cc1 binary understands how to generate
|
|
|
|
# dependency files. These options are based on analyzing what the
|
|
|
|
# normal clang driver sends to cc1 when given the "correct"
|
|
|
|
# dependency options.
|
|
|
|
return [
|
|
|
|
'-Xclang', '-MP',
|
|
|
|
'-Xclang', '-dependency-file',
|
|
|
|
'-Xclang', '$(MDDEPDIR)/$(@F).pp',
|
|
|
|
'-Xclang', '-MT',
|
|
|
|
'-Xclang', '$@'
|
|
|
|
]
|
|
|
|
elif using_sccache:
|
|
|
|
# sccache supports a special flag to create depfiles
|
|
|
|
# by parsing MSVC's -showIncludes output.
|
|
|
|
return ['-deps$(MDDEPDIR)/$(@F).pp']
|
|
|
|
|
|
|
|
|
|
|
|
set_config('_DEPEND_CFLAGS', depend_cflags)
|
|
|
|
|
|
|
|
|
2018-08-02 00:59:23 +03:00
|
|
|
@depends(c_compiler, check_build_environment, target)
|
2017-08-04 20:56:38 +03:00
|
|
|
@imports('multiprocessing')
|
|
|
|
@imports(_from='__builtin__', _import='min')
|
2018-08-02 00:59:23 +03:00
|
|
|
def pgo_flags(compiler, build_env, target):
|
|
|
|
topobjdir = build_env.topobjdir
|
|
|
|
if topobjdir.endswith('/js/src'):
|
|
|
|
topobjdir = topobjdir[:-7]
|
|
|
|
|
2018-08-08 05:08:48 +03:00
|
|
|
if compiler.type == 'gcc':
|
2017-08-04 20:56:38 +03:00
|
|
|
return namespace(
|
|
|
|
gen_cflags=['-fprofile-generate'],
|
|
|
|
gen_ldflags=['-fprofile-generate'],
|
|
|
|
use_cflags=['-fprofile-use', '-fprofile-correction',
|
|
|
|
'-Wcoverage-mismatch'],
|
|
|
|
use_ldflags=['-fprofile-use'],
|
|
|
|
)
|
|
|
|
|
2018-08-08 05:08:48 +03:00
|
|
|
if compiler.type in ('clang-cl', 'clang'):
|
2018-08-02 00:59:23 +03:00
|
|
|
profdata = os.path.join(topobjdir, 'merged.profdata')
|
2018-08-08 05:08:48 +03:00
|
|
|
if compiler.type == 'clang-cl':
|
|
|
|
if target.cpu == 'x86_64':
|
|
|
|
gen_ldflags = ['clang_rt.profile-x86_64.lib']
|
2018-08-16 10:44:36 +03:00
|
|
|
elif target.cpu == 'x86':
|
|
|
|
gen_ldflags = ['clang_rt.profile-i386.lib']
|
2018-08-08 05:08:48 +03:00
|
|
|
else:
|
|
|
|
gen_ldflags = None
|
|
|
|
else:
|
|
|
|
gen_ldflags = ['-fprofile-instr-generate']
|
|
|
|
|
|
|
|
if gen_ldflags:
|
|
|
|
return namespace(
|
|
|
|
gen_cflags=['-fprofile-instr-generate'],
|
|
|
|
gen_ldflags=gen_ldflags,
|
|
|
|
use_cflags=['-fprofile-instr-use=%s' % profdata,
|
|
|
|
'-Wno-error=profile-instr-out-of-date',
|
|
|
|
'-Wno-error=profile-instr-unprofiled'],
|
|
|
|
use_ldflags=[],
|
|
|
|
)
|
2018-08-02 00:59:23 +03:00
|
|
|
|
2017-08-04 20:56:38 +03:00
|
|
|
if compiler.type == 'msvc':
|
|
|
|
num_cores = min(8, multiprocessing.cpu_count())
|
|
|
|
cgthreads = '-CGTHREADS:%s' % num_cores
|
|
|
|
|
|
|
|
return namespace(
|
|
|
|
gen_cflags=['-GL'],
|
|
|
|
gen_ldflags=['-LTCG:PGINSTRUMENT', '-PogoSafeMode', cgthreads],
|
|
|
|
# XXX: PGO builds can fail with warnings treated as errors,
|
|
|
|
# specifically "no profile data available" appears to be
|
|
|
|
# treated as an error sometimes. This might be a consequence
|
|
|
|
# of using WARNINGS_AS_ERRORS in some modules, combined
|
|
|
|
# with the linker doing most of the work in the whole-program
|
|
|
|
# optimization/PGO case. I think it's probably a compiler bug,
|
|
|
|
# but we work around it here.
|
|
|
|
use_cflags=['-GL', '-wd4624', '-wd4952'],
|
|
|
|
# XXX: should be -LTCG:PGOPTIMIZE, but that fails on libxul.
|
|
|
|
# Probably also a compiler bug, but what can you do?
|
2018-03-07 07:26:32 +03:00
|
|
|
# /d2:-cgsummary prints a summary of what is happening during
|
|
|
|
# code generation. How long individual functions are optimized,
|
|
|
|
# which functions are optimized, etc.
|
|
|
|
use_ldflags=['-LTCG:PGUPDATE', cgthreads, '-d2:-cgsummary'],
|
2017-08-04 20:56:38 +03:00
|
|
|
)
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-08-04 20:56:38 +03:00
|
|
|
set_config('PROFILE_GEN_CFLAGS', pgo_flags.gen_cflags)
|
|
|
|
set_config('PROFILE_GEN_LDFLAGS', pgo_flags.gen_ldflags)
|
|
|
|
set_config('PROFILE_USE_CFLAGS', pgo_flags.use_cflags)
|
|
|
|
set_config('PROFILE_USE_LDFLAGS', pgo_flags.use_ldflags)
|
|
|
|
|
2018-08-02 00:59:23 +03:00
|
|
|
llvm_profdata = check_prog('LLVM_PROFDATA', ['llvm-profdata'],
|
|
|
|
allow_missing=True)
|
|
|
|
|
|
|
|
add_old_configure_assignment('LLVM_PROFDATA', llvm_profdata)
|
|
|
|
|
2017-12-04 16:14:06 +03:00
|
|
|
|
|
|
|
@depends(c_compiler)
|
|
|
|
def preprocess_option(compiler):
|
|
|
|
# The uses of PREPROCESS_OPTION depend on the spacing for -o/-Fi.
|
|
|
|
if compiler.type in ('gcc', 'clang'):
|
|
|
|
return '-E -o '
|
|
|
|
else:
|
|
|
|
return '-P -Fi'
|
|
|
|
|
|
|
|
|
|
|
|
set_config('PREPROCESS_OPTION', preprocess_option)
|
|
|
|
|
|
|
|
|
2017-04-19 18:18:01 +03:00
|
|
|
# We only want to include windows.configure when we are compiling on
|
|
|
|
# Windows, for Windows.
|
2017-10-12 16:22:59 +03:00
|
|
|
|
|
|
|
|
2017-04-19 18:18:01 +03:00
|
|
|
@depends(target, host)
|
|
|
|
def is_windows(target, host):
|
|
|
|
return host.kernel == 'WINNT' and target.kernel == 'WINNT'
|
2016-11-12 00:05:07 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2016-11-12 00:05:07 +03:00
|
|
|
include('windows.configure', when=is_windows)
|
2017-04-12 20:58:22 +03:00
|
|
|
|
2017-07-24 22:32:08 +03:00
|
|
|
# Shader Compiler for Windows (and MinGW Cross Compile)
|
|
|
|
# ==============================================================
|
|
|
|
|
|
|
|
fxc = check_prog('FXC', ('fxc.exe', 'fxc2.exe'), when=depends(target)
|
|
|
|
(lambda t: t.kernel == 'WINNT'))
|
|
|
|
wine = check_prog('WINE', ['wine'], when=depends(target, host)
|
|
|
|
(lambda t, h: t.kernel == 'WINNT' and h.kernel == 'Linux'))
|
|
|
|
|
2018-04-13 23:55:39 +03:00
|
|
|
# LTO
|
|
|
|
# ==============================================================
|
|
|
|
|
|
|
|
js_option('--enable-lto',
|
|
|
|
nargs='?',
|
|
|
|
choices=('full', 'thin'),
|
|
|
|
help='Enable LTO')
|
|
|
|
|
|
|
|
|
2018-07-17 00:59:49 +03:00
|
|
|
@depends('--enable-lto', 'MOZ_PGO', c_compiler)
|
2018-04-13 23:55:39 +03:00
|
|
|
@imports('multiprocessing')
|
2018-07-17 00:59:49 +03:00
|
|
|
def lto(value, pgo, c_compiler):
|
2018-07-16 19:25:40 +03:00
|
|
|
cflags = []
|
2018-04-13 23:55:39 +03:00
|
|
|
ldflags = []
|
2018-07-16 19:26:36 +03:00
|
|
|
enabled = None
|
2018-04-13 23:55:39 +03:00
|
|
|
|
2018-07-17 00:59:49 +03:00
|
|
|
# MSVC's implementation of PGO implies LTO. Make clang-cl match this.
|
|
|
|
if c_compiler.type == 'clang-cl' and pgo and value.origin == 'default':
|
|
|
|
value = ['thin']
|
|
|
|
|
2018-07-16 19:26:36 +03:00
|
|
|
if value:
|
|
|
|
enabled = True
|
|
|
|
if c_compiler.type == 'clang':
|
|
|
|
if len(value) and value[0].lower() == 'full':
|
|
|
|
cflags.append("-flto")
|
|
|
|
ldflags.append("-flto")
|
|
|
|
else:
|
|
|
|
cflags.append("-flto=thin")
|
|
|
|
ldflags.append("-flto=thin")
|
|
|
|
elif c_compiler.type == 'clang-cl':
|
|
|
|
if len(value) and value[0].lower() == 'full':
|
|
|
|
cflags.append("-flto")
|
|
|
|
else:
|
|
|
|
cflags.append("-flto=thin")
|
|
|
|
# With clang-cl, -flto can only be used with -c or -fuse-ld=lld.
|
|
|
|
# AC_TRY_LINKs during configure don't have -c, so pass -fuse-ld=lld.
|
2018-07-25 16:56:19 +03:00
|
|
|
cflags.append("-fuse-ld=lld");
|
2018-07-16 19:26:36 +03:00
|
|
|
else:
|
|
|
|
num_cores = multiprocessing.cpu_count()
|
2018-07-16 19:25:40 +03:00
|
|
|
cflags.append("-flto")
|
2018-07-16 19:26:36 +03:00
|
|
|
cflags.append("-flifetime-dse=1")
|
2018-04-13 23:55:39 +03:00
|
|
|
|
2018-07-16 19:26:36 +03:00
|
|
|
ldflags.append("-flto=%s" % num_cores)
|
|
|
|
ldflags.append("-flifetime-dse=1")
|
2018-04-13 23:55:39 +03:00
|
|
|
|
|
|
|
return namespace(
|
2018-07-16 19:26:36 +03:00
|
|
|
enabled=enabled,
|
2018-07-16 19:25:40 +03:00
|
|
|
cflags=cflags,
|
2018-04-13 23:55:39 +03:00
|
|
|
ldflags=ldflags
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-08-21 03:14:00 +03:00
|
|
|
add_old_configure_assignment('MOZ_LTO', lto.enabled)
|
2018-08-17 03:05:27 +03:00
|
|
|
set_config('MOZ_LTO', lto.enabled)
|
|
|
|
set_define('MOZ_LTO', lto.enabled)
|
|
|
|
set_config('MOZ_LTO_CFLAGS', lto.cflags)
|
|
|
|
set_config('MOZ_LTO_LDFLAGS', lto.ldflags)
|
2018-09-05 00:49:16 +03:00
|
|
|
add_old_configure_assignment('MOZ_LTO_CFLAGS', lto.cflags)
|
|
|
|
add_old_configure_assignment('MOZ_LTO_LDFLAGS', lto.ldflags)
|
2018-04-13 23:55:39 +03:00
|
|
|
|
|
|
|
# ASAN
|
2017-04-12 20:58:22 +03:00
|
|
|
# ==============================================================
|
|
|
|
|
2017-11-21 07:20:56 +03:00
|
|
|
js_option('--enable-address-sanitizer', help='Enable Address Sanitizer')
|
|
|
|
|
|
|
|
|
2018-09-06 18:49:55 +03:00
|
|
|
@depends_if('--enable-address-sanitizer', '--help')
|
|
|
|
def asan(value, _):
|
2017-11-21 07:20:56 +03:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
add_old_configure_assignment('MOZ_ASAN', asan)
|
|
|
|
|
2018-09-11 05:47:23 +03:00
|
|
|
# UBSAN
|
|
|
|
# ==============================================================
|
|
|
|
|
|
|
|
js_option('--enable-undefined-sanitizer',
|
|
|
|
nargs='*',
|
|
|
|
help='Enable UndefinedBehavior Sanitizer')
|
|
|
|
|
|
|
|
@depends_if('--enable-undefined-sanitizer')
|
|
|
|
def ubsan(options):
|
|
|
|
default_checks = [
|
|
|
|
'bool',
|
|
|
|
'bounds',
|
|
|
|
'vla-bound',
|
|
|
|
]
|
|
|
|
|
|
|
|
checks = options if len(options) else default_checks
|
|
|
|
|
|
|
|
return ','.join(checks)
|
|
|
|
|
|
|
|
add_old_configure_assignment('MOZ_UBSAN_CHECKS', ubsan)
|
2017-11-21 07:20:56 +03:00
|
|
|
|
2018-04-13 23:55:39 +03:00
|
|
|
# Security Hardening
|
|
|
|
# ==============================================================
|
|
|
|
|
2017-04-12 20:58:22 +03:00
|
|
|
option('--enable-hardening', env='MOZ_SECURITY_HARDENING',
|
|
|
|
help='Enables security hardening compiler options')
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-11-21 07:20:56 +03:00
|
|
|
@depends('--enable-hardening', '--enable-address-sanitizer',
|
|
|
|
'--enable-optimize', c_compiler, target)
|
|
|
|
def security_hardening_cflags(hardening_flag, asan, optimize, c_compiler, target):
|
|
|
|
compiler_is_gccish = c_compiler.type in ('gcc', 'clang')
|
2017-04-12 20:58:22 +03:00
|
|
|
|
2017-11-21 07:20:56 +03:00
|
|
|
flags = []
|
|
|
|
js_flags = []
|
|
|
|
|
|
|
|
# FORTIFY_SOURCE ------------------------------------
|
|
|
|
# If hardening is explicitly enabled, or not explicitly disabled
|
|
|
|
if hardening_flag.origin == "default" or hardening_flag:
|
|
|
|
# Require optimization for FORTIFY_SOURCE. See Bug 1417452
|
|
|
|
# Also, undefine it before defining it just in case a distro adds it, see Bug 1418398
|
|
|
|
if compiler_is_gccish and optimize and not asan:
|
|
|
|
# Don't enable FORTIFY_SOURCE on Android on the top-level, but do enable in js/
|
|
|
|
if target.os != 'Android':
|
|
|
|
flags.append("-U_FORTIFY_SOURCE")
|
|
|
|
flags.append("-D_FORTIFY_SOURCE=2")
|
|
|
|
js_flags.append("-U_FORTIFY_SOURCE")
|
|
|
|
js_flags.append("-D_FORTIFY_SOURCE=2")
|
|
|
|
|
|
|
|
# If ASAN _is_ on, undefine FOTIFY_SOURCE just to be safe
|
|
|
|
if asan:
|
|
|
|
flags.append("-U_FORTIFY_SOURCE")
|
|
|
|
js_flags.append("-U_FORTIFY_SOURCE")
|
|
|
|
|
|
|
|
# fstack-protector ------------------------------------
|
|
|
|
# Enable only if --enable-hardening is passed and ASAN is
|
|
|
|
# not on as ASAN will catch the crashes for us
|
|
|
|
if hardening_flag and compiler_is_gccish and not asan:
|
|
|
|
flags.append("-fstack-protector-strong")
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2018-01-16 17:00:31 +03:00
|
|
|
# fno-common -----------------------------------------
|
|
|
|
# Do not merge variables for ASAN; can detect some subtle bugs
|
|
|
|
if asan:
|
2018-03-13 18:32:15 +03:00
|
|
|
# clang-cl does not recognize the flag, it must be passed down to clang
|
|
|
|
if c_compiler.type == 'clang-cl':
|
|
|
|
flags.append("-Xclang")
|
2018-01-16 17:00:31 +03:00
|
|
|
flags.append("-fno-common")
|
|
|
|
|
2017-11-21 07:20:56 +03:00
|
|
|
return namespace(
|
|
|
|
flags=flags,
|
|
|
|
js_flags=js_flags,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
add_old_configure_assignment('MOZ_HARDENING_CFLAGS', security_hardening_cflags.flags)
|
|
|
|
add_old_configure_assignment('MOZ_HARDENING_CFLAGS_JS', security_hardening_cflags.js_flags)
|
2017-06-06 03:05:10 +03:00
|
|
|
|
2018-06-20 13:16:43 +03:00
|
|
|
# Code Coverage
|
|
|
|
# ==============================================================
|
|
|
|
|
|
|
|
js_option('--enable-coverage', env='MOZ_CODE_COVERAGE',
|
|
|
|
help='Enable code coverage')
|
|
|
|
|
|
|
|
|
|
|
|
@depends('--enable-coverage')
|
|
|
|
def code_coverage(value):
|
|
|
|
if value:
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
set_config('MOZ_CODE_COVERAGE', code_coverage)
|
|
|
|
set_define('MOZ_CODE_COVERAGE', code_coverage)
|
|
|
|
|
2017-11-21 07:20:56 +03:00
|
|
|
# ==============================================================
|
|
|
|
|
2017-06-06 03:05:10 +03:00
|
|
|
option(env='RUSTFLAGS',
|
|
|
|
nargs=1,
|
|
|
|
help='Rust compiler flags')
|
|
|
|
set_config('RUSTFLAGS', depends('RUSTFLAGS')(lambda flags: flags))
|
2017-06-21 04:29:28 +03:00
|
|
|
|
|
|
|
|
2017-10-25 00:42:01 +03:00
|
|
|
# Rust compiler flags
|
|
|
|
# ==============================================================
|
|
|
|
|
2017-10-25 02:48:58 +03:00
|
|
|
js_option(env='RUSTC_OPT_LEVEL',
|
|
|
|
nargs=1,
|
|
|
|
help='Rust compiler optimization level (-C opt-level=%s)')
|
|
|
|
|
|
|
|
# --enable-release kicks in full optimizations.
|
|
|
|
imply_option('RUSTC_OPT_LEVEL', '2', when='--enable-release')
|
|
|
|
|
2017-10-25 20:57:51 +03:00
|
|
|
|
2018-03-12 20:25:39 +03:00
|
|
|
@depends('RUSTC_OPT_LEVEL', moz_optimize)
|
|
|
|
def rustc_opt_level(opt_level_option, moz_optimize):
|
|
|
|
if opt_level_option:
|
|
|
|
return opt_level_option[0]
|
|
|
|
else:
|
|
|
|
return '1' if moz_optimize.optimize else '0'
|
|
|
|
|
2017-10-25 00:42:01 +03:00
|
|
|
|
2018-03-12 20:25:39 +03:00
|
|
|
@depends(rustc_opt_level, debug_rust, '--enable-debug-symbols')
|
|
|
|
def rust_compiler_flags(opt_level, debug_rust, debug_symbols):
|
2017-10-25 00:42:01 +03:00
|
|
|
# Cargo currently supports only two interesting profiles for building:
|
|
|
|
# development and release. Those map (roughly) to --enable-debug and
|
|
|
|
# --disable-debug in Gecko, respectively.
|
|
|
|
#
|
|
|
|
# But we'd also like to support an additional axis of control for
|
|
|
|
# optimization level. Since Cargo only supports 2 profiles, we're in
|
|
|
|
# a bit of a bind.
|
|
|
|
#
|
|
|
|
# Code here derives various compiler options given other configure options.
|
|
|
|
# The options defined here effectively override defaults specified in
|
|
|
|
# Cargo.toml files.
|
|
|
|
|
|
|
|
debug_assertions = None
|
|
|
|
debug_info = None
|
|
|
|
|
|
|
|
# opt-level=0 implies -C debug-assertions, which may not be desired
|
|
|
|
# unless Rust debugging is enabled.
|
|
|
|
if opt_level == '0' and not debug_rust:
|
|
|
|
debug_assertions = False
|
|
|
|
|
|
|
|
if debug_symbols:
|
2017-12-28 12:01:50 +03:00
|
|
|
debug_info = '2'
|
2017-10-25 00:42:01 +03:00
|
|
|
|
2017-10-26 21:26:14 +03:00
|
|
|
opts = []
|
2017-10-25 00:42:01 +03:00
|
|
|
|
|
|
|
if opt_level is not None:
|
2017-10-26 21:26:14 +03:00
|
|
|
opts.append('opt-level=%s' % opt_level)
|
2017-10-25 00:42:01 +03:00
|
|
|
if debug_assertions is not None:
|
2017-10-26 21:26:14 +03:00
|
|
|
opts.append('debug-assertions=%s' %
|
2017-10-26 21:40:19 +03:00
|
|
|
('yes' if debug_assertions else 'no'))
|
2017-10-25 00:42:01 +03:00
|
|
|
if debug_info is not None:
|
2017-10-26 21:26:14 +03:00
|
|
|
opts.append('debuginfo=%s' % debug_info)
|
|
|
|
|
|
|
|
flags = []
|
|
|
|
for opt in opts:
|
|
|
|
flags.extend(['-C', opt])
|
2017-10-25 00:42:01 +03:00
|
|
|
|
|
|
|
return flags
|
|
|
|
|
2017-10-25 20:57:51 +03:00
|
|
|
|
2017-10-25 00:42:01 +03:00
|
|
|
set_config('MOZ_RUST_DEFAULT_FLAGS', rust_compiler_flags)
|
|
|
|
|
2018-03-12 20:25:39 +03:00
|
|
|
# Rust incremental compilation
|
|
|
|
# ==============================================================
|
|
|
|
|
|
|
|
|
2018-06-20 13:16:43 +03:00
|
|
|
@depends(rustc_opt_level, debug_rust, 'MOZ_AUTOMATION', code_coverage)
|
|
|
|
def cargo_incremental(opt_level, debug_rust, automation, code_coverage):
|
2018-03-12 20:25:39 +03:00
|
|
|
"""Return a value for the CARGO_INCREMENTAL environment variable."""
|
|
|
|
|
|
|
|
# We never want to use incremental compilation in automation. sccache
|
|
|
|
# handles our automation use case much better than incremental compilation
|
|
|
|
# would.
|
|
|
|
if automation:
|
|
|
|
return '0'
|
|
|
|
|
2018-06-20 13:16:43 +03:00
|
|
|
# Coverage instrumentation doesn't play well with incremental compilation
|
|
|
|
# https://github.com/rust-lang/rust/issues/50203.
|
|
|
|
if code_coverage:
|
|
|
|
return '0'
|
|
|
|
|
2018-03-12 20:25:39 +03:00
|
|
|
# Incremental compilation is automatically turned on for debug builds, so
|
|
|
|
# we don't need to do anything special here.
|
|
|
|
if debug_rust:
|
|
|
|
return
|
|
|
|
|
|
|
|
# --enable-release automatically sets -O2 for Rust code, and people can
|
|
|
|
# set RUSTC_OPT_LEVEL to 2 or even 3 if they want to profile Rust code.
|
|
|
|
# Let's assume that if Rust code is using -O2 or higher, we shouldn't
|
|
|
|
# be using incremental compilation, because we'd be imposing a
|
|
|
|
# significant runtime cost.
|
|
|
|
if opt_level not in ('0', '1'):
|
|
|
|
return
|
|
|
|
|
|
|
|
# We're clear to use incremental compilation!
|
|
|
|
return '1'
|
2018-03-12 20:25:39 +03:00
|
|
|
|
|
|
|
|
|
|
|
set_config('CARGO_INCREMENTAL', cargo_incremental)
|
|
|
|
|
2017-07-05 12:27:56 +03:00
|
|
|
# Linker detection
|
|
|
|
# ==============================================================
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2017-07-05 12:27:56 +03:00
|
|
|
@depends(target)
|
2017-10-10 13:01:32 +03:00
|
|
|
def is_linker_option_enabled(target):
|
Bug 1469088 - Relax the assumptions of --enable-lto, and make it work for macOS builds. r=ted
Currently, --enable-lto just implies --enable-linker=lld, which
essentially only works on Linux, and assumes one can't do lto with
anything other than lld. Which is not true. As a matter of fact, even
ld.bfd can do lto, as long as the gold plugin for llvm is available,
or when doing lto with GCC instead of clang.
Anyways, to allow more lto setups, we adapt the --enable-linker setup
to:
- work on macOS, which it currently doesn't, and add support for the mac
linker (ld64), which, unfortunately, doesn't have a clean way to be
detected, so work around that.
- default to lld if lto is enable, no linker was explicitly given, the
compiler is clang *and* the build target is not macOS.
--HG--
extra : rebase_source : 1dab2ad6230d18e7f4285943e76352e23b987d4e
2018-07-05 05:35:31 +03:00
|
|
|
if target.kernel not in ('WINNT', 'SunOS'):
|
2017-07-05 12:27:56 +03:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
option('--enable-gold',
|
|
|
|
env='MOZ_FORCE_GOLD',
|
|
|
|
help='Enable GNU Gold Linker when it is not already the default',
|
2017-10-10 13:01:32 +03:00
|
|
|
when=is_linker_option_enabled)
|
2017-07-05 12:27:56 +03:00
|
|
|
|
2017-10-10 13:01:32 +03:00
|
|
|
imply_option('--enable-linker', 'gold', when='--enable-gold')
|
2017-07-05 12:27:56 +03:00
|
|
|
|
2018-04-26 14:27:36 +03:00
|
|
|
js_option('--enable-linker', nargs=1,
|
Bug 1469088 - Relax the assumptions of --enable-lto, and make it work for macOS builds. r=ted
Currently, --enable-lto just implies --enable-linker=lld, which
essentially only works on Linux, and assumes one can't do lto with
anything other than lld. Which is not true. As a matter of fact, even
ld.bfd can do lto, as long as the gold plugin for llvm is available,
or when doing lto with GCC instead of clang.
Anyways, to allow more lto setups, we adapt the --enable-linker setup
to:
- work on macOS, which it currently doesn't, and add support for the mac
linker (ld64), which, unfortunately, doesn't have a clean way to be
detected, so work around that.
- default to lld if lto is enable, no linker was explicitly given, the
compiler is clang *and* the build target is not macOS.
--HG--
extra : rebase_source : 1dab2ad6230d18e7f4285943e76352e23b987d4e
2018-07-05 05:35:31 +03:00
|
|
|
help='Select the linker {bfd, gold, ld64, lld, lld-*}',
|
2018-04-26 14:27:36 +03:00
|
|
|
when=is_linker_option_enabled)
|
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
2018-06-07 02:46:31 +03:00
|
|
|
@depends('--enable-linker', c_compiler, developer_options, '--enable-gold',
|
2018-09-04 04:49:31 +03:00
|
|
|
extra_toolchain_flags, target, when=is_linker_option_enabled)
|
2018-04-26 14:27:36 +03:00
|
|
|
@checking('for linker', lambda x: x.KIND)
|
2017-07-05 12:27:56 +03:00
|
|
|
@imports('os')
|
|
|
|
@imports('shutil')
|
2018-06-07 02:46:31 +03:00
|
|
|
def select_linker(linker, c_compiler, developer_options, enable_gold,
|
2018-09-04 04:49:31 +03:00
|
|
|
toolchain_flags, target):
|
Bug 1469088 - Relax the assumptions of --enable-lto, and make it work for macOS builds. r=ted
Currently, --enable-lto just implies --enable-linker=lld, which
essentially only works on Linux, and assumes one can't do lto with
anything other than lld. Which is not true. As a matter of fact, even
ld.bfd can do lto, as long as the gold plugin for llvm is available,
or when doing lto with GCC instead of clang.
Anyways, to allow more lto setups, we adapt the --enable-linker setup
to:
- work on macOS, which it currently doesn't, and add support for the mac
linker (ld64), which, unfortunately, doesn't have a clean way to be
detected, so work around that.
- default to lld if lto is enable, no linker was explicitly given, the
compiler is clang *and* the build target is not macOS.
--HG--
extra : rebase_source : 1dab2ad6230d18e7f4285943e76352e23b987d4e
2018-07-05 05:35:31 +03:00
|
|
|
|
|
|
|
if linker:
|
|
|
|
linker = linker[0]
|
|
|
|
else:
|
|
|
|
linker = None
|
2018-04-26 14:27:36 +03:00
|
|
|
|
Bug 1469088 - Relax the assumptions of --enable-lto, and make it work for macOS builds. r=ted
Currently, --enable-lto just implies --enable-linker=lld, which
essentially only works on Linux, and assumes one can't do lto with
anything other than lld. Which is not true. As a matter of fact, even
ld.bfd can do lto, as long as the gold plugin for llvm is available,
or when doing lto with GCC instead of clang.
Anyways, to allow more lto setups, we adapt the --enable-linker setup
to:
- work on macOS, which it currently doesn't, and add support for the mac
linker (ld64), which, unfortunately, doesn't have a clean way to be
detected, so work around that.
- default to lld if lto is enable, no linker was explicitly given, the
compiler is clang *and* the build target is not macOS.
--HG--
extra : rebase_source : 1dab2ad6230d18e7f4285943e76352e23b987d4e
2018-07-05 05:35:31 +03:00
|
|
|
def is_valid_linker(linker):
|
|
|
|
if target.kernel == 'Darwin':
|
|
|
|
valid_linkers = ('ld64', 'lld')
|
|
|
|
else:
|
|
|
|
valid_linkers = ('bfd', 'gold', 'lld')
|
|
|
|
if linker in valid_linkers:
|
|
|
|
return True
|
|
|
|
if 'lld' in valid_linkers and linker.startswith('lld-'):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
if linker and not is_valid_linker(linker):
|
2018-05-09 14:53:16 +03:00
|
|
|
# Check that we are trying to use a supported linker
|
|
|
|
die('Unsupported linker ' + linker)
|
|
|
|
|
2018-04-26 14:27:36 +03:00
|
|
|
# Check the kind of linker
|
2017-07-05 12:27:56 +03:00
|
|
|
version_check = ['-Wl,--version']
|
|
|
|
cmd_base = c_compiler.wrapper + [c_compiler.compiler] + c_compiler.flags
|
|
|
|
|
2018-06-07 02:46:31 +03:00
|
|
|
def try_linker(linker):
|
|
|
|
# Generate the compiler flag
|
Bug 1469088 - Relax the assumptions of --enable-lto, and make it work for macOS builds. r=ted
Currently, --enable-lto just implies --enable-linker=lld, which
essentially only works on Linux, and assumes one can't do lto with
anything other than lld. Which is not true. As a matter of fact, even
ld.bfd can do lto, as long as the gold plugin for llvm is available,
or when doing lto with GCC instead of clang.
Anyways, to allow more lto setups, we adapt the --enable-linker setup
to:
- work on macOS, which it currently doesn't, and add support for the mac
linker (ld64), which, unfortunately, doesn't have a clean way to be
detected, so work around that.
- default to lld if lto is enable, no linker was explicitly given, the
compiler is clang *and* the build target is not macOS.
--HG--
extra : rebase_source : 1dab2ad6230d18e7f4285943e76352e23b987d4e
2018-07-05 05:35:31 +03:00
|
|
|
if linker == 'ld64':
|
|
|
|
linker_flag = ['-fuse-ld=ld']
|
|
|
|
elif linker:
|
|
|
|
linker_flag = ["-fuse-ld=" + linker]
|
|
|
|
else:
|
|
|
|
linker_flag = []
|
2018-06-07 02:46:31 +03:00
|
|
|
cmd = cmd_base + linker_flag + version_check
|
|
|
|
if toolchain_flags:
|
|
|
|
cmd += toolchain_flags
|
2018-06-07 02:46:31 +03:00
|
|
|
|
Bug 1469088 - Relax the assumptions of --enable-lto, and make it work for macOS builds. r=ted
Currently, --enable-lto just implies --enable-linker=lld, which
essentially only works on Linux, and assumes one can't do lto with
anything other than lld. Which is not true. As a matter of fact, even
ld.bfd can do lto, as long as the gold plugin for llvm is available,
or when doing lto with GCC instead of clang.
Anyways, to allow more lto setups, we adapt the --enable-linker setup
to:
- work on macOS, which it currently doesn't, and add support for the mac
linker (ld64), which, unfortunately, doesn't have a clean way to be
detected, so work around that.
- default to lld if lto is enable, no linker was explicitly given, the
compiler is clang *and* the build target is not macOS.
--HG--
extra : rebase_source : 1dab2ad6230d18e7f4285943e76352e23b987d4e
2018-07-05 05:35:31 +03:00
|
|
|
# ld64 doesn't have anything to print out a version. It does print out
|
|
|
|
# "ld64: For information on command line options please use 'man ld'."
|
|
|
|
# but that would require doing two attempts, one with --version, that
|
|
|
|
# would fail, and another with --help.
|
|
|
|
# Instead, abuse its LD_PRINT_OPTIONS feature to detect a message
|
|
|
|
# specific to it on stderr when it fails to process --version.
|
|
|
|
env = dict(os.environ)
|
|
|
|
env['LD_PRINT_OPTIONS'] = '1'
|
|
|
|
retcode, stdout, stderr = get_cmd_output(*cmd, env=env)
|
|
|
|
cmd_output = stdout.decode('utf-8')
|
|
|
|
stderr = stderr.decode('utf-8')
|
|
|
|
if retcode == 1 and 'Logging ld64 options' in stderr:
|
|
|
|
kind = 'ld64'
|
|
|
|
|
|
|
|
elif retcode != 0:
|
2018-07-05 03:28:49 +03:00
|
|
|
return None
|
|
|
|
|
Bug 1469088 - Relax the assumptions of --enable-lto, and make it work for macOS builds. r=ted
Currently, --enable-lto just implies --enable-linker=lld, which
essentially only works on Linux, and assumes one can't do lto with
anything other than lld. Which is not true. As a matter of fact, even
ld.bfd can do lto, as long as the gold plugin for llvm is available,
or when doing lto with GCC instead of clang.
Anyways, to allow more lto setups, we adapt the --enable-linker setup
to:
- work on macOS, which it currently doesn't, and add support for the mac
linker (ld64), which, unfortunately, doesn't have a clean way to be
detected, so work around that.
- default to lld if lto is enable, no linker was explicitly given, the
compiler is clang *and* the build target is not macOS.
--HG--
extra : rebase_source : 1dab2ad6230d18e7f4285943e76352e23b987d4e
2018-07-05 05:35:31 +03:00
|
|
|
elif 'GNU ld' in cmd_output:
|
2018-06-07 02:46:31 +03:00
|
|
|
# We are using the normal linker
|
|
|
|
kind = 'bfd'
|
2018-06-07 02:46:31 +03:00
|
|
|
|
2018-06-07 02:46:31 +03:00
|
|
|
elif 'GNU gold' in cmd_output:
|
|
|
|
kind = 'gold'
|
|
|
|
|
|
|
|
elif 'LLD' in cmd_output:
|
|
|
|
kind = 'lld'
|
|
|
|
|
|
|
|
else:
|
|
|
|
kind = 'unknown'
|
2017-07-05 12:27:56 +03:00
|
|
|
|
2018-04-26 14:27:36 +03:00
|
|
|
return namespace(
|
2018-06-07 02:46:31 +03:00
|
|
|
KIND=kind,
|
2018-04-26 14:27:36 +03:00
|
|
|
LINKER_FLAG=linker_flag,
|
|
|
|
)
|
2018-06-07 02:46:31 +03:00
|
|
|
|
|
|
|
result = try_linker(linker)
|
2018-07-05 03:28:49 +03:00
|
|
|
if result is None:
|
|
|
|
if linker:
|
|
|
|
die("Could not use {} as linker".format(linker))
|
|
|
|
die("Failed to find a linker")
|
2018-06-07 02:46:31 +03:00
|
|
|
|
|
|
|
if (linker is None and enable_gold.origin == 'default' and
|
|
|
|
developer_options and result.KIND == 'bfd'):
|
2018-07-05 03:28:49 +03:00
|
|
|
# try and use lld if available.
|
|
|
|
tried = try_linker('lld')
|
|
|
|
if tried is None or tried.KIND != 'lld':
|
|
|
|
tried = try_linker('gold')
|
|
|
|
if tried is None or tried.KIND != 'gold':
|
|
|
|
tried = None
|
|
|
|
if tried:
|
|
|
|
result = tried
|
2018-06-07 02:46:31 +03:00
|
|
|
|
|
|
|
# If an explicit linker was given, error out if what we found is different.
|
|
|
|
if linker and not linker.startswith(result.KIND):
|
2018-05-09 14:53:16 +03:00
|
|
|
die("Could not use {} as linker".format(linker))
|
2018-04-26 14:27:36 +03:00
|
|
|
|
2018-06-07 02:46:31 +03:00
|
|
|
return result
|
2017-07-05 12:27:56 +03:00
|
|
|
|
2017-10-12 16:22:59 +03:00
|
|
|
|
|
|
|
set_config('LD_IS_BFD', depends(select_linker.KIND)
|
|
|
|
(lambda x: x == 'bfd' or None))
|
2018-07-04 10:18:48 +03:00
|
|
|
add_old_configure_assignment('LINKER_LDFLAGS', select_linker.LINKER_FLAG)
|
2017-10-05 19:30:26 +03:00
|
|
|
|
2017-10-26 01:12:10 +03:00
|
|
|
|
|
|
|
js_option('--enable-clang-plugin', env='ENABLE_CLANG_PLUGIN',
|
|
|
|
help="Enable building with the mozilla clang plugin")
|
|
|
|
|
|
|
|
add_old_configure_assignment('ENABLE_CLANG_PLUGIN',
|
|
|
|
depends_if('--enable-clang-plugin')(lambda _: True))
|
|
|
|
|
2017-11-10 02:04:33 +03:00
|
|
|
js_option('--enable-mozsearch-plugin', env='ENABLE_MOZSEARCH_PLUGIN',
|
|
|
|
help="Enable building with the mozsearch indexer plugin")
|
|
|
|
|
|
|
|
add_old_configure_assignment('ENABLE_MOZSEARCH_PLUGIN',
|
|
|
|
depends_if('--enable-mozsearch-plugin')(lambda _: True))
|
|
|
|
|
2018-06-12 08:28:40 +03:00
|
|
|
# Libstdc++ compatibility hacks
|
|
|
|
# ==============================================================
|
|
|
|
#
|
|
|
|
js_option('--enable-stdcxx-compat', env='MOZ_STDCXX_COMPAT',
|
|
|
|
help='Enable compatibility with older libstdc++')
|
|
|
|
|
|
|
|
|
|
|
|
@template
|
2018-08-09 03:04:18 +03:00
|
|
|
def libstdcxx_version(var, compiler, host_or_target):
|
|
|
|
@depends(compiler, host_or_target, when='--enable-stdcxx-compat')
|
2018-06-12 08:28:40 +03:00
|
|
|
@imports(_from='mozbuild.configure.libstdcxx', _import='find_version')
|
2018-08-09 03:04:18 +03:00
|
|
|
def version(compiler, host_or_target):
|
|
|
|
if host_or_target.os == 'Android':
|
|
|
|
return None
|
2018-06-12 08:28:40 +03:00
|
|
|
result = find_version(
|
|
|
|
compiler.wrapper + [compiler.compiler] + compiler.flags)
|
|
|
|
if result:
|
|
|
|
return str(result)
|
|
|
|
|
|
|
|
set_config(var, version)
|
|
|
|
return version
|
|
|
|
|
|
|
|
|
|
|
|
add_gcc_flag(
|
|
|
|
'-D_GLIBCXX_USE_CXX11_ABI=0', cxx_compiler,
|
2018-08-09 03:04:18 +03:00
|
|
|
when=libstdcxx_version(
|
|
|
|
'MOZ_LIBSTDCXX_TARGET_VERSION', cxx_compiler, target))
|
2018-06-12 08:28:40 +03:00
|
|
|
add_gcc_flag(
|
|
|
|
'-D_GLIBCXX_USE_CXX11_ABI=0', host_cxx_compiler,
|
2018-08-09 03:04:18 +03:00
|
|
|
when=libstdcxx_version(
|
|
|
|
'MOZ_LIBSTDCXX_HOST_VERSION', host_cxx_compiler, host))
|
2018-06-12 08:28:40 +03:00
|
|
|
|
|
|
|
|
2018-05-24 22:11:46 +03:00
|
|
|
@depends(c_compiler.try_compile(flags=['-fsanitize=fuzzer-no-link'],
|
|
|
|
check_msg='whether the C compiler supports -fsanitize=fuzzer-no-link'))
|
2018-09-21 00:21:38 +03:00
|
|
|
def libfuzzer_flags(value):
|
2018-05-24 22:11:46 +03:00
|
|
|
if value:
|
2018-09-21 00:21:38 +03:00
|
|
|
no_link_flag_supported = True
|
|
|
|
# recommended for (and only supported by) clang >= 6
|
|
|
|
use_flags = ['-fsanitize=fuzzer-no-link']
|
|
|
|
else:
|
|
|
|
no_link_flag_supported = False
|
|
|
|
use_flags = ['-fsanitize-coverage=trace-pc-guard,trace-cmp']
|
2018-05-24 22:11:46 +03:00
|
|
|
|
2018-09-21 00:21:38 +03:00
|
|
|
return namespace(
|
|
|
|
no_link_flag_supported=no_link_flag_supported,
|
|
|
|
use_flags=use_flags,
|
|
|
|
)
|
2018-05-24 22:11:46 +03:00
|
|
|
|
2018-09-21 00:21:38 +03:00
|
|
|
set_config('HAVE_LIBFUZZER_FLAG_FUZZER_NO_LINK', libfuzzer_flags.no_link_flag_supported)
|
|
|
|
set_config('LIBFUZZER_FLAGS', libfuzzer_flags.use_flags)
|
|
|
|
add_old_configure_assignment('LIBFUZZER_FLAGS', libfuzzer_flags.use_flags)
|
2018-09-19 17:03:42 +03:00
|
|
|
|
|
|
|
# Shared library building
|
|
|
|
# ==============================================================
|
|
|
|
|
|
|
|
# XXX: The use of makefile constructs in these variables is awful.
|
|
|
|
@depends(target, c_compiler)
|
|
|
|
def make_shared_library(target, compiler):
|
|
|
|
if target.os == 'WINNT':
|
|
|
|
if compiler.type in ('gcc', 'clang'):
|
|
|
|
return namespace(
|
|
|
|
mkshlib=['$(CXX)', '$(DSO_LDOPTS)', '-o', '$@'],
|
|
|
|
mkcshlib=['$(CC)', '$(DSO_LDOPTS)', '-o', '$@'],
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
linker = [
|
|
|
|
'$(LINKER)',
|
|
|
|
'-NOLOGO', '-DLL',
|
|
|
|
'-OUT:$@',
|
|
|
|
'-PDB:$(LINK_PDBFILE)',
|
|
|
|
'$(DSO_LDOPTS)'
|
|
|
|
]
|
|
|
|
return namespace(
|
|
|
|
mkshlib=linker,
|
|
|
|
mkcshlib=linker,
|
|
|
|
)
|
|
|
|
|
|
|
|
cc = ['$(CC)', '$(COMPUTED_C_LDFLAGS)']
|
|
|
|
cxx = ['$(CXX)', '$(COMPUTED_CXX_LDFLAGS)']
|
|
|
|
flags = ['$(PGO_CFLAGS)', '$(DSO_PIC_CFLAGS)', '$(DSO_LDOPTS)']
|
|
|
|
output = ['-o', '$@']
|
|
|
|
|
|
|
|
if target.kernel == 'Darwin':
|
|
|
|
soname = []
|
|
|
|
elif target.os == 'NetBSD':
|
|
|
|
soname = ['-Wl,-soname,$(DSO_SONAME)']
|
|
|
|
else:
|
|
|
|
assert compiler.type in ('gcc', 'clang')
|
|
|
|
|
|
|
|
soname = ['-Wl,-h,$(DSO_SONAME)']
|
|
|
|
|
|
|
|
return namespace(
|
|
|
|
mkshlib=cxx + flags + soname + output,
|
|
|
|
mkcshlib=cc + flags + soname + output,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
set_config('MKSHLIB', make_shared_library.mkshlib)
|
|
|
|
set_config('MKCSHLIB', make_shared_library.mkcshlib)
|