1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 include('build/moz.configure/init.configure')
10 # - Gecko-specific options and rules should go in toolkit/moz.configure.
11 # - Firefox-specific options and rules should go in browser/moz.configure.
12 # - Fennec-specific options and rules should go in
13 # mobile/android/moz.configure.
14 # - Spidermonkey-specific options and rules should go in js/moz.configure.
17 option('--enable-artifact-builds', env='MOZ_ARTIFACT_BUILDS',
18 help='Download and use prebuilt binary artifacts.')
20 @depends('--enable-artifact-builds')
21 def artifact_builds(value):
25 set_config('MOZ_ARTIFACT_BUILDS', artifact_builds)
27 imply_option('--enable-artifact-build-symbols',
28 depends(artifact_builds)(lambda v: False if v is None else None),
29 reason='--disable-artifact-builds')
31 option('--enable-artifact-build-symbols', nargs='?', choices=('full',),
32 help='Download symbols when artifact builds are enabled.')
34 @depends('--enable-artifact-build-symbols', 'MOZ_AUTOMATION', target)
35 def enable_artifact_build_symbols(value, automation, target):
39 if target.os == 'Android' and not automation:
44 set_config('MOZ_ARTIFACT_BUILD_SYMBOLS',
45 enable_artifact_build_symbols)
47 @depends('--enable-artifact-builds')
48 def imply_disable_compile_environment(value):
52 option(env='MOZ_COPY_PDBS',
53 help='For builds that do not support symbols in the normal fashion,'
54 ' generate and copy them into the resulting build archive.')
56 set_config('MOZ_COPY_PDBS', depends_if('MOZ_COPY_PDBS')(lambda _: True))
58 imply_option('--enable-compile-environment', imply_disable_compile_environment)
60 option('--disable-compile-environment',
61 help='Disable compiler/library checks')
63 @depends('--disable-compile-environment')
64 def compile_environment(compile_env):
68 set_config('COMPILE_ENVIRONMENT', compile_environment)
69 add_old_configure_assignment('COMPILE_ENVIRONMENT', compile_environment)
71 js_option('--disable-tests',
72 help='Do not build test libraries & programs')
74 @depends('--disable-tests')
75 def enable_tests(value):
79 set_config('ENABLE_TESTS', enable_tests)
80 set_define('ENABLE_TESTS', enable_tests)
82 @depends(enable_tests)
83 def gtest_has_rtti(value):
87 set_define('GTEST_HAS_RTTI', gtest_has_rtti)
89 @depends(target, enable_tests)
90 def linux_gtest_defines(target, enable_tests):
91 if enable_tests and target.os == 'Android':
92 return namespace(os_linux_android=True,
93 use_own_tr1_tuple=True,
96 set_define('GTEST_OS_LINUX_ANDROID',
97 linux_gtest_defines.os_linux_android)
98 set_define('GTEST_USE_OWN_TR1_TUPLE',
99 linux_gtest_defines.use_own_tr1_tuple)
100 set_define('GTEST_HAS_CLONE',
101 linux_gtest_defines.has_clone)
103 js_option('--enable-debug',
105 help='Enable building with developer debug info '
106 '(using the given compiler flags).')
108 @depends('--enable-debug')
109 def moz_debug(debug):
113 set_config('MOZ_DEBUG', moz_debug)
114 set_define('MOZ_DEBUG', moz_debug)
115 # Override any value MOZ_DEBUG may have from the environment when passing it
116 # down to old-configure.
117 add_old_configure_assignment('MOZ_DEBUG',
118 depends('--enable-debug')(lambda x: bool(x)))
120 js_option('--enable-rust-debug',
121 default=depends(when='--enable-debug')(lambda: True),
122 help='{Build|Do not build} Rust code with debug assertions turned '
125 @depends(when='--enable-rust-debug')
129 set_config('MOZ_DEBUG_RUST', debug_rust)
130 set_define('MOZ_DEBUG_RUST', debug_rust)
132 js_option(env='MOZ_PGO', help='Build with profile guided optimizations')
134 set_config('MOZ_PGO', depends('MOZ_PGO')(lambda x: bool(x)))
138 'WINE', ['wine64', 'wine'], allow_missing=True,
139 when=depends(target, host)(
140 lambda t, h: t.kernel == 'WINNT' and h.kernel == 'Linux'))
143 include('build/moz.configure/toolchain.configure',
144 when='--enable-compile-environment')
146 include('build/moz.configure/pkg.configure')
147 # Make this assignment here rather than in pkg.configure to avoid
148 # requiring this file in unit tests.
149 add_old_configure_assignment('PKG_CONFIG', pkg_config)
151 include('build/moz.configure/memory.configure',
152 when='--enable-compile-environment')
153 include('build/moz.configure/headers.configure',
154 when='--enable-compile-environment')
155 include('build/moz.configure/warnings.configure',
156 when='--enable-compile-environment')
157 include('build/moz.configure/lto-pgo.configure',
158 when='--enable-compile-environment')
159 include('build/moz.configure/flags.configure',
160 when='--enable-compile-environment')
161 # rust.configure is included by js/moz.configure.
163 js_option('--enable-valgrind',
164 help='Enable Valgrind integration hooks')
166 valgrind_h = check_header('valgrind/valgrind.h', when='--enable-valgrind')
168 @depends('--enable-valgrind', valgrind_h)
169 def check_valgrind(valgrind, valgrind_h):
172 die('--enable-valgrind specified but Valgrind is not installed')
175 set_define('MOZ_VALGRIND', check_valgrind)
176 set_config('MOZ_VALGRIND', check_valgrind)
178 @depends(target, host)
179 def is_openbsd(target, host):
180 return target.kernel == 'OpenBSD' or host.kernel == 'OpenBSD'
182 option(env='SO_VERSION', nargs=1, default='1.0', when=is_openbsd,
183 help='Shared library version for OpenBSD systems')
185 @depends('SO_VERSION', when=is_openbsd)
186 def so_version(value):
190 def library_name_info_template(host_or_target):
191 assert host_or_target in {host, target}
193 host: host_c_compiler,
197 @depends(host_or_target, compiler, so_version)
198 def library_name_info_impl(host_or_target, compiler, so_version):
199 if host_or_target.kernel == 'WINNT':
200 # There aren't artifacts for mingw builds, so it's OK that the
201 # results are inaccurate in that case.
202 if compiler and compiler.type != 'clang-cl':
204 dll=namespace(prefix='', suffix='.dll'),
205 lib=namespace(prefix='lib', suffix='a'),
206 import_lib=namespace(prefix='lib', suffix='a'),
207 rust_lib=namespace(prefix='', suffix='lib'),
208 obj=namespace(prefix='', suffix='o'),
212 dll=namespace(prefix='', suffix='.dll'),
213 lib=namespace(prefix='', suffix='lib'),
214 import_lib=namespace(prefix='', suffix='lib'),
215 rust_lib=namespace(prefix='', suffix='lib'),
216 obj=namespace(prefix='', suffix='obj'),
219 elif host_or_target.kernel == 'Darwin':
221 dll=namespace(prefix='lib', suffix='.dylib'),
222 lib=namespace(prefix='lib', suffix='a'),
223 import_lib=namespace(prefix=None, suffix=''),
224 rust_lib=namespace(prefix='lib', suffix='a'),
225 obj=namespace(prefix='', suffix='o'),
228 so = '.so.%s' % so_version
233 dll=namespace(prefix='lib', suffix=so),
234 lib=namespace(prefix='lib', suffix='a'),
235 import_lib=namespace(prefix=None, suffix=''),
236 rust_lib=namespace(prefix='lib', suffix='a'),
237 obj=namespace(prefix='', suffix='o'),
240 return library_name_info_impl
242 host_library_name_info = library_name_info_template(host)
243 library_name_info = library_name_info_template(target)
245 set_config('DLL_PREFIX', library_name_info.dll.prefix)
246 set_config('DLL_SUFFIX', library_name_info.dll.suffix)
247 set_config('HOST_DLL_PREFIX', host_library_name_info.dll.prefix)
248 set_config('HOST_DLL_SUFFIX', host_library_name_info.dll.suffix)
249 set_config('LIB_PREFIX', library_name_info.lib.prefix)
250 set_config('LIB_SUFFIX', library_name_info.lib.suffix)
251 set_config('RUST_LIB_PREFIX', library_name_info.rust_lib.prefix)
252 set_config('RUST_LIB_SUFFIX', library_name_info.rust_lib.suffix)
253 set_config('OBJ_SUFFIX', library_name_info.obj.suffix)
254 # Lots of compilation tests depend on this variable being present.
255 add_old_configure_assignment('OBJ_SUFFIX', library_name_info.obj.suffix)
256 set_config('IMPORT_LIB_SUFFIX', library_name_info.import_lib.suffix)
257 set_define('MOZ_DLL_PREFIX', depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s))
258 set_define('MOZ_DLL_SUFFIX', depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s))
259 set_config('WASM_OBJ_SUFFIX', 'wasm')
261 include(include_project_configure)
264 @imports(_from='mozbuild.backend', _import='backends')
265 def build_backends_choices(_):
266 return tuple(backends)
269 @deprecated_option('--enable-build-backend', nargs='+',
270 choices=build_backends_choices)
271 def build_backend(backends):
273 return tuple('+%s' % b for b in backends)
275 imply_option('--build-backends', build_backend)
278 @depends('--enable-artifact-builds', '--disable-compile-environment',
279 '--enable-build-backend', '--enable-project', '--enable-application',
282 def build_backend_defaults(artifact_builds, compile_environment, requested_backends,
283 project, application, _):
285 project = application[0]
289 if 'Tup' in requested_backends:
290 # As a special case, if Tup was requested, do not combine it with any
291 # Make based backend by default.
293 elif artifact_builds:
294 all_backends = ['FasterMake+RecursiveMake']
296 all_backends = ['RecursiveMake', 'FasterMake']
297 # Normally, we'd use target.os == 'WINNT', but a dependency on target
298 # would require target to depend on --help, as well as host and shell,
299 # and this is not a can of worms we can open at the moment.
300 if sys.platform == 'win32' and compile_environment and project != 'mobile/android':
301 all_backends.append('VisualStudio')
302 return tuple(all_backends) or None
304 option('--build-backends', nargs='+', default=build_backend_defaults,
305 choices=build_backends_choices, help='Build backends to generate')
307 @depends('--build-backends')
308 def build_backends(backends):
311 set_config('BUILD_BACKENDS', build_backends)
314 @depends(check_build_environment, build_backends)
316 def check_objdir_backend_reuse(build_env, backends):
317 # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
318 # intentionally vague for use with the substring match below.
319 incompatible_backends = (
323 for backend_file in glob.iglob(os.path.join(build_env.topobjdir,
324 'backend.*Backend')):
325 for prev, curr in incompatible_backends:
326 if prev in backend_file and any(curr in b for b in backends):
327 die("The active objdir, %s, was previously "
328 "used to build with a %s based backend. "
329 "Change objdirs (by setting MOZ_OBJDIR in "
330 "your mozconfig) or clobber to continue.\n",
331 build_env.topobjdir, prev)
334 option('--disable-gtest-in-build',
335 help='Force disable building the gtest libxul during the build.',
336 when='--enable-compile-environment')
338 # Determine whether to build the gtest xul. This happens in automation
339 # on Android and Desktop platforms with the exception of:
340 # - Windows PGO, where linking xul-gtest.dll takes too long;
341 # - Android other than x86_64, where gtest is not required.
342 @depends('MOZ_PGO', build_project, target, 'MOZ_AUTOMATION', '--disable-gtest-in-build',
343 enable_tests, when='--enable-compile-environment')
344 def build_gtest(pgo, build_project, target, automation, enabled, enable_tests):
345 if not enable_tests or not enabled:
347 if (automation and build_project in ('browser', 'comm/mail', 'mobile/android') and
348 not ((pgo and target.os == 'WINNT') or (target.os == 'Android' and target.cpu != 'x86_64'))):
351 set_config('LINK_GTEST_DURING_COMPILE', build_gtest)
354 # ==============================================================
355 option('--enable-ui-locale', default='en-US',
356 help='Select the user interface locale (default: en-US)')
358 set_config('MOZ_UI_LOCALE', depends('--enable-ui-locale')(lambda x: x))
360 # clang-plugin location
361 # ==============================================================
362 @depends(host_library_name_info, check_build_environment,
363 when='--enable-clang-plugin')
364 def clang_plugin_path(library_name_info, build_env):
365 topobjdir = build_env.topobjdir
366 if topobjdir.endswith('/js/src'):
367 topobjdir = topobjdir[:-7]
368 return os.path.abspath(
369 os.path.join(topobjdir, 'build', 'clang-plugin',
370 '%sclang-plugin%s' % (library_name_info.dll.prefix,
371 library_name_info.dll.suffix))
374 add_old_configure_assignment('CLANG_PLUGIN', clang_plugin_path)
378 # ==============================================================
379 awk = check_prog('AWK', ('gawk', 'mawk', 'nawk', 'awk'))
381 # Until the AWK variable is not necessary in old-configure
383 def awk_for_old_configure(value):
386 add_old_configure_assignment('AWK', awk_for_old_configure)
390 # ==============================================================
391 perl = check_prog('PERL', ('perl5', 'perl'))
393 # Until the PERL variable is not necessary in old-configure
395 def perl_for_old_configure(value):
398 add_old_configure_assignment('PERL', perl_for_old_configure)
401 def perl_version_check(min_version):
403 @checking('for minimum required perl version >= %s' % min_version)
404 def get_perl_version(perl):
405 return Version(check_cmd_output(
406 perl, '-e', 'print $]',
407 onerror=lambda: die('Failed to get perl version.')
410 @depends(get_perl_version)
411 def check_perl_version(version):
412 if version < min_version:
413 die('Perl %s or higher is required.', min_version)
416 @checking('for full perl installation')
417 @imports('subprocess')
418 def has_full_perl_installation(perl):
419 ret = subprocess.call(
420 [perl, '-e', 'use Config; exit(!-d $Config{archlib})'])
423 @depends(has_full_perl_installation)
424 def require_full_perl_installation(has_full_perl_installation):
425 if not has_full_perl_installation:
426 die('Cannot find Config.pm or $Config{archlib}. '
427 'A full perl installation is required.')
429 perl_version_check('5.006')
433 # ==============================================================
434 option(env='MAKE', nargs=1, help='Path to GNU make')
436 @depends('MAKE', host)
437 def possible_makes(make, host):
439 if host.kernel == 'WINNT':
440 candidates.append('mingw32-make')
442 candidates.append(make[0])
443 if host.kernel == 'WINNT':
444 candidates.extend(('make', 'gmake'))
446 candidates.extend(('gmake', 'make'))
449 check_prog('GMAKE', possible_makes)
452 # ==============================================================
454 option(env='WATCHMAN', nargs=1, help='Path to the watchman program')
456 @depends(host, 'WATCHMAN')
457 @checking('for watchman', callback=lambda w: w.path if w else 'not found')
458 def watchman(host, prog):
459 # On Windows, `watchman` is only supported on 64-bit hosts.
460 if host.os == 'WINNT' and host.cpu != 'x86_64':
464 prog = find_program('watchman')
469 # `watchman version` will talk to the Watchman daemon service.
470 # This can hang due to permissions problems. e.g.
471 # https://github.com/facebook/watchman/issues/376. So use
472 # `watchman --version` to prevent a class of failures.
473 out = check_cmd_output(prog, '--version', onerror=lambda: None)
477 return namespace(path=prog, version=Version(out.strip()))
479 @depends_if(watchman)
480 @checking('for watchman version')
481 def watchman_version(w):
484 set_config('WATCHMAN', watchman.path)
486 @depends_all(hg_version, hg_config, watchman)
487 @checking('for watchman Mercurial integration')
489 def watchman_hg(hg_version, hg_config, watchman):
490 if hg_version < Version('3.8'):
491 return 'no (Mercurial 3.8+ required)'
494 mode_disabled = False
496 for k in ('extensions.fsmonitor', 'extensions.hgext.fsmonitor'):
497 if k in hg_config and hg_config[k] != '!':
500 mode_disabled = hg_config.get('fsmonitor.mode') == 'off'
503 return 'no (fsmonitor extension not enabled)'
505 return 'no (fsmonitor.mode=off disables fsmonitor)'
509 # Miscellaneous programs
510 # ==============================================================
511 check_prog('XARGS', ('xargs',))
514 def extra_programs(target):
515 if target.kernel == 'Darwin':
517 DSYMUTIL=('dsymutil', 'llvm-dsymutil'),
518 MKFSHFS=('newfs_hfs', 'mkfs.hfsplus'),
519 HFS_TOOL=('hfsplus',)
521 if target.os == 'GNU' and target.kernel == 'Linux':
522 return namespace(RPMBUILD=('rpmbuild',))
524 check_prog('DSYMUTIL', extra_programs.DSYMUTIL,
526 check_prog('MKFSHFS', extra_programs.MKFSHFS,
528 check_prog('HFS_TOOL', extra_programs.HFS_TOOL,
530 check_prog('RPMBUILD', extra_programs.RPMBUILD,
536 def makensis_progs(target):
537 if target.kernel != 'WINNT':
547 # Look for nsis installed by msys environment. But only the 32-bit version.
548 # We use an absolute path and insert as the first entry so it is preferred
549 # over a 64-bit exe that may be in PATH.
550 if 'MSYSTEM_PREFIX' in os.environ:
551 prefix = os.path.dirname(os.environ['MSYSTEM_PREFIX'])
552 candidates.insert(0, os.path.join(prefix, 'mingw32', 'bin', 'makensis.exe'))
554 return tuple(candidates)
556 nsis = check_prog('MAKENSISU', makensis_progs, allow_missing=True)
558 # Make sure the version of makensis is up to date.
560 @checking('for NSIS version')
562 def nsis_version(nsis, wine):
565 nsis_min_version = '3.0b1'
566 onerror = lambda: die('Failed to get nsis version.')
567 if wine and nsis.lower().endswith('.exe'):
568 out = check_cmd_output(wine, nsis, '-version', onerror=onerror)
570 out = check_cmd_output(nsis, '-version', onerror=onerror)
572 m = re.search(r'(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?', out)
575 raise FatalCheckError('Unknown version of makensis')
576 ver = Version(m.group(0))
578 # Versions comparisons don't quite work well with beta versions, so ensure
579 # it works for the non-beta version.
580 if ver < nsis_min_version and (ver >= '3.0a' or ver < '3'):
581 raise FatalCheckError('To build the installer you must have NSIS'
582 ' version %s or greater in your path'
587 # And that makensis is 32-bit (but only on Windows).
588 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == 'WINNT'))
589 @checking('for 32-bit NSIS')
590 def nsis_binary_type(nsis):
591 bin_type = windows_binary_type(nsis)
592 if bin_type != 'win32':
593 raise FatalCheckError('%s is not a 32-bit Windows application' % nsis)
597 # And any flags we have to give to makensis
599 def nsis_flags(host):
600 if host.kernel != 'WINNT':
604 set_config('MAKENSISU_FLAGS', nsis_flags)
606 check_prog('7Z', ('7z', '7za'), allow_missing=True, when=target_is_windows)
607 check_prog('UPX', ('upx',), allow_missing=True, when=target_is_windows)
610 @depends(host_c_compiler, c_compiler, bindgen_config_paths)
611 def llvm_objdump(host_c_compiler, c_compiler, bindgen_config_paths):
613 for compiler in (host_c_compiler, c_compiler):
614 if compiler and compiler.type == 'clang':
615 clang = compiler.compiler
617 elif compiler and compiler.type == 'clang-cl':
618 clang = os.path.join(os.path.dirname(compiler.compiler), 'clang')
621 if not clang and bindgen_config_paths:
622 clang = bindgen_config_paths.clang_path
623 llvm_objdump = 'llvm-objdump'
625 out = check_cmd_output(clang, '--print-prog-name=llvm-objdump',
626 onerror=lambda: None)
628 llvm_objdump = out.rstrip()
629 return (llvm_objdump,)
632 llvm_objdump = check_prog('LLVM_OBJDUMP', llvm_objdump, what='llvm-objdump',
633 when='--enable-compile-environment',
634 paths=toolchain_search_path)
636 add_old_configure_assignment('LLVM_OBJDUMP', llvm_objdump)
639 js_option('--enable-dtrace', help='Build with dtrace support')
641 dtrace = check_header('sys/sdt.h', when='--enable-dtrace',
642 onerror=lambda: die('dtrace enabled but sys/sdt.h not found'))
644 set_config('HAVE_DTRACE', True, when=dtrace)
645 set_define('INCLUDE_MOZILLA_DTRACE', True, when=dtrace)
646 add_old_configure_assignment('enable_dtrace', 'yes', when=dtrace)
649 js_option('--disable-icf', help='Disable Identical Code Folding')
651 add_old_configure_assignment(
652 'MOZ_DISABLE_ICF', '1', when=depends('--enable-icf')(lambda x: not x))
655 @depends(compile_environment, target)
656 def may_strip(compile_environment, target):
657 return compile_environment and target.kernel != 'WINNT'
659 js_option('--enable-strip', when=may_strip, help='Enable stripping of libs & executables')
661 set_config('ENABLE_STRIP', True, when='--enable-strip')
663 js_option('--disable-install-strip', when=may_strip,
664 help='Enable stripping of libs & executables when packaging')
666 # The nested depends is because depending on --enable-install-strip needs the
667 # `when=may_strip`, but we also need to test when may_strip is False.
668 @depends(depends('--enable-install-strip', when=may_strip)(lambda x: x), may_strip)
669 def pkg_skip_strip(install_strip, may_strip):
670 return not install_strip or not may_strip
672 set_config('PKG_SKIP_STRIP', True, when=pkg_skip_strip)
675 # Please do not add configure checks from here on.
677 # Fallthrough to autoconf-based configure
678 include('build/moz.configure/old.configure')
681 include('js/sub.configure', when=compile_environment & toolkit)
684 @depends(check_build_environment, build_project)
685 @imports('__sandbox__')
687 @imports(_from='os.path', _import='exists')
688 def config_status_deps(build_env, build_project):
690 topsrcdir = build_env.topsrcdir
691 topobjdir = build_env.topobjdir
693 if not topobjdir.endswith('js/src'):
694 extra_deps = [os.path.join(topobjdir, '.mozconfig.json')]
696 # mozconfig changes may impact js configure.
697 extra_deps = [os.path.join(topobjdir[:-7], '.mozconfig.json')]
699 confvars = os.path.join(topsrcdir, build_project, 'confvars.sh')
701 extra_deps.append(confvars)
703 return list(__sandbox__._all_paths) + extra_deps + [
704 os.path.join(topsrcdir, 'CLOBBER'),
705 os.path.join(topsrcdir, 'configure'),
706 os.path.join(topsrcdir, 'js', 'src', 'configure'),
707 os.path.join(topsrcdir, 'configure.in'),
708 os.path.join(topsrcdir, 'js', 'src', 'configure.in'),
709 os.path.join(topsrcdir, 'nsprpub', 'configure'),
710 os.path.join(topsrcdir, 'config', 'milestone.txt'),
711 os.path.join(topsrcdir, 'browser', 'config', 'version.txt'),
712 os.path.join(topsrcdir, 'browser', 'config', 'version_display.txt'),
713 os.path.join(topsrcdir, 'build', 'virtualenv_packages.txt'),
714 os.path.join(topsrcdir, 'python', 'mozbuild', 'mozbuild', 'virtualenv.py'),
715 os.path.join(topsrcdir, 'testing', 'mozbase', 'packages.txt'),
716 os.path.join(topsrcdir, 'aclocal.m4'),
717 os.path.join(topsrcdir, 'old-configure.in'),
718 os.path.join(topsrcdir, 'js', 'src', 'aclocal.m4'),
719 os.path.join(topsrcdir, 'js', 'src', 'old-configure.in'),
720 ] + glob.glob(os.path.join(topsrcdir, 'build', 'autoconf', '*.m4'))
722 set_config('CONFIG_STATUS_DEPS', config_status_deps)
723 # Please do not add anything after setting config_dep_paths.