Bug 1769522 [wpt PR 34071] - Update wpt metadata, a=testonly
[gecko.git] / moz.configure
blob8b74afbabec18f79caca2b25cf85f0df9c7b7dc5
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 make:
601         candidates.append(make[0])
602     if host.kernel == "WINNT":
603         candidates.extend(("mozmake", "mingw32-make", "make", "gmake"))
604     else:
605         candidates.extend(("gmake", "make"))
606     return candidates
609 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
611 # watchman detection
612 # ==============================================================
614 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
617 @depends(host, "WATCHMAN")
618 @checking("for watchman", callback=lambda w: w.path if w else "not found")
619 def watchman(host, prog):
620     # On Windows, `watchman` is only supported on 64-bit hosts.
621     if host.os == "WINNT" and host.cpu != "x86_64":
622         return
624     if not prog:
625         prog = find_program("watchman")
627     if not prog:
628         return
630     # `watchman version` will talk to the Watchman daemon service.
631     # This can hang due to permissions problems. e.g.
632     # https://github.com/facebook/watchman/issues/376. So use
633     # `watchman --version` to prevent a class of failures.
634     out = check_cmd_output(prog, "--version", onerror=lambda: None)
635     if out is None:
636         return
638     return namespace(path=prog, version=Version(out.strip()))
641 @depends_if(watchman)
642 @checking("for watchman version")
643 def watchman_version(w):
644     return w.version
647 set_config("WATCHMAN", watchman.path)
650 @depends_all(hg_version, hg_config, watchman)
651 @checking("for watchman Mercurial integration")
652 @imports("os")
653 def watchman_hg(hg_version, hg_config, watchman):
654     if hg_version < Version("3.8"):
655         return "no (Mercurial 3.8+ required)"
657     ext_enabled = False
658     mode_disabled = False
660     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
661         if k in hg_config and hg_config[k] != "!":
662             ext_enabled = True
664     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
666     if not ext_enabled:
667         return "no (fsmonitor extension not enabled)"
668     if mode_disabled:
669         return "no (fsmonitor.mode=off disables fsmonitor)"
671     return True
674 # Miscellaneous programs
675 # ==============================================================
676 check_prog("XARGS", ("xargs",))
679 @depends(target)
680 def extra_programs(target):
681     if target.kernel == "Darwin":
682         return namespace(
683             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
684             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
685             HFS_TOOL=("hfsplus",),
686         )
687     if target.os == "GNU" and target.kernel == "Linux":
688         return namespace(RPMBUILD=("rpmbuild",))
691 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
692 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
693 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
694 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
697 nsis = check_prog(
698     "MAKENSISU",
699     ("makensis",),
700     bootstrap="nsis/bin",
701     allow_missing=True,
702     when=target_is_windows,
705 # Make sure the version of makensis is up to date.
708 @depends_if(nsis)
709 @checking("for NSIS version")
710 @imports("re")
711 def nsis_version(nsis):
712     nsis_min_version = "3.0b1"
714     def onerror():
715         return die("Failed to get nsis version.")
717     out = check_cmd_output(nsis, "-version", onerror=onerror)
719     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
721     if not m:
722         raise FatalCheckError("Unknown version of makensis")
723     ver = Version(m.group(0))
725     # Versions comparisons don't quite work well with beta versions, so ensure
726     # it works for the non-beta version.
727     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
728         raise FatalCheckError(
729             "To build the installer you must have NSIS"
730             " version %s or greater in your path" % nsis_min_version
731         )
733     return ver
736 # And that makensis is 32-bit (but only on Windows).
737 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
738 @checking("for 32-bit NSIS")
739 def nsis_binary_type(nsis):
740     bin_type = windows_binary_type(nsis)
741     if bin_type != "win32":
742         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
744     return "yes"
747 # And any flags we have to give to makensis
748 @depends(host)
749 def nsis_flags(host):
750     if host.kernel != "WINNT":
751         return "-nocd"
752     return ""
755 set_config("MAKENSISU_FLAGS", nsis_flags)
757 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
758 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
761 @template
762 def llvm_tool(name):
763     @depends(host_c_compiler, c_compiler, bindgen_config_paths)
764     def llvm_tool(host_c_compiler, c_compiler, bindgen_config_paths):
765         clang = None
766         for compiler in (host_c_compiler, c_compiler):
767             if compiler and compiler.type == "clang":
768                 clang = compiler.compiler
769                 break
770             elif compiler and compiler.type == "clang-cl":
771                 clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
772                 break
774         if not clang and bindgen_config_paths:
775             clang = bindgen_config_paths.clang_path
776         tool = name
777         if clang:
778             out = check_cmd_output(
779                 clang, "--print-prog-name=%s" % tool, onerror=lambda: None
780             )
781             if out:
782                 tool = out.rstrip()
783         return (tool,)
785     return llvm_tool
788 llvm_objdump = check_prog(
789     "LLVM_OBJDUMP",
790     llvm_tool("llvm-objdump"),
791     what="llvm-objdump",
792     when="--enable-compile-environment",
793     paths=clang_search_path,
796 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
799 @depends(llvm_tool("llvm-readelf"), toolchain_prefix)
800 def readelf(llvm_readelf, toolchain_prefix):
801     commands = [llvm_readelf[0], "readelf"]
802     for prefix in toolchain_prefix or ():
803         commands.insert(1, "%sreadelf" % prefix)
804     return tuple(commands)
807 def validate_readelf(path):
808     # llvm-readelf from llvm < 8 doesn't support the GNU binutils-compatible `-d`
809     # flag. We could try running `$path -d $some_binary` but we might be cross
810     # compiling and not have a binary at hand to run that against. `$path -d` alone
811     # would fail whether the flag is supported or not. So we resort to look for the
812     # option in the `--help` output, which fortunately, s compatible between
813     # llvm-readelf and readelf.
814     retcode, stdout, stderr = get_cmd_output(path, "--help")
815     return retcode == 0 and any(l.startswith("  -d ") for l in stdout.splitlines())
818 @depends("--enable-compile-environment", target, host)
819 def readelf_when(compile_env, target, host):
820     return compile_env and any(
821         x.kernel not in ("Darwin", "WINNT") for x in (target, host)
822     )
825 check_prog(
826     "READELF",
827     readelf,
828     when=readelf_when,
829     paths=clang_search_path,
830     validate=validate_readelf,
834 @depends(llvm_tool("llvm-objcopy"), toolchain_prefix)
835 def objcopy(llvm_objcopy, toolchain_prefix):
836     commands = [llvm_objcopy[0], "objcopy"]
837     for prefix in toolchain_prefix or ():
838         commands.insert(1, "%sreadelf" % prefix)
839     return tuple(commands)
842 def validate_objcopy(path):
843     if "llvm-objcopy" not in path:
844         return True
845     # llvm-objcopy doesn't support --only-keep-debug before llvm 9.0.
846     retcode, stdout, stderr = get_cmd_output(path, "--help")
847     return retcode == 0 and any(
848         l.startswith("  --only-keep-debug ") for l in stdout.splitlines()
849     )
852 check_prog(
853     "OBJCOPY",
854     objcopy,
855     when=readelf_when,
856     paths=clang_search_path,
857     validate=validate_objcopy,
860 option("--enable-dtrace", help="Build with dtrace support")
862 dtrace = check_header(
863     "sys/sdt.h",
864     when="--enable-dtrace",
865     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
868 set_config("HAVE_DTRACE", True, when=dtrace)
869 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
870 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
873 option("--disable-icf", help="Disable Identical Code Folding")
875 add_old_configure_assignment(
876     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
880 option(
881     "--enable-strip",
882     when=compile_environment,
883     help="Enable stripping of libs & executables",
886 # This should be handled as a `when` once bug 1617793 is fixed.
889 @depends("--enable-strip", c_compiler, when=compile_environment)
890 def enable_strip(strip, c_compiler):
891     if strip and c_compiler.type != "clang-cl":
892         return True
895 set_config("ENABLE_STRIP", enable_strip)
897 option(
898     "--disable-install-strip",
899     when=compile_environment,
900     help="Enable stripping of libs & executables when packaging",
903 # This should be handled as a `when` once bug 1617793 is fixed.
906 @depends("--enable-install-strip", c_compiler, when=compile_environment)
907 def enable_install_strip(strip, c_compiler):
908     if strip and c_compiler.type != "clang-cl":
909         return True
912 set_config("PKG_STRIP", enable_install_strip)
915 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
916 def strip(strip, install_strip):
917     return strip or install_strip
920 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
923 @depends("STRIP_FLAGS", profiling, target, when=strip)
924 def strip_flags(flags, profiling, target):
925     if flags:
926         return flags[0].split()
927     if profiling:
928         # Only strip debug info and symbols when profiling is enabled, keeping
929         # local symbols.
930         if target.kernel == "Darwin":
931             return ["-S"]
932         elif target.os == "Android":
933             # The tooling we use with Android supports detached symbols, and the
934             # size increase caused by local symbols are too much for mobile. So,
935             # don't restrict the amount of stripping with a flag.
936             return
937         else:
938             return ["--strip-debug"]
939     # Otherwise strip everything we can, which happens without flags on non-Darwin.
940     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
941     elif target.kernel == "Darwin":
942         return ["-x", "-S"]
945 set_config("STRIP_FLAGS", strip_flags)
948 @depends(llvm_tool("llvm-strip"), toolchain_prefix, target)
949 def strip(llvm_strip, toolchain_prefix, target):
950     commands = ["strip"]
951     for prefix in toolchain_prefix or ():
952         commands.insert(0, "%sstrip" % prefix)
953     # llvm-strip causes some problems on macos targets.
954     if target.kernel == "Darwin":
955         commands.append(llvm_strip[0])
956     else:
957         commands.insert(0, llvm_strip[0])
958     return tuple(commands)
961 def validate_strip(path):
962     if "llvm-strip" not in path:
963         return True
964     # llvm-strip doesn't support -S before llvm 8.0.
965     retcode, stdout, stderr = get_cmd_output(path, "--help")
966     return retcode == 0 and any(l.startswith("  -S ") for l in stdout.splitlines())
969 @depends("--enable-compile-environment", target, host)
970 def strip_when(compile_env, target, host):
971     return compile_env and any(x.kernel != "WINNT" for x in (target, host))
974 check_prog(
975     "STRIP",
976     strip,
977     when=strip_when,
978     paths=clang_search_path,
979     validate=validate_strip,
983 @depends(js_standalone, target)
984 def system_zlib_default(js_standalone, target):
985     return js_standalone and target.kernel not in ("WINNT", "Darwin")
988 option(
989     "--with-system-zlib",
990     nargs="?",
991     default=system_zlib_default,
992     help="{Use|Do not use} system libz",
996 @depends("--with-system-zlib")
997 def deprecated_system_zlib_path(value):
998     if len(value) == 1:
999         die(
1000             "--with-system-zlib=PATH is not supported anymore. Please use "
1001             "--with-system-zlib and set any necessary pkg-config environment variable."
1002         )
1005 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
1007 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1010 @depends("--with-system-zlib", js_shared, moz_linker, target.os)
1011 def zlib_in_mozglue(system_zlib, js_shared, linker, os):
1012     if not system_zlib and (js_shared or linker or os == "Android"):
1013         return True
1016 set_config("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
1017 set_define("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
1020 # Please do not add configure checks from here on.
1022 # Fallthrough to autoconf-based configure
1023 include("build/moz.configure/old.configure")
1025 # JS Subconfigure.
1026 include("js/sub.configure", when=compile_environment & toolkit)
1029 @depends(build_environment, build_project)
1030 @imports("__sandbox__")
1031 @imports("glob")
1032 @imports(_from="os.path", _import="exists")
1033 def config_status_deps(build_env, build_project):
1035     topsrcdir = build_env.topsrcdir
1036     topobjdir = build_env.topobjdir
1038     if not topobjdir.endswith("js/src"):
1039         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
1040     else:
1041         # mozconfig changes may impact js configure.
1042         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
1044     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
1045     if exists(confvars):
1046         extra_deps.append(confvars)
1048     return (
1049         list(__sandbox__._all_paths)
1050         + extra_deps
1051         + [
1052             os.path.join(topsrcdir, "CLOBBER"),
1053             os.path.join(topsrcdir, "configure.in"),
1054             os.path.join(topsrcdir, "js", "src", "configure.in"),
1055             os.path.join(topsrcdir, "nsprpub", "configure"),
1056             os.path.join(topsrcdir, "config", "milestone.txt"),
1057             os.path.join(topsrcdir, "browser", "config", "version.txt"),
1058             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
1059             os.path.join(topsrcdir, "python", "sites", "build.txt"),
1060             os.path.join(topsrcdir, "python", "sites", "common.txt"),
1061             os.path.join(topsrcdir, "python", "sites", "mach.txt"),
1062             os.path.join(topsrcdir, "python", "mach", "mach", "site.py"),
1063             os.path.join(topsrcdir, "aclocal.m4"),
1064             os.path.join(topsrcdir, "old-configure.in"),
1065             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1066             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1067         ]
1068         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1069     )
1072 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1073 # Please do not add anything after setting config_dep_paths.