Bug 1726269: part 1) Repeatedly call `::OleSetClipboard` for the Windows-specific...
[gecko.git] / moz.configure
blob87882d0d31d58700a7fd5fa975a2a2b81e07f525
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 @depends(target, host)
412 def want_wine(target, host):
413     return target.kernel == "WINNT" and host.kernel != "WINNT"
416 wine = check_prog(
417     "WINE",
418     ["wine64", "wine"],
419     allow_missing=True,
420     when=want_wine,
421     bootstrap="wine/bin",
423 check_prog("WGET", ("wget",), allow_missing=True)
426 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
428 include("build/moz.configure/pkg.configure")
429 # Make this assignment here rather than in pkg.configure to avoid
430 # requiring this file in unit tests.
431 add_old_configure_assignment("PKG_CONFIG", pkg_config)
433 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
434 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
435 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
436 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
437 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
438 # rust.configure is included by js/moz.configure.
440 option("--enable-valgrind", help="Enable Valgrind integration hooks")
442 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
445 @depends("--enable-valgrind", valgrind_h)
446 def check_valgrind(valgrind, valgrind_h):
447     if valgrind:
448         if not valgrind_h:
449             die("--enable-valgrind specified but Valgrind is not installed")
450         return True
453 set_define("MOZ_VALGRIND", check_valgrind)
454 set_config("MOZ_VALGRIND", check_valgrind)
457 @depends(target, host)
458 def is_openbsd(target, host):
459     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
462 option(
463     env="SO_VERSION",
464     nargs=1,
465     default="1.0",
466     when=is_openbsd,
467     help="Shared library version for OpenBSD systems",
471 @depends("SO_VERSION", when=is_openbsd)
472 def so_version(value):
473     return value
476 @template
477 def library_name_info_template(host_or_target):
478     assert host_or_target in {host, target}
479     compiler = {
480         host: host_c_compiler,
481         target: c_compiler,
482     }[host_or_target]
484     @depends(host_or_target, compiler, so_version)
485     def library_name_info_impl(host_or_target, compiler, so_version):
486         if host_or_target.kernel == "WINNT":
487             # There aren't artifacts for mingw builds, so it's OK that the
488             # results are inaccurate in that case.
489             if compiler and compiler.type != "clang-cl":
490                 return namespace(
491                     dll=namespace(prefix="", suffix=".dll"),
492                     lib=namespace(prefix="lib", suffix="a"),
493                     import_lib=namespace(prefix="lib", suffix="a"),
494                     obj=namespace(prefix="", suffix="o"),
495                 )
497             return namespace(
498                 dll=namespace(prefix="", suffix=".dll"),
499                 lib=namespace(prefix="", suffix="lib"),
500                 import_lib=namespace(prefix="", suffix="lib"),
501                 obj=namespace(prefix="", suffix="obj"),
502             )
504         elif host_or_target.kernel == "Darwin":
505             return namespace(
506                 dll=namespace(prefix="lib", suffix=".dylib"),
507                 lib=namespace(prefix="lib", suffix="a"),
508                 import_lib=namespace(prefix=None, suffix=""),
509                 obj=namespace(prefix="", suffix="o"),
510             )
511         elif so_version:
512             so = ".so.%s" % so_version
513         else:
514             so = ".so"
516         return namespace(
517             dll=namespace(prefix="lib", suffix=so),
518             lib=namespace(prefix="lib", suffix="a"),
519             import_lib=namespace(prefix=None, suffix=""),
520             obj=namespace(prefix="", suffix="o"),
521         )
523     return library_name_info_impl
526 host_library_name_info = library_name_info_template(host)
527 library_name_info = library_name_info_template(target)
529 set_config("DLL_PREFIX", library_name_info.dll.prefix)
530 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
531 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
532 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
533 set_config("LIB_PREFIX", library_name_info.lib.prefix)
534 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
535 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
536 # Lots of compilation tests depend on this variable being present.
537 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
538 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
539 set_define(
540     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
542 set_define(
543     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
545 set_config("WASM_OBJ_SUFFIX", "wasm")
547 # Make `profiling` available to this file even when js/moz.configure
548 # doesn't end up included.
549 profiling = dependable(False)
550 # Same for js_standalone
551 js_standalone = dependable(False)
552 # Same for fold_libs
553 fold_libs = dependable(False)
555 include(include_project_configure)
558 @depends("--help")
559 @imports(_from="mozbuild.backend", _import="backends")
560 def build_backends_choices(_):
561     return tuple(backends)
564 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
565 def build_backend(backends):
566     if backends:
567         return tuple("+%s" % b for b in backends)
570 imply_option("--build-backends", build_backend)
573 @depends(
574     "--enable-artifact-builds",
575     "--disable-compile-environment",
576     "--enable-build-backend",
577     "--enable-project",
578     "--enable-application",
579     "--help",
581 @imports("sys")
582 def build_backend_defaults(
583     artifact_builds, compile_environment, requested_backends, project, application, _
585     if application:
586         project = application[0]
587     elif project:
588         project = project[0]
590     if "Tup" in requested_backends:
591         # As a special case, if Tup was requested, do not combine it with any
592         # Make based backend by default.
593         all_backends = []
594     elif artifact_builds:
595         all_backends = ["FasterMake+RecursiveMake"]
596     else:
597         all_backends = ["RecursiveMake", "FasterMake"]
598     # Normally, we'd use target.os == 'WINNT', but a dependency on target
599     # would require target to depend on --help, as well as host and shell,
600     # and this is not a can of worms we can open at the moment.
601     if (
602         sys.platform == "win32"
603         and compile_environment
604         and project not in ("mobile/android", "memory", "tools/update-programs")
605     ):
606         all_backends.append("VisualStudio")
607     return tuple(all_backends) or None
610 option(
611     "--build-backends",
612     nargs="+",
613     default=build_backend_defaults,
614     choices=build_backends_choices,
615     help="Build backends to generate",
619 @depends("--build-backends")
620 def build_backends(backends):
621     return backends
624 set_config("BUILD_BACKENDS", build_backends)
627 @depends(check_build_environment, build_backends)
628 @imports("glob")
629 def check_objdir_backend_reuse(build_env, backends):
630     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
631     # intentionally vague for use with the substring match below.
632     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
633     for backend_file in glob.iglob(
634         os.path.join(build_env.topobjdir, "backend.*Backend")
635     ):
636         for prev, curr in incompatible_backends:
637             if prev in backend_file and any(curr in b for b in backends):
638                 die(
639                     "The active objdir, %s, was previously "
640                     "used to build with a %s based backend. "
641                     "Change objdirs (by setting MOZ_OBJDIR in "
642                     "your mozconfig) or clobber to continue.\n",
643                     build_env.topobjdir,
644                     prev,
645                 )
648 # Determine whether to build the gtest xul. This happens in automation
649 # on Android and Desktop platforms with the exception of:
650 #  - Windows PGO, where linking xul-gtest.dll takes too long;
651 #  - Android other than x86_64, where gtest is not required.
652 @depends(
653     "MOZ_PGO",
654     build_project,
655     target,
656     "MOZ_AUTOMATION",
657     enable_tests,
658     when="--enable-compile-environment",
660 def build_gtest(pgo, build_project, target, automation, enable_tests):
661     return bool(
662         enable_tests
663         and automation
664         and build_project in ("browser", "comm/mail", "mobile/android")
665         and not (
666             (pgo and target.os == "WINNT")
667             or (target.os == "Android" and target.cpu != "x86_64")
668         )
669     )
672 option(
673     "--enable-gtest-in-build",
674     default=build_gtest,
675     help="{Enable|Force disable} building the gtest libxul during the build.",
676     when="--enable-compile-environment",
679 set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build")
681 # Localization
682 # ==============================================================
683 option(
684     "--enable-ui-locale",
685     default="en-US",
686     help="Select the user interface locale (default: en-US)",
689 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
691 # clang-plugin location
692 # ==============================================================
695 @depends(host_library_name_info, check_build_environment, when="--enable-clang-plugin")
696 def clang_plugin_path(library_name_info, build_env):
697     topobjdir = build_env.topobjdir
698     if topobjdir.endswith("/js/src"):
699         topobjdir = topobjdir[:-7]
700     return os.path.abspath(
701         os.path.join(
702             topobjdir,
703             "build",
704             "clang-plugin",
705             "%sclang-plugin%s"
706             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
707         )
708     )
711 set_config("CLANG_PLUGIN", clang_plugin_path)
712 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
715 # Awk detection
716 # ==============================================================
717 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
719 # Until the AWK variable is not necessary in old-configure
722 @depends(awk)
723 def awk_for_old_configure(value):
724     return value
727 add_old_configure_assignment("AWK", awk_for_old_configure)
730 # Perl detection
731 # ==============================================================
732 perl = check_prog("PERL", ("perl5", "perl"))
734 # Until the PERL variable is not necessary in old-configure
737 @depends(perl)
738 def perl_for_old_configure(value):
739     return value
742 add_old_configure_assignment("PERL", perl_for_old_configure)
745 @template
746 def perl_version_check(min_version):
747     @depends(perl)
748     @checking("for minimum required perl version >= %s" % min_version)
749     def get_perl_version(perl):
750         return Version(
751             check_cmd_output(
752                 perl,
753                 "-e",
754                 "print $]",
755                 onerror=lambda: die("Failed to get perl version."),
756             )
757         )
759     @depends(get_perl_version)
760     def check_perl_version(version):
761         if version < min_version:
762             die("Perl %s or higher is required.", min_version)
764     @depends(perl)
765     @checking("for full perl installation")
766     @imports("subprocess")
767     def has_full_perl_installation(perl):
768         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
769         return ret == 0
771     @depends(has_full_perl_installation)
772     def require_full_perl_installation(has_full_perl_installation):
773         if not has_full_perl_installation:
774             die(
775                 "Cannot find Config.pm or $Config{archlib}. "
776                 "A full perl installation is required."
777             )
780 perl_version_check("5.006")
783 # GNU make detection
784 # ==============================================================
785 option(env="MAKE", nargs=1, help="Path to GNU make")
788 @depends("MAKE", host)
789 def possible_makes(make, host):
790     candidates = []
791     if host.kernel == "WINNT":
792         candidates.append("mingw32-make")
793     if make:
794         candidates.append(make[0])
795     if host.kernel == "WINNT":
796         candidates.extend(("mozmake", "make", "gmake"))
797     else:
798         candidates.extend(("gmake", "make"))
799     return candidates
802 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
804 # watchman detection
805 # ==============================================================
807 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
810 @depends(host, "WATCHMAN")
811 @checking("for watchman", callback=lambda w: w.path if w else "not found")
812 def watchman(host, prog):
813     # On Windows, `watchman` is only supported on 64-bit hosts.
814     if host.os == "WINNT" and host.cpu != "x86_64":
815         return
817     if not prog:
818         prog = find_program("watchman")
820     if not prog:
821         return
823     # `watchman version` will talk to the Watchman daemon service.
824     # This can hang due to permissions problems. e.g.
825     # https://github.com/facebook/watchman/issues/376. So use
826     # `watchman --version` to prevent a class of failures.
827     out = check_cmd_output(prog, "--version", onerror=lambda: None)
828     if out is None:
829         return
831     return namespace(path=prog, version=Version(out.strip()))
834 @depends_if(watchman)
835 @checking("for watchman version")
836 def watchman_version(w):
837     return w.version
840 set_config("WATCHMAN", watchman.path)
843 @depends_all(hg_version, hg_config, watchman)
844 @checking("for watchman Mercurial integration")
845 @imports("os")
846 def watchman_hg(hg_version, hg_config, watchman):
847     if hg_version < Version("3.8"):
848         return "no (Mercurial 3.8+ required)"
850     ext_enabled = False
851     mode_disabled = False
853     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
854         if k in hg_config and hg_config[k] != "!":
855             ext_enabled = True
857     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
859     if not ext_enabled:
860         return "no (fsmonitor extension not enabled)"
861     if mode_disabled:
862         return "no (fsmonitor.mode=off disables fsmonitor)"
864     return True
867 # Miscellaneous programs
868 # ==============================================================
869 check_prog("XARGS", ("xargs",))
872 @depends(target)
873 def extra_programs(target):
874     if target.kernel == "Darwin":
875         return namespace(
876             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
877             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
878             HFS_TOOL=("hfsplus",),
879         )
880     if target.os == "GNU" and target.kernel == "Linux":
881         return namespace(RPMBUILD=("rpmbuild",))
884 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
885 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
886 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
887 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
890 nsis = check_prog(
891     "MAKENSISU",
892     ("makensis",),
893     bootstrap="nsis/bin",
894     allow_missing=True,
895     when=target_is_windows,
898 # Make sure the version of makensis is up to date.
901 @depends_if(nsis)
902 @checking("for NSIS version")
903 @imports("re")
904 def nsis_version(nsis):
905     nsis_min_version = "3.0b1"
907     def onerror():
908         return die("Failed to get nsis version.")
910     out = check_cmd_output(nsis, "-version", onerror=onerror)
912     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
914     if not m:
915         raise FatalCheckError("Unknown version of makensis")
916     ver = Version(m.group(0))
918     # Versions comparisons don't quite work well with beta versions, so ensure
919     # it works for the non-beta version.
920     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
921         raise FatalCheckError(
922             "To build the installer you must have NSIS"
923             " version %s or greater in your path" % nsis_min_version
924         )
926     return ver
929 # And that makensis is 32-bit (but only on Windows).
930 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
931 @checking("for 32-bit NSIS")
932 def nsis_binary_type(nsis):
933     bin_type = windows_binary_type(nsis)
934     if bin_type != "win32":
935         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
937     return "yes"
940 # And any flags we have to give to makensis
941 @depends(host)
942 def nsis_flags(host):
943     if host.kernel != "WINNT":
944         return "-nocd"
945     return ""
948 set_config("MAKENSISU_FLAGS", nsis_flags)
950 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
951 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
954 @depends(host_c_compiler, c_compiler, bindgen_config_paths)
955 def llvm_objdump(host_c_compiler, c_compiler, bindgen_config_paths):
956     clang = None
957     for compiler in (host_c_compiler, c_compiler):
958         if compiler and compiler.type == "clang":
959             clang = compiler.compiler
960             break
961         elif compiler and compiler.type == "clang-cl":
962             clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
963             break
965     if not clang and bindgen_config_paths:
966         clang = bindgen_config_paths.clang_path
967     llvm_objdump = "llvm-objdump"
968     if clang:
969         out = check_cmd_output(
970             clang, "--print-prog-name=llvm-objdump", onerror=lambda: None
971         )
972         if out:
973             llvm_objdump = out.rstrip()
974     return (llvm_objdump,)
977 llvm_objdump = check_prog(
978     "LLVM_OBJDUMP",
979     llvm_objdump,
980     what="llvm-objdump",
981     when="--enable-compile-environment",
982     paths=clang_search_path,
985 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
988 option("--enable-dtrace", help="Build with dtrace support")
990 dtrace = check_header(
991     "sys/sdt.h",
992     when="--enable-dtrace",
993     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
996 set_config("HAVE_DTRACE", True, when=dtrace)
997 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
998 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
1001 option("--disable-icf", help="Disable Identical Code Folding")
1003 add_old_configure_assignment(
1004     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
1008 option(
1009     "--enable-strip",
1010     when=compile_environment,
1011     help="Enable stripping of libs & executables",
1014 # This should be handled as a `when` once bug 1617793 is fixed.
1017 @depends("--enable-strip", c_compiler, when=compile_environment)
1018 def enable_strip(strip, c_compiler):
1019     if strip and c_compiler.type != "clang-cl":
1020         return True
1023 set_config("ENABLE_STRIP", enable_strip)
1025 option(
1026     "--disable-install-strip",
1027     when=compile_environment,
1028     help="Enable stripping of libs & executables when packaging",
1031 # This should be handled as a `when` once bug 1617793 is fixed.
1034 @depends("--enable-install-strip", c_compiler, when=compile_environment)
1035 def enable_install_strip(strip, c_compiler):
1036     if strip and c_compiler.type != "clang-cl":
1037         return True
1040 set_config("PKG_STRIP", enable_install_strip)
1043 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
1044 def strip(strip, install_strip):
1045     return strip or install_strip
1048 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
1051 @depends("STRIP_FLAGS", profiling, target, when=strip)
1052 def strip_flags(flags, profiling, target):
1053     if flags:
1054         return flags[0].split()
1055     if profiling:
1056         # Only strip debug info and symbols when profiling is enabled, keeping
1057         # local symbols.
1058         if target.kernel == "Darwin":
1059             return ["-S"]
1060         elif target.os == "Android":
1061             # The tooling we use with Android supports detached symbols, and the
1062             # size increase caused by local symbols are too much for mobile. So,
1063             # don't restrict the amount of stripping with a flag.
1064             return
1065         else:
1066             return ["--strip-debug"]
1067     # Otherwise strip everything we can, which happens without flags on non-Darwin.
1068     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
1069     elif target.kernel == "Darwin":
1070         return ["-x", "-S"]
1073 set_config("STRIP_FLAGS", strip_flags)
1076 @depends(js_standalone, target)
1077 def system_zlib_default(js_standalone, target):
1078     return js_standalone and target.kernel not in ("WINNT", "Darwin")
1081 option(
1082     "--with-system-zlib",
1083     nargs="?",
1084     default=system_zlib_default,
1085     help="{Use|Do not use} system libz",
1089 @depends("--with-system-zlib")
1090 def deprecated_system_zlib_path(value):
1091     if len(value) == 1:
1092         die(
1093             "--with-system-zlib=PATH is not supported anymore. Please use "
1094             "--with-system-zlib and set any necessary pkg-config environment variable."
1095         )
1098 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
1100 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1101 add_old_configure_assignment("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1104 # Please do not add configure checks from here on.
1106 # Fallthrough to autoconf-based configure
1107 include("build/moz.configure/old.configure")
1109 # JS Subconfigure.
1110 include("js/sub.configure", when=compile_environment & toolkit)
1113 @depends(check_build_environment, build_project)
1114 @imports("__sandbox__")
1115 @imports("glob")
1116 @imports(_from="os.path", _import="exists")
1117 def config_status_deps(build_env, build_project):
1119     topsrcdir = build_env.topsrcdir
1120     topobjdir = build_env.topobjdir
1122     if not topobjdir.endswith("js/src"):
1123         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
1124     else:
1125         # mozconfig changes may impact js configure.
1126         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
1128     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
1129     if exists(confvars):
1130         extra_deps.append(confvars)
1132     return (
1133         list(__sandbox__._all_paths)
1134         + extra_deps
1135         + [
1136             os.path.join(topsrcdir, "CLOBBER"),
1137             os.path.join(topsrcdir, "configure.in"),
1138             os.path.join(topsrcdir, "js", "src", "configure.in"),
1139             os.path.join(topsrcdir, "nsprpub", "configure"),
1140             os.path.join(topsrcdir, "config", "milestone.txt"),
1141             os.path.join(topsrcdir, "browser", "config", "version.txt"),
1142             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
1143             os.path.join(topsrcdir, "build", "build_virtualenv_packages.txt"),
1144             os.path.join(topsrcdir, "build", "common_virtualenv_packages.txt"),
1145             os.path.join(topsrcdir, "build", "mach_virtualenv_packages.txt"),
1146             os.path.join(topsrcdir, "python", "mozbuild", "mozbuild", "virtualenv.py"),
1147             os.path.join(topsrcdir, "aclocal.m4"),
1148             os.path.join(topsrcdir, "old-configure.in"),
1149             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1150             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1151         ]
1152         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1153     )
1156 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1157 # Please do not add anything after setting config_dep_paths.