Bug 1881551 - Mark replacestate.tentative.html as intermittent on mac !debug. a=test...
[gecko.git] / moz.configure
blob79d5c269a416c52e9aff077cf32410a0682d7c20
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 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 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
210 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
211 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
212 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
213 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
214 # rust.configure is included by js/moz.configure.
216 option("--enable-valgrind", help="Enable Valgrind integration hooks")
218 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
221 @depends("--enable-valgrind", valgrind_h)
222 def check_valgrind(valgrind, valgrind_h):
223     if valgrind:
224         if not valgrind_h:
225             die("--enable-valgrind specified but Valgrind is not installed")
226         return True
229 set_define("MOZ_VALGRIND", check_valgrind)
230 set_config("MOZ_VALGRIND", check_valgrind)
233 @depends(target, host)
234 def is_openbsd(target, host):
235     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
238 option(
239     env="SO_VERSION",
240     nargs=1,
241     default="1.0",
242     when=is_openbsd,
243     help="Shared library version for OpenBSD systems",
247 @depends("SO_VERSION", when=is_openbsd)
248 def so_version(value):
249     return value
252 @template
253 def library_name_info_template(host_or_target):
254     assert host_or_target in {host, target}
255     windows_abi = {
256         host: host_windows_abi,
257         target: target_windows_abi,
258     }[host_or_target]
260     @depends(host_or_target, host_or_target.abi | windows_abi, so_version)
261     def library_name_info_impl(host_or_target, windows_abi, so_version):
262         if host_or_target.kernel == "WINNT":
263             # There aren't artifacts for mingw builds, so it's OK that the
264             # results are inaccurate in that case.
265             if windows_abi and windows_abi != "msvc":
266                 return namespace(
267                     dll=namespace(prefix="", suffix=".dll"),
268                     lib=namespace(prefix="lib", suffix="a"),
269                     import_lib=namespace(prefix="lib", suffix="a"),
270                     obj=namespace(prefix="", suffix="o"),
271                 )
273             return namespace(
274                 dll=namespace(prefix="", suffix=".dll"),
275                 lib=namespace(prefix="", suffix="lib"),
276                 import_lib=namespace(prefix="", suffix="lib"),
277                 obj=namespace(prefix="", suffix="obj"),
278             )
280         elif host_or_target.kernel == "Darwin":
281             return namespace(
282                 dll=namespace(prefix="lib", suffix=".dylib"),
283                 lib=namespace(prefix="lib", suffix="a"),
284                 import_lib=namespace(prefix=None, suffix=""),
285                 obj=namespace(prefix="", suffix="o"),
286             )
287         elif so_version:
288             so = ".so.%s" % so_version
289         else:
290             so = ".so"
292         return namespace(
293             dll=namespace(prefix="lib", suffix=so),
294             lib=namespace(prefix="lib", suffix="a"),
295             import_lib=namespace(prefix=None, suffix=""),
296             obj=namespace(prefix="", suffix="o"),
297         )
299     return library_name_info_impl
302 host_library_name_info = library_name_info_template(host)
303 library_name_info = library_name_info_template(target)
305 set_config("DLL_PREFIX", library_name_info.dll.prefix)
306 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
307 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
308 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
309 set_config("LIB_PREFIX", library_name_info.lib.prefix)
310 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
311 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
312 # Lots of compilation tests depend on this variable being present.
313 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
314 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
315 set_define(
316     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
318 set_define(
319     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
321 set_config("HOST_LIB_PREFIX", host_library_name_info.lib.prefix)
322 set_config("HOST_IMPORT_LIB_SUFFIX", host_library_name_info.import_lib.suffix)
323 set_config("WASM_OBJ_SUFFIX", "wasm")
326 @template
327 def llvm_tool(name):
328     @depends(host_c_compiler, c_compiler, bindgen_config_paths)
329     def llvm_tool(host_c_compiler, c_compiler, bindgen_config_paths):
330         clang = None
331         for compiler in (host_c_compiler, c_compiler):
332             if compiler and compiler.type == "clang":
333                 clang = compiler.compiler
334                 break
335             elif compiler and compiler.type == "clang-cl":
336                 clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
337                 break
339         if not clang and bindgen_config_paths:
340             clang = bindgen_config_paths.clang_path
341         tool = name
342         if clang:
343             out = check_cmd_output(
344                 clang, "--print-prog-name=%s" % tool, onerror=lambda: None
345             )
346             if out:
347                 tool = out.rstrip()
348         return (tool,)
350     return llvm_tool
353 @template
354 def plain_llvm_or_prefixed(name, llvm_name=None):
355     # look for a tool, using the following alternatives, in that order:
356     # 1. llvm-${llvm_name}, or llvm-${name} if ${llvm_name} is not provided
357     # 2. ${toolchain_prefix}${name}
358     # 3. ${name}
360     @depends(llvm_tool("llvm-{}".format(llvm_name or name)), toolchain_prefix)
361     def plain_llvm_or_prefixed(llvm_tool, toolchain_prefix):
362         commands = [llvm_tool[0], name]
363         for prefix in toolchain_prefix or ():
364             commands.insert(1, f"{prefix}{name}")
365         return tuple(commands)
367     return plain_llvm_or_prefixed
370 llvm_objdump = check_prog(
371     "LLVM_OBJDUMP",
372     llvm_tool("llvm-objdump"),
373     what="llvm-objdump",
374     when="--enable-compile-environment",
375     paths=clang_search_path,
378 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
381 def validate_readelf(path):
382     # llvm-readelf from llvm < 8 doesn't support the GNU binutils-compatible `-d`
383     # flag. We could try running `$path -d $some_binary` but we might be cross
384     # compiling and not have a binary at hand to run that against. `$path -d` alone
385     # would fail whether the flag is supported or not. So we resort to look for the
386     # option in the `--help` output, which fortunately, s compatible between
387     # llvm-readelf and readelf.
388     retcode, stdout, stderr = get_cmd_output(path, "--help")
389     return retcode == 0 and any(l.startswith("  -d ") for l in stdout.splitlines())
392 @depends("--enable-compile-environment", target, host)
393 def readelf_when(compile_env, target, host):
394     return compile_env and any(
395         x.kernel not in ("Darwin", "WINNT") for x in (target, host)
396     )
399 readelf = check_prog(
400     "READELF",
401     plain_llvm_or_prefixed("readelf"),
402     when=readelf_when,
403     paths=clang_search_path,
404     validate=validate_readelf,
408 def validate_objcopy(path):
409     if "llvm-objcopy" not in path:
410         return True
411     # llvm-objcopy doesn't support --only-keep-debug before llvm 9.0.
412     retcode, stdout, stderr = get_cmd_output(path, "--help")
413     return retcode == 0 and any(
414         l.startswith("  --only-keep-debug ") for l in stdout.splitlines()
415     )
418 check_prog(
419     "OBJCOPY",
420     plain_llvm_or_prefixed("objcopy"),
421     when=readelf_when,
422     paths=clang_search_path,
423     validate=validate_objcopy,
427 # Make `profiling` available to this file even when js/moz.configure
428 # doesn't end up included.
429 profiling = dependable(False)
430 # Same for js_standalone
431 js_standalone = dependable(False)
432 js_shared = dependable(False)
433 moz_linker = dependable(False)
434 # Same for fold_libs
435 fold_libs = dependable(False)
436 # And dmd
437 dmd = dependable(False)
439 include(include_project_configure)
442 @depends("--help")
443 @imports(_from="mozbuild.backend", _import="backends")
444 def build_backends_choices(_):
445     return tuple(backends)
448 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
449 def build_backend(backends):
450     if backends:
451         return tuple("+%s" % b for b in backends)
454 imply_option("--build-backends", build_backend)
457 @depends(
458     host,
459     target,
460     "--enable-artifact-builds",
461     "--disable-compile-environment",
462     "--enable-project",
463     "--enable-application",
464     "--help",
466 @imports("sys")
467 def build_backend_defaults(
468     host,
469     target,
470     artifact_builds,
471     compile_environment,
472     project,
473     application,
474     _,
476     if application:
477         project = application[0]
478     elif project:
479         project = project[0]
481     if artifact_builds:
482         all_backends = ["FasterMake+RecursiveMake"]
483     else:
484         all_backends = ["RecursiveMake", "FasterMake"]
485     if (
486         host.os == "WINNT"
487         and target.os == "WINNT"
488         and compile_environment
489         and project not in ("mobile/android", "memory", "tools/update-programs")
490     ):
491         all_backends.append("VisualStudio")
492     if compile_environment and project not in ("memory", "tools/update-programs"):
493         all_backends.append("Clangd")
494     return tuple(all_backends) or None
497 option(
498     "--build-backends",
499     nargs="+",
500     default=build_backend_defaults,
501     choices=build_backends_choices,
502     help="Build backends to generate",
506 @depends("--build-backends")
507 def build_backends(backends):
508     return backends
511 set_config("BUILD_BACKENDS", build_backends)
514 # Determine whether to build the gtest xul. This happens in automation
515 # on Android and Desktop platforms with the exception of:
516 #  - Windows PGO, where linking xul-gtest.dll takes too long;
517 #  - Android other than x86_64, where gtest is not required.
518 @depends(
519     build_project,
520     target,
521     "MOZ_AUTOMATION",
522     enable_tests,
523     when="--enable-compile-environment",
525 def build_gtest(build_project, target, automation, enable_tests):
526     return bool(
527         enable_tests
528         and automation
529         and build_project in ("browser", "comm/mail", "mobile/android")
530         and not (target.os == "Android" and target.cpu != "x86_64")
531     )
534 option(
535     "--enable-gtest-in-build",
536     default=build_gtest,
537     help="{Enable|Force disable} building the gtest libxul during the build.",
538     when="--enable-compile-environment",
541 set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build")
543 # Localization
544 # ==============================================================
545 option(
546     "--enable-ui-locale",
547     default="en-US",
548     help="Select the user interface locale (default: en-US)",
551 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
553 option(
554     "--disable-icu4x",
555     help="Disable using ICU4X",
558 set_config("MOZ_ICU4X", True, when="--enable-icu4x")
559 set_define("MOZ_ICU4X", True, when="--enable-icu4x")
561 # clang-plugin location
562 # ==============================================================
565 @depends(host_library_name_info, build_environment, when="--enable-clang-plugin")
566 def clang_plugin_path(library_name_info, build_env):
567     topobjdir = build_env.topobjdir
568     if topobjdir.endswith("/js/src"):
569         topobjdir = topobjdir[:-7]
570     return os.path.abspath(
571         os.path.join(
572             topobjdir,
573             "build",
574             "clang-plugin",
575             "%sclang-plugin%s"
576             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
577         )
578     )
581 set_config("CLANG_PLUGIN", clang_plugin_path)
582 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
585 # Awk detection
586 # ==============================================================
587 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"), paths=prefer_mozillabuild_path)
589 # Until the AWK variable is not necessary in old-configure
592 @depends(awk)
593 def awk_for_old_configure(value):
594     return value
597 add_old_configure_assignment("AWK", awk_for_old_configure)
600 # GNU make detection
601 # ==============================================================
602 option(env="MAKE", nargs=1, help="Path to GNU make")
605 @depends("MAKE", host)
606 def possible_makes(make, host):
607     candidates = []
608     if make:
609         candidates.append(make[0])
610     if host.kernel == "WINNT":
611         candidates.extend(("mozmake", "mingw32-make", "make", "gmake"))
612     else:
613         candidates.extend(("gmake", "make"))
614     return candidates
617 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
619 # watchman detection
620 # ==============================================================
622 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
625 @depends(host, "WATCHMAN")
626 @checking("for watchman", callback=lambda w: w.path if w else "not found")
627 def watchman(host, prog):
628     # On Windows, `watchman` is only supported on 64-bit hosts.
629     if host.os == "WINNT" and host.cpu != "x86_64":
630         return
632     if not prog:
633         prog = find_program("watchman")
635     if not prog:
636         return
638     # `watchman version` will talk to the Watchman daemon service.
639     # This can hang due to permissions problems. e.g.
640     # https://github.com/facebook/watchman/issues/376. So use
641     # `watchman --version` to prevent a class of failures.
642     out = check_cmd_output(prog, "--version", onerror=lambda: None)
643     if out is None:
644         return
646     return namespace(path=prog, version=Version(out.strip()))
649 @depends_if(watchman)
650 @checking("for watchman version")
651 def watchman_version(w):
652     return w.version
655 set_config("WATCHMAN", watchman.path)
658 @depends_all(hg_version, hg_config, watchman)
659 @checking("for watchman Mercurial integration")
660 @imports("os")
661 def watchman_hg(hg_version, hg_config, watchman):
662     if hg_version < Version("3.8"):
663         return "no (Mercurial 3.8+ required)"
665     ext_enabled = False
666     mode_disabled = False
668     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
669         if k in hg_config and hg_config[k] != "!":
670             ext_enabled = True
672     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
674     if not ext_enabled:
675         return "no (fsmonitor extension not enabled)"
676     if mode_disabled:
677         return "no (fsmonitor.mode=off disables fsmonitor)"
679     return True
682 # Miscellaneous programs
683 # ==============================================================
684 check_prog("XARGS", ("xargs",))
687 @depends(target)
688 def extra_programs(target):
689     if target.kernel == "Darwin":
690         return namespace(
691             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
692             HFS_TOOL=("hfsplus",),
693         )
694     if target.os == "GNU" and target.kernel == "Linux":
695         return namespace(RPMBUILD=("rpmbuild",))
698 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
699 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
700 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
703 nsis = check_prog(
704     "MAKENSISU",
705     ("makensis",),
706     bootstrap="nsis/bin",
707     allow_missing=True,
708     when=target_is_windows,
711 # Make sure the version of makensis is up to date.
714 @depends_if(nsis)
715 @checking("for NSIS version")
716 @imports("re")
717 def nsis_version(nsis):
718     nsis_min_version = "3.0b1"
720     def onerror():
721         return die("Failed to get nsis version.")
723     out = check_cmd_output(nsis, "-version", onerror=onerror)
725     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
727     if not m:
728         raise FatalCheckError("Unknown version of makensis")
729     ver = Version(m.group(0))
731     # Versions comparisons don't quite work well with beta versions, so ensure
732     # it works for the non-beta version.
733     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
734         raise FatalCheckError(
735             "To build the installer you must have NSIS"
736             " version %s or greater in your path" % nsis_min_version
737         )
739     return ver
742 # And that makensis is 32-bit (but only on Windows).
743 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
744 @checking("for 32-bit NSIS")
745 def nsis_binary_type(nsis):
746     bin_type = windows_binary_type(nsis)
747     if bin_type != "win32":
748         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
750     return "yes"
753 # And any flags we have to give to makensis
754 @depends(host)
755 def nsis_flags(host):
756     if host.kernel != "WINNT":
757         return "-nocd"
758     return ""
761 set_config("MAKENSISU_FLAGS", nsis_flags)
763 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
764 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
767 check_prog(
768     "DSYMUTIL",
769     llvm_tool("dsymutil"),
770     when=compile_environment & target_is_darwin,
771     paths=clang_search_path,
775 check_prog(
776     "OTOOL",
777     plain_llvm_or_prefixed("otool"),
778     when=compile_environment & target_is_darwin,
779     paths=clang_search_path,
782 check_prog(
783     "INSTALL_NAME_TOOL",
784     plain_llvm_or_prefixed("install_name_tool", llvm_name="install-name-tool"),
785     when=compile_environment & target_is_darwin & js_standalone,
786     paths=clang_search_path,
789 option("--enable-dtrace", help="Build with dtrace support")
791 dtrace = check_header(
792     "sys/sdt.h",
793     when="--enable-dtrace",
794     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
797 set_config("HAVE_DTRACE", True, when=dtrace)
798 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
799 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
802 option("--disable-icf", help="Disable Identical Code Folding")
804 add_old_configure_assignment(
805     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
809 option(
810     "--enable-strip",
811     when=compile_environment,
812     help="Enable stripping of libs & executables",
815 # This should be handled as a `when` once bug 1617793 is fixed.
818 @depends("--enable-strip", c_compiler, when=compile_environment)
819 def enable_strip(strip, c_compiler):
820     if strip and c_compiler.type != "clang-cl":
821         return True
824 set_config("ENABLE_STRIP", enable_strip)
826 option(
827     "--disable-install-strip",
828     when=compile_environment,
829     help="Enable stripping of libs & executables when packaging",
832 # This should be handled as a `when` once bug 1617793 is fixed.
835 @depends("--enable-install-strip", c_compiler, when=compile_environment)
836 def enable_install_strip(strip, c_compiler):
837     if strip and c_compiler.type != "clang-cl":
838         return True
841 set_config("PKG_STRIP", enable_install_strip)
844 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
845 def strip(strip, install_strip):
846     return strip or install_strip
849 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
852 @depends("STRIP_FLAGS", profiling, target, when=strip)
853 def strip_flags(flags, profiling, target):
854     if flags:
855         return flags[0].split()
856     if profiling:
857         # Only strip debug info and symbols when profiling is enabled, keeping
858         # local symbols.
859         if target.kernel == "Darwin":
860             return ["-S"]
861         elif target.os == "Android":
862             # The tooling we use with Android supports detached symbols, and the
863             # size increase caused by local symbols are too much for mobile. So,
864             # don't restrict the amount of stripping with a flag.
865             return
866         else:
867             return ["--strip-debug"]
868     # Otherwise strip everything we can, which happens without flags on non-Darwin.
869     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
870     elif target.kernel == "Darwin":
871         return ["-x", "-S"]
874 set_config("STRIP_FLAGS", strip_flags)
877 def validate_strip(path):
878     if "llvm-strip" not in path:
879         return True
880     # llvm-strip doesn't support -S before llvm 8.0.
881     retcode, stdout, stderr = get_cmd_output(path, "--help")
882     return retcode == 0 and any(l.startswith("  -S ") for l in stdout.splitlines())
885 @depends("--enable-compile-environment", target, host)
886 def strip_when(compile_env, target, host):
887     return compile_env and any(x.kernel != "WINNT" for x in (target, host))
890 check_prog(
891     "STRIP",
892     plain_llvm_or_prefixed("strip"),
893     when=strip_when,
894     paths=clang_search_path,
895     validate=validate_strip,
899 @depends(js_standalone, target)
900 def system_zlib_default(js_standalone, target):
901     return (
902         js_standalone
903         and target.kernel not in ("WINNT", "Darwin")
904         and target.os != "Android"
905     )
908 option(
909     "--with-system-zlib",
910     nargs="?",
911     default=system_zlib_default,
912     help="{Use|Do not use} system libz",
916 @depends("--with-system-zlib")
917 def deprecated_system_zlib_path(value):
918     if len(value) == 1:
919         die(
920             "--with-system-zlib=PATH is not supported anymore. Please use "
921             "--with-system-zlib and set any necessary pkg-config environment variable."
922         )
925 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
927 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
930 @depends("--with-system-zlib", js_shared, moz_linker, target.os)
931 def zlib_in_mozglue(system_zlib, js_shared, linker, os):
932     if not system_zlib and (js_shared or linker or os == "Android"):
933         return True
936 set_config("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
937 set_define("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
940 # Please do not add configure checks from here on.
942 # Fallthrough to autoconf-based configure
943 include("build/moz.configure/old.configure")
945 # JS Subconfigure.
946 include("js/sub.configure", when=compile_environment & toolkit)
949 @depends(build_environment, configure_cache)
950 @imports(_import="json")
951 @imports(_from="pathlib", _import="Path")
952 def save_cache(build_environment, configure_cache):
953     cache_file = Path(build_environment.topobjdir) / "configure.cache"
955     with cache_file.open(mode="w") as fd:
956         json.dump(configure_cache, fd, indent=4)
959 @depends(build_environment, build_project)
960 @imports("__sandbox__")
961 @imports("glob")
962 @imports(_from="os.path", _import="exists")
963 def config_status_deps(build_env, build_project):
964     topsrcdir = build_env.topsrcdir
965     topobjdir = build_env.topobjdir
967     if not topobjdir.endswith("js/src"):
968         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
969     else:
970         # mozconfig changes may impact js configure.
971         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
973     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
974     if exists(confvars):
975         extra_deps.append(confvars)
977     return (
978         list(__sandbox__._all_paths)
979         + extra_deps
980         + [
981             os.path.join(topsrcdir, "CLOBBER"),
982             os.path.join(topsrcdir, "configure"),
983             os.path.join(topsrcdir, "js", "src", "configure"),
984             os.path.join(topsrcdir, "nsprpub", "configure"),
985             os.path.join(topsrcdir, "config", "milestone.txt"),
986             os.path.join(topsrcdir, "browser", "config", "version.txt"),
987             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
988             os.path.join(topsrcdir, "python", "sites", "build.txt"),
989             os.path.join(topsrcdir, "python", "sites", "common.txt"),
990             os.path.join(topsrcdir, "python", "sites", "mach.txt"),
991             os.path.join(topsrcdir, "python", "mach", "mach", "site.py"),
992             os.path.join(topsrcdir, "aclocal.m4"),
993             os.path.join(topsrcdir, "old-configure.in"),
994             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
995             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
996         ]
997         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
998     )
1001 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1002 # Please do not add anything after setting config_dep_paths.