Backed out changeset f9ccd9f31b9c (bug 1917901) for causing networking crashes. a...
[gecko.git] / moz.configure
blobbeffb5a9d2a328fbbed0ad6a0cf4004278dfc9c2
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="Path to the moz.build file that will be executed as if it were "
55     "appended to 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)
91 option("--disable-tests", help="Do not build test libraries & programs")
94 @depends("--disable-tests")
95 def enable_tests(value):
96     if value:
97         return True
100 set_config("ENABLE_TESTS", enable_tests)
101 set_define("ENABLE_TESTS", enable_tests)
104 @depends(enable_tests)
105 def gtest_has_rtti(value):
106     if value:
107         return "0"
110 set_define("GTEST_HAS_RTTI", gtest_has_rtti)
113 @depends(target, enable_tests)
114 def linux_gtest_defines(target, enable_tests):
115     if enable_tests and target.os == "Android":
116         return namespace(os_linux_android=True, use_own_tr1_tuple=True, has_clone="0")
119 set_define("GTEST_OS_LINUX_ANDROID", linux_gtest_defines.os_linux_android)
120 set_define("GTEST_USE_OWN_TR1_TUPLE", linux_gtest_defines.use_own_tr1_tuple)
121 set_define("GTEST_HAS_CLONE", linux_gtest_defines.has_clone)
123 set_define("FMT_API", "MFBT_API")
124 set_define("FMT_ENFORCE_COMPILE_STRING", 1)
125 set_define("FMT_USE_EXCEPTIONS", 0)
126 set_define("FMT_USE_WRITE_CONSOLE", 1)
127 set_define("FMT_USE_LOCALE", 0)
129 option(
130     "--enable-debug",
131     nargs="?",
132     help="Enable building with developer debug info "
133     "(using the given compiler flags)",
137 @depends("--enable-debug")
138 def moz_debug(debug):
139     if debug:
140         return bool(debug)
143 set_config("MOZ_DEBUG", moz_debug)
144 set_define("MOZ_DEBUG", moz_debug)
145 # Override any value MOZ_DEBUG may have from the environment when passing it
146 # down to old-configure.
147 add_old_configure_assignment("MOZ_DEBUG", depends("--enable-debug")(lambda x: bool(x)))
150 set_config(
151     "MOZ_DIAGNOSTIC_ASSERT_ENABLED",
152     True,
153     when=moz_debug | milestone.is_early_beta_or_earlier,
155 set_define(
156     "MOZ_DIAGNOSTIC_ASSERT_ENABLED",
157     True,
158     when=moz_debug | milestone.is_early_beta_or_earlier,
161 option(
162     "--with-debug-label",
163     nargs="+",
164     help="Debug DEBUG_<value> for each comma-separated value given",
168 @depends(moz_debug, "--with-debug-label")
169 def debug_defines(debug, labels):
170     if debug:
171         return ["DEBUG"] + ["DEBUG_%s" % label for label in labels]
172     return ["NDEBUG", "TRIMMED"]
175 set_config("MOZ_DEBUG_DEFINES", debug_defines)
177 option(env="MOZ_PGO", help="Build with profile guided optimizations")
179 set_config("MOZ_PGO", depends("MOZ_PGO")(lambda x: bool(x)))
182 # Imply --enable-release when MOZILLA_OFFICIAL is set rather than adjusting the
183 # default so that we can't have both MOZILLA_OFFICIAL and --disable-release set.
184 imply_option("--enable-release", mozilla_official)
186 option(
187     "--enable-release",
188     default=milestone.is_release_or_beta | depends("MOZ_AUTOMATION")(lambda x: bool(x)),
189     help="{Build|Do not build} with more conservative, release "
190     "engineering-oriented options.{ This may slow down builds.|}",
194 @depends("--enable-release")
195 def developer_options(value):
196     if not value:
197         return True
200 set_config("DEVELOPER_OPTIONS", developer_options)
203 # hybrid build handling
204 # ==============================================================
206 option(
207     "--disable-unified-build",
208     help="Enable building modules in non unified context",
211 set_config("ENABLE_UNIFIED_BUILD", True, when="--disable-unified-build")
214 include("build/moz.configure/bootstrap.configure")
217 # The execution model of the configure sandbox doesn't allow for
218 # check_prog to use bootstrap_search_path directly because check_prog
219 # comes first, so we use a trick to allow it. Uses of check_prog
220 # happening before here won't allow bootstrap.
223 @template
224 def check_prog(*args, **kwargs):
225     kwargs["bootstrap_search_path"] = bootstrap_search_path
226     return check_prog(*args, **kwargs)
229 check_prog("WGET", ("wget",), allow_missing=True)
232 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
234 include("build/moz.configure/pkg.configure")
235 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
236 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
237 include("build/moz.configure/libraries.configure", when="--enable-compile-environment")
238 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
239 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
240 include("build/moz.configure/default-flags.configure", when=~compile_environment)
241 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
242 # rust.configure is included by js/moz.configure.
245 option("--enable-valgrind", help="Enable Valgrind integration hooks")
247 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
250 @depends("--enable-valgrind", valgrind_h)
251 def check_valgrind(valgrind, valgrind_h):
252     if valgrind:
253         if not valgrind_h:
254             die("--enable-valgrind specified but Valgrind is not installed")
255         return True
258 set_define("MOZ_VALGRIND", check_valgrind)
259 set_config("MOZ_VALGRIND", check_valgrind)
262 @depends(target, host)
263 def is_openbsd(target, host):
264     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
267 option(
268     env="SO_VERSION",
269     nargs=1,
270     default="1.0",
271     when=is_openbsd,
272     help="Shared library version for OpenBSD systems",
276 @depends("SO_VERSION", when=is_openbsd)
277 def so_version(value):
278     return value
281 @template
282 def library_name_info_template(host_or_target):
283     assert host_or_target in {host, target}
284     windows_abi = {
285         host: host_windows_abi,
286         target: target_windows_abi,
287     }[host_or_target]
289     @depends(host_or_target, host_or_target.abi | windows_abi, so_version)
290     def library_name_info_impl(host_or_target, windows_abi, so_version):
291         if host_or_target.kernel == "WINNT":
292             # There aren't artifacts for mingw builds, so it's OK that the
293             # results are inaccurate in that case.
294             if windows_abi and windows_abi != "msvc":
295                 return namespace(
296                     dll=namespace(prefix="", suffix=".dll"),
297                     lib=namespace(prefix="lib", suffix="a"),
298                     import_lib=namespace(prefix="lib", suffix="a"),
299                     obj=namespace(prefix="", suffix="o"),
300                 )
302             return namespace(
303                 dll=namespace(prefix="", suffix=".dll"),
304                 lib=namespace(prefix="", suffix="lib"),
305                 import_lib=namespace(prefix="", suffix="lib"),
306                 obj=namespace(prefix="", suffix="obj"),
307             )
309         elif host_or_target.kernel == "Darwin":
310             return namespace(
311                 dll=namespace(prefix="lib", suffix=".dylib"),
312                 lib=namespace(prefix="lib", suffix="a"),
313                 import_lib=namespace(prefix=None, suffix=""),
314                 obj=namespace(prefix="", suffix="o"),
315             )
316         elif so_version:
317             so = ".so.%s" % so_version
318         else:
319             so = ".so"
321         return namespace(
322             dll=namespace(prefix="lib", suffix=so),
323             lib=namespace(prefix="lib", suffix="a"),
324             import_lib=namespace(prefix=None, suffix=""),
325             obj=namespace(prefix="", suffix="o"),
326         )
328     return library_name_info_impl
331 host_library_name_info = library_name_info_template(host)
332 library_name_info = library_name_info_template(target)
334 set_config("DLL_PREFIX", library_name_info.dll.prefix)
335 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
336 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
337 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
338 set_config("LIB_PREFIX", library_name_info.lib.prefix)
339 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
340 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
341 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
342 set_define(
343     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
345 set_define(
346     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
348 set_config("HOST_LIB_PREFIX", host_library_name_info.lib.prefix)
349 set_config("HOST_IMPORT_LIB_SUFFIX", host_library_name_info.import_lib.suffix)
350 set_config("WASM_OBJ_SUFFIX", "wasm")
353 @template
354 def bin_suffix(host_or_target):
355     return depends(host_or_target)(
356         lambda host_or_target: ".exe" if host_or_target.os == "WINNT" else ""
357     )
360 set_config("BIN_SUFFIX", bin_suffix(target))
361 set_config("HOST_BIN_SUFFIX", bin_suffix(host))
364 @template
365 def plain_llvm_or_prefixed(name, llvm_name=None):
366     # look for a tool, using the following alternatives, in that order:
367     # 1. llvm-${llvm_name}, or llvm-${name} if ${llvm_name} is not provided
368     # 2. ${toolchain_prefix}${name}
369     # 3. ${name}
371     @depends(llvm_tool("llvm-{}".format(llvm_name or name)), toolchain_prefix)
372     def plain_llvm_or_prefixed(llvm_tool, toolchain_prefix):
373         commands = [llvm_tool[0], name]
374         for prefix in toolchain_prefix or ():
375             commands.insert(1, f"{prefix}{name}")
376         return tuple(commands)
378     return plain_llvm_or_prefixed
381 def validate_readelf(path):
382     # llvm-readelf from llvm < 8 doesn't support the GNU binutils-compatible `-d`
383     # flag. We could try running `$path -d $some_binary` but we might be cross
384     # compiling and not have a binary at hand to run that against. `$path -d` alone
385     # would fail whether the flag is supported or not. So we resort to look for the
386     # option in the `--help` output, which fortunately, s compatible between
387     # llvm-readelf and readelf.
388     retcode, stdout, stderr = get_cmd_output(path, "--help")
389     return retcode == 0 and any(l.startswith("  -d ") for l in stdout.splitlines())
392 @depends("--enable-compile-environment", target, host)
393 def readelf_when(compile_env, target, host):
394     return compile_env and any(
395         x.kernel not in ("Darwin", "WINNT") for x in (target, host)
396     )
399 readelf = check_prog(
400     "READELF",
401     plain_llvm_or_prefixed("readelf"),
402     when=readelf_when,
403     paths=clang_search_path,
404     validate=validate_readelf,
408 def validate_objcopy(path):
409     if "llvm-objcopy" not in path:
410         return True
411     # llvm-objcopy doesn't support --only-keep-debug before llvm 9.0.
412     retcode, stdout, stderr = get_cmd_output(path, "--help")
413     return retcode == 0 and any(
414         l.startswith("  --only-keep-debug ") for l in stdout.splitlines()
415     )
418 check_prog(
419     "OBJCOPY",
420     plain_llvm_or_prefixed("objcopy"),
421     when=readelf_when,
422     paths=clang_search_path,
423     validate=validate_objcopy,
427 # Make `profiling` available to this file even when js/moz.configure
428 # doesn't end up included.
429 profiling = dependable(False)
430 # Same for js_standalone
431 js_standalone = dependable(False)
432 # Same for fold_libs
433 fold_libs = dependable(False)
434 # And dmd
435 dmd = dependable(False)
437 # Only available when toolkit/moz.configure is included
438 pack_relative_relocs_flags = dependable(False)
440 include(include_project_configure)
443 # Final flags validation and gathering
444 # -------------------------------------------------
446 include(
447     "build/moz.configure/finalize-flags.configure", when="--enable-compile-environment"
450 # -------------------------------------------------
453 @depends("--help")
454 @imports(_from="mozbuild.backend", _import="backends")
455 def build_backends_choices(_):
456     return tuple(backends)
459 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
460 def build_backend(backends):
461     if backends:
462         return tuple("+%s" % b for b in backends)
465 imply_option("--build-backends", build_backend)
468 @depends(
469     host,
470     target,
471     "--enable-artifact-builds",
472     "--disable-compile-environment",
473     "--enable-project",
474     "--enable-application",
475     "--help",
477 @imports("sys")
478 def build_backend_defaults(
479     host,
480     target,
481     artifact_builds,
482     compile_environment,
483     project,
484     application,
485     _,
487     if application:
488         project = application[0]
489     elif project:
490         project = project[0]
492     if artifact_builds:
493         all_backends = ["FasterMake+RecursiveMake"]
494     else:
495         all_backends = ["RecursiveMake", "FasterMake"]
496     if (
497         host.os == "WINNT"
498         and target.os == "WINNT"
499         and compile_environment
500         and project not in ("mobile/android", "memory", "tools/update-programs")
501     ):
502         all_backends.append("VisualStudio")
503     if compile_environment and project not in ("memory", "tools/update-programs"):
504         all_backends.append("Clangd")
505     return tuple(all_backends) or None
508 option(
509     "--build-backends",
510     nargs="+",
511     default=build_backend_defaults,
512     choices=build_backends_choices,
513     help="Build backends to generate",
517 @depends("--build-backends")
518 def build_backends(backends):
519     return backends
522 set_config("BUILD_BACKENDS", build_backends)
525 # Determine whether to build the gtest xul. This happens in automation
526 # on Android and Desktop platforms with the exception of:
527 #  - Windows PGO, where linking xul-gtest.dll takes too long;
528 #  - Android other than x86_64, where gtest is not required.
529 @depends(
530     build_project,
531     target,
532     "MOZ_AUTOMATION",
533     enable_tests,
534     when="--enable-compile-environment",
536 def build_gtest(build_project, target, automation, enable_tests):
537     return bool(
538         enable_tests
539         and automation
540         and build_project in ("browser", "comm/mail", "mobile/android")
541         and not (target.os == "Android" and target.cpu != "x86_64")
542     )
545 option(
546     "--enable-gtest-in-build",
547     default=build_gtest,
548     help="{Enable|Force disable} building the gtest libxul during the build",
549     when="--enable-compile-environment",
552 set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build")
554 # Localization
555 # ==============================================================
556 option(
557     "--enable-ui-locale",
558     default="en-US",
559     help="Select the user interface locale (default: en-US)",
562 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
564 # clang-plugin location
565 # ==============================================================
566 include(
567     "build/moz.configure/clang_plugin.configure", when="--enable-compile-environment"
571 # Awk detection
572 # ==============================================================
573 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"), paths=prefer_mozillabuild_path)
575 # Until the AWK variable is not necessary in old-configure
578 @depends(awk)
579 def awk_for_old_configure(value):
580     return value
583 # GNU make detection
584 # ==============================================================
585 option(env="MAKE", nargs=1, help="Path to GNU make")
588 @depends("MAKE", host)
589 def possible_makes(make, host):
590     candidates = []
591     if make:
592         candidates.append(make[0])
593     if host.kernel == "WINNT":
594         candidates.extend(("mozmake", "mingw32-make", "make", "gmake"))
595     else:
596         candidates.extend(("gmake", "make"))
597     return candidates
600 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
602 # watchman detection
603 # ==============================================================
605 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
608 @depends(host, "WATCHMAN")
609 @checking("for watchman", callback=lambda w: w.path if w else "not found")
610 def watchman(host, prog):
611     # On Windows, `watchman` is only supported on 64-bit hosts.
612     if host.os == "WINNT" and host.cpu != "x86_64":
613         return
615     if not prog:
616         prog = find_program("watchman")
618     if not prog:
619         return
621     # `watchman version` will talk to the Watchman daemon service.
622     # This can hang due to permissions problems. e.g.
623     # https://github.com/facebook/watchman/issues/376. So use
624     # `watchman --version` to prevent a class of failures.
625     out = check_cmd_output(prog, "--version", onerror=lambda: None)
626     if out is None:
627         return
629     return namespace(path=prog, version=Version(out.strip()))
632 @depends_if(watchman)
633 @checking("for watchman version")
634 def watchman_version(w):
635     return w.version
638 set_config("WATCHMAN", watchman.path)
641 @depends_all(hg_version, hg_config, watchman)
642 @checking("for watchman Mercurial integration")
643 @imports("os")
644 def watchman_hg(hg_version, hg_config, watchman):
645     if hg_version < Version("3.8"):
646         return "no (Mercurial 3.8+ required)"
648     ext_enabled = False
649     mode_disabled = False
651     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
652         if k in hg_config and hg_config[k] != "!":
653             ext_enabled = True
655     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
657     if not ext_enabled:
658         return "no (fsmonitor extension not enabled)"
659     if mode_disabled:
660         return "no (fsmonitor.mode=off disables fsmonitor)"
662     return True
665 # Miscellaneous programs
666 # ==============================================================
667 check_prog("XARGS", ("xargs",))
670 @depends(target)
671 def extra_programs(target):
672     if target.kernel == "Darwin":
673         return namespace(
674             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
675             HFS_TOOL=("hfsplus",),
676         )
677     if target.os == "GNU" and target.kernel == "Linux":
678         return namespace(RPMBUILD=("rpmbuild",))
681 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
682 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
683 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
686 nsis = check_prog(
687     "MAKENSISU",
688     ("makensis",),
689     bootstrap="nsis/bin",
690     allow_missing=True,
691     when=target_is_windows,
694 # Make sure the version of makensis is up to date.
697 @depends_if(nsis)
698 @checking("for NSIS version")
699 @imports("re")
700 def nsis_version(nsis):
701     nsis_min_version = "3.0b1"
703     def onerror():
704         return die("Failed to get nsis version.")
706     out = check_cmd_output(nsis, "-version", onerror=onerror)
708     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
710     if not m:
711         raise FatalCheckError("Unknown version of makensis")
712     ver = Version(m.group(0))
714     # Versions comparisons don't quite work well with beta versions, so ensure
715     # it works for the non-beta version.
716     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
717         raise FatalCheckError(
718             "To build the installer you must have NSIS"
719             " version %s or greater in your path" % nsis_min_version
720         )
722     return ver
725 # And that makensis is 32-bit (but only on Windows).
726 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
727 @checking("for 32-bit NSIS")
728 def nsis_binary_type(nsis):
729     bin_type = windows_binary_type(nsis)
730     if bin_type != "win32":
731         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
733     return "yes"
736 # And any flags we have to give to makensis
737 @depends(host)
738 def nsis_flags(host):
739     if host.kernel != "WINNT":
740         return "-nocd"
741     return ""
744 set_config("MAKENSISU_FLAGS", nsis_flags)
746 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
747 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
750 check_prog(
751     "DSYMUTIL",
752     llvm_tool("dsymutil"),
753     when=compile_environment & target_is_darwin,
754     paths=clang_search_path,
758 check_prog(
759     "OTOOL",
760     plain_llvm_or_prefixed("otool"),
761     when=compile_environment & target_is_darwin,
762     paths=clang_search_path,
765 check_prog(
766     "INSTALL_NAME_TOOL",
767     plain_llvm_or_prefixed("install_name_tool", llvm_name="install-name-tool"),
768     when=compile_environment & target_is_darwin & js_standalone,
769     paths=clang_search_path,
772 option(
773     "--enable-strip",
774     when=compile_environment,
775     help="Enable stripping of libs & executables",
778 # This should be handled as a `when` once bug 1617793 is fixed.
781 @depends("--enable-strip", c_compiler, when=compile_environment)
782 def enable_strip(strip, c_compiler):
783     if strip and c_compiler.type != "clang-cl":
784         return True
787 set_config("ENABLE_STRIP", enable_strip)
789 option(
790     "--disable-install-strip",
791     when=compile_environment,
792     help="Enable stripping of libs & executables when packaging",
795 # This should be handled as a `when` once bug 1617793 is fixed.
798 @depends("--enable-install-strip", c_compiler, when=compile_environment)
799 def enable_install_strip(strip, c_compiler):
800     if strip and c_compiler.type != "clang-cl":
801         return True
804 set_config("PKG_STRIP", enable_install_strip)
807 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
808 def strip(strip, install_strip):
809     return strip or install_strip
812 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
815 @depends("STRIP_FLAGS", profiling, target, when=strip)
816 def strip_flags(flags, profiling, target):
817     if flags:
818         return flags[0].split()
819     if profiling:
820         # Only strip debug info and symbols when profiling is enabled, keeping
821         # local symbols.
822         if target.kernel == "Darwin":
823             return ["-S"]
824         elif target.os == "Android":
825             # The tooling we use with Android supports detached symbols, and the
826             # size increase caused by local symbols are too much for mobile. So,
827             # don't restrict the amount of stripping with a flag.
828             return
829         else:
830             return ["--strip-debug"]
831     # Otherwise strip everything we can, which happens without flags on non-Darwin.
832     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
833     elif target.kernel == "Darwin":
834         return ["-x", "-S"]
837 set_config("STRIP_FLAGS", strip_flags)
840 def validate_strip(path):
841     if "llvm-strip" not in path:
842         return True
843     # llvm-strip doesn't support -S before llvm 8.0.
844     retcode, stdout, stderr = get_cmd_output(path, "--help")
845     return retcode == 0 and any(l.startswith("  -S ") for l in stdout.splitlines())
848 @depends("--enable-compile-environment", target, host)
849 def strip_when(compile_env, target, host):
850     return compile_env and any(x.kernel != "WINNT" for x in (target, host))
853 check_prog(
854     "STRIP",
855     plain_llvm_or_prefixed("strip"),
856     when=strip_when,
857     paths=clang_search_path,
858     validate=validate_strip,
862 @depends(js_standalone, target)
863 def system_zlib_default(js_standalone, target):
864     return (
865         js_standalone
866         and target.kernel not in ("WINNT", "Darwin")
867         and target.os != "Android"
868     )
871 option(
872     "--with-system-zlib",
873     nargs="?",
874     default=system_zlib_default,
875     help="{Use|Do not use} system libz",
876     when=use_pkg_config,
880 @depends("--with-system-zlib", when=use_pkg_config)
881 def with_system_zlib_option(with_system_zlib):
882     return with_system_zlib
885 @depends(with_system_zlib_option)
886 def deprecated_system_zlib_path(value):
887     if value and len(value) == 1:
888         die(
889             "--with-system-zlib=PATH is not supported anymore. Please use "
890             "--with-system-zlib and set any necessary pkg-config environment variable."
891         )
894 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
896 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
898 option(
899     env="USE_LIBZ_RS",
900     help="Use libz-rs-sys instead of zlib",
901     when=toolkit & ~with_system_zlib_option,
904 set_config("USE_LIBZ_RS", True, when="USE_LIBZ_RS")
906 with only_when(cross_compiling):
907     option(
908         env="JS_BINARY",
909         nargs=1,
910         help="Host JavaScript runtime, if any, to use during cross compiles",
911     )
912     set_config("JS_BINARY", depends_if("JS_BINARY")(lambda value: value[0]))
914 # Please do not add configure checks from here on.
916 # Fallthrough to autoconf-based configure
917 include("build/moz.configure/old.configure")
919 # JS Subconfigure.
920 include("js/sub.configure", when=compile_environment & toolkit)
923 @depends(build_environment, configure_cache)
924 @imports(_import="json")
925 @imports(_from="pathlib", _import="Path")
926 def save_cache(build_environment, configure_cache):
927     cache_file = Path(build_environment.topobjdir) / "configure.cache"
929     with cache_file.open(mode="w") as fd:
930         json.dump(configure_cache, fd, indent=4)
933 @depends(build_environment, build_project)
934 @imports("__sandbox__")
935 @imports("glob")
936 @imports(_from="os.path", _import="exists")
937 def config_status_deps(build_env, build_project):
938     topsrcdir = build_env.topsrcdir
939     topobjdir = build_env.topobjdir
941     if not topobjdir.endswith("js/src"):
942         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
943     else:
944         # mozconfig changes may impact js configure.
945         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
947     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
948     if exists(confvars):
949         extra_deps.append(confvars)
951     return (
952         list(__sandbox__._all_paths)
953         + extra_deps
954         + [
955             os.path.join(topsrcdir, "CLOBBER"),
956             os.path.join(topsrcdir, "configure"),
957             os.path.join(topsrcdir, "js", "src", "configure"),
958             os.path.join(topsrcdir, "nsprpub", "configure"),
959             os.path.join(topsrcdir, "config", "milestone.txt"),
960             os.path.join(topsrcdir, "browser", "config", "version.txt"),
961             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
962             os.path.join(topsrcdir, "python", "sites", "build.txt"),
963             os.path.join(topsrcdir, "python", "sites", "common.txt"),
964             os.path.join(topsrcdir, "python", "sites", "mach.txt"),
965             os.path.join(topsrcdir, "python", "mach", "mach", "site.py"),
966             os.path.join(topsrcdir, "aclocal.m4"),
967             os.path.join(topsrcdir, "old-configure.in"),
968             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
969             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
970         ]
971         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
972     )
975 set_config("CONFIG_STATUS_DEPS", config_status_deps)
976 # Please do not add anything after setting config_dep_paths.