Bug 1794956 - TransferToImageBitmap should reset bitmap but not state. r=gfx-reviewer...
[gecko.git] / moz.configure
blob2b6446c6c81f1c2850c08e341f1205f73334d831
1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 include("build/moz.configure/init.configure")
9 # Note:
10 # - Gecko-specific options and rules should go in toolkit/moz.configure.
11 # - Firefox-specific options and rules should go in browser/moz.configure.
12 # - Fennec-specific options and rules should go in
13 #   mobile/android/moz.configure.
14 # - Spidermonkey-specific options and rules should go in js/moz.configure.
15 # - etc.
17 imply_option(
18     "--enable-artifact-build-symbols",
19     depends(artifact_builds)(lambda v: False if v is None else None),
20     reason="--disable-artifact-builds",
23 option(
24     "--enable-artifact-build-symbols",
25     nargs="?",
26     choices=("full",),
27     help="Download symbols when artifact builds are enabled.",
31 @depends("--enable-artifact-build-symbols", "MOZ_AUTOMATION", target)
32 def enable_artifact_build_symbols(value, automation, target):
33     if len(value):
34         return value[0]
35     if bool(value):
36         if target.os == "Android" and not automation:
37             return "full"
38         return True
39     return None
42 set_config("MOZ_ARTIFACT_BUILD_SYMBOLS", enable_artifact_build_symbols)
45 @depends("--enable-artifact-builds")
46 def imply_disable_compile_environment(value):
47     if value:
48         return False
51 option(
52     env="MOZ_COPY_PDBS",
53     help="For builds that do not support symbols in the normal fashion,"
54     " generate and copy them into the resulting build archive.",
57 set_config("MOZ_COPY_PDBS", depends_if("MOZ_COPY_PDBS")(lambda _: True))
59 imply_option("--enable-compile-environment", imply_disable_compile_environment)
61 option("--disable-compile-environment", help="Disable compiler/library checks")
64 @depends("--disable-compile-environment")
65 def compile_environment(compile_env):
66     if compile_env:
67         return True
70 set_config("COMPILE_ENVIRONMENT", compile_environment)
71 add_old_configure_assignment("COMPILE_ENVIRONMENT", compile_environment)
73 option("--disable-tests", help="Do not build test libraries & programs")
76 @depends("--disable-tests")
77 def enable_tests(value):
78     if value:
79         return True
82 set_config("ENABLE_TESTS", enable_tests)
83 set_define("ENABLE_TESTS", enable_tests)
86 @depends(enable_tests)
87 def gtest_has_rtti(value):
88     if value:
89         return "0"
92 set_define("GTEST_HAS_RTTI", gtest_has_rtti)
95 @depends(target, enable_tests)
96 def linux_gtest_defines(target, enable_tests):
97     if enable_tests and target.os == "Android":
98         return namespace(os_linux_android=True, use_own_tr1_tuple=True, has_clone="0")
101 set_define("GTEST_OS_LINUX_ANDROID", linux_gtest_defines.os_linux_android)
102 set_define("GTEST_USE_OWN_TR1_TUPLE", linux_gtest_defines.use_own_tr1_tuple)
103 set_define("GTEST_HAS_CLONE", linux_gtest_defines.has_clone)
105 option(
106     "--enable-debug",
107     nargs="?",
108     help="Enable building with developer debug info "
109     "(using the given compiler flags).",
113 @depends("--enable-debug")
114 def moz_debug(debug):
115     if debug:
116         return bool(debug)
119 set_config("MOZ_DEBUG", moz_debug)
120 set_define("MOZ_DEBUG", moz_debug)
121 # Override any value MOZ_DEBUG may have from the environment when passing it
122 # down to old-configure.
123 add_old_configure_assignment("MOZ_DEBUG", depends("--enable-debug")(lambda x: bool(x)))
125 set_config(
126     "MOZ_DIAGNOSTIC_ASSERT_ENABLED",
127     True,
128     when=moz_debug | milestone.is_early_beta_or_earlier,
130 set_define(
131     "MOZ_DIAGNOSTIC_ASSERT_ENABLED",
132     True,
133     when=moz_debug | milestone.is_early_beta_or_earlier,
136 option(
137     "--with-debug-label",
138     nargs="+",
139     help="Debug DEBUG_<value> for each comma-separated value given",
143 @depends(moz_debug, "--with-debug-label")
144 def debug_defines(debug, labels):
145     if debug:
146         return ["DEBUG"] + ["DEBUG_%s" % label for label in labels]
147     return ["NDEBUG", "TRIMMED"]
150 set_config("MOZ_DEBUG_DEFINES", debug_defines)
152 option(env="MOZ_PGO", help="Build with profile guided optimizations")
154 set_config("MOZ_PGO", depends("MOZ_PGO")(lambda x: bool(x)))
157 # Imply --enable-release when MOZILLA_OFFICIAL is set rather than adjusting the
158 # default so that we can't have both MOZILLA_OFFICIAL and --disable-release set.
159 imply_option("--enable-release", mozilla_official)
161 option(
162     "--enable-release",
163     default=milestone.is_release_or_beta | depends("MOZ_AUTOMATION")(lambda x: bool(x)),
164     help="{Build|Do not build} with more conservative, release "
165     "engineering-oriented options.{ This may slow down builds.|}",
169 @depends("--enable-release")
170 def developer_options(value):
171     if not value:
172         return True
175 add_old_configure_assignment("DEVELOPER_OPTIONS", developer_options)
176 set_config("DEVELOPER_OPTIONS", developer_options)
179 # hybrid build handling
180 # ==============================================================
182 option(
183     "--disable-unified-build",
184     help="Enable building modules that are not marked with `REQUIRES_UNIFIED_BUILD` in non unified context",
187 set_config("ENABLE_UNIFIED_BUILD", True, when="--disable-unified-build")
190 include("build/moz.configure/bootstrap.configure")
192 # The execution model of the configure sandbox doesn't allow for
193 # check_prog to use bootstrap_search_path directly because check_prog
194 # comes first, so we use a trick to allow it. Uses of check_prog
195 # happening before here won't allow bootstrap.
196 @template
197 def check_prog(*args, **kwargs):
198     kwargs["bootstrap_search_path"] = bootstrap_search_path
199     return check_prog(*args, **kwargs)
202 check_prog("WGET", ("wget",), allow_missing=True)
205 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
207 include("build/moz.configure/pkg.configure")
208 # Make this assignment here rather than in pkg.configure to avoid
209 # requiring this file in unit tests.
210 add_old_configure_assignment("PKG_CONFIG", pkg_config)
212 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
213 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
214 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
215 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
216 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
217 # rust.configure is included by js/moz.configure.
219 option("--enable-valgrind", help="Enable Valgrind integration hooks")
221 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
224 @depends("--enable-valgrind", valgrind_h)
225 def check_valgrind(valgrind, valgrind_h):
226     if valgrind:
227         if not valgrind_h:
228             die("--enable-valgrind specified but Valgrind is not installed")
229         return True
232 set_define("MOZ_VALGRIND", check_valgrind)
233 set_config("MOZ_VALGRIND", check_valgrind)
236 @depends(target, host)
237 def is_openbsd(target, host):
238     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
241 option(
242     env="SO_VERSION",
243     nargs=1,
244     default="1.0",
245     when=is_openbsd,
246     help="Shared library version for OpenBSD systems",
250 @depends("SO_VERSION", when=is_openbsd)
251 def so_version(value):
252     return value
255 @template
256 def library_name_info_template(host_or_target):
257     assert host_or_target in {host, target}
258     compiler = {
259         host: host_c_compiler,
260         target: c_compiler,
261     }[host_or_target]
263     @depends(host_or_target, compiler, so_version)
264     def library_name_info_impl(host_or_target, compiler, so_version):
265         if host_or_target.kernel == "WINNT":
266             # There aren't artifacts for mingw builds, so it's OK that the
267             # results are inaccurate in that case.
268             if compiler and compiler.type != "clang-cl":
269                 return namespace(
270                     dll=namespace(prefix="", suffix=".dll"),
271                     lib=namespace(prefix="lib", suffix="a"),
272                     import_lib=namespace(prefix="lib", suffix="a"),
273                     obj=namespace(prefix="", suffix="o"),
274                 )
276             return namespace(
277                 dll=namespace(prefix="", suffix=".dll"),
278                 lib=namespace(prefix="", suffix="lib"),
279                 import_lib=namespace(prefix="", suffix="lib"),
280                 obj=namespace(prefix="", suffix="obj"),
281             )
283         elif host_or_target.kernel == "Darwin":
284             return namespace(
285                 dll=namespace(prefix="lib", suffix=".dylib"),
286                 lib=namespace(prefix="lib", suffix="a"),
287                 import_lib=namespace(prefix=None, suffix=""),
288                 obj=namespace(prefix="", suffix="o"),
289             )
290         elif so_version:
291             so = ".so.%s" % so_version
292         else:
293             so = ".so"
295         return namespace(
296             dll=namespace(prefix="lib", suffix=so),
297             lib=namespace(prefix="lib", suffix="a"),
298             import_lib=namespace(prefix=None, suffix=""),
299             obj=namespace(prefix="", suffix="o"),
300         )
302     return library_name_info_impl
305 host_library_name_info = library_name_info_template(host)
306 library_name_info = library_name_info_template(target)
308 set_config("DLL_PREFIX", library_name_info.dll.prefix)
309 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
310 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
311 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
312 set_config("LIB_PREFIX", library_name_info.lib.prefix)
313 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
314 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
315 # Lots of compilation tests depend on this variable being present.
316 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
317 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
318 set_define(
319     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
321 set_define(
322     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
324 set_config("HOST_LIB_PREFIX", host_library_name_info.lib.prefix)
325 set_config("HOST_IMPORT_LIB_SUFFIX", host_library_name_info.import_lib.suffix)
326 set_config("WASM_OBJ_SUFFIX", "wasm")
328 # Make `profiling` available to this file even when js/moz.configure
329 # doesn't end up included.
330 profiling = dependable(False)
331 # Same for js_standalone
332 js_standalone = dependable(False)
333 js_shared = dependable(False)
334 moz_linker = dependable(False)
335 # Same for fold_libs
336 fold_libs = dependable(False)
337 # And dmd
338 dmd = dependable(False)
340 include(include_project_configure)
343 @depends("--help")
344 @imports(_from="mozbuild.backend", _import="backends")
345 def build_backends_choices(_):
346     return tuple(backends)
349 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
350 def build_backend(backends):
351     if backends:
352         return tuple("+%s" % b for b in backends)
355 imply_option("--build-backends", build_backend)
358 @depends(
359     host,
360     target,
361     "--enable-artifact-builds",
362     "--disable-compile-environment",
363     "--enable-build-backend",
364     "--enable-project",
365     "--enable-application",
366     "--help",
368 @imports("sys")
369 @imports(_from="mozbuild.backend.clangd", _import="find_vscode_cmd")
370 def build_backend_defaults(
371     host,
372     target,
373     artifact_builds,
374     compile_environment,
375     requested_backends,
376     project,
377     application,
378     _,
380     if application:
381         project = application[0]
382     elif project:
383         project = project[0]
385     if "Tup" in requested_backends:
386         # As a special case, if Tup was requested, do not combine it with any
387         # Make based backend by default.
388         all_backends = []
389     elif artifact_builds:
390         all_backends = ["FasterMake+RecursiveMake"]
391     else:
392         all_backends = ["RecursiveMake", "FasterMake"]
393     if (
394         host.os == "WINNT"
395         and target.os == "WINNT"
396         and compile_environment
397         and project not in ("mobile/android", "memory", "tools/update-programs")
398     ):
399         all_backends.append("VisualStudio")
400     if (
401         compile_environment
402         and find_vscode_cmd()
403         and project not in ("mobile/android", "memory", "tools/update-programs")
404     ):
405         all_backends.append("Clangd")
406     return tuple(all_backends) or None
409 option(
410     "--build-backends",
411     nargs="+",
412     default=build_backend_defaults,
413     choices=build_backends_choices,
414     help="Build backends to generate",
418 @depends("--build-backends")
419 def build_backends(backends):
420     return backends
423 set_config("BUILD_BACKENDS", build_backends)
426 @depends(build_environment, build_backends)
427 @imports("glob")
428 def check_objdir_backend_reuse(build_env, backends):
429     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
430     # intentionally vague for use with the substring match below.
431     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
432     for backend_file in glob.iglob(
433         os.path.join(build_env.topobjdir, "backend.*Backend")
434     ):
435         for prev, curr in incompatible_backends:
436             if prev in backend_file and any(curr in b for b in backends):
437                 die(
438                     "The active objdir, %s, was previously "
439                     "used to build with a %s based backend. "
440                     "Change objdirs (by setting MOZ_OBJDIR in "
441                     "your mozconfig) or clobber to continue.\n",
442                     build_env.topobjdir,
443                     prev,
444                 )
447 # Determine whether to build the gtest xul. This happens in automation
448 # on Android and Desktop platforms with the exception of:
449 #  - Windows PGO, where linking xul-gtest.dll takes too long;
450 #  - Android other than x86_64, where gtest is not required.
451 @depends(
452     build_project,
453     target,
454     "MOZ_AUTOMATION",
455     enable_tests,
456     when="--enable-compile-environment",
458 def build_gtest(build_project, target, automation, enable_tests):
459     return bool(
460         enable_tests
461         and automation
462         and build_project in ("browser", "comm/mail", "mobile/android")
463         and not (target.os == "Android" and target.cpu != "x86_64")
464     )
467 option(
468     "--enable-gtest-in-build",
469     default=build_gtest,
470     help="{Enable|Force disable} building the gtest libxul during the build.",
471     when="--enable-compile-environment",
474 set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build")
476 # Localization
477 # ==============================================================
478 option(
479     "--enable-ui-locale",
480     default="en-US",
481     help="Select the user interface locale (default: en-US)",
484 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
486 option(
487     "--enable-icu4x",
488     help="An experiment to use ICU4X instead of ICU4C. See intl/ICU4X.md",
491 set_config("MOZ_ICU4X", True, when="--enable-icu4x")
493 # clang-plugin location
494 # ==============================================================
497 @depends(host_library_name_info, build_environment, when="--enable-clang-plugin")
498 def clang_plugin_path(library_name_info, build_env):
499     topobjdir = build_env.topobjdir
500     if topobjdir.endswith("/js/src"):
501         topobjdir = topobjdir[:-7]
502     return os.path.abspath(
503         os.path.join(
504             topobjdir,
505             "build",
506             "clang-plugin",
507             "%sclang-plugin%s"
508             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
509         )
510     )
513 set_config("CLANG_PLUGIN", clang_plugin_path)
514 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
517 # Awk detection
518 # ==============================================================
519 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
521 # Until the AWK variable is not necessary in old-configure
524 @depends(awk)
525 def awk_for_old_configure(value):
526     return value
529 add_old_configure_assignment("AWK", awk_for_old_configure)
532 # Perl detection
533 # ==============================================================
534 perl = check_prog("PERL", ("perl5", "perl"))
536 # Until the PERL variable is not necessary in old-configure
539 @depends(perl)
540 def perl_for_old_configure(value):
541     return value
544 add_old_configure_assignment("PERL", perl_for_old_configure)
547 @template
548 def perl_version_check(min_version):
549     @depends(perl)
550     @checking("for minimum required perl version >= %s" % min_version)
551     def get_perl_version(perl):
552         return Version(
553             check_cmd_output(
554                 perl,
555                 "-e",
556                 "print $]",
557                 onerror=lambda: die("Failed to get perl version."),
558             )
559         )
561     @depends(get_perl_version)
562     def check_perl_version(version):
563         if version < min_version:
564             die("Perl %s or higher is required.", min_version)
566     @depends(perl)
567     @checking("for full perl installation")
568     @imports("subprocess")
569     def has_full_perl_installation(perl):
570         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
571         return ret == 0
573     @depends(has_full_perl_installation)
574     def require_full_perl_installation(has_full_perl_installation):
575         if not has_full_perl_installation:
576             die(
577                 "Cannot find Config.pm or $Config{archlib}. "
578                 "A full perl installation is required."
579             )
582 perl_version_check("5.006")
585 # GNU make detection
586 # ==============================================================
587 option(env="MAKE", nargs=1, help="Path to GNU make")
590 @depends("MAKE", host)
591 def possible_makes(make, host):
592     candidates = []
593     if make:
594         candidates.append(make[0])
595     if host.kernel == "WINNT":
596         candidates.extend(("mozmake", "mingw32-make", "make", "gmake"))
597     else:
598         candidates.extend(("gmake", "make"))
599     return candidates
602 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
604 # watchman detection
605 # ==============================================================
607 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
610 @depends(host, "WATCHMAN")
611 @checking("for watchman", callback=lambda w: w.path if w else "not found")
612 def watchman(host, prog):
613     # On Windows, `watchman` is only supported on 64-bit hosts.
614     if host.os == "WINNT" and host.cpu != "x86_64":
615         return
617     if not prog:
618         prog = find_program("watchman")
620     if not prog:
621         return
623     # `watchman version` will talk to the Watchman daemon service.
624     # This can hang due to permissions problems. e.g.
625     # https://github.com/facebook/watchman/issues/376. So use
626     # `watchman --version` to prevent a class of failures.
627     out = check_cmd_output(prog, "--version", onerror=lambda: None)
628     if out is None:
629         return
631     return namespace(path=prog, version=Version(out.strip()))
634 @depends_if(watchman)
635 @checking("for watchman version")
636 def watchman_version(w):
637     return w.version
640 set_config("WATCHMAN", watchman.path)
643 @depends_all(hg_version, hg_config, watchman)
644 @checking("for watchman Mercurial integration")
645 @imports("os")
646 def watchman_hg(hg_version, hg_config, watchman):
647     if hg_version < Version("3.8"):
648         return "no (Mercurial 3.8+ required)"
650     ext_enabled = False
651     mode_disabled = False
653     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
654         if k in hg_config and hg_config[k] != "!":
655             ext_enabled = True
657     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
659     if not ext_enabled:
660         return "no (fsmonitor extension not enabled)"
661     if mode_disabled:
662         return "no (fsmonitor.mode=off disables fsmonitor)"
664     return True
667 # Miscellaneous programs
668 # ==============================================================
669 check_prog("XARGS", ("xargs",))
672 @depends(target)
673 def extra_programs(target):
674     if target.kernel == "Darwin":
675         return namespace(
676             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
677             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
678             HFS_TOOL=("hfsplus",),
679         )
680     if target.os == "GNU" and target.kernel == "Linux":
681         return namespace(RPMBUILD=("rpmbuild",))
684 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
685 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
686 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
687 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
690 nsis = check_prog(
691     "MAKENSISU",
692     ("makensis",),
693     bootstrap="nsis/bin",
694     allow_missing=True,
695     when=target_is_windows,
698 # Make sure the version of makensis is up to date.
701 @depends_if(nsis)
702 @checking("for NSIS version")
703 @imports("re")
704 def nsis_version(nsis):
705     nsis_min_version = "3.0b1"
707     def onerror():
708         return die("Failed to get nsis version.")
710     out = check_cmd_output(nsis, "-version", onerror=onerror)
712     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
714     if not m:
715         raise FatalCheckError("Unknown version of makensis")
716     ver = Version(m.group(0))
718     # Versions comparisons don't quite work well with beta versions, so ensure
719     # it works for the non-beta version.
720     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
721         raise FatalCheckError(
722             "To build the installer you must have NSIS"
723             " version %s or greater in your path" % nsis_min_version
724         )
726     return ver
729 # And that makensis is 32-bit (but only on Windows).
730 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
731 @checking("for 32-bit NSIS")
732 def nsis_binary_type(nsis):
733     bin_type = windows_binary_type(nsis)
734     if bin_type != "win32":
735         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
737     return "yes"
740 # And any flags we have to give to makensis
741 @depends(host)
742 def nsis_flags(host):
743     if host.kernel != "WINNT":
744         return "-nocd"
745     return ""
748 set_config("MAKENSISU_FLAGS", nsis_flags)
750 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
751 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
754 @template
755 def llvm_tool(name):
756     @depends(host_c_compiler, c_compiler, bindgen_config_paths)
757     def llvm_tool(host_c_compiler, c_compiler, bindgen_config_paths):
758         clang = None
759         for compiler in (host_c_compiler, c_compiler):
760             if compiler and compiler.type == "clang":
761                 clang = compiler.compiler
762                 break
763             elif compiler and compiler.type == "clang-cl":
764                 clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
765                 break
767         if not clang and bindgen_config_paths:
768             clang = bindgen_config_paths.clang_path
769         tool = name
770         if clang:
771             out = check_cmd_output(
772                 clang, "--print-prog-name=%s" % tool, onerror=lambda: None
773             )
774             if out:
775                 tool = out.rstrip()
776         return (tool,)
778     return llvm_tool
781 llvm_objdump = check_prog(
782     "LLVM_OBJDUMP",
783     llvm_tool("llvm-objdump"),
784     what="llvm-objdump",
785     when="--enable-compile-environment",
786     paths=clang_search_path,
789 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
792 @depends(llvm_tool("llvm-readelf"), toolchain_prefix)
793 def readelf(llvm_readelf, toolchain_prefix):
794     commands = [llvm_readelf[0], "readelf"]
795     for prefix in toolchain_prefix or ():
796         commands.insert(1, "%sreadelf" % prefix)
797     return tuple(commands)
800 def validate_readelf(path):
801     # llvm-readelf from llvm < 8 doesn't support the GNU binutils-compatible `-d`
802     # flag. We could try running `$path -d $some_binary` but we might be cross
803     # compiling and not have a binary at hand to run that against. `$path -d` alone
804     # would fail whether the flag is supported or not. So we resort to look for the
805     # option in the `--help` output, which fortunately, s compatible between
806     # llvm-readelf and readelf.
807     retcode, stdout, stderr = get_cmd_output(path, "--help")
808     return retcode == 0 and any(l.startswith("  -d ") for l in stdout.splitlines())
811 @depends("--enable-compile-environment", target, host)
812 def readelf_when(compile_env, target, host):
813     return compile_env and any(
814         x.kernel not in ("Darwin", "WINNT") for x in (target, host)
815     )
818 check_prog(
819     "READELF",
820     readelf,
821     when=readelf_when,
822     paths=clang_search_path,
823     validate=validate_readelf,
827 @depends(llvm_tool("llvm-objcopy"), toolchain_prefix)
828 def objcopy(llvm_objcopy, toolchain_prefix):
829     commands = [llvm_objcopy[0], "objcopy"]
830     for prefix in toolchain_prefix or ():
831         commands.insert(1, "%sreadelf" % prefix)
832     return tuple(commands)
835 def validate_objcopy(path):
836     if "llvm-objcopy" not in path:
837         return True
838     # llvm-objcopy doesn't support --only-keep-debug before llvm 9.0.
839     retcode, stdout, stderr = get_cmd_output(path, "--help")
840     return retcode == 0 and any(
841         l.startswith("  --only-keep-debug ") for l in stdout.splitlines()
842     )
845 check_prog(
846     "OBJCOPY",
847     objcopy,
848     when=readelf_when,
849     paths=clang_search_path,
850     validate=validate_objcopy,
853 option("--enable-dtrace", help="Build with dtrace support")
855 dtrace = check_header(
856     "sys/sdt.h",
857     when="--enable-dtrace",
858     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
861 set_config("HAVE_DTRACE", True, when=dtrace)
862 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
863 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
866 option("--disable-icf", help="Disable Identical Code Folding")
868 add_old_configure_assignment(
869     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
873 option(
874     "--enable-strip",
875     when=compile_environment,
876     help="Enable stripping of libs & executables",
879 # This should be handled as a `when` once bug 1617793 is fixed.
882 @depends("--enable-strip", c_compiler, when=compile_environment)
883 def enable_strip(strip, c_compiler):
884     if strip and c_compiler.type != "clang-cl":
885         return True
888 set_config("ENABLE_STRIP", enable_strip)
890 option(
891     "--disable-install-strip",
892     when=compile_environment,
893     help="Enable stripping of libs & executables when packaging",
896 # This should be handled as a `when` once bug 1617793 is fixed.
899 @depends("--enable-install-strip", c_compiler, when=compile_environment)
900 def enable_install_strip(strip, c_compiler):
901     if strip and c_compiler.type != "clang-cl":
902         return True
905 set_config("PKG_STRIP", enable_install_strip)
908 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
909 def strip(strip, install_strip):
910     return strip or install_strip
913 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
916 @depends("STRIP_FLAGS", profiling, target, when=strip)
917 def strip_flags(flags, profiling, target):
918     if flags:
919         return flags[0].split()
920     if profiling:
921         # Only strip debug info and symbols when profiling is enabled, keeping
922         # local symbols.
923         if target.kernel == "Darwin":
924             return ["-S"]
925         elif target.os == "Android":
926             # The tooling we use with Android supports detached symbols, and the
927             # size increase caused by local symbols are too much for mobile. So,
928             # don't restrict the amount of stripping with a flag.
929             return
930         else:
931             return ["--strip-debug"]
932     # Otherwise strip everything we can, which happens without flags on non-Darwin.
933     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
934     elif target.kernel == "Darwin":
935         return ["-x", "-S"]
938 set_config("STRIP_FLAGS", strip_flags)
941 @depends(llvm_tool("llvm-strip"), toolchain_prefix, target)
942 def strip(llvm_strip, toolchain_prefix, target):
943     commands = ["strip"]
944     for prefix in toolchain_prefix or ():
945         commands.insert(0, "%sstrip" % prefix)
946     # llvm-strip causes some problems on macos targets.
947     if target.kernel == "Darwin":
948         commands.append(llvm_strip[0])
949     else:
950         commands.insert(0, llvm_strip[0])
951     return tuple(commands)
954 def validate_strip(path):
955     if "llvm-strip" not in path:
956         return True
957     # llvm-strip doesn't support -S before llvm 8.0.
958     retcode, stdout, stderr = get_cmd_output(path, "--help")
959     return retcode == 0 and any(l.startswith("  -S ") for l in stdout.splitlines())
962 @depends("--enable-compile-environment", target, host)
963 def strip_when(compile_env, target, host):
964     return compile_env and any(x.kernel != "WINNT" for x in (target, host))
967 check_prog(
968     "STRIP",
969     strip,
970     when=strip_when,
971     paths=clang_search_path,
972     validate=validate_strip,
976 @depends(js_standalone, target)
977 def system_zlib_default(js_standalone, target):
978     return js_standalone and target.kernel not in ("WINNT", "Darwin")
981 option(
982     "--with-system-zlib",
983     nargs="?",
984     default=system_zlib_default,
985     help="{Use|Do not use} system libz",
989 @depends("--with-system-zlib")
990 def deprecated_system_zlib_path(value):
991     if len(value) == 1:
992         die(
993             "--with-system-zlib=PATH is not supported anymore. Please use "
994             "--with-system-zlib and set any necessary pkg-config environment variable."
995         )
998 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
1000 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1003 @depends("--with-system-zlib", js_shared, moz_linker, target.os)
1004 def zlib_in_mozglue(system_zlib, js_shared, linker, os):
1005     if not system_zlib and (js_shared or linker or os == "Android"):
1006         return True
1009 set_config("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
1010 set_define("ZLIB_IN_MOZGLUE", zlib_in_mozglue)
1013 # Please do not add configure checks from here on.
1015 # Fallthrough to autoconf-based configure
1016 include("build/moz.configure/old.configure")
1018 # JS Subconfigure.
1019 include("js/sub.configure", when=compile_environment & toolkit)
1022 @depends(build_environment, build_project)
1023 @imports("__sandbox__")
1024 @imports("glob")
1025 @imports(_from="os.path", _import="exists")
1026 def config_status_deps(build_env, build_project):
1028     topsrcdir = build_env.topsrcdir
1029     topobjdir = build_env.topobjdir
1031     if not topobjdir.endswith("js/src"):
1032         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
1033     else:
1034         # mozconfig changes may impact js configure.
1035         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
1037     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
1038     if exists(confvars):
1039         extra_deps.append(confvars)
1041     return (
1042         list(__sandbox__._all_paths)
1043         + extra_deps
1044         + [
1045             os.path.join(topsrcdir, "CLOBBER"),
1046             os.path.join(topsrcdir, "configure"),
1047             os.path.join(topsrcdir, "js", "src", "configure"),
1048             os.path.join(topsrcdir, "nsprpub", "configure"),
1049             os.path.join(topsrcdir, "config", "milestone.txt"),
1050             os.path.join(topsrcdir, "browser", "config", "version.txt"),
1051             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
1052             os.path.join(topsrcdir, "python", "sites", "build.txt"),
1053             os.path.join(topsrcdir, "python", "sites", "common.txt"),
1054             os.path.join(topsrcdir, "python", "sites", "mach.txt"),
1055             os.path.join(topsrcdir, "python", "mach", "mach", "site.py"),
1056             os.path.join(topsrcdir, "aclocal.m4"),
1057             os.path.join(topsrcdir, "old-configure.in"),
1058             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1059             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1060         ]
1061         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1062     )
1065 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1066 # Please do not add anything after setting config_dep_paths.