Bug 1806664 - Use python toolchain tasks to build firefox r=glandium,taskgraph-review...
[gecko.git] / moz.configure
blob5efc07ece3666df4e68f30ca69c47ccd9ca65cee
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")
9 # Note:
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.
15 # - etc.
17 imply_option(
18     "--enable-artifact-build-symbols",
19     depends(artifact_builds)(lambda v: False if v is None else None),
20     reason="--disable-artifact-builds",
23 option(
24     "--enable-artifact-build-symbols",
25     nargs="?",
26     choices=("full",),
27     help="Download symbols when artifact builds are enabled.",
31 @depends("--enable-artifact-build-symbols", "MOZ_AUTOMATION", target)
32 def enable_artifact_build_symbols(value, automation, target):
33     if len(value):
34         return value[0]
35     if bool(value):
36         if target.os == "Android" and not automation:
37             return "full"
38         return True
39     return None
42 set_config("MOZ_ARTIFACT_BUILD_SYMBOLS", enable_artifact_build_symbols)
45 @depends("--enable-artifact-builds")
46 def imply_disable_compile_environment(value):
47     if value:
48         return False
51 option(
52     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.",
57 set_config("MOZ_COPY_PDBS", depends_if("MOZ_COPY_PDBS")(lambda _: True))
59 imply_option("--enable-compile-environment", imply_disable_compile_environment)
61 option("--disable-compile-environment", help="Disable compiler/library checks")
64 @depends("--disable-compile-environment")
65 def compile_environment(compile_env):
66     if compile_env:
67         return True
70 set_config("COMPILE_ENVIRONMENT", compile_environment)
71 add_old_configure_assignment("COMPILE_ENVIRONMENT", compile_environment)
73 option("--disable-tests", help="Do not build test libraries & programs")
76 @depends("--disable-tests")
77 def enable_tests(value):
78     if value:
79         return True
82 set_config("ENABLE_TESTS", enable_tests)
83 set_define("ENABLE_TESTS", enable_tests)
86 @depends(enable_tests)
87 def gtest_has_rtti(value):
88     if value:
89         return "0"
92 set_define("GTEST_HAS_RTTI", gtest_has_rtti)
95 @depends(target, enable_tests)
96 def linux_gtest_defines(target, enable_tests):
97     if enable_tests and target.os == "Android":
98         return namespace(os_linux_android=True, use_own_tr1_tuple=True, has_clone="0")
101 set_define("GTEST_OS_LINUX_ANDROID", linux_gtest_defines.os_linux_android)
102 set_define("GTEST_USE_OWN_TR1_TUPLE", linux_gtest_defines.use_own_tr1_tuple)
103 set_define("GTEST_HAS_CLONE", linux_gtest_defines.has_clone)
105 option(
106     "--enable-debug",
107     nargs="?",
108     help="Enable building with developer debug info "
109     "(using the given compiler flags).",
113 @depends("--enable-debug")
114 def moz_debug(debug):
115     if debug:
116         return bool(debug)
119 set_config("MOZ_DEBUG", moz_debug)
120 set_define("MOZ_DEBUG", moz_debug)
121 # Override any value MOZ_DEBUG may have from the environment when passing it
122 # down to old-configure.
123 add_old_configure_assignment("MOZ_DEBUG", depends("--enable-debug")(lambda x: bool(x)))
125 set_config(
126     "MOZ_DIAGNOSTIC_ASSERT_ENABLED",
127     True,
128     when=moz_debug | milestone.is_early_beta_or_earlier,
130 set_define(
131     "MOZ_DIAGNOSTIC_ASSERT_ENABLED",
132     True,
133     when=moz_debug | milestone.is_early_beta_or_earlier,
136 option(
137     "--with-debug-label",
138     nargs="+",
139     help="Debug DEBUG_<value> for each comma-separated value given",
143 @depends(moz_debug, "--with-debug-label")
144 def debug_defines(debug, labels):
145     if debug:
146         return ["DEBUG"] + ["DEBUG_%s" % label for label in labels]
147     return ["NDEBUG", "TRIMMED"]
150 set_config("MOZ_DEBUG_DEFINES", debug_defines)
152 option(env="MOZ_PGO", help="Build with profile guided optimizations")
154 set_config("MOZ_PGO", depends("MOZ_PGO")(lambda x: bool(x)))
157 # Imply --enable-release when MOZILLA_OFFICIAL is set rather than adjusting the
158 # default so that we can't have both MOZILLA_OFFICIAL and --disable-release set.
159 imply_option("--enable-release", mozilla_official)
161 option(
162     "--enable-release",
163     default=milestone.is_release_or_beta | depends("MOZ_AUTOMATION")(lambda x: bool(x)),
164     help="{Build|Do not build} with more conservative, release "
165     "engineering-oriented options.{ This may slow down builds.|}",
169 @depends("--enable-release")
170 def developer_options(value):
171     if not value:
172         return True
175 add_old_configure_assignment("DEVELOPER_OPTIONS", developer_options)
176 set_config("DEVELOPER_OPTIONS", developer_options)
179 # hybrid build handling
180 # ==============================================================
182 option(
183     "--disable-unified-build",
184     help="Enable building modules that are not marked with `REQUIRES_UNIFIED_BUILD` in non unified context",
187 set_config("ENABLE_UNIFIED_BUILD", True, when="--disable-unified-build")
190 include("build/moz.configure/bootstrap.configure")
193 # The execution model of the configure sandbox doesn't allow for
194 # check_prog to use bootstrap_search_path directly because check_prog
195 # comes first, so we use a trick to allow it. Uses of check_prog
196 # happening before here won't allow bootstrap.
197 @template
198 def check_prog(*args, **kwargs):
199     kwargs["bootstrap_search_path"] = bootstrap_search_path
200     return check_prog(*args, **kwargs)
203 check_prog("WGET", ("wget",), allow_missing=True)
206 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
208 include("build/moz.configure/pkg.configure")
209 # Make this assignment here rather than in pkg.configure to avoid
210 # requiring this file in unit tests.
211 add_old_configure_assignment("PKG_CONFIG", pkg_config)
213 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
214 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
215 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
216 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
217 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
218 # rust.configure is included by js/moz.configure.
220 option("--enable-valgrind", help="Enable Valgrind integration hooks")
222 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
225 @depends("--enable-valgrind", valgrind_h)
226 def check_valgrind(valgrind, valgrind_h):
227     if valgrind:
228         if not valgrind_h:
229             die("--enable-valgrind specified but Valgrind is not installed")
230         return True
233 set_define("MOZ_VALGRIND", check_valgrind)
234 set_config("MOZ_VALGRIND", check_valgrind)
237 @depends(target, host)
238 def is_openbsd(target, host):
239     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
242 option(
243     env="SO_VERSION",
244     nargs=1,
245     default="1.0",
246     when=is_openbsd,
247     help="Shared library version for OpenBSD systems",
251 @depends("SO_VERSION", when=is_openbsd)
252 def so_version(value):
253     return value
256 @template
257 def library_name_info_template(host_or_target):
258     assert host_or_target in {host, target}
259     windows_abi = {
260         host: host_windows_abi,
261         target: target_windows_abi,
262     }[host_or_target]
264     @depends(host_or_target, host_or_target.abi | windows_abi, so_version)
265     def library_name_info_impl(host_or_target, windows_abi, so_version):
266         if host_or_target.kernel == "WINNT":
267             # There aren't artifacts for mingw builds, so it's OK that the
268             # results are inaccurate in that case.
269             if windows_abi and windows_abi != "msvc":
270                 return namespace(
271                     dll=namespace(prefix="", suffix=".dll"),
272                     lib=namespace(prefix="lib", suffix="a"),
273                     import_lib=namespace(prefix="lib", suffix="a"),
274                     obj=namespace(prefix="", suffix="o"),
275                 )
277             return namespace(
278                 dll=namespace(prefix="", suffix=".dll"),
279                 lib=namespace(prefix="", suffix="lib"),
280                 import_lib=namespace(prefix="", suffix="lib"),
281                 obj=namespace(prefix="", suffix="obj"),
282             )
284         elif host_or_target.kernel == "Darwin":
285             return namespace(
286                 dll=namespace(prefix="lib", suffix=".dylib"),
287                 lib=namespace(prefix="lib", suffix="a"),
288                 import_lib=namespace(prefix=None, suffix=""),
289                 obj=namespace(prefix="", suffix="o"),
290             )
291         elif so_version:
292             so = ".so.%s" % so_version
293         else:
294             so = ".so"
296         return namespace(
297             dll=namespace(prefix="lib", suffix=so),
298             lib=namespace(prefix="lib", suffix="a"),
299             import_lib=namespace(prefix=None, suffix=""),
300             obj=namespace(prefix="", suffix="o"),
301         )
303     return library_name_info_impl
306 host_library_name_info = library_name_info_template(host)
307 library_name_info = library_name_info_template(target)
309 set_config("DLL_PREFIX", library_name_info.dll.prefix)
310 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
311 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
312 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
313 set_config("LIB_PREFIX", library_name_info.lib.prefix)
314 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
315 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
316 # Lots of compilation tests depend on this variable being present.
317 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
318 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
319 set_define(
320     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
322 set_define(
323     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
325 set_config("HOST_LIB_PREFIX", host_library_name_info.lib.prefix)
326 set_config("HOST_IMPORT_LIB_SUFFIX", host_library_name_info.import_lib.suffix)
327 set_config("WASM_OBJ_SUFFIX", "wasm")
329 # Make `profiling` available to this file even when js/moz.configure
330 # doesn't end up included.
331 profiling = dependable(False)
332 # Same for js_standalone
333 js_standalone = dependable(False)
334 js_shared = dependable(False)
335 moz_linker = dependable(False)
336 # Same for fold_libs
337 fold_libs = dependable(False)
338 # And dmd
339 dmd = dependable(False)
341 include(include_project_configure)
344 @depends("--help")
345 @imports(_from="mozbuild.backend", _import="backends")
346 def build_backends_choices(_):
347     return tuple(backends)
350 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
351 def build_backend(backends):
352     if backends:
353         return tuple("+%s" % b for b in backends)
356 imply_option("--build-backends", build_backend)
359 @depends(
360     host,
361     target,
362     "--enable-artifact-builds",
363     "--disable-compile-environment",
364     "--enable-build-backend",
365     "--enable-project",
366     "--enable-application",
367     "--help",
369 @imports("sys")
370 @imports(_from="mozbuild.backend.clangd", _import="find_vscode_cmd")
371 def build_backend_defaults(
372     host,
373     target,
374     artifact_builds,
375     compile_environment,
376     requested_backends,
377     project,
378     application,
379     _,
381     if application:
382         project = application[0]
383     elif project:
384         project = project[0]
386     if "Tup" in requested_backends:
387         # As a special case, if Tup was requested, do not combine it with any
388         # Make based backend by default.
389         all_backends = []
390     elif artifact_builds:
391         all_backends = ["FasterMake+RecursiveMake"]
392     else:
393         all_backends = ["RecursiveMake", "FasterMake"]
394     if (
395         host.os == "WINNT"
396         and target.os == "WINNT"
397         and compile_environment
398         and project not in ("mobile/android", "memory", "tools/update-programs")
399     ):
400         all_backends.append("VisualStudio")
401     if (
402         compile_environment
403         and find_vscode_cmd()
404         and project not in ("mobile/android", "memory", "tools/update-programs")
405     ):
406         all_backends.append("Clangd")
407     return tuple(all_backends) or None
410 option(
411     "--build-backends",
412     nargs="+",
413     default=build_backend_defaults,
414     choices=build_backends_choices,
415     help="Build backends to generate",
419 @depends("--build-backends")
420 def build_backends(backends):
421     return backends
424 set_config("BUILD_BACKENDS", build_backends)
427 @depends(build_environment, build_backends)
428 @imports("glob")
429 def check_objdir_backend_reuse(build_env, backends):
430     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
431     # intentionally vague for use with the substring match below.
432     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
433     for backend_file in glob.iglob(
434         os.path.join(build_env.topobjdir, "backend.*Backend")
435     ):
436         for prev, curr in incompatible_backends:
437             if prev in backend_file and any(curr in b for b in backends):
438                 die(
439                     "The active objdir, %s, was previously "
440                     "used to build with a %s based backend. "
441                     "Change objdirs (by setting MOZ_OBJDIR in "
442                     "your mozconfig) or clobber to continue.\n",
443                     build_env.topobjdir,
444                     prev,
445                 )
448 # Determine whether to build the gtest xul. This happens in automation
449 # on Android and Desktop platforms with the exception of:
450 #  - Windows PGO, where linking xul-gtest.dll takes too long;
451 #  - Android other than x86_64, where gtest is not required.
452 @depends(
453     build_project,
454     target,
455     "MOZ_AUTOMATION",
456     enable_tests,
457     when="--enable-compile-environment",
459 def build_gtest(build_project, target, automation, enable_tests):
460     return bool(
461         enable_tests
462         and automation
463         and build_project in ("browser", "comm/mail", "mobile/android")
464         and not (target.os == "Android" and target.cpu != "x86_64")
465     )
468 option(
469     "--enable-gtest-in-build",
470     default=build_gtest,
471     help="{Enable|Force disable} building the gtest libxul during the build.",
472     when="--enable-compile-environment",
475 set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build")
477 # Localization
478 # ==============================================================
479 option(
480     "--enable-ui-locale",
481     default="en-US",
482     help="Select the user interface locale (default: en-US)",
485 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
487 option(
488     "--enable-icu4x",
489     help="An experiment to use ICU4X instead of ICU4C. See intl/ICU4X.md",
492 set_config("MOZ_ICU4X", True, when="--enable-icu4x")
494 # clang-plugin location
495 # ==============================================================
498 @depends(host_library_name_info, build_environment, when="--enable-clang-plugin")
499 def clang_plugin_path(library_name_info, build_env):
500     topobjdir = build_env.topobjdir
501     if topobjdir.endswith("/js/src"):
502         topobjdir = topobjdir[:-7]
503     return os.path.abspath(
504         os.path.join(
505             topobjdir,
506             "build",
507             "clang-plugin",
508             "%sclang-plugin%s"
509             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
510         )
511     )
514 set_config("CLANG_PLUGIN", clang_plugin_path)
515 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
518 # Awk detection
519 # ==============================================================
520 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"), paths=prefer_mozillabuild_path)
522 # Until the AWK variable is not necessary in old-configure
525 @depends(awk)
526 def awk_for_old_configure(value):
527     return value
530 add_old_configure_assignment("AWK", awk_for_old_configure)
533 # Perl detection
534 # ==============================================================
535 perl = check_prog("PERL", ("perl5", "perl"))
537 # Until the PERL variable is not necessary in old-configure
540 @depends(perl)
541 def perl_for_old_configure(value):
542     return value
545 add_old_configure_assignment("PERL", perl_for_old_configure)
548 @template
549 def perl_version_check(min_version):
550     @depends(perl)
551     @checking("for minimum required perl version >= %s" % min_version)
552     def get_perl_version(perl):
553         return Version(
554             check_cmd_output(
555                 perl,
556                 "-e",
557                 "print $]",
558                 onerror=lambda: die("Failed to get perl version."),
559             )
560         )
562     @depends(get_perl_version)
563     def check_perl_version(version):
564         if version < min_version:
565             die("Perl %s or higher is required.", min_version)
567     @depends(perl)
568     @checking("for full perl installation")
569     @imports("subprocess")
570     def has_full_perl_installation(perl):
571         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
572         return ret == 0
574     @depends(has_full_perl_installation)
575     def require_full_perl_installation(has_full_perl_installation):
576         if not has_full_perl_installation:
577             die(
578                 "Cannot find Config.pm or $Config{archlib}. "
579                 "A full perl installation is required."
580             )
583 perl_version_check("5.006")
586 # GNU make detection
587 # ==============================================================
588 option(env="MAKE", nargs=1, help="Path to GNU make")
591 @depends("MAKE", host)
592 def possible_makes(make, host):
593     candidates = []
594     if make:
595         candidates.append(make[0])
596     if host.kernel == "WINNT":
597         candidates.extend(("mozmake", "mingw32-make", "make", "gmake"))
598     else:
599         candidates.extend(("gmake", "make"))
600     return candidates
603 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
605 # watchman detection
606 # ==============================================================
608 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
611 @depends(host, "WATCHMAN")
612 @checking("for watchman", callback=lambda w: w.path if w else "not found")
613 def watchman(host, prog):
614     # On Windows, `watchman` is only supported on 64-bit hosts.
615     if host.os == "WINNT" and host.cpu != "x86_64":
616         return
618     if not prog:
619         prog = find_program("watchman")
621     if not prog:
622         return
624     # `watchman version` will talk to the Watchman daemon service.
625     # This can hang due to permissions problems. e.g.
626     # https://github.com/facebook/watchman/issues/376. So use
627     # `watchman --version` to prevent a class of failures.
628     out = check_cmd_output(prog, "--version", onerror=lambda: None)
629     if out is None:
630         return
632     return namespace(path=prog, version=Version(out.strip()))
635 @depends_if(watchman)
636 @checking("for watchman version")
637 def watchman_version(w):
638     return w.version
641 set_config("WATCHMAN", watchman.path)
644 @depends_all(hg_version, hg_config, watchman)
645 @checking("for watchman Mercurial integration")
646 @imports("os")
647 def watchman_hg(hg_version, hg_config, watchman):
648     if hg_version < Version("3.8"):
649         return "no (Mercurial 3.8+ required)"
651     ext_enabled = False
652     mode_disabled = False
654     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
655         if k in hg_config and hg_config[k] != "!":
656             ext_enabled = True
658     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
660     if not ext_enabled:
661         return "no (fsmonitor extension not enabled)"
662     if mode_disabled:
663         return "no (fsmonitor.mode=off disables fsmonitor)"
665     return True
668 # Miscellaneous programs
669 # ==============================================================
670 check_prog("XARGS", ("xargs",))
673 @depends(target)
674 def extra_programs(target):
675     if target.kernel == "Darwin":
676         return namespace(
677             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
678             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
679             HFS_TOOL=("hfsplus",),
680         )
681     if target.os == "GNU" and target.kernel == "Linux":
682         return namespace(RPMBUILD=("rpmbuild",))
685 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
686 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
687 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
688 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
691 nsis = check_prog(
692     "MAKENSISU",
693     ("makensis",),
694     bootstrap="nsis/bin",
695     allow_missing=True,
696     when=target_is_windows,
699 # Make sure the version of makensis is up to date.
702 @depends_if(nsis)
703 @checking("for NSIS version")
704 @imports("re")
705 def nsis_version(nsis):
706     nsis_min_version = "3.0b1"
708     def onerror():
709         return die("Failed to get nsis version.")
711     out = check_cmd_output(nsis, "-version", onerror=onerror)
713     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
715     if not m:
716         raise FatalCheckError("Unknown version of makensis")
717     ver = Version(m.group(0))
719     # Versions comparisons don't quite work well with beta versions, so ensure
720     # it works for the non-beta version.
721     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
722         raise FatalCheckError(
723             "To build the installer you must have NSIS"
724             " version %s or greater in your path" % nsis_min_version
725         )
727     return ver
730 # And that makensis is 32-bit (but only on Windows).
731 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
732 @checking("for 32-bit NSIS")
733 def nsis_binary_type(nsis):
734     bin_type = windows_binary_type(nsis)
735     if bin_type != "win32":
736         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
738     return "yes"
741 # And any flags we have to give to makensis
742 @depends(host)
743 def nsis_flags(host):
744     if host.kernel != "WINNT":
745         return "-nocd"
746     return ""
749 set_config("MAKENSISU_FLAGS", nsis_flags)
751 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
752 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
755 @template
756 def llvm_tool(name):
757     @depends(host_c_compiler, c_compiler, bindgen_config_paths)
758     def llvm_tool(host_c_compiler, c_compiler, bindgen_config_paths):
759         clang = None
760         for compiler in (host_c_compiler, c_compiler):
761             if compiler and compiler.type == "clang":
762                 clang = compiler.compiler
763                 break
764             elif compiler and compiler.type == "clang-cl":
765                 clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
766                 break
768         if not clang and bindgen_config_paths:
769             clang = bindgen_config_paths.clang_path
770         tool = name
771         if clang:
772             out = check_cmd_output(
773                 clang, "--print-prog-name=%s" % tool, onerror=lambda: None
774             )
775             if out:
776                 tool = out.rstrip()
777         return (tool,)
779     return llvm_tool
782 llvm_objdump = check_prog(
783     "LLVM_OBJDUMP",
784     llvm_tool("llvm-objdump"),
785     what="llvm-objdump",
786     when="--enable-compile-environment",
787     paths=clang_search_path,
790 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
793 @depends(llvm_tool("llvm-readelf"), toolchain_prefix)
794 def readelf(llvm_readelf, toolchain_prefix):
795     commands = [llvm_readelf[0], "readelf"]
796     for prefix in toolchain_prefix or ():
797         commands.insert(1, "%sreadelf" % prefix)
798     return tuple(commands)
801 def validate_readelf(path):
802     # llvm-readelf from llvm < 8 doesn't support the GNU binutils-compatible `-d`
803     # flag. We could try running `$path -d $some_binary` but we might be cross
804     # compiling and not have a binary at hand to run that against. `$path -d` alone
805     # would fail whether the flag is supported or not. So we resort to look for the
806     # option in the `--help` output, which fortunately, s compatible between
807     # llvm-readelf and readelf.
808     retcode, stdout, stderr = get_cmd_output(path, "--help")
809     return retcode == 0 and any(l.startswith("  -d ") for l in stdout.splitlines())
812 @depends("--enable-compile-environment", target, host)
813 def readelf_when(compile_env, target, host):
814     return compile_env and any(
815         x.kernel not in ("Darwin", "WINNT") for x in (target, host)
816     )
819 check_prog(
820     "READELF",
821     readelf,
822     when=readelf_when,
823     paths=clang_search_path,
824     validate=validate_readelf,
828 @depends(llvm_tool("llvm-objcopy"), toolchain_prefix)
829 def objcopy(llvm_objcopy, toolchain_prefix):
830     commands = [llvm_objcopy[0], "objcopy"]
831     for prefix in toolchain_prefix or ():
832         commands.insert(1, "%sreadelf" % prefix)
833     return tuple(commands)
836 def validate_objcopy(path):
837     if "llvm-objcopy" not in path:
838         return True
839     # llvm-objcopy doesn't support --only-keep-debug before llvm 9.0.
840     retcode, stdout, stderr = get_cmd_output(path, "--help")
841     return retcode == 0 and any(
842         l.startswith("  --only-keep-debug ") for l in stdout.splitlines()
843     )
846 check_prog(
847     "OBJCOPY",
848     objcopy,
849     when=readelf_when,
850     paths=clang_search_path,
851     validate=validate_objcopy,
854 option("--enable-dtrace", help="Build with dtrace support")
856 dtrace = check_header(
857     "sys/sdt.h",
858     when="--enable-dtrace",
859     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
862 set_config("HAVE_DTRACE", True, when=dtrace)
863 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
864 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
867 option("--disable-icf", help="Disable Identical Code Folding")
869 add_old_configure_assignment(
870     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
874 option(
875     "--enable-strip",
876     when=compile_environment,
877     help="Enable stripping of libs & executables",
880 # This should be handled as a `when` once bug 1617793 is fixed.
883 @depends("--enable-strip", c_compiler, when=compile_environment)
884 def enable_strip(strip, c_compiler):
885     if strip and c_compiler.type != "clang-cl":
886         return True
889 set_config("ENABLE_STRIP", enable_strip)
891 option(
892     "--disable-install-strip",
893     when=compile_environment,
894     help="Enable stripping of libs & executables when packaging",
897 # This should be handled as a `when` once bug 1617793 is fixed.
900 @depends("--enable-install-strip", c_compiler, when=compile_environment)
901 def enable_install_strip(strip, c_compiler):
902     if strip and c_compiler.type != "clang-cl":
903         return True
906 set_config("PKG_STRIP", enable_install_strip)
909 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
910 def strip(strip, install_strip):
911     return strip or install_strip
914 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
917 @depends("STRIP_FLAGS", profiling, target, when=strip)
918 def strip_flags(flags, profiling, target):
919     if flags:
920         return flags[0].split()
921     if profiling:
922         # Only strip debug info and symbols when profiling is enabled, keeping
923         # local symbols.
924         if target.kernel == "Darwin":
925             return ["-S"]
926         elif target.os == "Android":
927             # The tooling we use with Android supports detached symbols, and the
928             # size increase caused by local symbols are too much for mobile. So,
929             # don't restrict the amount of stripping with a flag.
930             return
931         else:
932             return ["--strip-debug"]
933     # Otherwise strip everything we can, which happens without flags on non-Darwin.
934     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
935     elif target.kernel == "Darwin":
936         return ["-x", "-S"]
939 set_config("STRIP_FLAGS", strip_flags)
942 @depends(llvm_tool("llvm-strip"), toolchain_prefix, target)
943 def strip(llvm_strip, toolchain_prefix, target):
944     commands = ["strip"]
945     for prefix in toolchain_prefix or ():
946         commands.insert(0, "%sstrip" % prefix)
947     # llvm-strip causes some problems on macos targets.
948     if target.kernel == "Darwin":
949         commands.append(llvm_strip[0])
950     else:
951         commands.insert(0, llvm_strip[0])
952     return tuple(commands)
955 def validate_strip(path):
956     if "llvm-strip" not in path:
957         return True
958     # llvm-strip doesn't support -S before llvm 8.0.
959     retcode, stdout, stderr = get_cmd_output(path, "--help")
960     return retcode == 0 and any(l.startswith("  -S ") for l in stdout.splitlines())
963 @depends("--enable-compile-environment", target, host)
964 def strip_when(compile_env, target, host):
965     return compile_env and any(x.kernel != "WINNT" for x in (target, host))
968 check_prog(
969     "STRIP",
970     strip,
971     when=strip_when,
972     paths=clang_search_path,
973     validate=validate_strip,
977 @depends(js_standalone, target)
978 def system_zlib_default(js_standalone, target):
979     return (
980         js_standalone
981         and target.kernel not in ("WINNT", "Darwin")
982         and target.os != "Android"
983     )
986 option(
987     "--with-system-zlib",
988     nargs="?",
989     default=system_zlib_default,
990     help="{Use|Do not use} system libz",
994 @depends("--with-system-zlib")
995 def deprecated_system_zlib_path(value):
996     if len(value) == 1:
997         die(
998             "--with-system-zlib=PATH is not supported anymore. Please use "
999             "--with-system-zlib and set any necessary pkg-config environment variable."
1000         )
1003 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
1005 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1008 @depends("--with-system-zlib", js_shared, moz_linker, target.os)
1009 def zlib_in_mozglue(system_zlib, js_shared, linker, os):
1010     if not system_zlib and (js_shared or linker or os == "Android"):
1011         return True
1014 set_config("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
1015 set_define("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
1018 # Please do not add configure checks from here on.
1020 # Fallthrough to autoconf-based configure
1021 include("build/moz.configure/old.configure")
1023 # JS Subconfigure.
1024 include("js/sub.configure", when=compile_environment & toolkit)
1027 @depends(build_environment, configure_cache)
1028 @imports(_import="json")
1029 @imports(_from="pathlib", _import="Path")
1030 def save_cache(build_environment, configure_cache):
1031     cache_file = Path(build_environment.topobjdir) / "configure.cache"
1033     with cache_file.open(mode="w") as fd:
1034         json.dump(configure_cache, fd, indent=4)
1037 @depends(build_environment, build_project)
1038 @imports("__sandbox__")
1039 @imports("glob")
1040 @imports(_from="os.path", _import="exists")
1041 def config_status_deps(build_env, build_project):
1043     topsrcdir = build_env.topsrcdir
1044     topobjdir = build_env.topobjdir
1046     if not topobjdir.endswith("js/src"):
1047         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
1048     else:
1049         # mozconfig changes may impact js configure.
1050         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
1052     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
1053     if exists(confvars):
1054         extra_deps.append(confvars)
1056     return (
1057         list(__sandbox__._all_paths)
1058         + extra_deps
1059         + [
1060             os.path.join(topsrcdir, "CLOBBER"),
1061             os.path.join(topsrcdir, "configure"),
1062             os.path.join(topsrcdir, "js", "src", "configure"),
1063             os.path.join(topsrcdir, "nsprpub", "configure"),
1064             os.path.join(topsrcdir, "config", "milestone.txt"),
1065             os.path.join(topsrcdir, "browser", "config", "version.txt"),
1066             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
1067             os.path.join(topsrcdir, "python", "sites", "build.txt"),
1068             os.path.join(topsrcdir, "python", "sites", "common.txt"),
1069             os.path.join(topsrcdir, "python", "sites", "mach.txt"),
1070             os.path.join(topsrcdir, "python", "mach", "mach", "site.py"),
1071             os.path.join(topsrcdir, "aclocal.m4"),
1072             os.path.join(topsrcdir, "old-configure.in"),
1073             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1074             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1075         ]
1076         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1077     )
1080 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1081 # Please do not add anything after setting config_dep_paths.