Bug 1725074 - Allow attribs with the same names as uniforms. r=gfx-reviewers,lsalzman
[gecko.git] / moz.configure
blob042853133953a2040b4bdc06e326200ffa850b6e
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             os.makedirs(toolchains_base_dir, exist_ok=True)
345             subprocess.run(
346                 [
347                     shell,
348                     os.path.join(build_env.topsrcdir, "mach"),
349                     "--log-no-times",
350                     "artifact",
351                     "toolchain",
352                     "--from-build",
353                     label,
354                 ],
355                 cwd=toolchains_base_dir,
356                 check=True,
357             )
358             ensureParentDir(index_file)
359             with open(index_file, "w") as fh:
360                 fh.write(task_index)
361             return True
363         path = os.path.join(toolchains_base_dir, *path_parts)
364         if bootstrap:
365             try:
366                 if not try_bootstrap(os.path.exists(path)):
367                     # If there aren't toolchain artifacts to use for this build,
368                     # don't return a path.
369                     return None
370             except Exception as e:
371                 log.error("%s", e)
372                 die("If you can't fix the above, retry with --disable-bootstrap.")
373         # We re-test whether the path exists because it may have been created by
374         # try_bootstrap. Automation will not have gone through the bootstrap
375         # process, but we want to return the path if it exists.
376         if os.path.exists(path):
377             return path
379     return bootstrap_path
382 @template
383 def bootstrap_search_path(path, paths=original_path, **kwargs):
384     @depends(
385         bootstrap_path(path, **kwargs),
386         bootstrap_search_path_order,
387         paths,
388         original_path,
389     )
390     def bootstrap_search_path(path, order, paths, original_path):
391         if paths is None:
392             paths = original_path
393         if not path:
394             return paths
395         if order == "prepend":
396             return [path] + paths
397         return paths + [path]
399     return bootstrap_search_path
402 # The execution model of the configure sandbox doesn't allow for
403 # check_prog to use bootstrap_search_path directly because check_prog
404 # comes first, so we use a trick to allow it. Uses of check_prog
405 # happening before here won't allow bootstrap.
406 @template
407 def check_prog(*args, **kwargs):
408     kwargs["bootstrap_search_path"] = bootstrap_search_path
409     return check_prog(*args, **kwargs)
412 check_prog("WGET", ("wget",), allow_missing=True)
415 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
417 include("build/moz.configure/pkg.configure")
418 # Make this assignment here rather than in pkg.configure to avoid
419 # requiring this file in unit tests.
420 add_old_configure_assignment("PKG_CONFIG", pkg_config)
422 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
423 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
424 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
425 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
426 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
427 # rust.configure is included by js/moz.configure.
429 option("--enable-valgrind", help="Enable Valgrind integration hooks")
431 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
434 @depends("--enable-valgrind", valgrind_h)
435 def check_valgrind(valgrind, valgrind_h):
436     if valgrind:
437         if not valgrind_h:
438             die("--enable-valgrind specified but Valgrind is not installed")
439         return True
442 set_define("MOZ_VALGRIND", check_valgrind)
443 set_config("MOZ_VALGRIND", check_valgrind)
446 @depends(target, host)
447 def is_openbsd(target, host):
448     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
451 option(
452     env="SO_VERSION",
453     nargs=1,
454     default="1.0",
455     when=is_openbsd,
456     help="Shared library version for OpenBSD systems",
460 @depends("SO_VERSION", when=is_openbsd)
461 def so_version(value):
462     return value
465 @template
466 def library_name_info_template(host_or_target):
467     assert host_or_target in {host, target}
468     compiler = {
469         host: host_c_compiler,
470         target: c_compiler,
471     }[host_or_target]
473     @depends(host_or_target, compiler, so_version)
474     def library_name_info_impl(host_or_target, compiler, so_version):
475         if host_or_target.kernel == "WINNT":
476             # There aren't artifacts for mingw builds, so it's OK that the
477             # results are inaccurate in that case.
478             if compiler and compiler.type != "clang-cl":
479                 return namespace(
480                     dll=namespace(prefix="", suffix=".dll"),
481                     lib=namespace(prefix="lib", suffix="a"),
482                     import_lib=namespace(prefix="lib", suffix="a"),
483                     obj=namespace(prefix="", suffix="o"),
484                 )
486             return namespace(
487                 dll=namespace(prefix="", suffix=".dll"),
488                 lib=namespace(prefix="", suffix="lib"),
489                 import_lib=namespace(prefix="", suffix="lib"),
490                 obj=namespace(prefix="", suffix="obj"),
491             )
493         elif host_or_target.kernel == "Darwin":
494             return namespace(
495                 dll=namespace(prefix="lib", suffix=".dylib"),
496                 lib=namespace(prefix="lib", suffix="a"),
497                 import_lib=namespace(prefix=None, suffix=""),
498                 obj=namespace(prefix="", suffix="o"),
499             )
500         elif so_version:
501             so = ".so.%s" % so_version
502         else:
503             so = ".so"
505         return namespace(
506             dll=namespace(prefix="lib", suffix=so),
507             lib=namespace(prefix="lib", suffix="a"),
508             import_lib=namespace(prefix=None, suffix=""),
509             obj=namespace(prefix="", suffix="o"),
510         )
512     return library_name_info_impl
515 host_library_name_info = library_name_info_template(host)
516 library_name_info = library_name_info_template(target)
518 set_config("DLL_PREFIX", library_name_info.dll.prefix)
519 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
520 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
521 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
522 set_config("LIB_PREFIX", library_name_info.lib.prefix)
523 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
524 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
525 # Lots of compilation tests depend on this variable being present.
526 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
527 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
528 set_define(
529     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
531 set_define(
532     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
534 set_config("WASM_OBJ_SUFFIX", "wasm")
536 # Make `profiling` available to this file even when js/moz.configure
537 # doesn't end up included.
538 profiling = dependable(False)
539 # Same for js_standalone
540 js_standalone = dependable(False)
541 # Same for fold_libs
542 fold_libs = dependable(False)
544 include(include_project_configure)
547 @depends("--help")
548 @imports(_from="mozbuild.backend", _import="backends")
549 def build_backends_choices(_):
550     return tuple(backends)
553 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
554 def build_backend(backends):
555     if backends:
556         return tuple("+%s" % b for b in backends)
559 imply_option("--build-backends", build_backend)
562 @depends(
563     "--enable-artifact-builds",
564     "--disable-compile-environment",
565     "--enable-build-backend",
566     "--enable-project",
567     "--enable-application",
568     "--help",
570 @imports("sys")
571 def build_backend_defaults(
572     artifact_builds, compile_environment, requested_backends, project, application, _
574     if application:
575         project = application[0]
576     elif project:
577         project = project[0]
579     if "Tup" in requested_backends:
580         # As a special case, if Tup was requested, do not combine it with any
581         # Make based backend by default.
582         all_backends = []
583     elif artifact_builds:
584         all_backends = ["FasterMake+RecursiveMake"]
585     else:
586         all_backends = ["RecursiveMake", "FasterMake"]
587     # Normally, we'd use target.os == 'WINNT', but a dependency on target
588     # would require target to depend on --help, as well as host and shell,
589     # and this is not a can of worms we can open at the moment.
590     if (
591         sys.platform == "win32"
592         and compile_environment
593         and project not in ("mobile/android", "memory", "tools/update-programs")
594     ):
595         all_backends.append("VisualStudio")
596     return tuple(all_backends) or None
599 option(
600     "--build-backends",
601     nargs="+",
602     default=build_backend_defaults,
603     choices=build_backends_choices,
604     help="Build backends to generate",
608 @depends("--build-backends")
609 def build_backends(backends):
610     return backends
613 set_config("BUILD_BACKENDS", build_backends)
616 @depends(check_build_environment, build_backends)
617 @imports("glob")
618 def check_objdir_backend_reuse(build_env, backends):
619     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
620     # intentionally vague for use with the substring match below.
621     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
622     for backend_file in glob.iglob(
623         os.path.join(build_env.topobjdir, "backend.*Backend")
624     ):
625         for prev, curr in incompatible_backends:
626             if prev in backend_file and any(curr in b for b in backends):
627                 die(
628                     "The active objdir, %s, was previously "
629                     "used to build with a %s based backend. "
630                     "Change objdirs (by setting MOZ_OBJDIR in "
631                     "your mozconfig) or clobber to continue.\n",
632                     build_env.topobjdir,
633                     prev,
634                 )
637 # Determine whether to build the gtest xul. This happens in automation
638 # on Android and Desktop platforms with the exception of:
639 #  - Windows PGO, where linking xul-gtest.dll takes too long;
640 #  - Android other than x86_64, where gtest is not required.
641 @depends(
642     build_project,
643     target,
644     "MOZ_AUTOMATION",
645     enable_tests,
646     when="--enable-compile-environment",
648 def build_gtest(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 (target.os == "Android" and target.cpu != "x86_64")
654     )
657 option(
658     "--enable-gtest-in-build",
659     default=build_gtest,
660     help="{Enable|Force disable} building the gtest libxul during the build.",
661     when="--enable-compile-environment",
664 set_config("LINK_GTEST_DURING_COMPILE", True, when="--enable-gtest-in-build")
666 # Localization
667 # ==============================================================
668 option(
669     "--enable-ui-locale",
670     default="en-US",
671     help="Select the user interface locale (default: en-US)",
674 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
676 option(
677     "--enable-icu4x",
678     help="An experiment to use ICU4X instead of ICU4C. See intl/ICU4X.md",
681 set_config("MOZ_ICU4X", True, when="--enable-icu4x")
683 # clang-plugin location
684 # ==============================================================
687 @depends(host_library_name_info, check_build_environment, when="--enable-clang-plugin")
688 def clang_plugin_path(library_name_info, build_env):
689     topobjdir = build_env.topobjdir
690     if topobjdir.endswith("/js/src"):
691         topobjdir = topobjdir[:-7]
692     return os.path.abspath(
693         os.path.join(
694             topobjdir,
695             "build",
696             "clang-plugin",
697             "%sclang-plugin%s"
698             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
699         )
700     )
703 set_config("CLANG_PLUGIN", clang_plugin_path)
704 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
707 # Awk detection
708 # ==============================================================
709 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
711 # Until the AWK variable is not necessary in old-configure
714 @depends(awk)
715 def awk_for_old_configure(value):
716     return value
719 add_old_configure_assignment("AWK", awk_for_old_configure)
722 # Perl detection
723 # ==============================================================
724 perl = check_prog("PERL", ("perl5", "perl"))
726 # Until the PERL variable is not necessary in old-configure
729 @depends(perl)
730 def perl_for_old_configure(value):
731     return value
734 add_old_configure_assignment("PERL", perl_for_old_configure)
737 @template
738 def perl_version_check(min_version):
739     @depends(perl)
740     @checking("for minimum required perl version >= %s" % min_version)
741     def get_perl_version(perl):
742         return Version(
743             check_cmd_output(
744                 perl,
745                 "-e",
746                 "print $]",
747                 onerror=lambda: die("Failed to get perl version."),
748             )
749         )
751     @depends(get_perl_version)
752     def check_perl_version(version):
753         if version < min_version:
754             die("Perl %s or higher is required.", min_version)
756     @depends(perl)
757     @checking("for full perl installation")
758     @imports("subprocess")
759     def has_full_perl_installation(perl):
760         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
761         return ret == 0
763     @depends(has_full_perl_installation)
764     def require_full_perl_installation(has_full_perl_installation):
765         if not has_full_perl_installation:
766             die(
767                 "Cannot find Config.pm or $Config{archlib}. "
768                 "A full perl installation is required."
769             )
772 perl_version_check("5.006")
775 # GNU make detection
776 # ==============================================================
777 option(env="MAKE", nargs=1, help="Path to GNU make")
780 @depends("MAKE", host)
781 def possible_makes(make, host):
782     candidates = []
783     if host.kernel == "WINNT":
784         candidates.append("mingw32-make")
785     if make:
786         candidates.append(make[0])
787     if host.kernel == "WINNT":
788         candidates.extend(("mozmake", "make", "gmake"))
789     else:
790         candidates.extend(("gmake", "make"))
791     return candidates
794 check_prog("GMAKE", possible_makes, bootstrap="mozmake")
796 # watchman detection
797 # ==============================================================
799 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
802 @depends(host, "WATCHMAN")
803 @checking("for watchman", callback=lambda w: w.path if w else "not found")
804 def watchman(host, prog):
805     # On Windows, `watchman` is only supported on 64-bit hosts.
806     if host.os == "WINNT" and host.cpu != "x86_64":
807         return
809     if not prog:
810         prog = find_program("watchman")
812     if not prog:
813         return
815     # `watchman version` will talk to the Watchman daemon service.
816     # This can hang due to permissions problems. e.g.
817     # https://github.com/facebook/watchman/issues/376. So use
818     # `watchman --version` to prevent a class of failures.
819     out = check_cmd_output(prog, "--version", onerror=lambda: None)
820     if out is None:
821         return
823     return namespace(path=prog, version=Version(out.strip()))
826 @depends_if(watchman)
827 @checking("for watchman version")
828 def watchman_version(w):
829     return w.version
832 set_config("WATCHMAN", watchman.path)
835 @depends_all(hg_version, hg_config, watchman)
836 @checking("for watchman Mercurial integration")
837 @imports("os")
838 def watchman_hg(hg_version, hg_config, watchman):
839     if hg_version < Version("3.8"):
840         return "no (Mercurial 3.8+ required)"
842     ext_enabled = False
843     mode_disabled = False
845     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
846         if k in hg_config and hg_config[k] != "!":
847             ext_enabled = True
849     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
851     if not ext_enabled:
852         return "no (fsmonitor extension not enabled)"
853     if mode_disabled:
854         return "no (fsmonitor.mode=off disables fsmonitor)"
856     return True
859 # Miscellaneous programs
860 # ==============================================================
861 check_prog("XARGS", ("xargs",))
864 @depends(target)
865 def extra_programs(target):
866     if target.kernel == "Darwin":
867         return namespace(
868             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
869             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
870             HFS_TOOL=("hfsplus",),
871         )
872     if target.os == "GNU" and target.kernel == "Linux":
873         return namespace(RPMBUILD=("rpmbuild",))
876 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
877 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
878 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
879 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
882 nsis = check_prog(
883     "MAKENSISU",
884     ("makensis",),
885     bootstrap="nsis/bin",
886     allow_missing=True,
887     when=target_is_windows,
890 # Make sure the version of makensis is up to date.
893 @depends_if(nsis)
894 @checking("for NSIS version")
895 @imports("re")
896 def nsis_version(nsis):
897     nsis_min_version = "3.0b1"
899     def onerror():
900         return die("Failed to get nsis version.")
902     out = check_cmd_output(nsis, "-version", onerror=onerror)
904     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
906     if not m:
907         raise FatalCheckError("Unknown version of makensis")
908     ver = Version(m.group(0))
910     # Versions comparisons don't quite work well with beta versions, so ensure
911     # it works for the non-beta version.
912     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
913         raise FatalCheckError(
914             "To build the installer you must have NSIS"
915             " version %s or greater in your path" % nsis_min_version
916         )
918     return ver
921 # And that makensis is 32-bit (but only on Windows).
922 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
923 @checking("for 32-bit NSIS")
924 def nsis_binary_type(nsis):
925     bin_type = windows_binary_type(nsis)
926     if bin_type != "win32":
927         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
929     return "yes"
932 # And any flags we have to give to makensis
933 @depends(host)
934 def nsis_flags(host):
935     if host.kernel != "WINNT":
936         return "-nocd"
937     return ""
940 set_config("MAKENSISU_FLAGS", nsis_flags)
942 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
943 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
946 @template
947 def llvm_tool(name):
948     @depends(host_c_compiler, c_compiler, bindgen_config_paths)
949     def llvm_tool(host_c_compiler, c_compiler, bindgen_config_paths):
950         clang = None
951         for compiler in (host_c_compiler, c_compiler):
952             if compiler and compiler.type == "clang":
953                 clang = compiler.compiler
954                 break
955             elif compiler and compiler.type == "clang-cl":
956                 clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
957                 break
959         if not clang and bindgen_config_paths:
960             clang = bindgen_config_paths.clang_path
961         tool = name
962         if clang:
963             out = check_cmd_output(
964                 clang, "--print-prog-name=%s" % tool, onerror=lambda: None
965             )
966             if out:
967                 tool = out.rstrip()
968         return (tool,)
970     return llvm_tool
973 llvm_objdump = check_prog(
974     "LLVM_OBJDUMP",
975     llvm_tool("llvm-objdump"),
976     what="llvm-objdump",
977     when="--enable-compile-environment",
978     paths=clang_search_path,
981 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
984 @depends(llvm_tool("llvm-readelf"), toolchain_prefix)
985 def readelf(llvm_readelf, toolchain_prefix):
986     commands = [llvm_readelf[0], "readelf"]
987     for prefix in toolchain_prefix or ():
988         commands.insert(1, "%sreadelf" % prefix)
989     return tuple(commands)
992 def validate_readelf(path):
993     # llvm-readelf from llvm < 8 doesn't support the GNU binutils-compatible `-d`
994     # flag. We could try running `$path -d $some_binary` but we might be cross
995     # compiling and not have a binary at hand to run that against. `$path -d` alone
996     # would fail whether the flag is supported or not. So we resort to look for the
997     # option in the `--help` output, which fortunately, s compatible between
998     # llvm-readelf and readelf.
999     retcode, stdout, stderr = get_cmd_output(path, "--help")
1000     return retcode == 0 and any(l.startswith("  -d ") for l in stdout.splitlines())
1003 @depends("--enable-compile-environment", target, host)
1004 def readelf_when(compile_env, target, host):
1005     return compile_env and any(
1006         x.kernel not in ("Darwin", "WINNT") for x in (target, host)
1007     )
1010 check_prog(
1011     "READELF",
1012     readelf,
1013     what="readelf",
1014     when=readelf_when,
1015     paths=clang_search_path,
1016     validate=validate_readelf,
1019 option("--enable-dtrace", help="Build with dtrace support")
1021 dtrace = check_header(
1022     "sys/sdt.h",
1023     when="--enable-dtrace",
1024     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
1027 set_config("HAVE_DTRACE", True, when=dtrace)
1028 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
1029 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
1032 option("--disable-icf", help="Disable Identical Code Folding")
1034 add_old_configure_assignment(
1035     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
1039 option(
1040     "--enable-strip",
1041     when=compile_environment,
1042     help="Enable stripping of libs & executables",
1045 # This should be handled as a `when` once bug 1617793 is fixed.
1048 @depends("--enable-strip", c_compiler, when=compile_environment)
1049 def enable_strip(strip, c_compiler):
1050     if strip and c_compiler.type != "clang-cl":
1051         return True
1054 set_config("ENABLE_STRIP", enable_strip)
1056 option(
1057     "--disable-install-strip",
1058     when=compile_environment,
1059     help="Enable stripping of libs & executables when packaging",
1062 # This should be handled as a `when` once bug 1617793 is fixed.
1065 @depends("--enable-install-strip", c_compiler, when=compile_environment)
1066 def enable_install_strip(strip, c_compiler):
1067     if strip and c_compiler.type != "clang-cl":
1068         return True
1071 set_config("PKG_STRIP", enable_install_strip)
1074 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
1075 def strip(strip, install_strip):
1076     return strip or install_strip
1079 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
1082 @depends("STRIP_FLAGS", profiling, target, when=strip)
1083 def strip_flags(flags, profiling, target):
1084     if flags:
1085         return flags[0].split()
1086     if profiling:
1087         # Only strip debug info and symbols when profiling is enabled, keeping
1088         # local symbols.
1089         if target.kernel == "Darwin":
1090             return ["-S"]
1091         elif target.os == "Android":
1092             # The tooling we use with Android supports detached symbols, and the
1093             # size increase caused by local symbols are too much for mobile. So,
1094             # don't restrict the amount of stripping with a flag.
1095             return
1096         else:
1097             return ["--strip-debug"]
1098     # Otherwise strip everything we can, which happens without flags on non-Darwin.
1099     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
1100     elif target.kernel == "Darwin":
1101         return ["-x", "-S"]
1104 set_config("STRIP_FLAGS", strip_flags)
1107 @depends(js_standalone, target)
1108 def system_zlib_default(js_standalone, target):
1109     return js_standalone and target.kernel not in ("WINNT", "Darwin")
1112 option(
1113     "--with-system-zlib",
1114     nargs="?",
1115     default=system_zlib_default,
1116     help="{Use|Do not use} system libz",
1120 @depends("--with-system-zlib")
1121 def deprecated_system_zlib_path(value):
1122     if len(value) == 1:
1123         die(
1124             "--with-system-zlib=PATH is not supported anymore. Please use "
1125             "--with-system-zlib and set any necessary pkg-config environment variable."
1126         )
1129 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
1131 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1132 add_old_configure_assignment("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1135 # Please do not add configure checks from here on.
1137 # Fallthrough to autoconf-based configure
1138 include("build/moz.configure/old.configure")
1140 # JS Subconfigure.
1141 include("js/sub.configure", when=compile_environment & toolkit)
1144 @depends(check_build_environment, build_project)
1145 @imports("__sandbox__")
1146 @imports("glob")
1147 @imports(_from="os.path", _import="exists")
1148 def config_status_deps(build_env, build_project):
1150     topsrcdir = build_env.topsrcdir
1151     topobjdir = build_env.topobjdir
1153     if not topobjdir.endswith("js/src"):
1154         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
1155     else:
1156         # mozconfig changes may impact js configure.
1157         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
1159     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
1160     if exists(confvars):
1161         extra_deps.append(confvars)
1163     return (
1164         list(__sandbox__._all_paths)
1165         + extra_deps
1166         + [
1167             os.path.join(topsrcdir, "CLOBBER"),
1168             os.path.join(topsrcdir, "configure.in"),
1169             os.path.join(topsrcdir, "js", "src", "configure.in"),
1170             os.path.join(topsrcdir, "nsprpub", "configure"),
1171             os.path.join(topsrcdir, "config", "milestone.txt"),
1172             os.path.join(topsrcdir, "browser", "config", "version.txt"),
1173             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
1174             os.path.join(topsrcdir, "build", "build_virtualenv_packages.txt"),
1175             os.path.join(topsrcdir, "build", "common_virtualenv_packages.txt"),
1176             os.path.join(topsrcdir, "build", "mach_virtualenv_packages.txt"),
1177             os.path.join(topsrcdir, "python", "mach", "mach", "site.py"),
1178             os.path.join(topsrcdir, "aclocal.m4"),
1179             os.path.join(topsrcdir, "old-configure.in"),
1180             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1181             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1182         ]
1183         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1184     )
1187 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1188 # Please do not add anything after setting config_dep_paths.