Bug 1872003 uninline AudioSegment::Resample() to remove MediaTrackGraph.h include...
[gecko.git] / moz.configure
bloba970eed3cd4f55275f7f41501da5db7aed4d1078
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):
355     @depends(llvm_tool(f"llvm-{name}"), toolchain_prefix)
356     def plain_llvm_or_prefixed(llvm_tool, toolchain_prefix):
357         commands = [llvm_tool[0], name]
358         for prefix in toolchain_prefix or ():
359             commands.insert(1, f"{prefix}{name}")
360         return tuple(commands)
362     return plain_llvm_or_prefixed
365 llvm_objdump = check_prog(
366     "LLVM_OBJDUMP",
367     llvm_tool("llvm-objdump"),
368     what="llvm-objdump",
369     when="--enable-compile-environment",
370     paths=clang_search_path,
373 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
376 def validate_readelf(path):
377     # llvm-readelf from llvm < 8 doesn't support the GNU binutils-compatible `-d`
378     # flag. We could try running `$path -d $some_binary` but we might be cross
379     # compiling and not have a binary at hand to run that against. `$path -d` alone
380     # would fail whether the flag is supported or not. So we resort to look for the
381     # option in the `--help` output, which fortunately, s compatible between
382     # llvm-readelf and readelf.
383     retcode, stdout, stderr = get_cmd_output(path, "--help")
384     return retcode == 0 and any(l.startswith("  -d ") for l in stdout.splitlines())
387 @depends("--enable-compile-environment", target, host)
388 def readelf_when(compile_env, target, host):
389     return compile_env and any(
390         x.kernel not in ("Darwin", "WINNT") for x in (target, host)
391     )
394 readelf = check_prog(
395     "READELF",
396     plain_llvm_or_prefixed("readelf"),
397     when=readelf_when,
398     paths=clang_search_path,
399     validate=validate_readelf,
403 def validate_objcopy(path):
404     if "llvm-objcopy" not in path:
405         return True
406     # llvm-objcopy doesn't support --only-keep-debug before llvm 9.0.
407     retcode, stdout, stderr = get_cmd_output(path, "--help")
408     return retcode == 0 and any(
409         l.startswith("  --only-keep-debug ") for l in stdout.splitlines()
410     )
413 check_prog(
414     "OBJCOPY",
415     plain_llvm_or_prefixed("objcopy"),
416     when=readelf_when,
417     paths=clang_search_path,
418     validate=validate_objcopy,
422 # Make `profiling` available to this file even when js/moz.configure
423 # doesn't end up included.
424 profiling = dependable(False)
425 # Same for js_standalone
426 js_standalone = dependable(False)
427 js_shared = dependable(False)
428 moz_linker = dependable(False)
429 # Same for fold_libs
430 fold_libs = dependable(False)
431 # And dmd
432 dmd = dependable(False)
434 include(include_project_configure)
437 @depends("--help")
438 @imports(_from="mozbuild.backend", _import="backends")
439 def build_backends_choices(_):
440     return tuple(backends)
443 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
444 def build_backend(backends):
445     if backends:
446         return tuple("+%s" % b for b in backends)
449 imply_option("--build-backends", build_backend)
452 @depends(
453     host,
454     target,
455     "--enable-artifact-builds",
456     "--disable-compile-environment",
457     "--enable-project",
458     "--enable-application",
459     "--help",
461 @imports("sys")
462 def build_backend_defaults(
463     host,
464     target,
465     artifact_builds,
466     compile_environment,
467     project,
468     application,
469     _,
471     if application:
472         project = application[0]
473     elif project:
474         project = project[0]
476     if artifact_builds:
477         all_backends = ["FasterMake+RecursiveMake"]
478     else:
479         all_backends = ["RecursiveMake", "FasterMake"]
480     if (
481         host.os == "WINNT"
482         and target.os == "WINNT"
483         and compile_environment
484         and project not in ("mobile/android", "memory", "tools/update-programs")
485     ):
486         all_backends.append("VisualStudio")
487     if compile_environment and project not in ("memory", "tools/update-programs"):
488         all_backends.append("Clangd")
489     return tuple(all_backends) or None
492 option(
493     "--build-backends",
494     nargs="+",
495     default=build_backend_defaults,
496     choices=build_backends_choices,
497     help="Build backends to generate",
501 @depends("--build-backends")
502 def build_backends(backends):
503     return backends
506 set_config("BUILD_BACKENDS", build_backends)
509 # Determine whether to build the gtest xul. This happens in automation
510 # on Android and Desktop platforms with the exception of:
511 #  - Windows PGO, where linking xul-gtest.dll takes too long;
512 #  - Android other than x86_64, where gtest is not required.
513 @depends(
514     build_project,
515     target,
516     "MOZ_AUTOMATION",
517     enable_tests,
518     when="--enable-compile-environment",
520 def build_gtest(build_project, target, automation, enable_tests):
521     return bool(
522         enable_tests
523         and automation
524         and build_project in ("browser", "comm/mail", "mobile/android")
525         and not (target.os == "Android" and target.cpu != "x86_64")
526     )
529 option(
530     "--enable-gtest-in-build",
531     default=build_gtest,
532     help="{Enable|Force disable} building the gtest libxul during the build.",
533     when="--enable-compile-environment",
536 set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build")
538 # Localization
539 # ==============================================================
540 option(
541     "--enable-ui-locale",
542     default="en-US",
543     help="Select the user interface locale (default: en-US)",
546 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
548 option(
549     "--disable-icu4x",
550     help="Disable using ICU4X",
553 set_config("MOZ_ICU4X", True, when="--enable-icu4x")
554 set_define("MOZ_ICU4X", True, when="--enable-icu4x")
556 # clang-plugin location
557 # ==============================================================
560 @depends(host_library_name_info, build_environment, when="--enable-clang-plugin")
561 def clang_plugin_path(library_name_info, build_env):
562     topobjdir = build_env.topobjdir
563     if topobjdir.endswith("/js/src"):
564         topobjdir = topobjdir[:-7]
565     return os.path.abspath(
566         os.path.join(
567             topobjdir,
568             "build",
569             "clang-plugin",
570             "%sclang-plugin%s"
571             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
572         )
573     )
576 set_config("CLANG_PLUGIN", clang_plugin_path)
577 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
580 # Awk detection
581 # ==============================================================
582 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"), paths=prefer_mozillabuild_path)
584 # Until the AWK variable is not necessary in old-configure
587 @depends(awk)
588 def awk_for_old_configure(value):
589     return value
592 add_old_configure_assignment("AWK", awk_for_old_configure)
595 # GNU make detection
596 # ==============================================================
597 option(env="MAKE", nargs=1, help="Path to GNU make")
600 @depends("MAKE", host)
601 def possible_makes(make, host):
602     candidates = []
603     if make:
604         candidates.append(make[0])
605     if host.kernel == "WINNT":
606         candidates.extend(("mozmake", "mingw32-make", "make", "gmake"))
607     else:
608         candidates.extend(("gmake", "make"))
609     return candidates
612 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
614 # watchman detection
615 # ==============================================================
617 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
620 @depends(host, "WATCHMAN")
621 @checking("for watchman", callback=lambda w: w.path if w else "not found")
622 def watchman(host, prog):
623     # On Windows, `watchman` is only supported on 64-bit hosts.
624     if host.os == "WINNT" and host.cpu != "x86_64":
625         return
627     if not prog:
628         prog = find_program("watchman")
630     if not prog:
631         return
633     # `watchman version` will talk to the Watchman daemon service.
634     # This can hang due to permissions problems. e.g.
635     # https://github.com/facebook/watchman/issues/376. So use
636     # `watchman --version` to prevent a class of failures.
637     out = check_cmd_output(prog, "--version", onerror=lambda: None)
638     if out is None:
639         return
641     return namespace(path=prog, version=Version(out.strip()))
644 @depends_if(watchman)
645 @checking("for watchman version")
646 def watchman_version(w):
647     return w.version
650 set_config("WATCHMAN", watchman.path)
653 @depends_all(hg_version, hg_config, watchman)
654 @checking("for watchman Mercurial integration")
655 @imports("os")
656 def watchman_hg(hg_version, hg_config, watchman):
657     if hg_version < Version("3.8"):
658         return "no (Mercurial 3.8+ required)"
660     ext_enabled = False
661     mode_disabled = False
663     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
664         if k in hg_config and hg_config[k] != "!":
665             ext_enabled = True
667     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
669     if not ext_enabled:
670         return "no (fsmonitor extension not enabled)"
671     if mode_disabled:
672         return "no (fsmonitor.mode=off disables fsmonitor)"
674     return True
677 # Miscellaneous programs
678 # ==============================================================
679 check_prog("XARGS", ("xargs",))
682 @depends(target)
683 def extra_programs(target):
684     if target.kernel == "Darwin":
685         return namespace(
686             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
687             HFS_TOOL=("hfsplus",),
688         )
689     if target.os == "GNU" and target.kernel == "Linux":
690         return namespace(RPMBUILD=("rpmbuild",))
693 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
694 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
695 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
698 nsis = check_prog(
699     "MAKENSISU",
700     ("makensis",),
701     bootstrap="nsis/bin",
702     allow_missing=True,
703     when=target_is_windows,
706 # Make sure the version of makensis is up to date.
709 @depends_if(nsis)
710 @checking("for NSIS version")
711 @imports("re")
712 def nsis_version(nsis):
713     nsis_min_version = "3.0b1"
715     def onerror():
716         return die("Failed to get nsis version.")
718     out = check_cmd_output(nsis, "-version", onerror=onerror)
720     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
722     if not m:
723         raise FatalCheckError("Unknown version of makensis")
724     ver = Version(m.group(0))
726     # Versions comparisons don't quite work well with beta versions, so ensure
727     # it works for the non-beta version.
728     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
729         raise FatalCheckError(
730             "To build the installer you must have NSIS"
731             " version %s or greater in your path" % nsis_min_version
732         )
734     return ver
737 # And that makensis is 32-bit (but only on Windows).
738 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
739 @checking("for 32-bit NSIS")
740 def nsis_binary_type(nsis):
741     bin_type = windows_binary_type(nsis)
742     if bin_type != "win32":
743         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
745     return "yes"
748 # And any flags we have to give to makensis
749 @depends(host)
750 def nsis_flags(host):
751     if host.kernel != "WINNT":
752         return "-nocd"
753     return ""
756 set_config("MAKENSISU_FLAGS", nsis_flags)
758 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
759 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
762 check_prog(
763     "DSYMUTIL",
764     llvm_tool("dsymutil"),
765     when=compile_environment & target_is_darwin,
766     paths=clang_search_path,
770 check_prog(
771     "OTOOL",
772     plain_llvm_or_prefixed("otool"),
773     when=compile_environment & target_is_darwin,
774     paths=clang_search_path,
777 check_prog(
778     "INSTALL_NAME_TOOL",
779     plain_llvm_or_prefixed("install-name-tool"),
780     when=compile_environment & target_is_darwin & js_standalone,
781     paths=clang_search_path,
784 option("--enable-dtrace", help="Build with dtrace support")
786 dtrace = check_header(
787     "sys/sdt.h",
788     when="--enable-dtrace",
789     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
792 set_config("HAVE_DTRACE", True, when=dtrace)
793 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
794 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
797 option("--disable-icf", help="Disable Identical Code Folding")
799 add_old_configure_assignment(
800     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
804 option(
805     "--enable-strip",
806     when=compile_environment,
807     help="Enable stripping of libs & executables",
810 # This should be handled as a `when` once bug 1617793 is fixed.
813 @depends("--enable-strip", c_compiler, when=compile_environment)
814 def enable_strip(strip, c_compiler):
815     if strip and c_compiler.type != "clang-cl":
816         return True
819 set_config("ENABLE_STRIP", enable_strip)
821 option(
822     "--disable-install-strip",
823     when=compile_environment,
824     help="Enable stripping of libs & executables when packaging",
827 # This should be handled as a `when` once bug 1617793 is fixed.
830 @depends("--enable-install-strip", c_compiler, when=compile_environment)
831 def enable_install_strip(strip, c_compiler):
832     if strip and c_compiler.type != "clang-cl":
833         return True
836 set_config("PKG_STRIP", enable_install_strip)
839 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
840 def strip(strip, install_strip):
841     return strip or install_strip
844 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
847 @depends("STRIP_FLAGS", profiling, target, when=strip)
848 def strip_flags(flags, profiling, target):
849     if flags:
850         return flags[0].split()
851     if profiling:
852         # Only strip debug info and symbols when profiling is enabled, keeping
853         # local symbols.
854         if target.kernel == "Darwin":
855             return ["-S"]
856         elif target.os == "Android":
857             # The tooling we use with Android supports detached symbols, and the
858             # size increase caused by local symbols are too much for mobile. So,
859             # don't restrict the amount of stripping with a flag.
860             return
861         else:
862             return ["--strip-debug"]
863     # Otherwise strip everything we can, which happens without flags on non-Darwin.
864     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
865     elif target.kernel == "Darwin":
866         return ["-x", "-S"]
869 set_config("STRIP_FLAGS", strip_flags)
872 def validate_strip(path):
873     if "llvm-strip" not in path:
874         return True
875     # llvm-strip doesn't support -S before llvm 8.0.
876     retcode, stdout, stderr = get_cmd_output(path, "--help")
877     return retcode == 0 and any(l.startswith("  -S ") for l in stdout.splitlines())
880 @depends("--enable-compile-environment", target, host)
881 def strip_when(compile_env, target, host):
882     return compile_env and any(x.kernel != "WINNT" for x in (target, host))
885 check_prog(
886     "STRIP",
887     plain_llvm_or_prefixed("strip"),
888     when=strip_when,
889     paths=clang_search_path,
890     validate=validate_strip,
894 @depends(js_standalone, target)
895 def system_zlib_default(js_standalone, target):
896     return (
897         js_standalone
898         and target.kernel not in ("WINNT", "Darwin")
899         and target.os != "Android"
900     )
903 option(
904     "--with-system-zlib",
905     nargs="?",
906     default=system_zlib_default,
907     help="{Use|Do not use} system libz",
911 @depends("--with-system-zlib")
912 def deprecated_system_zlib_path(value):
913     if len(value) == 1:
914         die(
915             "--with-system-zlib=PATH is not supported anymore. Please use "
916             "--with-system-zlib and set any necessary pkg-config environment variable."
917         )
920 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
922 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
925 @depends("--with-system-zlib", js_shared, moz_linker, target.os)
926 def zlib_in_mozglue(system_zlib, js_shared, linker, os):
927     if not system_zlib and (js_shared or linker or os == "Android"):
928         return True
931 set_config("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
932 set_define("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
935 # Please do not add configure checks from here on.
937 # Fallthrough to autoconf-based configure
938 include("build/moz.configure/old.configure")
940 # JS Subconfigure.
941 include("js/sub.configure", when=compile_environment & toolkit)
944 @depends(build_environment, configure_cache)
945 @imports(_import="json")
946 @imports(_from="pathlib", _import="Path")
947 def save_cache(build_environment, configure_cache):
948     cache_file = Path(build_environment.topobjdir) / "configure.cache"
950     with cache_file.open(mode="w") as fd:
951         json.dump(configure_cache, fd, indent=4)
954 @depends(build_environment, build_project)
955 @imports("__sandbox__")
956 @imports("glob")
957 @imports(_from="os.path", _import="exists")
958 def config_status_deps(build_env, build_project):
959     topsrcdir = build_env.topsrcdir
960     topobjdir = build_env.topobjdir
962     if not topobjdir.endswith("js/src"):
963         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
964     else:
965         # mozconfig changes may impact js configure.
966         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
968     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
969     if exists(confvars):
970         extra_deps.append(confvars)
972     return (
973         list(__sandbox__._all_paths)
974         + extra_deps
975         + [
976             os.path.join(topsrcdir, "CLOBBER"),
977             os.path.join(topsrcdir, "configure"),
978             os.path.join(topsrcdir, "js", "src", "configure"),
979             os.path.join(topsrcdir, "nsprpub", "configure"),
980             os.path.join(topsrcdir, "config", "milestone.txt"),
981             os.path.join(topsrcdir, "browser", "config", "version.txt"),
982             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
983             os.path.join(topsrcdir, "python", "sites", "build.txt"),
984             os.path.join(topsrcdir, "python", "sites", "common.txt"),
985             os.path.join(topsrcdir, "python", "sites", "mach.txt"),
986             os.path.join(topsrcdir, "python", "mach", "mach", "site.py"),
987             os.path.join(topsrcdir, "aclocal.m4"),
988             os.path.join(topsrcdir, "old-configure.in"),
989             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
990             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
991         ]
992         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
993     )
996 set_config("CONFIG_STATUS_DEPS", config_status_deps)
997 # Please do not add anything after setting config_dep_paths.