Bug 1902140 - Make ReFS detection work for volumes mounted on NTFS drives r=firefox...
[gecko.git] / moz.configure
blob959f3c4ab90f13e8f3d53480cd0485965d880483
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_BUILD_HOOK",
53     nargs=1,
54     help="moz.build file that will be executed as if it were appended to"
55     " every moz.build in the tree.",
59 @depends_if("MOZ_BUILD_HOOK")
60 @imports("os")
61 def moz_build_hook(value):
62     if not os.path.exists(value[0]):
63         die(f"MOZ_BUILD_HOOK set to {value[0]} but the file doesn't exist")
64     return os.path.abspath(value[0])
67 set_config("MOZ_BUILD_HOOK", moz_build_hook)
70 option(
71     env="MOZ_COPY_PDBS",
72     help="For builds that do not support symbols in the normal fashion,"
73     " generate and copy them into the resulting build archive.",
76 set_config("MOZ_COPY_PDBS", depends_if("MOZ_COPY_PDBS")(lambda _: True))
78 imply_option("--enable-compile-environment", imply_disable_compile_environment)
80 option("--disable-compile-environment", help="Disable compiler/library checks")
83 @depends("--disable-compile-environment")
84 def compile_environment(compile_env):
85     if compile_env:
86         return True
89 set_config("COMPILE_ENVIRONMENT", compile_environment)
90 add_old_configure_assignment("COMPILE_ENVIRONMENT", compile_environment)
92 option("--disable-tests", help="Do not build test libraries & programs")
95 @depends("--disable-tests")
96 def enable_tests(value):
97     if value:
98         return True
101 set_config("ENABLE_TESTS", enable_tests)
102 set_define("ENABLE_TESTS", enable_tests)
105 @depends(enable_tests)
106 def gtest_has_rtti(value):
107     if value:
108         return "0"
111 set_define("GTEST_HAS_RTTI", gtest_has_rtti)
114 @depends(target, enable_tests)
115 def linux_gtest_defines(target, enable_tests):
116     if enable_tests and target.os == "Android":
117         return namespace(os_linux_android=True, use_own_tr1_tuple=True, has_clone="0")
120 set_define("GTEST_OS_LINUX_ANDROID", linux_gtest_defines.os_linux_android)
121 set_define("GTEST_USE_OWN_TR1_TUPLE", linux_gtest_defines.use_own_tr1_tuple)
122 set_define("GTEST_HAS_CLONE", linux_gtest_defines.has_clone)
124 option(
125     "--enable-debug",
126     nargs="?",
127     help="Enable building with developer debug info "
128     "(using the given compiler flags).",
132 @depends("--enable-debug")
133 def moz_debug(debug):
134     if debug:
135         return bool(debug)
138 set_config("MOZ_DEBUG", moz_debug)
139 set_define("MOZ_DEBUG", moz_debug)
140 # Override any value MOZ_DEBUG may have from the environment when passing it
141 # down to old-configure.
142 add_old_configure_assignment("MOZ_DEBUG", depends("--enable-debug")(lambda x: bool(x)))
144 set_config(
145     "MOZ_DIAGNOSTIC_ASSERT_ENABLED",
146     True,
147     when=moz_debug | milestone.is_early_beta_or_earlier,
149 set_define(
150     "MOZ_DIAGNOSTIC_ASSERT_ENABLED",
151     True,
152     when=moz_debug | milestone.is_early_beta_or_earlier,
155 option(
156     "--with-debug-label",
157     nargs="+",
158     help="Debug DEBUG_<value> for each comma-separated value given",
162 @depends(moz_debug, "--with-debug-label")
163 def debug_defines(debug, labels):
164     if debug:
165         return ["DEBUG"] + ["DEBUG_%s" % label for label in labels]
166     return ["NDEBUG", "TRIMMED"]
169 set_config("MOZ_DEBUG_DEFINES", debug_defines)
171 option(env="MOZ_PGO", help="Build with profile guided optimizations")
173 set_config("MOZ_PGO", depends("MOZ_PGO")(lambda x: bool(x)))
176 # Imply --enable-release when MOZILLA_OFFICIAL is set rather than adjusting the
177 # default so that we can't have both MOZILLA_OFFICIAL and --disable-release set.
178 imply_option("--enable-release", mozilla_official)
180 option(
181     "--enable-release",
182     default=milestone.is_release_or_beta | depends("MOZ_AUTOMATION")(lambda x: bool(x)),
183     help="{Build|Do not build} with more conservative, release "
184     "engineering-oriented options.{ This may slow down builds.|}",
188 @depends("--enable-release")
189 def developer_options(value):
190     if not value:
191         return True
194 add_old_configure_assignment("DEVELOPER_OPTIONS", developer_options)
195 set_config("DEVELOPER_OPTIONS", developer_options)
198 # hybrid build handling
199 # ==============================================================
201 option(
202     "--disable-unified-build",
203     help="Enable building modules in non unified context",
206 set_config("ENABLE_UNIFIED_BUILD", True, when="--disable-unified-build")
209 include("build/moz.configure/bootstrap.configure")
212 # The execution model of the configure sandbox doesn't allow for
213 # check_prog to use bootstrap_search_path directly because check_prog
214 # comes first, so we use a trick to allow it. Uses of check_prog
215 # happening before here won't allow bootstrap.
218 @template
219 def check_prog(*args, **kwargs):
220     kwargs["bootstrap_search_path"] = bootstrap_search_path
221     return check_prog(*args, **kwargs)
224 check_prog("WGET", ("wget",), allow_missing=True)
227 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
229 include("build/moz.configure/pkg.configure")
230 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
231 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
232 include("build/moz.configure/libraries.configure", when="--enable-compile-environment")
233 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
234 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
235 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
236 # rust.configure is included by js/moz.configure.
239 option("--enable-valgrind", help="Enable Valgrind integration hooks")
241 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
244 @depends("--enable-valgrind", valgrind_h)
245 def check_valgrind(valgrind, valgrind_h):
246     if valgrind:
247         if not valgrind_h:
248             die("--enable-valgrind specified but Valgrind is not installed")
249         return True
252 set_define("MOZ_VALGRIND", check_valgrind)
253 set_config("MOZ_VALGRIND", check_valgrind)
256 @depends(target, host)
257 def is_openbsd(target, host):
258     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
261 option(
262     env="SO_VERSION",
263     nargs=1,
264     default="1.0",
265     when=is_openbsd,
266     help="Shared library version for OpenBSD systems",
270 @depends("SO_VERSION", when=is_openbsd)
271 def so_version(value):
272     return value
275 @template
276 def library_name_info_template(host_or_target):
277     assert host_or_target in {host, target}
278     windows_abi = {
279         host: host_windows_abi,
280         target: target_windows_abi,
281     }[host_or_target]
283     @depends(host_or_target, host_or_target.abi | windows_abi, so_version)
284     def library_name_info_impl(host_or_target, windows_abi, so_version):
285         if host_or_target.kernel == "WINNT":
286             # There aren't artifacts for mingw builds, so it's OK that the
287             # results are inaccurate in that case.
288             if windows_abi and windows_abi != "msvc":
289                 return namespace(
290                     dll=namespace(prefix="", suffix=".dll"),
291                     lib=namespace(prefix="lib", suffix="a"),
292                     import_lib=namespace(prefix="lib", suffix="a"),
293                     obj=namespace(prefix="", suffix="o"),
294                 )
296             return namespace(
297                 dll=namespace(prefix="", suffix=".dll"),
298                 lib=namespace(prefix="", suffix="lib"),
299                 import_lib=namespace(prefix="", suffix="lib"),
300                 obj=namespace(prefix="", suffix="obj"),
301             )
303         elif host_or_target.kernel == "Darwin":
304             return namespace(
305                 dll=namespace(prefix="lib", suffix=".dylib"),
306                 lib=namespace(prefix="lib", suffix="a"),
307                 import_lib=namespace(prefix=None, suffix=""),
308                 obj=namespace(prefix="", suffix="o"),
309             )
310         elif so_version:
311             so = ".so.%s" % so_version
312         else:
313             so = ".so"
315         return namespace(
316             dll=namespace(prefix="lib", suffix=so),
317             lib=namespace(prefix="lib", suffix="a"),
318             import_lib=namespace(prefix=None, suffix=""),
319             obj=namespace(prefix="", suffix="o"),
320         )
322     return library_name_info_impl
325 host_library_name_info = library_name_info_template(host)
326 library_name_info = library_name_info_template(target)
328 set_config("DLL_PREFIX", library_name_info.dll.prefix)
329 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
330 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
331 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
332 set_config("LIB_PREFIX", library_name_info.lib.prefix)
333 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
334 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
335 # Lots of compilation tests depend on this variable being present.
336 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
337 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
338 set_define(
339     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
341 set_define(
342     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
344 set_config("HOST_LIB_PREFIX", host_library_name_info.lib.prefix)
345 set_config("HOST_IMPORT_LIB_SUFFIX", host_library_name_info.import_lib.suffix)
346 set_config("WASM_OBJ_SUFFIX", "wasm")
349 @template
350 def plain_llvm_or_prefixed(name, llvm_name=None):
351     # look for a tool, using the following alternatives, in that order:
352     # 1. llvm-${llvm_name}, or llvm-${name} if ${llvm_name} is not provided
353     # 2. ${toolchain_prefix}${name}
354     # 3. ${name}
356     @depends(llvm_tool("llvm-{}".format(llvm_name or name)), toolchain_prefix)
357     def plain_llvm_or_prefixed(llvm_tool, toolchain_prefix):
358         commands = [llvm_tool[0], name]
359         for prefix in toolchain_prefix or ():
360             commands.insert(1, f"{prefix}{name}")
361         return tuple(commands)
363     return plain_llvm_or_prefixed
366 def validate_readelf(path):
367     # llvm-readelf from llvm < 8 doesn't support the GNU binutils-compatible `-d`
368     # flag. We could try running `$path -d $some_binary` but we might be cross
369     # compiling and not have a binary at hand to run that against. `$path -d` alone
370     # would fail whether the flag is supported or not. So we resort to look for the
371     # option in the `--help` output, which fortunately, s compatible between
372     # llvm-readelf and readelf.
373     retcode, stdout, stderr = get_cmd_output(path, "--help")
374     return retcode == 0 and any(l.startswith("  -d ") for l in stdout.splitlines())
377 @depends("--enable-compile-environment", target, host)
378 def readelf_when(compile_env, target, host):
379     return compile_env and any(
380         x.kernel not in ("Darwin", "WINNT") for x in (target, host)
381     )
384 readelf = check_prog(
385     "READELF",
386     plain_llvm_or_prefixed("readelf"),
387     when=readelf_when,
388     paths=clang_search_path,
389     validate=validate_readelf,
393 def validate_objcopy(path):
394     if "llvm-objcopy" not in path:
395         return True
396     # llvm-objcopy doesn't support --only-keep-debug before llvm 9.0.
397     retcode, stdout, stderr = get_cmd_output(path, "--help")
398     return retcode == 0 and any(
399         l.startswith("  --only-keep-debug ") for l in stdout.splitlines()
400     )
403 check_prog(
404     "OBJCOPY",
405     plain_llvm_or_prefixed("objcopy"),
406     when=readelf_when,
407     paths=clang_search_path,
408     validate=validate_objcopy,
412 # Make `profiling` available to this file even when js/moz.configure
413 # doesn't end up included.
414 profiling = dependable(False)
415 # Same for js_standalone
416 js_standalone = dependable(False)
417 js_shared = dependable(False)
418 moz_linker = dependable(False)
419 # Same for fold_libs
420 fold_libs = dependable(False)
421 # And dmd
422 dmd = dependable(False)
424 include(include_project_configure)
427 @depends("--help")
428 @imports(_from="mozbuild.backend", _import="backends")
429 def build_backends_choices(_):
430     return tuple(backends)
433 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
434 def build_backend(backends):
435     if backends:
436         return tuple("+%s" % b for b in backends)
439 imply_option("--build-backends", build_backend)
442 @depends(
443     host,
444     target,
445     "--enable-artifact-builds",
446     "--disable-compile-environment",
447     "--enable-project",
448     "--enable-application",
449     "--help",
451 @imports("sys")
452 def build_backend_defaults(
453     host,
454     target,
455     artifact_builds,
456     compile_environment,
457     project,
458     application,
459     _,
461     if application:
462         project = application[0]
463     elif project:
464         project = project[0]
466     if artifact_builds:
467         all_backends = ["FasterMake+RecursiveMake"]
468     else:
469         all_backends = ["RecursiveMake", "FasterMake"]
470     if (
471         host.os == "WINNT"
472         and target.os == "WINNT"
473         and compile_environment
474         and project not in ("mobile/android", "memory", "tools/update-programs")
475     ):
476         all_backends.append("VisualStudio")
477     if compile_environment and project not in ("memory", "tools/update-programs"):
478         all_backends.append("Clangd")
479     return tuple(all_backends) or None
482 option(
483     "--build-backends",
484     nargs="+",
485     default=build_backend_defaults,
486     choices=build_backends_choices,
487     help="Build backends to generate",
491 @depends("--build-backends")
492 def build_backends(backends):
493     return backends
496 set_config("BUILD_BACKENDS", build_backends)
499 # Determine whether to build the gtest xul. This happens in automation
500 # on Android and Desktop platforms with the exception of:
501 #  - Windows PGO, where linking xul-gtest.dll takes too long;
502 #  - Android other than x86_64, where gtest is not required.
503 @depends(
504     build_project,
505     target,
506     "MOZ_AUTOMATION",
507     enable_tests,
508     when="--enable-compile-environment",
510 def build_gtest(build_project, target, automation, enable_tests):
511     return bool(
512         enable_tests
513         and automation
514         and build_project in ("browser", "comm/mail", "mobile/android")
515         and not (target.os == "Android" and target.cpu != "x86_64")
516     )
519 option(
520     "--enable-gtest-in-build",
521     default=build_gtest,
522     help="{Enable|Force disable} building the gtest libxul during the build.",
523     when="--enable-compile-environment",
526 set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build")
528 # Localization
529 # ==============================================================
530 option(
531     "--enable-ui-locale",
532     default="en-US",
533     help="Select the user interface locale (default: en-US)",
536 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
538 option(
539     "--disable-icu4x",
540     help="Disable using ICU4X",
543 set_config("MOZ_ICU4X", True, when="--enable-icu4x")
544 set_define("MOZ_ICU4X", True, when="--enable-icu4x")
546 # clang-plugin location
547 # ==============================================================
550 @depends(host_library_name_info, build_environment, when="--enable-clang-plugin")
551 def clang_plugin_path(library_name_info, build_env):
552     topobjdir = build_env.topobjdir
553     if topobjdir.endswith("/js/src"):
554         topobjdir = topobjdir[:-7]
555     return os.path.abspath(
556         os.path.join(
557             topobjdir,
558             "build",
559             "clang-plugin",
560             "%sclang-plugin%s"
561             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
562         )
563     )
566 set_config("CLANG_PLUGIN", clang_plugin_path)
567 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
570 # Awk detection
571 # ==============================================================
572 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"), paths=prefer_mozillabuild_path)
574 # Until the AWK variable is not necessary in old-configure
577 @depends(awk)
578 def awk_for_old_configure(value):
579     return value
582 add_old_configure_assignment("AWK", awk_for_old_configure)
585 # GNU make detection
586 # ==============================================================
587 option(env="MAKE", nargs=1, help="Path to GNU make")
590 @depends("MAKE", host)
591 def possible_makes(make, host):
592     candidates = []
593     if make:
594         candidates.append(make[0])
595     if host.kernel == "WINNT":
596         candidates.extend(("mozmake", "mingw32-make", "make", "gmake"))
597     else:
598         candidates.extend(("gmake", "make"))
599     return candidates
602 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
604 # watchman detection
605 # ==============================================================
607 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
610 @depends(host, "WATCHMAN")
611 @checking("for watchman", callback=lambda w: w.path if w else "not found")
612 def watchman(host, prog):
613     # On Windows, `watchman` is only supported on 64-bit hosts.
614     if host.os == "WINNT" and host.cpu != "x86_64":
615         return
617     if not prog:
618         prog = find_program("watchman")
620     if not prog:
621         return
623     # `watchman version` will talk to the Watchman daemon service.
624     # This can hang due to permissions problems. e.g.
625     # https://github.com/facebook/watchman/issues/376. So use
626     # `watchman --version` to prevent a class of failures.
627     out = check_cmd_output(prog, "--version", onerror=lambda: None)
628     if out is None:
629         return
631     return namespace(path=prog, version=Version(out.strip()))
634 @depends_if(watchman)
635 @checking("for watchman version")
636 def watchman_version(w):
637     return w.version
640 set_config("WATCHMAN", watchman.path)
643 @depends_all(hg_version, hg_config, watchman)
644 @checking("for watchman Mercurial integration")
645 @imports("os")
646 def watchman_hg(hg_version, hg_config, watchman):
647     if hg_version < Version("3.8"):
648         return "no (Mercurial 3.8+ required)"
650     ext_enabled = False
651     mode_disabled = False
653     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
654         if k in hg_config and hg_config[k] != "!":
655             ext_enabled = True
657     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
659     if not ext_enabled:
660         return "no (fsmonitor extension not enabled)"
661     if mode_disabled:
662         return "no (fsmonitor.mode=off disables fsmonitor)"
664     return True
667 # Miscellaneous programs
668 # ==============================================================
669 check_prog("XARGS", ("xargs",))
672 @depends(target)
673 def extra_programs(target):
674     if target.kernel == "Darwin":
675         return namespace(
676             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
677             HFS_TOOL=("hfsplus",),
678         )
679     if target.os == "GNU" and target.kernel == "Linux":
680         return namespace(RPMBUILD=("rpmbuild",))
683 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
684 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
685 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
688 nsis = check_prog(
689     "MAKENSISU",
690     ("makensis",),
691     bootstrap="nsis/bin",
692     allow_missing=True,
693     when=target_is_windows,
696 # Make sure the version of makensis is up to date.
699 @depends_if(nsis)
700 @checking("for NSIS version")
701 @imports("re")
702 def nsis_version(nsis):
703     nsis_min_version = "3.0b1"
705     def onerror():
706         return die("Failed to get nsis version.")
708     out = check_cmd_output(nsis, "-version", onerror=onerror)
710     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
712     if not m:
713         raise FatalCheckError("Unknown version of makensis")
714     ver = Version(m.group(0))
716     # Versions comparisons don't quite work well with beta versions, so ensure
717     # it works for the non-beta version.
718     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
719         raise FatalCheckError(
720             "To build the installer you must have NSIS"
721             " version %s or greater in your path" % nsis_min_version
722         )
724     return ver
727 # And that makensis is 32-bit (but only on Windows).
728 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
729 @checking("for 32-bit NSIS")
730 def nsis_binary_type(nsis):
731     bin_type = windows_binary_type(nsis)
732     if bin_type != "win32":
733         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
735     return "yes"
738 # And any flags we have to give to makensis
739 @depends(host)
740 def nsis_flags(host):
741     if host.kernel != "WINNT":
742         return "-nocd"
743     return ""
746 set_config("MAKENSISU_FLAGS", nsis_flags)
748 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
749 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
752 check_prog(
753     "DSYMUTIL",
754     llvm_tool("dsymutil"),
755     when=compile_environment & target_is_darwin,
756     paths=clang_search_path,
760 check_prog(
761     "OTOOL",
762     plain_llvm_or_prefixed("otool"),
763     when=compile_environment & target_is_darwin,
764     paths=clang_search_path,
767 check_prog(
768     "INSTALL_NAME_TOOL",
769     plain_llvm_or_prefixed("install_name_tool", llvm_name="install-name-tool"),
770     when=compile_environment & target_is_darwin & js_standalone,
771     paths=clang_search_path,
774 option(
775     "--enable-strip",
776     when=compile_environment,
777     help="Enable stripping of libs & executables",
780 # This should be handled as a `when` once bug 1617793 is fixed.
783 @depends("--enable-strip", c_compiler, when=compile_environment)
784 def enable_strip(strip, c_compiler):
785     if strip and c_compiler.type != "clang-cl":
786         return True
789 set_config("ENABLE_STRIP", enable_strip)
791 option(
792     "--disable-install-strip",
793     when=compile_environment,
794     help="Enable stripping of libs & executables when packaging",
797 # This should be handled as a `when` once bug 1617793 is fixed.
800 @depends("--enable-install-strip", c_compiler, when=compile_environment)
801 def enable_install_strip(strip, c_compiler):
802     if strip and c_compiler.type != "clang-cl":
803         return True
806 set_config("PKG_STRIP", enable_install_strip)
809 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
810 def strip(strip, install_strip):
811     return strip or install_strip
814 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
817 @depends("STRIP_FLAGS", profiling, target, when=strip)
818 def strip_flags(flags, profiling, target):
819     if flags:
820         return flags[0].split()
821     if profiling:
822         # Only strip debug info and symbols when profiling is enabled, keeping
823         # local symbols.
824         if target.kernel == "Darwin":
825             return ["-S"]
826         elif target.os == "Android":
827             # The tooling we use with Android supports detached symbols, and the
828             # size increase caused by local symbols are too much for mobile. So,
829             # don't restrict the amount of stripping with a flag.
830             return
831         else:
832             return ["--strip-debug"]
833     # Otherwise strip everything we can, which happens without flags on non-Darwin.
834     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
835     elif target.kernel == "Darwin":
836         return ["-x", "-S"]
839 set_config("STRIP_FLAGS", strip_flags)
842 def validate_strip(path):
843     if "llvm-strip" not in path:
844         return True
845     # llvm-strip doesn't support -S before llvm 8.0.
846     retcode, stdout, stderr = get_cmd_output(path, "--help")
847     return retcode == 0 and any(l.startswith("  -S ") for l in stdout.splitlines())
850 @depends("--enable-compile-environment", target, host)
851 def strip_when(compile_env, target, host):
852     return compile_env and any(x.kernel != "WINNT" for x in (target, host))
855 check_prog(
856     "STRIP",
857     plain_llvm_or_prefixed("strip"),
858     when=strip_when,
859     paths=clang_search_path,
860     validate=validate_strip,
864 @depends(js_standalone, target)
865 def system_zlib_default(js_standalone, target):
866     return (
867         js_standalone
868         and target.kernel not in ("WINNT", "Darwin")
869         and target.os != "Android"
870     )
873 option(
874     "--with-system-zlib",
875     nargs="?",
876     default=system_zlib_default,
877     help="{Use|Do not use} system libz",
878     when=use_pkg_config,
882 @depends("--with-system-zlib", when=use_pkg_config)
883 def with_system_zlib_option(with_system_zlib):
884     return with_system_zlib
887 @depends(with_system_zlib_option)
888 def deprecated_system_zlib_path(value):
889     if value and len(value) == 1:
890         die(
891             "--with-system-zlib=PATH is not supported anymore. Please use "
892             "--with-system-zlib and set any necessary pkg-config environment variable."
893         )
896 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
898 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
901 @depends(with_system_zlib_option, js_shared, moz_linker, target.os)
902 def zlib_in_mozglue(system_zlib, js_shared, linker, os):
903     if not system_zlib and (js_shared or linker or os == "Android"):
904         return True
907 set_config("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
908 set_define("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
911 with only_when(cross_compiling):
912     option(
913         env="JS_BINARY",
914         nargs=1,
915         help="Host JavaScript runtime, if any, to use during cross compiles",
916     )
917     set_config("JS_BINARY", depends_if("JS_BINARY")(lambda value: value[0]))
919 # Please do not add configure checks from here on.
921 # Fallthrough to autoconf-based configure
922 include("build/moz.configure/old.configure")
924 # JS Subconfigure.
925 include("js/sub.configure", when=compile_environment & toolkit)
928 @depends(build_environment, configure_cache)
929 @imports(_import="json")
930 @imports(_from="pathlib", _import="Path")
931 def save_cache(build_environment, configure_cache):
932     cache_file = Path(build_environment.topobjdir) / "configure.cache"
934     with cache_file.open(mode="w") as fd:
935         json.dump(configure_cache, fd, indent=4)
938 @depends(build_environment, build_project)
939 @imports("__sandbox__")
940 @imports("glob")
941 @imports(_from="os.path", _import="exists")
942 def config_status_deps(build_env, build_project):
943     topsrcdir = build_env.topsrcdir
944     topobjdir = build_env.topobjdir
946     if not topobjdir.endswith("js/src"):
947         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
948     else:
949         # mozconfig changes may impact js configure.
950         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
952     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
953     if exists(confvars):
954         extra_deps.append(confvars)
956     return (
957         list(__sandbox__._all_paths)
958         + extra_deps
959         + [
960             os.path.join(topsrcdir, "CLOBBER"),
961             os.path.join(topsrcdir, "configure"),
962             os.path.join(topsrcdir, "js", "src", "configure"),
963             os.path.join(topsrcdir, "nsprpub", "configure"),
964             os.path.join(topsrcdir, "config", "milestone.txt"),
965             os.path.join(topsrcdir, "browser", "config", "version.txt"),
966             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
967             os.path.join(topsrcdir, "python", "sites", "build.txt"),
968             os.path.join(topsrcdir, "python", "sites", "common.txt"),
969             os.path.join(topsrcdir, "python", "sites", "mach.txt"),
970             os.path.join(topsrcdir, "python", "mach", "mach", "site.py"),
971             os.path.join(topsrcdir, "aclocal.m4"),
972             os.path.join(topsrcdir, "old-configure.in"),
973             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
974             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
975         ]
976         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
977     )
980 set_config("CONFIG_STATUS_DEPS", config_status_deps)
981 # Please do not add anything after setting config_dep_paths.