Bug 1732219 - Add API for fetching the preview image. r=geckoview-reviewers,agi,mconley
[gecko.git] / moz.configure
blob2b5003197ce12b21ceff9a8d06b29b70259ce18a
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 option(
141     "--with-debug-label",
142     nargs="+",
143     help="Debug DEBUG_<value> for each comma-separated value given",
147 @depends(moz_debug, "--with-debug-label")
148 def debug_defines(debug, labels):
149     if debug:
150         return ["DEBUG"] + ["DEBUG_%s" % label for label in labels]
151     return ["NDEBUG", "TRIMMED"]
154 set_config("MOZ_DEBUG_DEFINES", debug_defines)
156 option(env="MOZ_PGO", help="Build with profile guided optimizations")
158 set_config("MOZ_PGO", depends("MOZ_PGO")(lambda x: bool(x)))
161 imply_option("--enable-release", mozilla_official)
162 imply_option("--enable-release", depends_if("MOZ_AUTOMATION")(lambda x: True))
164 option(
165     "--enable-release",
166     default=milestone.is_release_or_beta,
167     help="{Build|Do not build} with more conservative, release "
168     "engineering-oriented options.{ This may slow down builds.|}",
172 @depends("--enable-release")
173 def developer_options(value):
174     if not value:
175         return True
178 add_old_configure_assignment("DEVELOPER_OPTIONS", developer_options)
179 set_config("DEVELOPER_OPTIONS", developer_options)
182 # hybrid build handling
183 # ==============================================================
185 option(
186     "--disable-unified-build",
187     help="Enable building modules that are not marked with `REQUIRES_UNIFIED_BUILD` in non unified context",
190 set_config("ENABLE_UNIFIED_BUILD", True, when="--disable-unified-build")
193 option(
194     env="MOZ_FETCHES_DIR",
195     nargs=1,
196     when="MOZ_AUTOMATION",
197     help="Directory containing fetched artifacts",
201 @depends("MOZ_FETCHES_DIR", when="MOZ_AUTOMATION")
202 def moz_fetches_dir(value):
203     if value:
204         return value[0]
207 @depends(vcs_checkout_type, milestone.is_nightly, "MOZ_AUTOMATION")
208 def bootstrap_default(vcs_checkout_type, is_nightly, automation):
209     if automation:
210         return False
211     # We only enable if building off a VCS checkout of central.
212     if is_nightly and vcs_checkout_type:
213         return True
216 option(
217     "--enable-bootstrap",
218     default=bootstrap_default,
219     help="{Automatically bootstrap or update some toolchains|Disable bootstrap or update of toolchains}",
223 @depends(developer_options, "--enable-bootstrap", moz_fetches_dir)
224 def bootstrap_search_path_order(developer_options, bootstrap, moz_fetches_dir):
225     if moz_fetches_dir:
226         log.debug("Prioritizing MOZ_FETCHES_DIR in toolchain path.")
227         return "prepend"
229     if bootstrap:
230         log.debug(
231             "Prioritizing mozbuild state dir in toolchain paths because "
232             "bootstrap mode is enabled."
233         )
234         return "prepend"
236     if developer_options:
237         log.debug(
238             "Prioritizing mozbuild state dir in toolchain paths because "
239             "you are not building in release mode."
240         )
241         return "prepend"
243     log.debug(
244         "Prioritizing system over mozbuild state dir in "
245         "toolchain paths because you are building in "
246         "release mode."
247     )
248     return "append"
251 toolchains_base_dir = moz_fetches_dir | mozbuild_state_path
254 @dependable
255 @imports("os")
256 @imports(_from="os", _import="environ")
257 def original_path():
258     return environ["PATH"].split(os.pathsep)
261 @depends(host, when="--enable-bootstrap")
262 @imports("os")
263 @imports("traceback")
264 @imports(_from="mozbuild.toolchains", _import="toolchain_task_definitions")
265 @imports(_from="__builtin__", _import="Exception")
266 def bootstrap_toolchain_tasks(host):
267     prefix = {
268         ("x86_64", "GNU", "Linux"): "linux64",
269         ("x86_64", "OSX", "Darwin"): "macosx64",
270         ("aarch64", "OSX", "Darwin"): "macosx64-aarch64",
271         ("x86_64", "WINNT", "WINNT"): "win64",
272     }.get((host.cpu, host.os, host.kernel))
273     try:
274         return namespace(prefix=prefix, tasks=toolchain_task_definitions())
275     except Exception as e:
276         message = traceback.format_exc()
277         log.warning(str(e))
278         log.debug(message)
279         return None
282 @template
283 def bootstrap_path(path, **kwargs):
284     when = kwargs.pop("when", None)
285     if kwargs:
286         configure_error("bootstrap_path only takes `when` as a keyword argument")
288     @depends(
289         "--enable-bootstrap",
290         toolchains_base_dir,
291         bootstrap_toolchain_tasks,
292         shell,
293         check_build_environment,
294         dependable(path),
295         when=when,
296     )
297     @imports("os")
298     @imports("subprocess")
299     @imports(_from="mozbuild.util", _import="ensureParentDir")
300     @imports(_from="__builtin__", _import="open")
301     @imports(_from="__builtin__", _import="Exception")
302     def bootstrap_path(bootstrap, toolchains_base_dir, tasks, shell, build_env, path):
303         path_parts = path.split("/")
305         def try_bootstrap(exists):
306             if not tasks:
307                 return False
308             prefixes = [""]
309             if tasks.prefix:
310                 prefixes.insert(0, "{}-".format(tasks.prefix))
311             for prefix in prefixes:
312                 label = "toolchain-{}{}".format(prefix, path_parts[0])
313                 task = tasks.tasks.get(label)
314                 if task:
315                     break
316             log.debug("Trying to bootstrap %s", label)
317             if not task:
318                 return False
319             task_index = task.optimization.get("index-search")
320             if not task_index:
321                 return False
322             log.debug("Resolved %s to %s", label, task_index[0])
323             task_index = task_index[0].split(".")[-1]
324             artifact = task.attributes["toolchain-artifact"]
325             # `mach artifact toolchain` doesn't support authentication for
326             # private artifacts.
327             if not artifact.startswith("public/"):
328                 log.debug("Cannot bootstrap %s: not a public artifact", label)
329                 return False
330             index_file = os.path.join(toolchains_base_dir, "indices", path_parts[0])
331             try:
332                 with open(index_file) as fh:
333                     index = fh.read().strip()
334             except Exception:
335                 index = None
336             if index == task_index and exists:
337                 log.debug("%s is up-to-date", label)
338                 return True
339             log.info(
340                 "%s bootstrapped toolchain in %s",
341                 "Updating" if exists else "Installing",
342                 os.path.join(toolchains_base_dir, path_parts[0]),
343             )
344             subprocess.run(
345                 [
346                     shell,
347                     os.path.join(build_env.topsrcdir, "mach"),
348                     "--log-no-times",
349                     "artifact",
350                     "toolchain",
351                     "--from-build",
352                     label,
353                 ],
354                 cwd=toolchains_base_dir,
355                 check=True,
356             )
357             ensureParentDir(index_file)
358             with open(index_file, "w") as fh:
359                 fh.write(task_index)
360             return True
362         path = os.path.join(toolchains_base_dir, *path_parts)
363         if bootstrap:
364             try:
365                 if not try_bootstrap(os.path.exists(path)):
366                     # If there aren't toolchain artifacts to use for this build,
367                     # don't return a path.
368                     return None
369             except Exception as e:
370                 log.error("%s", e)
371                 die("If you can't fix the above, retry with --disable-bootstrap.")
372         # We re-test whether the path exists because it may have been created by
373         # try_bootstrap. Automation will not have gone through the bootstrap
374         # process, but we want to return the path if it exists.
375         if os.path.exists(path):
376             return path
378     return bootstrap_path
381 @template
382 def bootstrap_search_path(path, paths=original_path, **kwargs):
383     @depends(
384         bootstrap_path(path, **kwargs),
385         bootstrap_search_path_order,
386         paths,
387         original_path,
388     )
389     def bootstrap_search_path(path, order, paths, original_path):
390         if paths is None:
391             paths = original_path
392         if not path:
393             return paths
394         if order == "prepend":
395             return [path] + paths
396         return paths + [path]
398     return bootstrap_search_path
401 # The execution model of the configure sandbox doesn't allow for
402 # check_prog to use bootstrap_search_path directly because check_prog
403 # comes first, so we use a trick to allow it. Uses of check_prog
404 # happening before here won't allow bootstrap.
405 @template
406 def check_prog(*args, **kwargs):
407     kwargs["bootstrap_search_path"] = bootstrap_search_path
408     return check_prog(*args, **kwargs)
411 check_prog("WGET", ("wget",), allow_missing=True)
414 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
416 include("build/moz.configure/pkg.configure")
417 # Make this assignment here rather than in pkg.configure to avoid
418 # requiring this file in unit tests.
419 add_old_configure_assignment("PKG_CONFIG", pkg_config)
421 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
422 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
423 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
424 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
425 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
426 # rust.configure is included by js/moz.configure.
428 option("--enable-valgrind", help="Enable Valgrind integration hooks")
430 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
433 @depends("--enable-valgrind", valgrind_h)
434 def check_valgrind(valgrind, valgrind_h):
435     if valgrind:
436         if not valgrind_h:
437             die("--enable-valgrind specified but Valgrind is not installed")
438         return True
441 set_define("MOZ_VALGRIND", check_valgrind)
442 set_config("MOZ_VALGRIND", check_valgrind)
445 @depends(target, host)
446 def is_openbsd(target, host):
447     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
450 option(
451     env="SO_VERSION",
452     nargs=1,
453     default="1.0",
454     when=is_openbsd,
455     help="Shared library version for OpenBSD systems",
459 @depends("SO_VERSION", when=is_openbsd)
460 def so_version(value):
461     return value
464 @template
465 def library_name_info_template(host_or_target):
466     assert host_or_target in {host, target}
467     compiler = {
468         host: host_c_compiler,
469         target: c_compiler,
470     }[host_or_target]
472     @depends(host_or_target, compiler, so_version)
473     def library_name_info_impl(host_or_target, compiler, so_version):
474         if host_or_target.kernel == "WINNT":
475             # There aren't artifacts for mingw builds, so it's OK that the
476             # results are inaccurate in that case.
477             if compiler and compiler.type != "clang-cl":
478                 return namespace(
479                     dll=namespace(prefix="", suffix=".dll"),
480                     lib=namespace(prefix="lib", suffix="a"),
481                     import_lib=namespace(prefix="lib", suffix="a"),
482                     obj=namespace(prefix="", suffix="o"),
483                 )
485             return namespace(
486                 dll=namespace(prefix="", suffix=".dll"),
487                 lib=namespace(prefix="", suffix="lib"),
488                 import_lib=namespace(prefix="", suffix="lib"),
489                 obj=namespace(prefix="", suffix="obj"),
490             )
492         elif host_or_target.kernel == "Darwin":
493             return namespace(
494                 dll=namespace(prefix="lib", suffix=".dylib"),
495                 lib=namespace(prefix="lib", suffix="a"),
496                 import_lib=namespace(prefix=None, suffix=""),
497                 obj=namespace(prefix="", suffix="o"),
498             )
499         elif so_version:
500             so = ".so.%s" % so_version
501         else:
502             so = ".so"
504         return namespace(
505             dll=namespace(prefix="lib", suffix=so),
506             lib=namespace(prefix="lib", suffix="a"),
507             import_lib=namespace(prefix=None, suffix=""),
508             obj=namespace(prefix="", suffix="o"),
509         )
511     return library_name_info_impl
514 host_library_name_info = library_name_info_template(host)
515 library_name_info = library_name_info_template(target)
517 set_config("DLL_PREFIX", library_name_info.dll.prefix)
518 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
519 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
520 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
521 set_config("LIB_PREFIX", library_name_info.lib.prefix)
522 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
523 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
524 # Lots of compilation tests depend on this variable being present.
525 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
526 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
527 set_define(
528     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
530 set_define(
531     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
533 set_config("WASM_OBJ_SUFFIX", "wasm")
535 # Make `profiling` available to this file even when js/moz.configure
536 # doesn't end up included.
537 profiling = dependable(False)
538 # Same for js_standalone
539 js_standalone = dependable(False)
540 # Same for fold_libs
541 fold_libs = dependable(False)
543 include(include_project_configure)
546 @depends("--help")
547 @imports(_from="mozbuild.backend", _import="backends")
548 def build_backends_choices(_):
549     return tuple(backends)
552 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
553 def build_backend(backends):
554     if backends:
555         return tuple("+%s" % b for b in backends)
558 imply_option("--build-backends", build_backend)
561 @depends(
562     "--enable-artifact-builds",
563     "--disable-compile-environment",
564     "--enable-build-backend",
565     "--enable-project",
566     "--enable-application",
567     "--help",
569 @imports("sys")
570 def build_backend_defaults(
571     artifact_builds, compile_environment, requested_backends, project, application, _
573     if application:
574         project = application[0]
575     elif project:
576         project = project[0]
578     if "Tup" in requested_backends:
579         # As a special case, if Tup was requested, do not combine it with any
580         # Make based backend by default.
581         all_backends = []
582     elif artifact_builds:
583         all_backends = ["FasterMake+RecursiveMake"]
584     else:
585         all_backends = ["RecursiveMake", "FasterMake"]
586     # Normally, we'd use target.os == 'WINNT', but a dependency on target
587     # would require target to depend on --help, as well as host and shell,
588     # and this is not a can of worms we can open at the moment.
589     if (
590         sys.platform == "win32"
591         and compile_environment
592         and project not in ("mobile/android", "memory", "tools/update-programs")
593     ):
594         all_backends.append("VisualStudio")
595     return tuple(all_backends) or None
598 option(
599     "--build-backends",
600     nargs="+",
601     default=build_backend_defaults,
602     choices=build_backends_choices,
603     help="Build backends to generate",
607 @depends("--build-backends")
608 def build_backends(backends):
609     return backends
612 set_config("BUILD_BACKENDS", build_backends)
615 @depends(check_build_environment, build_backends)
616 @imports("glob")
617 def check_objdir_backend_reuse(build_env, backends):
618     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
619     # intentionally vague for use with the substring match below.
620     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
621     for backend_file in glob.iglob(
622         os.path.join(build_env.topobjdir, "backend.*Backend")
623     ):
624         for prev, curr in incompatible_backends:
625             if prev in backend_file and any(curr in b for b in backends):
626                 die(
627                     "The active objdir, %s, was previously "
628                     "used to build with a %s based backend. "
629                     "Change objdirs (by setting MOZ_OBJDIR in "
630                     "your mozconfig) or clobber to continue.\n",
631                     build_env.topobjdir,
632                     prev,
633                 )
636 # Determine whether to build the gtest xul. This happens in automation
637 # on Android and Desktop platforms with the exception of:
638 #  - Windows PGO, where linking xul-gtest.dll takes too long;
639 #  - Android other than x86_64, where gtest is not required.
640 @depends(
641     "MOZ_PGO",
642     build_project,
643     target,
644     "MOZ_AUTOMATION",
645     enable_tests,
646     when="--enable-compile-environment",
648 def build_gtest(pgo, build_project, target, automation, enable_tests):
649     return bool(
650         enable_tests
651         and automation
652         and build_project in ("browser", "comm/mail", "mobile/android")
653         and not (
654             (pgo and target.os == "WINNT")
655             or (target.os == "Android" and target.cpu != "x86_64")
656         )
657     )
660 option(
661     "--enable-gtest-in-build",
662     default=build_gtest,
663     help="{Enable|Force disable} building the gtest libxul during the build.",
664     when="--enable-compile-environment",
667 set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build")
669 # Localization
670 # ==============================================================
671 option(
672     "--enable-ui-locale",
673     default="en-US",
674     help="Select the user interface locale (default: en-US)",
677 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
679 # clang-plugin location
680 # ==============================================================
683 @depends(host_library_name_info, check_build_environment, when="--enable-clang-plugin")
684 def clang_plugin_path(library_name_info, build_env):
685     topobjdir = build_env.topobjdir
686     if topobjdir.endswith("/js/src"):
687         topobjdir = topobjdir[:-7]
688     return os.path.abspath(
689         os.path.join(
690             topobjdir,
691             "build",
692             "clang-plugin",
693             "%sclang-plugin%s"
694             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
695         )
696     )
699 set_config("CLANG_PLUGIN", clang_plugin_path)
700 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
703 # Awk detection
704 # ==============================================================
705 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
707 # Until the AWK variable is not necessary in old-configure
710 @depends(awk)
711 def awk_for_old_configure(value):
712     return value
715 add_old_configure_assignment("AWK", awk_for_old_configure)
718 # Perl detection
719 # ==============================================================
720 perl = check_prog("PERL", ("perl5", "perl"))
722 # Until the PERL variable is not necessary in old-configure
725 @depends(perl)
726 def perl_for_old_configure(value):
727     return value
730 add_old_configure_assignment("PERL", perl_for_old_configure)
733 @template
734 def perl_version_check(min_version):
735     @depends(perl)
736     @checking("for minimum required perl version >= %s" % min_version)
737     def get_perl_version(perl):
738         return Version(
739             check_cmd_output(
740                 perl,
741                 "-e",
742                 "print $]",
743                 onerror=lambda: die("Failed to get perl version."),
744             )
745         )
747     @depends(get_perl_version)
748     def check_perl_version(version):
749         if version < min_version:
750             die("Perl %s or higher is required.", min_version)
752     @depends(perl)
753     @checking("for full perl installation")
754     @imports("subprocess")
755     def has_full_perl_installation(perl):
756         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
757         return ret == 0
759     @depends(has_full_perl_installation)
760     def require_full_perl_installation(has_full_perl_installation):
761         if not has_full_perl_installation:
762             die(
763                 "Cannot find Config.pm or $Config{archlib}. "
764                 "A full perl installation is required."
765             )
768 perl_version_check("5.006")
771 # GNU make detection
772 # ==============================================================
773 option(env="MAKE", nargs=1, help="Path to GNU make")
776 @depends("MAKE", host)
777 def possible_makes(make, host):
778     candidates = []
779     if host.kernel == "WINNT":
780         candidates.append("mingw32-make")
781     if make:
782         candidates.append(make[0])
783     if host.kernel == "WINNT":
784         candidates.extend(("mozmake", "make", "gmake"))
785     else:
786         candidates.extend(("gmake", "make"))
787     return candidates
790 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
792 # watchman detection
793 # ==============================================================
795 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
798 @depends(host, "WATCHMAN")
799 @checking("for watchman", callback=lambda w: w.path if w else "not found")
800 def watchman(host, prog):
801     # On Windows, `watchman` is only supported on 64-bit hosts.
802     if host.os == "WINNT" and host.cpu != "x86_64":
803         return
805     if not prog:
806         prog = find_program("watchman")
808     if not prog:
809         return
811     # `watchman version` will talk to the Watchman daemon service.
812     # This can hang due to permissions problems. e.g.
813     # https://github.com/facebook/watchman/issues/376. So use
814     # `watchman --version` to prevent a class of failures.
815     out = check_cmd_output(prog, "--version", onerror=lambda: None)
816     if out is None:
817         return
819     return namespace(path=prog, version=Version(out.strip()))
822 @depends_if(watchman)
823 @checking("for watchman version")
824 def watchman_version(w):
825     return w.version
828 set_config("WATCHMAN", watchman.path)
831 @depends_all(hg_version, hg_config, watchman)
832 @checking("for watchman Mercurial integration")
833 @imports("os")
834 def watchman_hg(hg_version, hg_config, watchman):
835     if hg_version < Version("3.8"):
836         return "no (Mercurial 3.8+ required)"
838     ext_enabled = False
839     mode_disabled = False
841     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
842         if k in hg_config and hg_config[k] != "!":
843             ext_enabled = True
845     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
847     if not ext_enabled:
848         return "no (fsmonitor extension not enabled)"
849     if mode_disabled:
850         return "no (fsmonitor.mode=off disables fsmonitor)"
852     return True
855 # Miscellaneous programs
856 # ==============================================================
857 check_prog("XARGS", ("xargs",))
860 @depends(target)
861 def extra_programs(target):
862     if target.kernel == "Darwin":
863         return namespace(
864             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
865             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
866             HFS_TOOL=("hfsplus",),
867         )
868     if target.os == "GNU" and target.kernel == "Linux":
869         return namespace(RPMBUILD=("rpmbuild",))
872 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
873 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
874 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
875 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
878 nsis = check_prog(
879     "MAKENSISU",
880     ("makensis",),
881     bootstrap="nsis/bin",
882     allow_missing=True,
883     when=target_is_windows,
886 # Make sure the version of makensis is up to date.
889 @depends_if(nsis)
890 @checking("for NSIS version")
891 @imports("re")
892 def nsis_version(nsis):
893     nsis_min_version = "3.0b1"
895     def onerror():
896         return die("Failed to get nsis version.")
898     out = check_cmd_output(nsis, "-version", onerror=onerror)
900     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
902     if not m:
903         raise FatalCheckError("Unknown version of makensis")
904     ver = Version(m.group(0))
906     # Versions comparisons don't quite work well with beta versions, so ensure
907     # it works for the non-beta version.
908     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
909         raise FatalCheckError(
910             "To build the installer you must have NSIS"
911             " version %s or greater in your path" % nsis_min_version
912         )
914     return ver
917 # And that makensis is 32-bit (but only on Windows).
918 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
919 @checking("for 32-bit NSIS")
920 def nsis_binary_type(nsis):
921     bin_type = windows_binary_type(nsis)
922     if bin_type != "win32":
923         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
925     return "yes"
928 # And any flags we have to give to makensis
929 @depends(host)
930 def nsis_flags(host):
931     if host.kernel != "WINNT":
932         return "-nocd"
933     return ""
936 set_config("MAKENSISU_FLAGS", nsis_flags)
938 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
939 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
942 @depends(host_c_compiler, c_compiler, bindgen_config_paths)
943 def llvm_objdump(host_c_compiler, c_compiler, bindgen_config_paths):
944     clang = None
945     for compiler in (host_c_compiler, c_compiler):
946         if compiler and compiler.type == "clang":
947             clang = compiler.compiler
948             break
949         elif compiler and compiler.type == "clang-cl":
950             clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
951             break
953     if not clang and bindgen_config_paths:
954         clang = bindgen_config_paths.clang_path
955     llvm_objdump = "llvm-objdump"
956     if clang:
957         out = check_cmd_output(
958             clang, "--print-prog-name=llvm-objdump", onerror=lambda: None
959         )
960         if out:
961             llvm_objdump = out.rstrip()
962     return (llvm_objdump,)
965 llvm_objdump = check_prog(
966     "LLVM_OBJDUMP",
967     llvm_objdump,
968     what="llvm-objdump",
969     when="--enable-compile-environment",
970     paths=clang_search_path,
973 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
976 option("--enable-dtrace", help="Build with dtrace support")
978 dtrace = check_header(
979     "sys/sdt.h",
980     when="--enable-dtrace",
981     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
984 set_config("HAVE_DTRACE", True, when=dtrace)
985 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
986 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
989 option("--disable-icf", help="Disable Identical Code Folding")
991 add_old_configure_assignment(
992     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
996 option(
997     "--enable-strip",
998     when=compile_environment,
999     help="Enable stripping of libs & executables",
1002 # This should be handled as a `when` once bug 1617793 is fixed.
1005 @depends("--enable-strip", c_compiler, when=compile_environment)
1006 def enable_strip(strip, c_compiler):
1007     if strip and c_compiler.type != "clang-cl":
1008         return True
1011 set_config("ENABLE_STRIP", enable_strip)
1013 option(
1014     "--disable-install-strip",
1015     when=compile_environment,
1016     help="Enable stripping of libs & executables when packaging",
1019 # This should be handled as a `when` once bug 1617793 is fixed.
1022 @depends("--enable-install-strip", c_compiler, when=compile_environment)
1023 def enable_install_strip(strip, c_compiler):
1024     if strip and c_compiler.type != "clang-cl":
1025         return True
1028 set_config("PKG_STRIP", enable_install_strip)
1031 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
1032 def strip(strip, install_strip):
1033     return strip or install_strip
1036 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
1039 @depends("STRIP_FLAGS", profiling, target, when=strip)
1040 def strip_flags(flags, profiling, target):
1041     if flags:
1042         return flags[0].split()
1043     if profiling:
1044         # Only strip debug info and symbols when profiling is enabled, keeping
1045         # local symbols.
1046         if target.kernel == "Darwin":
1047             return ["-S"]
1048         elif target.os == "Android":
1049             # The tooling we use with Android supports detached symbols, and the
1050             # size increase caused by local symbols are too much for mobile. So,
1051             # don't restrict the amount of stripping with a flag.
1052             return
1053         else:
1054             return ["--strip-debug"]
1055     # Otherwise strip everything we can, which happens without flags on non-Darwin.
1056     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
1057     elif target.kernel == "Darwin":
1058         return ["-x", "-S"]
1061 set_config("STRIP_FLAGS", strip_flags)
1064 @depends(js_standalone, target)
1065 def system_zlib_default(js_standalone, target):
1066     return js_standalone and target.kernel not in ("WINNT", "Darwin")
1069 option(
1070     "--with-system-zlib",
1071     nargs="?",
1072     default=system_zlib_default,
1073     help="{Use|Do not use} system libz",
1077 @depends("--with-system-zlib")
1078 def deprecated_system_zlib_path(value):
1079     if len(value) == 1:
1080         die(
1081             "--with-system-zlib=PATH is not supported anymore. Please use "
1082             "--with-system-zlib and set any necessary pkg-config environment variable."
1083         )
1086 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
1088 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1089 add_old_configure_assignment("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1092 # Please do not add configure checks from here on.
1094 # Fallthrough to autoconf-based configure
1095 include("build/moz.configure/old.configure")
1097 # JS Subconfigure.
1098 include("js/sub.configure", when=compile_environment & toolkit)
1101 @depends(check_build_environment, build_project)
1102 @imports("__sandbox__")
1103 @imports("glob")
1104 @imports(_from="os.path", _import="exists")
1105 def config_status_deps(build_env, build_project):
1107     topsrcdir = build_env.topsrcdir
1108     topobjdir = build_env.topobjdir
1110     if not topobjdir.endswith("js/src"):
1111         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
1112     else:
1113         # mozconfig changes may impact js configure.
1114         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
1116     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
1117     if exists(confvars):
1118         extra_deps.append(confvars)
1120     return (
1121         list(__sandbox__._all_paths)
1122         + extra_deps
1123         + [
1124             os.path.join(topsrcdir, "CLOBBER"),
1125             os.path.join(topsrcdir, "configure.in"),
1126             os.path.join(topsrcdir, "js", "src", "configure.in"),
1127             os.path.join(topsrcdir, "nsprpub", "configure"),
1128             os.path.join(topsrcdir, "config", "milestone.txt"),
1129             os.path.join(topsrcdir, "browser", "config", "version.txt"),
1130             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
1131             os.path.join(topsrcdir, "build", "build_virtualenv_packages.txt"),
1132             os.path.join(topsrcdir, "build", "common_virtualenv_packages.txt"),
1133             os.path.join(topsrcdir, "build", "mach_virtualenv_packages.txt"),
1134             os.path.join(topsrcdir, "python", "mozbuild", "mozbuild", "virtualenv.py"),
1135             os.path.join(topsrcdir, "aclocal.m4"),
1136             os.path.join(topsrcdir, "old-configure.in"),
1137             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1138             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1139         ]
1140         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1141     )
1144 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1145 # Please do not add anything after setting config_dep_paths.