Backed out changeset 55d4631b4b19 (bug 1884392) for causing spidermonkey bustages...
[gecko.git] / moz.configure
blobfc6563d07570f598ce40ec80800f1e6ac41368ce
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/libraries.configure", when="--enable-compile-environment")
212 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
213 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
214 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
215 # 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     windows_abi = {
258         host: host_windows_abi,
259         target: target_windows_abi,
260     }[host_or_target]
262     @depends(host_or_target, host_or_target.abi | windows_abi, so_version)
263     def library_name_info_impl(host_or_target, windows_abi, 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 windows_abi and windows_abi != "msvc":
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")
328 @template
329 def llvm_tool(name):
330     @depends(host_c_compiler, c_compiler, bindgen_config_paths)
331     def llvm_tool(host_c_compiler, c_compiler, bindgen_config_paths):
332         clang = None
333         for compiler in (host_c_compiler, c_compiler):
334             if compiler and compiler.type == "clang":
335                 clang = compiler.compiler
336                 break
337             elif compiler and compiler.type == "clang-cl":
338                 clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
339                 break
341         if not clang and bindgen_config_paths:
342             clang = bindgen_config_paths.clang_path
343         tool = name
344         if clang:
345             out = check_cmd_output(
346                 clang, "--print-prog-name=%s" % tool, onerror=lambda: None
347             )
348             if out:
349                 tool = out.rstrip()
350         return (tool,)
352     return llvm_tool
355 @template
356 def plain_llvm_or_prefixed(name, llvm_name=None):
357     # look for a tool, using the following alternatives, in that order:
358     # 1. llvm-${llvm_name}, or llvm-${name} if ${llvm_name} is not provided
359     # 2. ${toolchain_prefix}${name}
360     # 3. ${name}
362     @depends(llvm_tool("llvm-{}".format(llvm_name or name)), toolchain_prefix)
363     def plain_llvm_or_prefixed(llvm_tool, toolchain_prefix):
364         commands = [llvm_tool[0], name]
365         for prefix in toolchain_prefix or ():
366             commands.insert(1, f"{prefix}{name}")
367         return tuple(commands)
369     return plain_llvm_or_prefixed
372 llvm_objdump = check_prog(
373     "LLVM_OBJDUMP",
374     llvm_tool("llvm-objdump"),
375     what="llvm-objdump",
376     when="--enable-compile-environment",
377     paths=clang_search_path,
380 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
383 def validate_readelf(path):
384     # llvm-readelf from llvm < 8 doesn't support the GNU binutils-compatible `-d`
385     # flag. We could try running `$path -d $some_binary` but we might be cross
386     # compiling and not have a binary at hand to run that against. `$path -d` alone
387     # would fail whether the flag is supported or not. So we resort to look for the
388     # option in the `--help` output, which fortunately, s compatible between
389     # llvm-readelf and readelf.
390     retcode, stdout, stderr = get_cmd_output(path, "--help")
391     return retcode == 0 and any(l.startswith("  -d ") for l in stdout.splitlines())
394 @depends("--enable-compile-environment", target, host)
395 def readelf_when(compile_env, target, host):
396     return compile_env and any(
397         x.kernel not in ("Darwin", "WINNT") for x in (target, host)
398     )
401 readelf = check_prog(
402     "READELF",
403     plain_llvm_or_prefixed("readelf"),
404     when=readelf_when,
405     paths=clang_search_path,
406     validate=validate_readelf,
410 def validate_objcopy(path):
411     if "llvm-objcopy" not in path:
412         return True
413     # llvm-objcopy doesn't support --only-keep-debug before llvm 9.0.
414     retcode, stdout, stderr = get_cmd_output(path, "--help")
415     return retcode == 0 and any(
416         l.startswith("  --only-keep-debug ") for l in stdout.splitlines()
417     )
420 check_prog(
421     "OBJCOPY",
422     plain_llvm_or_prefixed("objcopy"),
423     when=readelf_when,
424     paths=clang_search_path,
425     validate=validate_objcopy,
429 # Make `profiling` available to this file even when js/moz.configure
430 # doesn't end up included.
431 profiling = dependable(False)
432 # Same for js_standalone
433 js_standalone = dependable(False)
434 js_shared = dependable(False)
435 moz_linker = dependable(False)
436 # Same for fold_libs
437 fold_libs = dependable(False)
438 # And dmd
439 dmd = dependable(False)
441 include(include_project_configure)
444 @depends("--help")
445 @imports(_from="mozbuild.backend", _import="backends")
446 def build_backends_choices(_):
447     return tuple(backends)
450 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
451 def build_backend(backends):
452     if backends:
453         return tuple("+%s" % b for b in backends)
456 imply_option("--build-backends", build_backend)
459 @depends(
460     host,
461     target,
462     "--enable-artifact-builds",
463     "--disable-compile-environment",
464     "--enable-project",
465     "--enable-application",
466     "--help",
468 @imports("sys")
469 def build_backend_defaults(
470     host,
471     target,
472     artifact_builds,
473     compile_environment,
474     project,
475     application,
476     _,
478     if application:
479         project = application[0]
480     elif project:
481         project = project[0]
483     if artifact_builds:
484         all_backends = ["FasterMake+RecursiveMake"]
485     else:
486         all_backends = ["RecursiveMake", "FasterMake"]
487     if (
488         host.os == "WINNT"
489         and target.os == "WINNT"
490         and compile_environment
491         and project not in ("mobile/android", "memory", "tools/update-programs")
492     ):
493         all_backends.append("VisualStudio")
494     if compile_environment and project not in ("memory", "tools/update-programs"):
495         all_backends.append("Clangd")
496     return tuple(all_backends) or None
499 option(
500     "--build-backends",
501     nargs="+",
502     default=build_backend_defaults,
503     choices=build_backends_choices,
504     help="Build backends to generate",
508 @depends("--build-backends")
509 def build_backends(backends):
510     return backends
513 set_config("BUILD_BACKENDS", build_backends)
516 # Determine whether to build the gtest xul. This happens in automation
517 # on Android and Desktop platforms with the exception of:
518 #  - Windows PGO, where linking xul-gtest.dll takes too long;
519 #  - Android other than x86_64, where gtest is not required.
520 @depends(
521     build_project,
522     target,
523     "MOZ_AUTOMATION",
524     enable_tests,
525     when="--enable-compile-environment",
527 def build_gtest(build_project, target, automation, enable_tests):
528     return bool(
529         enable_tests
530         and automation
531         and build_project in ("browser", "comm/mail", "mobile/android")
532         and not (target.os == "Android" and target.cpu != "x86_64")
533     )
536 option(
537     "--enable-gtest-in-build",
538     default=build_gtest,
539     help="{Enable|Force disable} building the gtest libxul during the build.",
540     when="--enable-compile-environment",
543 set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build")
545 # Localization
546 # ==============================================================
547 option(
548     "--enable-ui-locale",
549     default="en-US",
550     help="Select the user interface locale (default: en-US)",
553 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
555 option(
556     "--disable-icu4x",
557     help="Disable using ICU4X",
560 set_config("MOZ_ICU4X", True, when="--enable-icu4x")
561 set_define("MOZ_ICU4X", True, when="--enable-icu4x")
563 # clang-plugin location
564 # ==============================================================
567 @depends(host_library_name_info, build_environment, when="--enable-clang-plugin")
568 def clang_plugin_path(library_name_info, build_env):
569     topobjdir = build_env.topobjdir
570     if topobjdir.endswith("/js/src"):
571         topobjdir = topobjdir[:-7]
572     return os.path.abspath(
573         os.path.join(
574             topobjdir,
575             "build",
576             "clang-plugin",
577             "%sclang-plugin%s"
578             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
579         )
580     )
583 set_config("CLANG_PLUGIN", clang_plugin_path)
584 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
587 # Awk detection
588 # ==============================================================
589 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"), paths=prefer_mozillabuild_path)
591 # Until the AWK variable is not necessary in old-configure
594 @depends(awk)
595 def awk_for_old_configure(value):
596     return value
599 add_old_configure_assignment("AWK", awk_for_old_configure)
602 # GNU make detection
603 # ==============================================================
604 option(env="MAKE", nargs=1, help="Path to GNU make")
607 @depends("MAKE", host)
608 def possible_makes(make, host):
609     candidates = []
610     if make:
611         candidates.append(make[0])
612     if host.kernel == "WINNT":
613         candidates.extend(("mozmake", "mingw32-make", "make", "gmake"))
614     else:
615         candidates.extend(("gmake", "make"))
616     return candidates
619 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
621 # watchman detection
622 # ==============================================================
624 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
627 @depends(host, "WATCHMAN")
628 @checking("for watchman", callback=lambda w: w.path if w else "not found")
629 def watchman(host, prog):
630     # On Windows, `watchman` is only supported on 64-bit hosts.
631     if host.os == "WINNT" and host.cpu != "x86_64":
632         return
634     if not prog:
635         prog = find_program("watchman")
637     if not prog:
638         return
640     # `watchman version` will talk to the Watchman daemon service.
641     # This can hang due to permissions problems. e.g.
642     # https://github.com/facebook/watchman/issues/376. So use
643     # `watchman --version` to prevent a class of failures.
644     out = check_cmd_output(prog, "--version", onerror=lambda: None)
645     if out is None:
646         return
648     return namespace(path=prog, version=Version(out.strip()))
651 @depends_if(watchman)
652 @checking("for watchman version")
653 def watchman_version(w):
654     return w.version
657 set_config("WATCHMAN", watchman.path)
660 @depends_all(hg_version, hg_config, watchman)
661 @checking("for watchman Mercurial integration")
662 @imports("os")
663 def watchman_hg(hg_version, hg_config, watchman):
664     if hg_version < Version("3.8"):
665         return "no (Mercurial 3.8+ required)"
667     ext_enabled = False
668     mode_disabled = False
670     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
671         if k in hg_config and hg_config[k] != "!":
672             ext_enabled = True
674     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
676     if not ext_enabled:
677         return "no (fsmonitor extension not enabled)"
678     if mode_disabled:
679         return "no (fsmonitor.mode=off disables fsmonitor)"
681     return True
684 # Miscellaneous programs
685 # ==============================================================
686 check_prog("XARGS", ("xargs",))
689 @depends(target)
690 def extra_programs(target):
691     if target.kernel == "Darwin":
692         return namespace(
693             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
694             HFS_TOOL=("hfsplus",),
695         )
696     if target.os == "GNU" and target.kernel == "Linux":
697         return namespace(RPMBUILD=("rpmbuild",))
700 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
701 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
702 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
705 nsis = check_prog(
706     "MAKENSISU",
707     ("makensis",),
708     bootstrap="nsis/bin",
709     allow_missing=True,
710     when=target_is_windows,
713 # Make sure the version of makensis is up to date.
716 @depends_if(nsis)
717 @checking("for NSIS version")
718 @imports("re")
719 def nsis_version(nsis):
720     nsis_min_version = "3.0b1"
722     def onerror():
723         return die("Failed to get nsis version.")
725     out = check_cmd_output(nsis, "-version", onerror=onerror)
727     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
729     if not m:
730         raise FatalCheckError("Unknown version of makensis")
731     ver = Version(m.group(0))
733     # Versions comparisons don't quite work well with beta versions, so ensure
734     # it works for the non-beta version.
735     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
736         raise FatalCheckError(
737             "To build the installer you must have NSIS"
738             " version %s or greater in your path" % nsis_min_version
739         )
741     return ver
744 # And that makensis is 32-bit (but only on Windows).
745 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
746 @checking("for 32-bit NSIS")
747 def nsis_binary_type(nsis):
748     bin_type = windows_binary_type(nsis)
749     if bin_type != "win32":
750         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
752     return "yes"
755 # And any flags we have to give to makensis
756 @depends(host)
757 def nsis_flags(host):
758     if host.kernel != "WINNT":
759         return "-nocd"
760     return ""
763 set_config("MAKENSISU_FLAGS", nsis_flags)
765 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
766 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
769 check_prog(
770     "DSYMUTIL",
771     llvm_tool("dsymutil"),
772     when=compile_environment & target_is_darwin,
773     paths=clang_search_path,
777 check_prog(
778     "OTOOL",
779     plain_llvm_or_prefixed("otool"),
780     when=compile_environment & target_is_darwin,
781     paths=clang_search_path,
784 check_prog(
785     "INSTALL_NAME_TOOL",
786     plain_llvm_or_prefixed("install_name_tool", llvm_name="install-name-tool"),
787     when=compile_environment & target_is_darwin & js_standalone,
788     paths=clang_search_path,
791 option("--disable-icf", help="Disable Identical Code Folding")
793 add_old_configure_assignment(
794     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
798 option(
799     "--enable-strip",
800     when=compile_environment,
801     help="Enable stripping of libs & executables",
804 # This should be handled as a `when` once bug 1617793 is fixed.
807 @depends("--enable-strip", c_compiler, when=compile_environment)
808 def enable_strip(strip, c_compiler):
809     if strip and c_compiler.type != "clang-cl":
810         return True
813 set_config("ENABLE_STRIP", enable_strip)
815 option(
816     "--disable-install-strip",
817     when=compile_environment,
818     help="Enable stripping of libs & executables when packaging",
821 # This should be handled as a `when` once bug 1617793 is fixed.
824 @depends("--enable-install-strip", c_compiler, when=compile_environment)
825 def enable_install_strip(strip, c_compiler):
826     if strip and c_compiler.type != "clang-cl":
827         return True
830 set_config("PKG_STRIP", enable_install_strip)
833 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
834 def strip(strip, install_strip):
835     return strip or install_strip
838 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
841 @depends("STRIP_FLAGS", profiling, target, when=strip)
842 def strip_flags(flags, profiling, target):
843     if flags:
844         return flags[0].split()
845     if profiling:
846         # Only strip debug info and symbols when profiling is enabled, keeping
847         # local symbols.
848         if target.kernel == "Darwin":
849             return ["-S"]
850         elif target.os == "Android":
851             # The tooling we use with Android supports detached symbols, and the
852             # size increase caused by local symbols are too much for mobile. So,
853             # don't restrict the amount of stripping with a flag.
854             return
855         else:
856             return ["--strip-debug"]
857     # Otherwise strip everything we can, which happens without flags on non-Darwin.
858     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
859     elif target.kernel == "Darwin":
860         return ["-x", "-S"]
863 set_config("STRIP_FLAGS", strip_flags)
866 def validate_strip(path):
867     if "llvm-strip" not in path:
868         return True
869     # llvm-strip doesn't support -S before llvm 8.0.
870     retcode, stdout, stderr = get_cmd_output(path, "--help")
871     return retcode == 0 and any(l.startswith("  -S ") for l in stdout.splitlines())
874 @depends("--enable-compile-environment", target, host)
875 def strip_when(compile_env, target, host):
876     return compile_env and any(x.kernel != "WINNT" for x in (target, host))
879 check_prog(
880     "STRIP",
881     plain_llvm_or_prefixed("strip"),
882     when=strip_when,
883     paths=clang_search_path,
884     validate=validate_strip,
888 @depends(js_standalone, target)
889 def system_zlib_default(js_standalone, target):
890     return (
891         js_standalone
892         and target.kernel not in ("WINNT", "Darwin")
893         and target.os != "Android"
894     )
897 option(
898     "--with-system-zlib",
899     nargs="?",
900     default=system_zlib_default,
901     help="{Use|Do not use} system libz",
905 @depends("--with-system-zlib")
906 def deprecated_system_zlib_path(value):
907     if len(value) == 1:
908         die(
909             "--with-system-zlib=PATH is not supported anymore. Please use "
910             "--with-system-zlib and set any necessary pkg-config environment variable."
911         )
914 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
916 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
919 @depends("--with-system-zlib", js_shared, moz_linker, target.os)
920 def zlib_in_mozglue(system_zlib, js_shared, linker, os):
921     if not system_zlib and (js_shared or linker or os == "Android"):
922         return True
925 set_config("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
926 set_define("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
929 # Please do not add configure checks from here on.
931 # Fallthrough to autoconf-based configure
932 include("build/moz.configure/old.configure")
934 # JS Subconfigure.
935 include("js/sub.configure", when=compile_environment & toolkit)
938 @depends(build_environment, configure_cache)
939 @imports(_import="json")
940 @imports(_from="pathlib", _import="Path")
941 def save_cache(build_environment, configure_cache):
942     cache_file = Path(build_environment.topobjdir) / "configure.cache"
944     with cache_file.open(mode="w") as fd:
945         json.dump(configure_cache, fd, indent=4)
948 @depends(build_environment, build_project)
949 @imports("__sandbox__")
950 @imports("glob")
951 @imports(_from="os.path", _import="exists")
952 def config_status_deps(build_env, build_project):
953     topsrcdir = build_env.topsrcdir
954     topobjdir = build_env.topobjdir
956     if not topobjdir.endswith("js/src"):
957         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
958     else:
959         # mozconfig changes may impact js configure.
960         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
962     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
963     if exists(confvars):
964         extra_deps.append(confvars)
966     return (
967         list(__sandbox__._all_paths)
968         + extra_deps
969         + [
970             os.path.join(topsrcdir, "CLOBBER"),
971             os.path.join(topsrcdir, "configure"),
972             os.path.join(topsrcdir, "js", "src", "configure"),
973             os.path.join(topsrcdir, "nsprpub", "configure"),
974             os.path.join(topsrcdir, "config", "milestone.txt"),
975             os.path.join(topsrcdir, "browser", "config", "version.txt"),
976             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
977             os.path.join(topsrcdir, "python", "sites", "build.txt"),
978             os.path.join(topsrcdir, "python", "sites", "common.txt"),
979             os.path.join(topsrcdir, "python", "sites", "mach.txt"),
980             os.path.join(topsrcdir, "python", "mach", "mach", "site.py"),
981             os.path.join(topsrcdir, "aclocal.m4"),
982             os.path.join(topsrcdir, "old-configure.in"),
983             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
984             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
985         ]
986         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
987     )
990 set_config("CONFIG_STATUS_DEPS", config_status_deps)
991 # Please do not add anything after setting config_dep_paths.