Bug 1780466 - Increase fuzzy tolerance due to new R-wr-dc3-c variant. r=gfx-reviewers...
[gecko.git] / moz.configure
blob95763e2c878102d4bfe9d7676b54b04bfea6e334
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_option("--enable-release", mozilla_official)
158 imply_option("--enable-release", depends_if("MOZ_AUTOMATION")(lambda x: True))
160 option(
161     "--enable-release",
162     default=milestone.is_release_or_beta,
163     help="{Build|Do not build} with more conservative, release "
164     "engineering-oriented options.{ This may slow down builds.|}",
168 @depends("--enable-release")
169 def developer_options(value):
170     if not value:
171         return True
174 add_old_configure_assignment("DEVELOPER_OPTIONS", developer_options)
175 set_config("DEVELOPER_OPTIONS", developer_options)
178 # hybrid build handling
179 # ==============================================================
181 option(
182     "--disable-unified-build",
183     help="Enable building modules that are not marked with `REQUIRES_UNIFIED_BUILD` in non unified context",
186 set_config("ENABLE_UNIFIED_BUILD", True, when="--disable-unified-build")
189 include("build/moz.configure/bootstrap.configure")
191 # The execution model of the configure sandbox doesn't allow for
192 # check_prog to use bootstrap_search_path directly because check_prog
193 # comes first, so we use a trick to allow it. Uses of check_prog
194 # happening before here won't allow bootstrap.
195 @template
196 def check_prog(*args, **kwargs):
197     kwargs["bootstrap_search_path"] = bootstrap_search_path
198     return check_prog(*args, **kwargs)
201 check_prog("WGET", ("wget",), allow_missing=True)
204 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
206 include("build/moz.configure/pkg.configure")
207 # Make this assignment here rather than in pkg.configure to avoid
208 # requiring this file in unit tests.
209 add_old_configure_assignment("PKG_CONFIG", pkg_config)
211 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
212 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
213 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
214 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
215 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
216 # rust.configure is included by js/moz.configure.
218 option("--enable-valgrind", help="Enable Valgrind integration hooks")
220 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
223 @depends("--enable-valgrind", valgrind_h)
224 def check_valgrind(valgrind, valgrind_h):
225     if valgrind:
226         if not valgrind_h:
227             die("--enable-valgrind specified but Valgrind is not installed")
228         return True
231 set_define("MOZ_VALGRIND", check_valgrind)
232 set_config("MOZ_VALGRIND", check_valgrind)
235 @depends(target, host)
236 def is_openbsd(target, host):
237     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
240 option(
241     env="SO_VERSION",
242     nargs=1,
243     default="1.0",
244     when=is_openbsd,
245     help="Shared library version for OpenBSD systems",
249 @depends("SO_VERSION", when=is_openbsd)
250 def so_version(value):
251     return value
254 @template
255 def library_name_info_template(host_or_target):
256     assert host_or_target in {host, target}
257     compiler = {
258         host: host_c_compiler,
259         target: c_compiler,
260     }[host_or_target]
262     @depends(host_or_target, compiler, so_version)
263     def library_name_info_impl(host_or_target, compiler, so_version):
264         if host_or_target.kernel == "WINNT":
265             # There aren't artifacts for mingw builds, so it's OK that the
266             # results are inaccurate in that case.
267             if compiler and compiler.type != "clang-cl":
268                 return namespace(
269                     dll=namespace(prefix="", suffix=".dll"),
270                     lib=namespace(prefix="lib", suffix="a"),
271                     import_lib=namespace(prefix="lib", suffix="a"),
272                     obj=namespace(prefix="", suffix="o"),
273                 )
275             return namespace(
276                 dll=namespace(prefix="", suffix=".dll"),
277                 lib=namespace(prefix="", suffix="lib"),
278                 import_lib=namespace(prefix="", suffix="lib"),
279                 obj=namespace(prefix="", suffix="obj"),
280             )
282         elif host_or_target.kernel == "Darwin":
283             return namespace(
284                 dll=namespace(prefix="lib", suffix=".dylib"),
285                 lib=namespace(prefix="lib", suffix="a"),
286                 import_lib=namespace(prefix=None, suffix=""),
287                 obj=namespace(prefix="", suffix="o"),
288             )
289         elif so_version:
290             so = ".so.%s" % so_version
291         else:
292             so = ".so"
294         return namespace(
295             dll=namespace(prefix="lib", suffix=so),
296             lib=namespace(prefix="lib", suffix="a"),
297             import_lib=namespace(prefix=None, suffix=""),
298             obj=namespace(prefix="", suffix="o"),
299         )
301     return library_name_info_impl
304 host_library_name_info = library_name_info_template(host)
305 library_name_info = library_name_info_template(target)
307 set_config("DLL_PREFIX", library_name_info.dll.prefix)
308 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
309 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
310 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
311 set_config("LIB_PREFIX", library_name_info.lib.prefix)
312 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
313 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
314 # Lots of compilation tests depend on this variable being present.
315 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
316 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
317 set_define(
318     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
320 set_define(
321     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
323 set_config("HOST_LIB_PREFIX", host_library_name_info.lib.prefix)
324 set_config("HOST_IMPORT_LIB_SUFFIX", host_library_name_info.import_lib.suffix)
325 set_config("WASM_OBJ_SUFFIX", "wasm")
327 # Make `profiling` available to this file even when js/moz.configure
328 # doesn't end up included.
329 profiling = dependable(False)
330 # Same for js_standalone
331 js_standalone = dependable(False)
332 js_shared = dependable(False)
333 moz_linker = dependable(False)
334 # Same for fold_libs
335 fold_libs = dependable(False)
336 # And dmd
337 dmd = dependable(False)
339 include(include_project_configure)
342 @depends("--help")
343 @imports(_from="mozbuild.backend", _import="backends")
344 def build_backends_choices(_):
345     return tuple(backends)
348 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
349 def build_backend(backends):
350     if backends:
351         return tuple("+%s" % b for b in backends)
354 imply_option("--build-backends", build_backend)
357 @depends(
358     host,
359     target,
360     "--enable-artifact-builds",
361     "--disable-compile-environment",
362     "--enable-build-backend",
363     "--enable-project",
364     "--enable-application",
365     "--help",
367 @imports("sys")
368 @imports(_from="mozbuild.backend.clangd", _import="find_vscode_cmd")
369 def build_backend_defaults(
370     host,
371     target,
372     artifact_builds,
373     compile_environment,
374     requested_backends,
375     project,
376     application,
377     _,
379     if application:
380         project = application[0]
381     elif project:
382         project = project[0]
384     if "Tup" in requested_backends:
385         # As a special case, if Tup was requested, do not combine it with any
386         # Make based backend by default.
387         all_backends = []
388     elif artifact_builds:
389         all_backends = ["FasterMake+RecursiveMake"]
390     else:
391         all_backends = ["RecursiveMake", "FasterMake"]
392     if (
393         host.os == "WINNT"
394         and target.os == "WINNT"
395         and compile_environment
396         and project not in ("mobile/android", "memory", "tools/update-programs")
397     ):
398         all_backends.append("VisualStudio")
399     if (
400         compile_environment
401         and find_vscode_cmd()
402         and project not in ("mobile/android", "memory", "tools/update-programs")
403     ):
404         all_backends.append("Clangd")
405     return tuple(all_backends) or None
408 option(
409     "--build-backends",
410     nargs="+",
411     default=build_backend_defaults,
412     choices=build_backends_choices,
413     help="Build backends to generate",
417 @depends("--build-backends")
418 def build_backends(backends):
419     return backends
422 set_config("BUILD_BACKENDS", build_backends)
425 @depends(build_environment, build_backends)
426 @imports("glob")
427 def check_objdir_backend_reuse(build_env, backends):
428     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
429     # intentionally vague for use with the substring match below.
430     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
431     for backend_file in glob.iglob(
432         os.path.join(build_env.topobjdir, "backend.*Backend")
433     ):
434         for prev, curr in incompatible_backends:
435             if prev in backend_file and any(curr in b for b in backends):
436                 die(
437                     "The active objdir, %s, was previously "
438                     "used to build with a %s based backend. "
439                     "Change objdirs (by setting MOZ_OBJDIR in "
440                     "your mozconfig) or clobber to continue.\n",
441                     build_env.topobjdir,
442                     prev,
443                 )
446 # Determine whether to build the gtest xul. This happens in automation
447 # on Android and Desktop platforms with the exception of:
448 #  - Windows PGO, where linking xul-gtest.dll takes too long;
449 #  - Android other than x86_64, where gtest is not required.
450 @depends(
451     build_project,
452     target,
453     "MOZ_AUTOMATION",
454     enable_tests,
455     when="--enable-compile-environment",
457 def build_gtest(build_project, target, automation, enable_tests):
458     return bool(
459         enable_tests
460         and automation
461         and build_project in ("browser", "comm/mail", "mobile/android")
462         and not (target.os == "Android" and target.cpu != "x86_64")
463     )
466 option(
467     "--enable-gtest-in-build",
468     default=build_gtest,
469     help="{Enable|Force disable} building the gtest libxul during the build.",
470     when="--enable-compile-environment",
473 set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build")
475 # Localization
476 # ==============================================================
477 option(
478     "--enable-ui-locale",
479     default="en-US",
480     help="Select the user interface locale (default: en-US)",
483 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
485 option(
486     "--enable-icu4x",
487     help="An experiment to use ICU4X instead of ICU4C. See intl/ICU4X.md",
490 set_config("MOZ_ICU4X", True, when="--enable-icu4x")
492 # clang-plugin location
493 # ==============================================================
496 @depends(host_library_name_info, build_environment, when="--enable-clang-plugin")
497 def clang_plugin_path(library_name_info, build_env):
498     topobjdir = build_env.topobjdir
499     if topobjdir.endswith("/js/src"):
500         topobjdir = topobjdir[:-7]
501     return os.path.abspath(
502         os.path.join(
503             topobjdir,
504             "build",
505             "clang-plugin",
506             "%sclang-plugin%s"
507             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
508         )
509     )
512 set_config("CLANG_PLUGIN", clang_plugin_path)
513 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
516 # Awk detection
517 # ==============================================================
518 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
520 # Until the AWK variable is not necessary in old-configure
523 @depends(awk)
524 def awk_for_old_configure(value):
525     return value
528 add_old_configure_assignment("AWK", awk_for_old_configure)
531 # Perl detection
532 # ==============================================================
533 perl = check_prog("PERL", ("perl5", "perl"))
535 # Until the PERL variable is not necessary in old-configure
538 @depends(perl)
539 def perl_for_old_configure(value):
540     return value
543 add_old_configure_assignment("PERL", perl_for_old_configure)
546 @template
547 def perl_version_check(min_version):
548     @depends(perl)
549     @checking("for minimum required perl version >= %s" % min_version)
550     def get_perl_version(perl):
551         return Version(
552             check_cmd_output(
553                 perl,
554                 "-e",
555                 "print $]",
556                 onerror=lambda: die("Failed to get perl version."),
557             )
558         )
560     @depends(get_perl_version)
561     def check_perl_version(version):
562         if version < min_version:
563             die("Perl %s or higher is required.", min_version)
565     @depends(perl)
566     @checking("for full perl installation")
567     @imports("subprocess")
568     def has_full_perl_installation(perl):
569         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
570         return ret == 0
572     @depends(has_full_perl_installation)
573     def require_full_perl_installation(has_full_perl_installation):
574         if not has_full_perl_installation:
575             die(
576                 "Cannot find Config.pm or $Config{archlib}. "
577                 "A full perl installation is required."
578             )
581 perl_version_check("5.006")
584 # GNU make detection
585 # ==============================================================
586 option(env="MAKE", nargs=1, help="Path to GNU make")
589 @depends("MAKE", host)
590 def possible_makes(make, host):
591     candidates = []
592     if make:
593         candidates.append(make[0])
594     if host.kernel == "WINNT":
595         candidates.extend(("mozmake", "mingw32-make", "make", "gmake"))
596     else:
597         candidates.extend(("gmake", "make"))
598     return candidates
601 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
603 # watchman detection
604 # ==============================================================
606 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
609 @depends(host, "WATCHMAN")
610 @checking("for watchman", callback=lambda w: w.path if w else "not found")
611 def watchman(host, prog):
612     # On Windows, `watchman` is only supported on 64-bit hosts.
613     if host.os == "WINNT" and host.cpu != "x86_64":
614         return
616     if not prog:
617         prog = find_program("watchman")
619     if not prog:
620         return
622     # `watchman version` will talk to the Watchman daemon service.
623     # This can hang due to permissions problems. e.g.
624     # https://github.com/facebook/watchman/issues/376. So use
625     # `watchman --version` to prevent a class of failures.
626     out = check_cmd_output(prog, "--version", onerror=lambda: None)
627     if out is None:
628         return
630     return namespace(path=prog, version=Version(out.strip()))
633 @depends_if(watchman)
634 @checking("for watchman version")
635 def watchman_version(w):
636     return w.version
639 set_config("WATCHMAN", watchman.path)
642 @depends_all(hg_version, hg_config, watchman)
643 @checking("for watchman Mercurial integration")
644 @imports("os")
645 def watchman_hg(hg_version, hg_config, watchman):
646     if hg_version < Version("3.8"):
647         return "no (Mercurial 3.8+ required)"
649     ext_enabled = False
650     mode_disabled = False
652     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
653         if k in hg_config and hg_config[k] != "!":
654             ext_enabled = True
656     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
658     if not ext_enabled:
659         return "no (fsmonitor extension not enabled)"
660     if mode_disabled:
661         return "no (fsmonitor.mode=off disables fsmonitor)"
663     return True
666 # Miscellaneous programs
667 # ==============================================================
668 check_prog("XARGS", ("xargs",))
671 @depends(target)
672 def extra_programs(target):
673     if target.kernel == "Darwin":
674         return namespace(
675             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
676             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
677             HFS_TOOL=("hfsplus",),
678         )
679     if target.os == "GNU" and target.kernel == "Linux":
680         return namespace(RPMBUILD=("rpmbuild",))
683 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
684 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
685 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
686 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
689 nsis = check_prog(
690     "MAKENSISU",
691     ("makensis",),
692     bootstrap="nsis/bin",
693     allow_missing=True,
694     when=target_is_windows,
697 # Make sure the version of makensis is up to date.
700 @depends_if(nsis)
701 @checking("for NSIS version")
702 @imports("re")
703 def nsis_version(nsis):
704     nsis_min_version = "3.0b1"
706     def onerror():
707         return die("Failed to get nsis version.")
709     out = check_cmd_output(nsis, "-version", onerror=onerror)
711     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
713     if not m:
714         raise FatalCheckError("Unknown version of makensis")
715     ver = Version(m.group(0))
717     # Versions comparisons don't quite work well with beta versions, so ensure
718     # it works for the non-beta version.
719     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
720         raise FatalCheckError(
721             "To build the installer you must have NSIS"
722             " version %s or greater in your path" % nsis_min_version
723         )
725     return ver
728 # And that makensis is 32-bit (but only on Windows).
729 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
730 @checking("for 32-bit NSIS")
731 def nsis_binary_type(nsis):
732     bin_type = windows_binary_type(nsis)
733     if bin_type != "win32":
734         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
736     return "yes"
739 # And any flags we have to give to makensis
740 @depends(host)
741 def nsis_flags(host):
742     if host.kernel != "WINNT":
743         return "-nocd"
744     return ""
747 set_config("MAKENSISU_FLAGS", nsis_flags)
749 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
750 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
753 @template
754 def llvm_tool(name):
755     @depends(host_c_compiler, c_compiler, bindgen_config_paths)
756     def llvm_tool(host_c_compiler, c_compiler, bindgen_config_paths):
757         clang = None
758         for compiler in (host_c_compiler, c_compiler):
759             if compiler and compiler.type == "clang":
760                 clang = compiler.compiler
761                 break
762             elif compiler and compiler.type == "clang-cl":
763                 clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
764                 break
766         if not clang and bindgen_config_paths:
767             clang = bindgen_config_paths.clang_path
768         tool = name
769         if clang:
770             out = check_cmd_output(
771                 clang, "--print-prog-name=%s" % tool, onerror=lambda: None
772             )
773             if out:
774                 tool = out.rstrip()
775         return (tool,)
777     return llvm_tool
780 llvm_objdump = check_prog(
781     "LLVM_OBJDUMP",
782     llvm_tool("llvm-objdump"),
783     what="llvm-objdump",
784     when="--enable-compile-environment",
785     paths=clang_search_path,
788 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
791 @depends(llvm_tool("llvm-readelf"), toolchain_prefix)
792 def readelf(llvm_readelf, toolchain_prefix):
793     commands = [llvm_readelf[0], "readelf"]
794     for prefix in toolchain_prefix or ():
795         commands.insert(1, "%sreadelf" % prefix)
796     return tuple(commands)
799 def validate_readelf(path):
800     # llvm-readelf from llvm < 8 doesn't support the GNU binutils-compatible `-d`
801     # flag. We could try running `$path -d $some_binary` but we might be cross
802     # compiling and not have a binary at hand to run that against. `$path -d` alone
803     # would fail whether the flag is supported or not. So we resort to look for the
804     # option in the `--help` output, which fortunately, s compatible between
805     # llvm-readelf and readelf.
806     retcode, stdout, stderr = get_cmd_output(path, "--help")
807     return retcode == 0 and any(l.startswith("  -d ") for l in stdout.splitlines())
810 @depends("--enable-compile-environment", target, host)
811 def readelf_when(compile_env, target, host):
812     return compile_env and any(
813         x.kernel not in ("Darwin", "WINNT") for x in (target, host)
814     )
817 check_prog(
818     "READELF",
819     readelf,
820     when=readelf_when,
821     paths=clang_search_path,
822     validate=validate_readelf,
826 @depends(llvm_tool("llvm-objcopy"), toolchain_prefix)
827 def objcopy(llvm_objcopy, toolchain_prefix):
828     commands = [llvm_objcopy[0], "objcopy"]
829     for prefix in toolchain_prefix or ():
830         commands.insert(1, "%sreadelf" % prefix)
831     return tuple(commands)
834 def validate_objcopy(path):
835     if "llvm-objcopy" not in path:
836         return True
837     # llvm-objcopy doesn't support --only-keep-debug before llvm 9.0.
838     retcode, stdout, stderr = get_cmd_output(path, "--help")
839     return retcode == 0 and any(
840         l.startswith("  --only-keep-debug ") for l in stdout.splitlines()
841     )
844 check_prog(
845     "OBJCOPY",
846     objcopy,
847     when=readelf_when,
848     paths=clang_search_path,
849     validate=validate_objcopy,
852 option("--enable-dtrace", help="Build with dtrace support")
854 dtrace = check_header(
855     "sys/sdt.h",
856     when="--enable-dtrace",
857     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
860 set_config("HAVE_DTRACE", True, when=dtrace)
861 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
862 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
865 option("--disable-icf", help="Disable Identical Code Folding")
867 add_old_configure_assignment(
868     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
872 option(
873     "--enable-strip",
874     when=compile_environment,
875     help="Enable stripping of libs & executables",
878 # This should be handled as a `when` once bug 1617793 is fixed.
881 @depends("--enable-strip", c_compiler, when=compile_environment)
882 def enable_strip(strip, c_compiler):
883     if strip and c_compiler.type != "clang-cl":
884         return True
887 set_config("ENABLE_STRIP", enable_strip)
889 option(
890     "--disable-install-strip",
891     when=compile_environment,
892     help="Enable stripping of libs & executables when packaging",
895 # This should be handled as a `when` once bug 1617793 is fixed.
898 @depends("--enable-install-strip", c_compiler, when=compile_environment)
899 def enable_install_strip(strip, c_compiler):
900     if strip and c_compiler.type != "clang-cl":
901         return True
904 set_config("PKG_STRIP", enable_install_strip)
907 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
908 def strip(strip, install_strip):
909     return strip or install_strip
912 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
915 @depends("STRIP_FLAGS", profiling, target, when=strip)
916 def strip_flags(flags, profiling, target):
917     if flags:
918         return flags[0].split()
919     if profiling:
920         # Only strip debug info and symbols when profiling is enabled, keeping
921         # local symbols.
922         if target.kernel == "Darwin":
923             return ["-S"]
924         elif target.os == "Android":
925             # The tooling we use with Android supports detached symbols, and the
926             # size increase caused by local symbols are too much for mobile. So,
927             # don't restrict the amount of stripping with a flag.
928             return
929         else:
930             return ["--strip-debug"]
931     # Otherwise strip everything we can, which happens without flags on non-Darwin.
932     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
933     elif target.kernel == "Darwin":
934         return ["-x", "-S"]
937 set_config("STRIP_FLAGS", strip_flags)
940 @depends(llvm_tool("llvm-strip"), toolchain_prefix, target)
941 def strip(llvm_strip, toolchain_prefix, target):
942     commands = ["strip"]
943     for prefix in toolchain_prefix or ():
944         commands.insert(0, "%sstrip" % prefix)
945     # llvm-strip causes some problems on macos targets.
946     if target.kernel == "Darwin":
947         commands.append(llvm_strip[0])
948     else:
949         commands.insert(0, llvm_strip[0])
950     return tuple(commands)
953 def validate_strip(path):
954     if "llvm-strip" not in path:
955         return True
956     # llvm-strip doesn't support -S before llvm 8.0.
957     retcode, stdout, stderr = get_cmd_output(path, "--help")
958     return retcode == 0 and any(l.startswith("  -S ") for l in stdout.splitlines())
961 @depends("--enable-compile-environment", target, host)
962 def strip_when(compile_env, target, host):
963     return compile_env and any(x.kernel != "WINNT" for x in (target, host))
966 check_prog(
967     "STRIP",
968     strip,
969     when=strip_when,
970     paths=clang_search_path,
971     validate=validate_strip,
975 @depends(js_standalone, target)
976 def system_zlib_default(js_standalone, target):
977     return js_standalone and target.kernel not in ("WINNT", "Darwin")
980 option(
981     "--with-system-zlib",
982     nargs="?",
983     default=system_zlib_default,
984     help="{Use|Do not use} system libz",
988 @depends("--with-system-zlib")
989 def deprecated_system_zlib_path(value):
990     if len(value) == 1:
991         die(
992             "--with-system-zlib=PATH is not supported anymore. Please use "
993             "--with-system-zlib and set any necessary pkg-config environment variable."
994         )
997 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
999 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1002 @depends("--with-system-zlib", js_shared, moz_linker, target.os)
1003 def zlib_in_mozglue(system_zlib, js_shared, linker, os):
1004     if not system_zlib and (js_shared or linker or os == "Android"):
1005         return True
1008 set_config("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
1009 set_define("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
1012 # Please do not add configure checks from here on.
1014 # Fallthrough to autoconf-based configure
1015 include("build/moz.configure/old.configure")
1017 # JS Subconfigure.
1018 include("js/sub.configure", when=compile_environment & toolkit)
1021 @depends(build_environment, build_project)
1022 @imports("__sandbox__")
1023 @imports("glob")
1024 @imports(_from="os.path", _import="exists")
1025 def config_status_deps(build_env, build_project):
1027     topsrcdir = build_env.topsrcdir
1028     topobjdir = build_env.topobjdir
1030     if not topobjdir.endswith("js/src"):
1031         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
1032     else:
1033         # mozconfig changes may impact js configure.
1034         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
1036     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
1037     if exists(confvars):
1038         extra_deps.append(confvars)
1040     return (
1041         list(__sandbox__._all_paths)
1042         + extra_deps
1043         + [
1044             os.path.join(topsrcdir, "CLOBBER"),
1045             os.path.join(topsrcdir, "configure.in"),
1046             os.path.join(topsrcdir, "js", "src", "configure.in"),
1047             os.path.join(topsrcdir, "nsprpub", "configure"),
1048             os.path.join(topsrcdir, "config", "milestone.txt"),
1049             os.path.join(topsrcdir, "browser", "config", "version.txt"),
1050             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
1051             os.path.join(topsrcdir, "python", "sites", "build.txt"),
1052             os.path.join(topsrcdir, "python", "sites", "common.txt"),
1053             os.path.join(topsrcdir, "python", "sites", "mach.txt"),
1054             os.path.join(topsrcdir, "python", "mach", "mach", "site.py"),
1055             os.path.join(topsrcdir, "aclocal.m4"),
1056             os.path.join(topsrcdir, "old-configure.in"),
1057             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1058             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1059         ]
1060         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1061     )
1064 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1065 # Please do not add anything after setting config_dep_paths.