Bug 1704668 [wpt PR 28449] - Fix surface layer size for remote frames, a=testonly
[gecko.git] / moz.configure
blobb6d76e4dc6d888a32f03a804ae5e73da1bf5b2af
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(
157     "--enable-rust-debug",
158     default=depends(when="--enable-debug")(lambda: True),
159     help="{Build|Do not build} Rust code with debug assertions turned " "on.",
163 @depends(when="--enable-rust-debug")
164 def debug_rust():
165     return True
168 set_config("MOZ_DEBUG_RUST", debug_rust)
169 set_define("MOZ_DEBUG_RUST", debug_rust)
171 option(env="MOZ_PGO", help="Build with profile guided optimizations")
173 set_config("MOZ_PGO", depends("MOZ_PGO")(lambda x: bool(x)))
176 imply_option("--enable-release", mozilla_official)
177 imply_option("--enable-release", depends_if("MOZ_AUTOMATION")(lambda x: True))
179 option(
180     "--enable-release",
181     default=milestone.is_release_or_beta,
182     help="{Build|Do not build} with more conservative, release "
183     "engineering-oriented options.{ This may slow down builds.|}",
187 @depends("--enable-release")
188 def developer_options(value):
189     if not value:
190         return True
193 add_old_configure_assignment("DEVELOPER_OPTIONS", developer_options)
194 set_config("DEVELOPER_OPTIONS", developer_options)
197 option(
198     env="MOZ_FETCHES_DIR",
199     nargs=1,
200     when="MOZ_AUTOMATION",
201     help="Directory containing fetched artifacts",
205 @depends("MOZ_FETCHES_DIR", when="MOZ_AUTOMATION")
206 def moz_fetches_dir(value):
207     if value:
208         return value[0]
211 @depends(host, milestone.is_nightly, "MOZ_AUTOMATION")
212 def bootstrap_default(host, is_nightly, automation):
213     if automation:
214         return False
215     if host.cpu == "aarch64" and host.os == "OSX" and is_nightly:
216         return True
219 option(
220     "--enable-bootstrap",
221     default=bootstrap_default,
222     help="{Automatically bootstrap or update some toolchains|Disable bootstrap or update of toolchains}",
226 @depends(developer_options, "--enable-bootstrap", moz_fetches_dir)
227 def bootstrap_search_path_order(developer_options, bootstrap, moz_fetches_dir):
228     if moz_fetches_dir:
229         log.debug("Prioritizing MOZ_FETCHES_DIR in toolchain path.")
230         return "prepend"
232     if bootstrap:
233         log.debug(
234             "Prioritizing mozbuild state dir in toolchain paths because "
235             "bootstrap mode is enabled."
236         )
237         return "prepend"
239     if developer_options:
240         log.debug(
241             "Prioritizing mozbuild state dir in toolchain paths because "
242             "you are not building in release mode."
243         )
244         return "prepend"
246     log.debug(
247         "Prioritizing system over mozbuild state dir in "
248         "toolchain paths because you are building in "
249         "release mode."
250     )
251     return "append"
254 toolchains_base_dir = moz_fetches_dir | mozbuild_state_path
257 @dependable
258 @imports("os")
259 @imports(_from="os", _import="environ")
260 def original_path():
261     return environ["PATH"].split(os.pathsep)
264 @template
265 def bootstrap_toolchain_tasks(host_or_target):
266     @depends(host_or_target, when="--enable-bootstrap")
267     @imports("os")
268     @imports(_from="mozbuild.toolchains", _import="toolchain_task_definitions")
269     @imports(_from="__builtin__", _import="Exception")
270     def bootstrap_toolchain_tasks(host_or_target):
271         prefix = {
272             ("x86", "GNU", "Linux"): "linux32",
273             ("x86_64", "GNU", "Linux"): "linux64",
274             ("aarch64", "GNU", "Linux"): "linux64-aarch64",
275             ("x86_64", "OSX", "Darwin"): "macosx64",
276             ("aarch64", "OSX", "Darwin"): "macosx64-aarch64",
277             ("x86_64", "WINNT", "WINNT"): "win64",
278         }.get((host_or_target.cpu, host_or_target.os, host_or_target.kernel))
279         if prefix:
280             try:
281                 return namespace(prefix=prefix, tasks=toolchain_task_definitions())
282             except Exception:
283                 return None
285     return bootstrap_toolchain_tasks
288 host_bootstrap_toolchain_tasks = bootstrap_toolchain_tasks(host)
289 target_bootstrap_toolchain_tasks = bootstrap_toolchain_tasks(target)
292 @template
293 def bootstrap_path(path, **kwargs):
294     when = kwargs.pop("when", None)
295     context = kwargs.pop("context", host)
296     if kwargs:
297         configure_error(
298             "bootstrap_path only takes `when` or `context` as keyword arguments"
299         )
301     path_parts = path.split("/")
302     bootstrap_toolchain_tasks = {
303         host: host_bootstrap_toolchain_tasks,
304         target: target_bootstrap_toolchain_tasks,
305     }[context]
307     @depends(
308         "--enable-bootstrap",
309         toolchains_base_dir,
310         bootstrap_toolchain_tasks,
311         shell,
312         check_build_environment,
313         when=when,
314     )
315     @imports("os")
316     @imports("subprocess")
317     @imports(_from="mozbuild.util", _import="ensureParentDir")
318     @imports(_from="__builtin__", _import="open")
319     @imports(_from="__builtin__", _import="Exception")
320     def bootstrap_path(bootstrap, toolchains_base_dir, tasks, shell, build_env):
321         def try_bootstrap(exists):
322             if not tasks:
323                 return False
324             label = "toolchain-{}-{}".format(
325                 tasks.prefix, path_parts[0].replace("_", "-")
326             )
327             task = tasks.tasks.get(label)
328             if not task:
329                 return False
330             task_index = task.optimization.get("index-search")
331             if not task_index:
332                 return False
333             task_index = task_index[0].split(".")[-1]
334             artifact = task.attributes["toolchain-artifact"]
335             # `mach artifact toolchain` doesn't support authentication for
336             # private artifacts.
337             if not artifact.startswith("public/"):
338                 return False
339             index_file = os.path.join(toolchains_base_dir, "indices", path_parts[0])
340             try:
341                 with open(index_file) as fh:
342                     index = fh.read().strip()
343             except Exception:
344                 index = None
345             if index == task_index and exists:
346                 return True
347             log.info(
348                 "%s bootstrapped toolchain in %s",
349                 "Updating" if exists else "Installing",
350                 os.path.join(toolchains_base_dir, path_parts[0]),
351             )
352             subprocess.run(
353                 [
354                     shell,
355                     os.path.join(build_env.topsrcdir, "mach"),
356                     "--log-no-times",
357                     "artifact",
358                     "toolchain",
359                     "--from-build",
360                     label,
361                 ],
362                 cwd=toolchains_base_dir,
363                 check=True,
364             )
365             ensureParentDir(index_file)
366             with open(index_file, "w") as fh:
367                 fh.write(task_index)
368             return True
370         path = os.path.join(toolchains_base_dir, *path_parts)
371         if bootstrap:
372             try:
373                 if not try_bootstrap(os.path.exists(path)):
374                     # If there aren't toolchain artifacts to use for this build,
375                     # don't return a path.
376                     return None
377             except Exception as e:
378                 log.error("%s", e)
379                 die("If you can't fix the above, retry with --disable-bootstrap.")
380         # We re-test whether the path exists because it may have been created by
381         # try_bootstrap. Automation will not have gone through the bootstrap
382         # process, but we want to return the path if it exists.
383         if os.path.exists(path):
384             return path
386     return bootstrap_path
389 @template
390 def bootstrap_search_path(path, paths=original_path, **kwargs):
391     @depends(
392         bootstrap_path(path, **kwargs),
393         bootstrap_search_path_order,
394         paths,
395         original_path,
396     )
397     def bootstrap_search_path(path, order, paths, original_path):
398         if paths is None:
399             paths = original_path
400         if not path:
401             return paths
402         if order == "prepend":
403             return [path] + paths
404         return paths + [path]
406     return bootstrap_search_path
409 # The execution model of the configure sandbox doesn't allow for
410 # check_prog to use bootstrap_search_path directly because check_prog
411 # comes first, so we use a trick to allow it. No use of check_prog
412 # happening before here won't allow bootstrap.
413 @template
414 def check_prog(*args, **kwargs):
415     kwargs["bootstrap_search_path"] = bootstrap_search_path
416     return check_prog(*args, **kwargs)
419 @depends(target, host)
420 def want_wine(target, host):
421     return target.kernel == "WINNT" and host.kernel != "WINNT"
424 wine = check_prog(
425     "WINE",
426     ["wine64", "wine"],
427     allow_missing=True,
428     when=want_wine,
429     bootstrap="wine/bin",
431 check_prog("WGET", ("wget",), allow_missing=True)
434 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
436 include("build/moz.configure/pkg.configure")
437 # Make this assignment here rather than in pkg.configure to avoid
438 # requiring this file in unit tests.
439 add_old_configure_assignment("PKG_CONFIG", pkg_config)
441 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
442 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
443 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
444 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
445 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
446 # rust.configure is included by js/moz.configure.
448 option("--enable-valgrind", help="Enable Valgrind integration hooks")
450 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
453 @depends("--enable-valgrind", valgrind_h)
454 def check_valgrind(valgrind, valgrind_h):
455     if valgrind:
456         if not valgrind_h:
457             die("--enable-valgrind specified but Valgrind is not installed")
458         return True
461 set_define("MOZ_VALGRIND", check_valgrind)
462 set_config("MOZ_VALGRIND", check_valgrind)
465 @depends(target, host)
466 def is_openbsd(target, host):
467     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
470 option(
471     env="SO_VERSION",
472     nargs=1,
473     default="1.0",
474     when=is_openbsd,
475     help="Shared library version for OpenBSD systems",
479 @depends("SO_VERSION", when=is_openbsd)
480 def so_version(value):
481     return value
484 @template
485 def library_name_info_template(host_or_target):
486     assert host_or_target in {host, target}
487     compiler = {
488         host: host_c_compiler,
489         target: c_compiler,
490     }[host_or_target]
492     @depends(host_or_target, compiler, so_version)
493     def library_name_info_impl(host_or_target, compiler, so_version):
494         if host_or_target.kernel == "WINNT":
495             # There aren't artifacts for mingw builds, so it's OK that the
496             # results are inaccurate in that case.
497             if compiler and compiler.type != "clang-cl":
498                 return namespace(
499                     dll=namespace(prefix="", suffix=".dll"),
500                     lib=namespace(prefix="lib", suffix="a"),
501                     import_lib=namespace(prefix="lib", suffix="a"),
502                     obj=namespace(prefix="", suffix="o"),
503                 )
505             return namespace(
506                 dll=namespace(prefix="", suffix=".dll"),
507                 lib=namespace(prefix="", suffix="lib"),
508                 import_lib=namespace(prefix="", suffix="lib"),
509                 obj=namespace(prefix="", suffix="obj"),
510             )
512         elif host_or_target.kernel == "Darwin":
513             return namespace(
514                 dll=namespace(prefix="lib", suffix=".dylib"),
515                 lib=namespace(prefix="lib", suffix="a"),
516                 import_lib=namespace(prefix=None, suffix=""),
517                 obj=namespace(prefix="", suffix="o"),
518             )
519         elif so_version:
520             so = ".so.%s" % so_version
521         else:
522             so = ".so"
524         return namespace(
525             dll=namespace(prefix="lib", suffix=so),
526             lib=namespace(prefix="lib", suffix="a"),
527             import_lib=namespace(prefix=None, suffix=""),
528             obj=namespace(prefix="", suffix="o"),
529         )
531     return library_name_info_impl
534 host_library_name_info = library_name_info_template(host)
535 library_name_info = library_name_info_template(target)
537 set_config("DLL_PREFIX", library_name_info.dll.prefix)
538 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
539 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
540 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
541 set_config("LIB_PREFIX", library_name_info.lib.prefix)
542 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
543 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
544 # Lots of compilation tests depend on this variable being present.
545 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
546 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
547 set_define(
548     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
550 set_define(
551     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
553 set_config("WASM_OBJ_SUFFIX", "wasm")
555 # Make `profiling` available to this file even when js/moz.configure
556 # doesn't end up included.
557 profiling = dependable(False)
558 # Same for js_standalone
559 js_standalone = dependable(False)
560 # Same for fold_libs
561 fold_libs = dependable(False)
563 include(include_project_configure)
566 @depends("--help")
567 @imports(_from="mozbuild.backend", _import="backends")
568 def build_backends_choices(_):
569     return tuple(backends)
572 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
573 def build_backend(backends):
574     if backends:
575         return tuple("+%s" % b for b in backends)
578 imply_option("--build-backends", build_backend)
581 @depends(
582     "--enable-artifact-builds",
583     "--disable-compile-environment",
584     "--enable-build-backend",
585     "--enable-project",
586     "--enable-application",
587     "--help",
589 @imports("sys")
590 def build_backend_defaults(
591     artifact_builds, compile_environment, requested_backends, project, application, _
593     if application:
594         project = application[0]
595     elif project:
596         project = project[0]
598     if "Tup" in requested_backends:
599         # As a special case, if Tup was requested, do not combine it with any
600         # Make based backend by default.
601         all_backends = []
602     elif artifact_builds:
603         all_backends = ["FasterMake+RecursiveMake"]
604     else:
605         all_backends = ["RecursiveMake", "FasterMake"]
606     # Normally, we'd use target.os == 'WINNT', but a dependency on target
607     # would require target to depend on --help, as well as host and shell,
608     # and this is not a can of worms we can open at the moment.
609     if sys.platform == "win32" and compile_environment and project != "mobile/android":
610         all_backends.append("VisualStudio")
611     return tuple(all_backends) or None
614 option(
615     "--build-backends",
616     nargs="+",
617     default=build_backend_defaults,
618     choices=build_backends_choices,
619     help="Build backends to generate",
623 @depends("--build-backends")
624 def build_backends(backends):
625     return backends
628 set_config("BUILD_BACKENDS", build_backends)
631 @depends(check_build_environment, build_backends)
632 @imports("glob")
633 def check_objdir_backend_reuse(build_env, backends):
634     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
635     # intentionally vague for use with the substring match below.
636     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
637     for backend_file in glob.iglob(
638         os.path.join(build_env.topobjdir, "backend.*Backend")
639     ):
640         for prev, curr in incompatible_backends:
641             if prev in backend_file and any(curr in b for b in backends):
642                 die(
643                     "The active objdir, %s, was previously "
644                     "used to build with a %s based backend. "
645                     "Change objdirs (by setting MOZ_OBJDIR in "
646                     "your mozconfig) or clobber to continue.\n",
647                     build_env.topobjdir,
648                     prev,
649                 )
652 option(
653     "--disable-gtest-in-build",
654     help="Force disable building the gtest libxul during the build.",
655     when="--enable-compile-environment",
658 # Determine whether to build the gtest xul. This happens in automation
659 # on Android and Desktop platforms with the exception of:
660 #  - Windows PGO, where linking xul-gtest.dll takes too long;
661 #  - Android other than x86_64, where gtest is not required.
662 @depends(
663     "MOZ_PGO",
664     build_project,
665     target,
666     "MOZ_AUTOMATION",
667     "--disable-gtest-in-build",
668     enable_tests,
669     when="--enable-compile-environment",
671 def build_gtest(pgo, build_project, target, automation, enabled, enable_tests):
672     if not enable_tests or not enabled:
673         return None
674     if (
675         automation
676         and build_project in ("browser", "comm/mail", "mobile/android")
677         and not (
678             (pgo and target.os == "WINNT")
679             or (target.os == "Android" and target.cpu != "x86_64")
680         )
681     ):
682         return True
685 set_config("LINK_GTEST_DURING_COMPILE", build_gtest)
687 # Localization
688 # ==============================================================
689 option(
690     "--enable-ui-locale",
691     default="en-US",
692     help="Select the user interface locale (default: en-US)",
695 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
697 # clang-plugin location
698 # ==============================================================
699 @depends(host_library_name_info, check_build_environment, when="--enable-clang-plugin")
700 def clang_plugin_path(library_name_info, build_env):
701     topobjdir = build_env.topobjdir
702     if topobjdir.endswith("/js/src"):
703         topobjdir = topobjdir[:-7]
704     return os.path.abspath(
705         os.path.join(
706             topobjdir,
707             "build",
708             "clang-plugin",
709             "%sclang-plugin%s"
710             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
711         )
712     )
715 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
718 # Awk detection
719 # ==============================================================
720 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
722 # Until the AWK variable is not necessary in old-configure
723 @depends(awk)
724 def awk_for_old_configure(value):
725     return value
728 add_old_configure_assignment("AWK", awk_for_old_configure)
731 # Perl detection
732 # ==============================================================
733 perl = check_prog("PERL", ("perl5", "perl"))
735 # Until the PERL variable is not necessary in old-configure
736 @depends(perl)
737 def perl_for_old_configure(value):
738     return value
741 add_old_configure_assignment("PERL", perl_for_old_configure)
744 @template
745 def perl_version_check(min_version):
746     @depends(perl)
747     @checking("for minimum required perl version >= %s" % min_version)
748     def get_perl_version(perl):
749         return Version(
750             check_cmd_output(
751                 perl,
752                 "-e",
753                 "print $]",
754                 onerror=lambda: die("Failed to get perl version."),
755             )
756         )
758     @depends(get_perl_version)
759     def check_perl_version(version):
760         if version < min_version:
761             die("Perl %s or higher is required.", min_version)
763     @depends(perl)
764     @checking("for full perl installation")
765     @imports("subprocess")
766     def has_full_perl_installation(perl):
767         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
768         return ret == 0
770     @depends(has_full_perl_installation)
771     def require_full_perl_installation(has_full_perl_installation):
772         if not has_full_perl_installation:
773             die(
774                 "Cannot find Config.pm or $Config{archlib}. "
775                 "A full perl installation is required."
776             )
779 perl_version_check("5.006")
782 # GNU make detection
783 # ==============================================================
784 option(env="MAKE", nargs=1, help="Path to GNU make")
787 @depends("MAKE", host)
788 def possible_makes(make, host):
789     candidates = []
790     if host.kernel == "WINNT":
791         candidates.append("mingw32-make")
792     if make:
793         candidates.append(make[0])
794     if host.kernel == "WINNT":
795         candidates.extend(("make", "gmake"))
796     else:
797         candidates.extend(("gmake", "make"))
798     return candidates
801 check_prog("GMAKE", possible_makes)
803 # watchman detection
804 # ==============================================================
806 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
809 @depends(host, "WATCHMAN")
810 @checking("for watchman", callback=lambda w: w.path if w else "not found")
811 def watchman(host, prog):
812     # On Windows, `watchman` is only supported on 64-bit hosts.
813     if host.os == "WINNT" and host.cpu != "x86_64":
814         return
816     if not prog:
817         prog = find_program("watchman")
819     if not prog:
820         return
822     # `watchman version` will talk to the Watchman daemon service.
823     # This can hang due to permissions problems. e.g.
824     # https://github.com/facebook/watchman/issues/376. So use
825     # `watchman --version` to prevent a class of failures.
826     out = check_cmd_output(prog, "--version", onerror=lambda: None)
827     if out is None:
828         return
830     return namespace(path=prog, version=Version(out.strip()))
833 @depends_if(watchman)
834 @checking("for watchman version")
835 def watchman_version(w):
836     return w.version
839 set_config("WATCHMAN", watchman.path)
842 @depends_all(hg_version, hg_config, watchman)
843 @checking("for watchman Mercurial integration")
844 @imports("os")
845 def watchman_hg(hg_version, hg_config, watchman):
846     if hg_version < Version("3.8"):
847         return "no (Mercurial 3.8+ required)"
849     ext_enabled = False
850     mode_disabled = False
852     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
853         if k in hg_config and hg_config[k] != "!":
854             ext_enabled = True
856     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
858     if not ext_enabled:
859         return "no (fsmonitor extension not enabled)"
860     if mode_disabled:
861         return "no (fsmonitor.mode=off disables fsmonitor)"
863     return True
866 # Miscellaneous programs
867 # ==============================================================
868 check_prog("XARGS", ("xargs",))
871 @depends(target)
872 def extra_programs(target):
873     if target.kernel == "Darwin":
874         return namespace(
875             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
876             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
877             HFS_TOOL=("hfsplus",),
878         )
879     if target.os == "GNU" and target.kernel == "Linux":
880         return namespace(RPMBUILD=("rpmbuild",))
883 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
884 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
885 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
886 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
889 @depends(target)
890 @imports("os")
891 def makensis_progs(target):
892     if target.kernel != "WINNT":
893         return
895     candidates = [
896         "makensis-3.01",
897         "makensis-3.0b3",
898         "makensis-3.0b1",
899         "makensis",
900     ]
902     # Look for nsis installed by msys environment. But only the 32-bit version.
903     # We use an absolute path and insert as the first entry so it is preferred
904     # over a 64-bit exe that may be in PATH.
905     if "MSYSTEM_PREFIX" in os.environ:
906         prefix = os.path.dirname(os.environ["MSYSTEM_PREFIX"])
907         candidates.insert(0, os.path.join(prefix, "mingw32", "bin", "makensis.exe"))
909     return tuple(candidates)
912 nsis = check_prog("MAKENSISU", makensis_progs, allow_missing=True)
914 # Make sure the version of makensis is up to date.
915 @depends(nsis, wine)
916 @checking("for NSIS version")
917 @imports("re")
918 def nsis_version(nsis, wine):
919     if not nsis:
920         return None
921     nsis_min_version = "3.0b1"
922     onerror = lambda: die("Failed to get nsis version.")
923     if wine and nsis.lower().endswith(".exe"):
924         out = check_cmd_output(wine, nsis, "-version", onerror=onerror)
925     else:
926         out = check_cmd_output(nsis, "-version", onerror=onerror)
928     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
930     if not m:
931         raise FatalCheckError("Unknown version of makensis")
932     ver = Version(m.group(0))
934     # Versions comparisons don't quite work well with beta versions, so ensure
935     # it works for the non-beta version.
936     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
937         raise FatalCheckError(
938             "To build the installer you must have NSIS"
939             " version %s or greater in your path" % nsis_min_version
940         )
942     return ver
945 # And that makensis is 32-bit (but only on Windows).
946 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
947 @checking("for 32-bit NSIS")
948 def nsis_binary_type(nsis):
949     bin_type = windows_binary_type(nsis)
950     if bin_type != "win32":
951         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
953     return "yes"
956 # And any flags we have to give to makensis
957 @depends(host)
958 def nsis_flags(host):
959     if host.kernel != "WINNT":
960         return "-nocd"
961     return ""
964 set_config("MAKENSISU_FLAGS", nsis_flags)
966 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
967 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
970 @depends(host_c_compiler, c_compiler, bindgen_config_paths)
971 def llvm_objdump(host_c_compiler, c_compiler, bindgen_config_paths):
972     clang = None
973     for compiler in (host_c_compiler, c_compiler):
974         if compiler and compiler.type == "clang":
975             clang = compiler.compiler
976             break
977         elif compiler and compiler.type == "clang-cl":
978             clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
979             break
981     if not clang and bindgen_config_paths:
982         clang = bindgen_config_paths.clang_path
983     llvm_objdump = "llvm-objdump"
984     if clang:
985         out = check_cmd_output(
986             clang, "--print-prog-name=llvm-objdump", onerror=lambda: None
987         )
988         if out:
989             llvm_objdump = out.rstrip()
990     return (llvm_objdump,)
993 llvm_objdump = check_prog(
994     "LLVM_OBJDUMP",
995     llvm_objdump,
996     what="llvm-objdump",
997     when="--enable-compile-environment",
998     paths=clang_search_path,
1001 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
1004 option("--enable-dtrace", help="Build with dtrace support")
1006 dtrace = check_header(
1007     "sys/sdt.h",
1008     when="--enable-dtrace",
1009     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
1012 set_config("HAVE_DTRACE", True, when=dtrace)
1013 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
1014 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
1017 option("--disable-icf", help="Disable Identical Code Folding")
1019 add_old_configure_assignment(
1020     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
1024 option(
1025     "--enable-strip",
1026     when=compile_environment,
1027     help="Enable stripping of libs & executables",
1030 # This should be handled as a `when` once bug 1617793 is fixed.
1031 @depends("--enable-strip", c_compiler, when=compile_environment)
1032 def enable_strip(strip, c_compiler):
1033     if strip and c_compiler.type != "clang-cl":
1034         return True
1037 set_config("ENABLE_STRIP", enable_strip)
1039 option(
1040     "--disable-install-strip",
1041     when=compile_environment,
1042     help="Enable stripping of libs & executables when packaging",
1045 # This should be handled as a `when` once bug 1617793 is fixed.
1046 @depends("--enable-install-strip", c_compiler, when=compile_environment)
1047 def enable_install_strip(strip, c_compiler):
1048     if strip and c_compiler.type != "clang-cl":
1049         return True
1052 set_config("PKG_STRIP", enable_install_strip)
1055 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
1056 def strip(strip, install_strip):
1057     return strip or install_strip
1060 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
1063 @depends("STRIP_FLAGS", profiling, target, when=strip)
1064 def strip_flags(flags, profiling, target):
1065     if flags:
1066         return flags[0].split()
1067     if profiling:
1068         # Only strip debug info and symbols when profiling is enabled, keeping
1069         # local symbols.
1070         if target.kernel == "Darwin":
1071             return ["-S"]
1072         elif target.os == "Android":
1073             # The tooling we use with Android supports detached symbols, and the
1074             # size increase caused by local symbols are too much for mobile. So,
1075             # don't restrict the amount of stripping with a flag.
1076             return
1077         else:
1078             return ["--strip-debug"]
1079     # Otherwise strip everything we can, which happens without flags on non-Darwin.
1080     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
1081     elif target.kernel == "Darwin":
1082         return ["-x", "-S"]
1085 set_config("STRIP_FLAGS", strip_flags)
1088 @depends(js_standalone, target)
1089 def system_zlib_default(js_standalone, target):
1090     return js_standalone and target.kernel != "WINNT"
1093 option(
1094     "--with-system-zlib",
1095     nargs="?",
1096     default=system_zlib_default,
1097     help="{Use|Do not use} system libz",
1101 @depends("--with-system-zlib")
1102 def deprecated_system_zlib_path(value):
1103     if len(value) == 1:
1104         die(
1105             "--with-system-zlib=PATH is not supported anymore. Please use "
1106             "--with-system-zlib and set any necessary pkg-config environment variable."
1107         )
1110 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
1112 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1113 add_old_configure_assignment("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1116 # Please do not add configure checks from here on.
1118 # Fallthrough to autoconf-based configure
1119 include("build/moz.configure/old.configure")
1121 # JS Subconfigure.
1122 include("js/sub.configure", when=compile_environment & toolkit)
1125 @depends(check_build_environment, build_project)
1126 @imports("__sandbox__")
1127 @imports("glob")
1128 @imports(_from="os.path", _import="exists")
1129 def config_status_deps(build_env, build_project):
1131     topsrcdir = build_env.topsrcdir
1132     topobjdir = build_env.topobjdir
1134     if not topobjdir.endswith("js/src"):
1135         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
1136     else:
1137         # mozconfig changes may impact js configure.
1138         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
1140     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
1141     if exists(confvars):
1142         extra_deps.append(confvars)
1144     return (
1145         list(__sandbox__._all_paths)
1146         + extra_deps
1147         + [
1148             os.path.join(topsrcdir, "CLOBBER"),
1149             os.path.join(topsrcdir, "configure.in"),
1150             os.path.join(topsrcdir, "js", "src", "configure.in"),
1151             os.path.join(topsrcdir, "nsprpub", "configure"),
1152             os.path.join(topsrcdir, "config", "milestone.txt"),
1153             os.path.join(topsrcdir, "browser", "config", "version.txt"),
1154             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
1155             os.path.join(topsrcdir, "build", "build_virtualenv_packages.txt"),
1156             os.path.join(topsrcdir, "build", "common_virtualenv_packages.txt"),
1157             os.path.join(topsrcdir, "build", "mach_virtualenv_packages.txt"),
1158             os.path.join(topsrcdir, "python", "mozbuild", "mozbuild", "virtualenv.py"),
1159             os.path.join(topsrcdir, "testing", "mozbase", "packages.txt"),
1160             os.path.join(topsrcdir, "aclocal.m4"),
1161             os.path.join(topsrcdir, "old-configure.in"),
1162             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1163             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1164         ]
1165         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1166     )
1169 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1170 # Please do not add anything after setting config_dep_paths.