Bug 1758813 [wpt PR 33142] - Implement RP sign out, a=testonly
[gecko.git] / moz.configure
blob5b69b6213ed4d78f0da5aeca15cc3db09fed9e90
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 option(
18     "--enable-artifact-builds",
19     env="MOZ_ARTIFACT_BUILDS",
20     help="Download and use prebuilt binary artifacts.",
24 @depends("--enable-artifact-builds")
25 def artifact_builds(value):
26     if value:
27         return True
30 set_config("MOZ_ARTIFACT_BUILDS", artifact_builds)
32 imply_option(
33     "--enable-artifact-build-symbols",
34     depends(artifact_builds)(lambda v: False if v is None else None),
35     reason="--disable-artifact-builds",
38 option(
39     "--enable-artifact-build-symbols",
40     nargs="?",
41     choices=("full",),
42     help="Download symbols when artifact builds are enabled.",
46 @depends("--enable-artifact-build-symbols", "MOZ_AUTOMATION", target)
47 def enable_artifact_build_symbols(value, automation, target):
48     if len(value):
49         return value[0]
50     if bool(value):
51         if target.os == "Android" and not automation:
52             return "full"
53         return True
54     return None
57 set_config("MOZ_ARTIFACT_BUILD_SYMBOLS", enable_artifact_build_symbols)
60 @depends("--enable-artifact-builds")
61 def imply_disable_compile_environment(value):
62     if value:
63         return False
66 option(
67     env="MOZ_COPY_PDBS",
68     help="For builds that do not support symbols in the normal fashion,"
69     " generate and copy them into the resulting build archive.",
72 set_config("MOZ_COPY_PDBS", depends_if("MOZ_COPY_PDBS")(lambda _: True))
74 imply_option("--enable-compile-environment", imply_disable_compile_environment)
76 option("--disable-compile-environment", help="Disable compiler/library checks")
79 @depends("--disable-compile-environment")
80 def compile_environment(compile_env):
81     if compile_env:
82         return True
85 set_config("COMPILE_ENVIRONMENT", compile_environment)
86 add_old_configure_assignment("COMPILE_ENVIRONMENT", compile_environment)
88 option("--disable-tests", help="Do not build test libraries & programs")
91 @depends("--disable-tests")
92 def enable_tests(value):
93     if value:
94         return True
97 set_config("ENABLE_TESTS", enable_tests)
98 set_define("ENABLE_TESTS", enable_tests)
101 @depends(enable_tests)
102 def gtest_has_rtti(value):
103     if value:
104         return "0"
107 set_define("GTEST_HAS_RTTI", gtest_has_rtti)
110 @depends(target, enable_tests)
111 def linux_gtest_defines(target, enable_tests):
112     if enable_tests and target.os == "Android":
113         return namespace(os_linux_android=True, use_own_tr1_tuple=True, has_clone="0")
116 set_define("GTEST_OS_LINUX_ANDROID", linux_gtest_defines.os_linux_android)
117 set_define("GTEST_USE_OWN_TR1_TUPLE", linux_gtest_defines.use_own_tr1_tuple)
118 set_define("GTEST_HAS_CLONE", linux_gtest_defines.has_clone)
120 option(
121     "--enable-debug",
122     nargs="?",
123     help="Enable building with developer debug info "
124     "(using the given compiler flags).",
128 @depends("--enable-debug")
129 def moz_debug(debug):
130     if debug:
131         return bool(debug)
134 set_config("MOZ_DEBUG", moz_debug)
135 set_define("MOZ_DEBUG", moz_debug)
136 # Override any value MOZ_DEBUG may have from the environment when passing it
137 # down to old-configure.
138 add_old_configure_assignment("MOZ_DEBUG", depends("--enable-debug")(lambda x: bool(x)))
140 set_config(
141     "MOZ_DIAGNOSTIC_ASSERT_ENABLED",
142     True,
143     when=moz_debug | milestone.is_early_beta_or_earlier,
145 set_define(
146     "MOZ_DIAGNOSTIC_ASSERT_ENABLED",
147     True,
148     when=moz_debug | milestone.is_early_beta_or_earlier,
151 option(
152     "--with-debug-label",
153     nargs="+",
154     help="Debug DEBUG_<value> for each comma-separated value given",
158 @depends(moz_debug, "--with-debug-label")
159 def debug_defines(debug, labels):
160     if debug:
161         return ["DEBUG"] + ["DEBUG_%s" % label for label in labels]
162     return ["NDEBUG", "TRIMMED"]
165 set_config("MOZ_DEBUG_DEFINES", debug_defines)
167 option(env="MOZ_PGO", help="Build with profile guided optimizations")
169 set_config("MOZ_PGO", depends("MOZ_PGO")(lambda x: bool(x)))
172 imply_option("--enable-release", mozilla_official)
173 imply_option("--enable-release", depends_if("MOZ_AUTOMATION")(lambda x: True))
175 option(
176     "--enable-release",
177     default=milestone.is_release_or_beta,
178     help="{Build|Do not build} with more conservative, release "
179     "engineering-oriented options.{ This may slow down builds.|}",
183 @depends("--enable-release")
184 def developer_options(value):
185     if not value:
186         return True
189 add_old_configure_assignment("DEVELOPER_OPTIONS", developer_options)
190 set_config("DEVELOPER_OPTIONS", developer_options)
193 # hybrid build handling
194 # ==============================================================
196 option(
197     "--disable-unified-build",
198     help="Enable building modules that are not marked with `REQUIRES_UNIFIED_BUILD` in non unified context",
201 set_config("ENABLE_UNIFIED_BUILD", True, when="--disable-unified-build")
204 include("build/moz.configure/bootstrap.configure")
206 # The execution model of the configure sandbox doesn't allow for
207 # check_prog to use bootstrap_search_path directly because check_prog
208 # comes first, so we use a trick to allow it. Uses of check_prog
209 # happening before here won't allow bootstrap.
210 @template
211 def check_prog(*args, **kwargs):
212     kwargs["bootstrap_search_path"] = bootstrap_search_path
213     return check_prog(*args, **kwargs)
216 check_prog("WGET", ("wget",), allow_missing=True)
219 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
221 include("build/moz.configure/pkg.configure")
222 # Make this assignment here rather than in pkg.configure to avoid
223 # requiring this file in unit tests.
224 add_old_configure_assignment("PKG_CONFIG", pkg_config)
226 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
227 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
228 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
229 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
230 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
231 # rust.configure is included by js/moz.configure.
233 option("--enable-valgrind", help="Enable Valgrind integration hooks")
235 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
238 @depends("--enable-valgrind", valgrind_h)
239 def check_valgrind(valgrind, valgrind_h):
240     if valgrind:
241         if not valgrind_h:
242             die("--enable-valgrind specified but Valgrind is not installed")
243         return True
246 set_define("MOZ_VALGRIND", check_valgrind)
247 set_config("MOZ_VALGRIND", check_valgrind)
250 @depends(target, host)
251 def is_openbsd(target, host):
252     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
255 option(
256     env="SO_VERSION",
257     nargs=1,
258     default="1.0",
259     when=is_openbsd,
260     help="Shared library version for OpenBSD systems",
264 @depends("SO_VERSION", when=is_openbsd)
265 def so_version(value):
266     return value
269 @template
270 def library_name_info_template(host_or_target):
271     assert host_or_target in {host, target}
272     compiler = {
273         host: host_c_compiler,
274         target: c_compiler,
275     }[host_or_target]
277     @depends(host_or_target, compiler, so_version)
278     def library_name_info_impl(host_or_target, compiler, so_version):
279         if host_or_target.kernel == "WINNT":
280             # There aren't artifacts for mingw builds, so it's OK that the
281             # results are inaccurate in that case.
282             if compiler and compiler.type != "clang-cl":
283                 return namespace(
284                     dll=namespace(prefix="", suffix=".dll"),
285                     lib=namespace(prefix="lib", suffix="a"),
286                     import_lib=namespace(prefix="lib", suffix="a"),
287                     obj=namespace(prefix="", suffix="o"),
288                 )
290             return namespace(
291                 dll=namespace(prefix="", suffix=".dll"),
292                 lib=namespace(prefix="", suffix="lib"),
293                 import_lib=namespace(prefix="", suffix="lib"),
294                 obj=namespace(prefix="", suffix="obj"),
295             )
297         elif host_or_target.kernel == "Darwin":
298             return namespace(
299                 dll=namespace(prefix="lib", suffix=".dylib"),
300                 lib=namespace(prefix="lib", suffix="a"),
301                 import_lib=namespace(prefix=None, suffix=""),
302                 obj=namespace(prefix="", suffix="o"),
303             )
304         elif so_version:
305             so = ".so.%s" % so_version
306         else:
307             so = ".so"
309         return namespace(
310             dll=namespace(prefix="lib", suffix=so),
311             lib=namespace(prefix="lib", suffix="a"),
312             import_lib=namespace(prefix=None, suffix=""),
313             obj=namespace(prefix="", suffix="o"),
314         )
316     return library_name_info_impl
319 host_library_name_info = library_name_info_template(host)
320 library_name_info = library_name_info_template(target)
322 set_config("DLL_PREFIX", library_name_info.dll.prefix)
323 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
324 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
325 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
326 set_config("LIB_PREFIX", library_name_info.lib.prefix)
327 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
328 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
329 # Lots of compilation tests depend on this variable being present.
330 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
331 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
332 set_define(
333     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
335 set_define(
336     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
338 set_config("HOST_LIB_PREFIX", host_library_name_info.lib.prefix)
339 set_config("HOST_IMPORT_LIB_SUFFIX", host_library_name_info.import_lib.suffix)
340 set_config("WASM_OBJ_SUFFIX", "wasm")
342 # Make `profiling` available to this file even when js/moz.configure
343 # doesn't end up included.
344 profiling = dependable(False)
345 # Same for js_standalone
346 js_standalone = dependable(False)
347 js_shared = dependable(False)
348 moz_linker = dependable(False)
349 # Same for fold_libs
350 fold_libs = dependable(False)
351 # And dmd
352 dmd = dependable(False)
354 include(include_project_configure)
357 @depends("--help")
358 @imports(_from="mozbuild.backend", _import="backends")
359 def build_backends_choices(_):
360     return tuple(backends)
363 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
364 def build_backend(backends):
365     if backends:
366         return tuple("+%s" % b for b in backends)
369 imply_option("--build-backends", build_backend)
372 @depends(
373     host,
374     target,
375     "--enable-artifact-builds",
376     "--disable-compile-environment",
377     "--enable-build-backend",
378     "--enable-project",
379     "--enable-application",
380     "--help",
382 @imports("sys")
383 def build_backend_defaults(
384     host,
385     target,
386     artifact_builds,
387     compile_environment,
388     requested_backends,
389     project,
390     application,
391     _,
393     if application:
394         project = application[0]
395     elif project:
396         project = project[0]
398     if "Tup" in requested_backends:
399         # As a special case, if Tup was requested, do not combine it with any
400         # Make based backend by default.
401         all_backends = []
402     elif artifact_builds:
403         all_backends = ["FasterMake+RecursiveMake"]
404     else:
405         all_backends = ["RecursiveMake", "FasterMake"]
406     if (
407         host.os == "WINNT"
408         and target.os == "WINNT"
409         and compile_environment
410         and project not in ("mobile/android", "memory", "tools/update-programs")
411     ):
412         all_backends.append("VisualStudio")
413     return tuple(all_backends) or None
416 option(
417     "--build-backends",
418     nargs="+",
419     default=build_backend_defaults,
420     choices=build_backends_choices,
421     help="Build backends to generate",
425 @depends("--build-backends")
426 def build_backends(backends):
427     return backends
430 set_config("BUILD_BACKENDS", build_backends)
433 @depends(build_environment, build_backends)
434 @imports("glob")
435 def check_objdir_backend_reuse(build_env, backends):
436     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
437     # intentionally vague for use with the substring match below.
438     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
439     for backend_file in glob.iglob(
440         os.path.join(build_env.topobjdir, "backend.*Backend")
441     ):
442         for prev, curr in incompatible_backends:
443             if prev in backend_file and any(curr in b for b in backends):
444                 die(
445                     "The active objdir, %s, was previously "
446                     "used to build with a %s based backend. "
447                     "Change objdirs (by setting MOZ_OBJDIR in "
448                     "your mozconfig) or clobber to continue.\n",
449                     build_env.topobjdir,
450                     prev,
451                 )
454 # Determine whether to build the gtest xul. This happens in automation
455 # on Android and Desktop platforms with the exception of:
456 #  - Windows PGO, where linking xul-gtest.dll takes too long;
457 #  - Android other than x86_64, where gtest is not required.
458 @depends(
459     build_project,
460     target,
461     "MOZ_AUTOMATION",
462     enable_tests,
463     when="--enable-compile-environment",
465 def build_gtest(build_project, target, automation, enable_tests):
466     return bool(
467         enable_tests
468         and automation
469         and build_project in ("browser", "comm/mail", "mobile/android")
470         and not (target.os == "Android" and target.cpu != "x86_64")
471     )
474 option(
475     "--enable-gtest-in-build",
476     default=build_gtest,
477     help="{Enable|Force disable} building the gtest libxul during the build.",
478     when="--enable-compile-environment",
481 set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build")
483 # Localization
484 # ==============================================================
485 option(
486     "--enable-ui-locale",
487     default="en-US",
488     help="Select the user interface locale (default: en-US)",
491 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
493 option(
494     "--enable-icu4x",
495     help="An experiment to use ICU4X instead of ICU4C. See intl/ICU4X.md",
498 set_config("MOZ_ICU4X", True, when="--enable-icu4x")
500 # clang-plugin location
501 # ==============================================================
504 @depends(host_library_name_info, build_environment, when="--enable-clang-plugin")
505 def clang_plugin_path(library_name_info, build_env):
506     topobjdir = build_env.topobjdir
507     if topobjdir.endswith("/js/src"):
508         topobjdir = topobjdir[:-7]
509     return os.path.abspath(
510         os.path.join(
511             topobjdir,
512             "build",
513             "clang-plugin",
514             "%sclang-plugin%s"
515             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
516         )
517     )
520 set_config("CLANG_PLUGIN", clang_plugin_path)
521 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
524 # Awk detection
525 # ==============================================================
526 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
528 # Until the AWK variable is not necessary in old-configure
531 @depends(awk)
532 def awk_for_old_configure(value):
533     return value
536 add_old_configure_assignment("AWK", awk_for_old_configure)
539 # Perl detection
540 # ==============================================================
541 perl = check_prog("PERL", ("perl5", "perl"))
543 # Until the PERL variable is not necessary in old-configure
546 @depends(perl)
547 def perl_for_old_configure(value):
548     return value
551 add_old_configure_assignment("PERL", perl_for_old_configure)
554 @template
555 def perl_version_check(min_version):
556     @depends(perl)
557     @checking("for minimum required perl version >= %s" % min_version)
558     def get_perl_version(perl):
559         return Version(
560             check_cmd_output(
561                 perl,
562                 "-e",
563                 "print $]",
564                 onerror=lambda: die("Failed to get perl version."),
565             )
566         )
568     @depends(get_perl_version)
569     def check_perl_version(version):
570         if version < min_version:
571             die("Perl %s or higher is required.", min_version)
573     @depends(perl)
574     @checking("for full perl installation")
575     @imports("subprocess")
576     def has_full_perl_installation(perl):
577         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
578         return ret == 0
580     @depends(has_full_perl_installation)
581     def require_full_perl_installation(has_full_perl_installation):
582         if not has_full_perl_installation:
583             die(
584                 "Cannot find Config.pm or $Config{archlib}. "
585                 "A full perl installation is required."
586             )
589 perl_version_check("5.006")
592 # GNU make detection
593 # ==============================================================
594 option(env="MAKE", nargs=1, help="Path to GNU make")
597 @depends("MAKE", host)
598 def possible_makes(make, host):
599     candidates = []
600     if host.kernel == "WINNT":
601         candidates.append("mingw32-make")
602     if make:
603         candidates.append(make[0])
604     if host.kernel == "WINNT":
605         candidates.extend(("mozmake", "make", "gmake"))
606     else:
607         candidates.extend(("gmake", "make"))
608     return candidates
611 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
613 # watchman detection
614 # ==============================================================
616 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
619 @depends(host, "WATCHMAN")
620 @checking("for watchman", callback=lambda w: w.path if w else "not found")
621 def watchman(host, prog):
622     # On Windows, `watchman` is only supported on 64-bit hosts.
623     if host.os == "WINNT" and host.cpu != "x86_64":
624         return
626     if not prog:
627         prog = find_program("watchman")
629     if not prog:
630         return
632     # `watchman version` will talk to the Watchman daemon service.
633     # This can hang due to permissions problems. e.g.
634     # https://github.com/facebook/watchman/issues/376. So use
635     # `watchman --version` to prevent a class of failures.
636     out = check_cmd_output(prog, "--version", onerror=lambda: None)
637     if out is None:
638         return
640     return namespace(path=prog, version=Version(out.strip()))
643 @depends_if(watchman)
644 @checking("for watchman version")
645 def watchman_version(w):
646     return w.version
649 set_config("WATCHMAN", watchman.path)
652 @depends_all(hg_version, hg_config, watchman)
653 @checking("for watchman Mercurial integration")
654 @imports("os")
655 def watchman_hg(hg_version, hg_config, watchman):
656     if hg_version < Version("3.8"):
657         return "no (Mercurial 3.8+ required)"
659     ext_enabled = False
660     mode_disabled = False
662     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
663         if k in hg_config and hg_config[k] != "!":
664             ext_enabled = True
666     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
668     if not ext_enabled:
669         return "no (fsmonitor extension not enabled)"
670     if mode_disabled:
671         return "no (fsmonitor.mode=off disables fsmonitor)"
673     return True
676 # Miscellaneous programs
677 # ==============================================================
678 check_prog("XARGS", ("xargs",))
681 @depends(target)
682 def extra_programs(target):
683     if target.kernel == "Darwin":
684         return namespace(
685             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
686             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
687             HFS_TOOL=("hfsplus",),
688         )
689     if target.os == "GNU" and target.kernel == "Linux":
690         return namespace(RPMBUILD=("rpmbuild",))
693 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
694 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
695 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
696 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
699 nsis = check_prog(
700     "MAKENSISU",
701     ("makensis",),
702     bootstrap="nsis/bin",
703     allow_missing=True,
704     when=target_is_windows,
707 # Make sure the version of makensis is up to date.
710 @depends_if(nsis)
711 @checking("for NSIS version")
712 @imports("re")
713 def nsis_version(nsis):
714     nsis_min_version = "3.0b1"
716     def onerror():
717         return die("Failed to get nsis version.")
719     out = check_cmd_output(nsis, "-version", onerror=onerror)
721     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
723     if not m:
724         raise FatalCheckError("Unknown version of makensis")
725     ver = Version(m.group(0))
727     # Versions comparisons don't quite work well with beta versions, so ensure
728     # it works for the non-beta version.
729     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
730         raise FatalCheckError(
731             "To build the installer you must have NSIS"
732             " version %s or greater in your path" % nsis_min_version
733         )
735     return ver
738 # And that makensis is 32-bit (but only on Windows).
739 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
740 @checking("for 32-bit NSIS")
741 def nsis_binary_type(nsis):
742     bin_type = windows_binary_type(nsis)
743     if bin_type != "win32":
744         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
746     return "yes"
749 # And any flags we have to give to makensis
750 @depends(host)
751 def nsis_flags(host):
752     if host.kernel != "WINNT":
753         return "-nocd"
754     return ""
757 set_config("MAKENSISU_FLAGS", nsis_flags)
759 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
760 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
763 @template
764 def llvm_tool(name):
765     @depends(host_c_compiler, c_compiler, bindgen_config_paths)
766     def llvm_tool(host_c_compiler, c_compiler, bindgen_config_paths):
767         clang = None
768         for compiler in (host_c_compiler, c_compiler):
769             if compiler and compiler.type == "clang":
770                 clang = compiler.compiler
771                 break
772             elif compiler and compiler.type == "clang-cl":
773                 clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
774                 break
776         if not clang and bindgen_config_paths:
777             clang = bindgen_config_paths.clang_path
778         tool = name
779         if clang:
780             out = check_cmd_output(
781                 clang, "--print-prog-name=%s" % tool, onerror=lambda: None
782             )
783             if out:
784                 tool = out.rstrip()
785         return (tool,)
787     return llvm_tool
790 llvm_objdump = check_prog(
791     "LLVM_OBJDUMP",
792     llvm_tool("llvm-objdump"),
793     what="llvm-objdump",
794     when="--enable-compile-environment",
795     paths=clang_search_path,
798 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
801 @depends(llvm_tool("llvm-readelf"), toolchain_prefix)
802 def readelf(llvm_readelf, toolchain_prefix):
803     commands = [llvm_readelf[0], "readelf"]
804     for prefix in toolchain_prefix or ():
805         commands.insert(1, "%sreadelf" % prefix)
806     return tuple(commands)
809 def validate_readelf(path):
810     # llvm-readelf from llvm < 8 doesn't support the GNU binutils-compatible `-d`
811     # flag. We could try running `$path -d $some_binary` but we might be cross
812     # compiling and not have a binary at hand to run that against. `$path -d` alone
813     # would fail whether the flag is supported or not. So we resort to look for the
814     # option in the `--help` output, which fortunately, s compatible between
815     # llvm-readelf and readelf.
816     retcode, stdout, stderr = get_cmd_output(path, "--help")
817     return retcode == 0 and any(l.startswith("  -d ") for l in stdout.splitlines())
820 @depends("--enable-compile-environment", target, host)
821 def readelf_when(compile_env, target, host):
822     return compile_env and any(
823         x.kernel not in ("Darwin", "WINNT") for x in (target, host)
824     )
827 check_prog(
828     "READELF",
829     readelf,
830     when=readelf_when,
831     paths=clang_search_path,
832     validate=validate_readelf,
836 @depends(llvm_tool("llvm-objcopy"), toolchain_prefix)
837 def objcopy(llvm_objcopy, toolchain_prefix):
838     commands = [llvm_objcopy[0], "objcopy"]
839     for prefix in toolchain_prefix or ():
840         commands.insert(1, "%sreadelf" % prefix)
841     return tuple(commands)
844 def validate_objcopy(path):
845     if "llvm-objcopy" not in path:
846         return True
847     # llvm-objcopy doesn't support --only-keep-debug before llvm 9.0.
848     retcode, stdout, stderr = get_cmd_output(path, "--help")
849     return retcode == 0 and any(
850         l.startswith("  --only-keep-debug ") for l in stdout.splitlines()
851     )
854 check_prog(
855     "OBJCOPY",
856     objcopy,
857     when=readelf_when,
858     paths=clang_search_path,
859     validate=validate_objcopy,
862 option("--enable-dtrace", help="Build with dtrace support")
864 dtrace = check_header(
865     "sys/sdt.h",
866     when="--enable-dtrace",
867     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
870 set_config("HAVE_DTRACE", True, when=dtrace)
871 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
872 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
875 option("--disable-icf", help="Disable Identical Code Folding")
877 add_old_configure_assignment(
878     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
882 option(
883     "--enable-strip",
884     when=compile_environment,
885     help="Enable stripping of libs & executables",
888 # This should be handled as a `when` once bug 1617793 is fixed.
891 @depends("--enable-strip", c_compiler, when=compile_environment)
892 def enable_strip(strip, c_compiler):
893     if strip and c_compiler.type != "clang-cl":
894         return True
897 set_config("ENABLE_STRIP", enable_strip)
899 option(
900     "--disable-install-strip",
901     when=compile_environment,
902     help="Enable stripping of libs & executables when packaging",
905 # This should be handled as a `when` once bug 1617793 is fixed.
908 @depends("--enable-install-strip", c_compiler, when=compile_environment)
909 def enable_install_strip(strip, c_compiler):
910     if strip and c_compiler.type != "clang-cl":
911         return True
914 set_config("PKG_STRIP", enable_install_strip)
917 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
918 def strip(strip, install_strip):
919     return strip or install_strip
922 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
925 @depends("STRIP_FLAGS", profiling, target, when=strip)
926 def strip_flags(flags, profiling, target):
927     if flags:
928         return flags[0].split()
929     if profiling:
930         # Only strip debug info and symbols when profiling is enabled, keeping
931         # local symbols.
932         if target.kernel == "Darwin":
933             return ["-S"]
934         elif target.os == "Android":
935             # The tooling we use with Android supports detached symbols, and the
936             # size increase caused by local symbols are too much for mobile. So,
937             # don't restrict the amount of stripping with a flag.
938             return
939         else:
940             return ["--strip-debug"]
941     # Otherwise strip everything we can, which happens without flags on non-Darwin.
942     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
943     elif target.kernel == "Darwin":
944         return ["-x", "-S"]
947 set_config("STRIP_FLAGS", strip_flags)
950 @depends(llvm_tool("llvm-strip"), toolchain_prefix, target)
951 def strip(llvm_strip, toolchain_prefix, target):
952     commands = ["strip"]
953     for prefix in toolchain_prefix or ():
954         commands.insert(0, "%sstrip" % prefix)
955     # llvm-strip causes some problems on macos targets.
956     if target.kernel == "Darwin":
957         commands.append(llvm_strip[0])
958     else:
959         commands.insert(0, llvm_strip[0])
960     return tuple(commands)
963 def validate_strip(path):
964     if "llvm-strip" not in path:
965         return True
966     # llvm-strip doesn't support -S before llvm 8.0.
967     retcode, stdout, stderr = get_cmd_output(path, "--help")
968     return retcode == 0 and any(l.startswith("  -S ") for l in stdout.splitlines())
971 @depends("--enable-compile-environment", target, host)
972 def strip_when(compile_env, target, host):
973     return compile_env and any(x.kernel != "WINNT" for x in (target, host))
976 check_prog(
977     "STRIP",
978     strip,
979     when=strip_when,
980     paths=clang_search_path,
981     validate=validate_strip,
985 @depends(js_standalone, target)
986 def system_zlib_default(js_standalone, target):
987     return js_standalone and target.kernel not in ("WINNT", "Darwin")
990 option(
991     "--with-system-zlib",
992     nargs="?",
993     default=system_zlib_default,
994     help="{Use|Do not use} system libz",
998 @depends("--with-system-zlib")
999 def deprecated_system_zlib_path(value):
1000     if len(value) == 1:
1001         die(
1002             "--with-system-zlib=PATH is not supported anymore. Please use "
1003             "--with-system-zlib and set any necessary pkg-config environment variable."
1004         )
1007 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
1009 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1012 @depends("--with-system-zlib", js_shared, moz_linker, target.os)
1013 def zlib_in_mozglue(system_zlib, js_shared, linker, os):
1014     if not system_zlib and (js_shared or linker or os == "Android"):
1015         return True
1018 set_config("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
1019 set_define("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
1022 # Please do not add configure checks from here on.
1024 # Fallthrough to autoconf-based configure
1025 include("build/moz.configure/old.configure")
1027 # JS Subconfigure.
1028 include("js/sub.configure", when=compile_environment & toolkit)
1031 @depends(build_environment, build_project)
1032 @imports("__sandbox__")
1033 @imports("glob")
1034 @imports(_from="os.path", _import="exists")
1035 def config_status_deps(build_env, build_project):
1037     topsrcdir = build_env.topsrcdir
1038     topobjdir = build_env.topobjdir
1040     if not topobjdir.endswith("js/src"):
1041         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
1042     else:
1043         # mozconfig changes may impact js configure.
1044         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
1046     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
1047     if exists(confvars):
1048         extra_deps.append(confvars)
1050     return (
1051         list(__sandbox__._all_paths)
1052         + extra_deps
1053         + [
1054             os.path.join(topsrcdir, "CLOBBER"),
1055             os.path.join(topsrcdir, "configure.in"),
1056             os.path.join(topsrcdir, "js", "src", "configure.in"),
1057             os.path.join(topsrcdir, "nsprpub", "configure"),
1058             os.path.join(topsrcdir, "config", "milestone.txt"),
1059             os.path.join(topsrcdir, "browser", "config", "version.txt"),
1060             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
1061             os.path.join(topsrcdir, "python", "sites", "build.txt"),
1062             os.path.join(topsrcdir, "python", "sites", "common.txt"),
1063             os.path.join(topsrcdir, "python", "sites", "mach.txt"),
1064             os.path.join(topsrcdir, "python", "mach", "mach", "site.py"),
1065             os.path.join(topsrcdir, "aclocal.m4"),
1066             os.path.join(topsrcdir, "old-configure.in"),
1067             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1068             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1069         ]
1070         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1071     )
1074 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1075 # Please do not add anything after setting config_dep_paths.