Bug 1687064 [wpt PR 27207] - Update wpt metadata, a=testonly
[gecko.git] / moz.configure
blob6c51112178f1b2ff537f250138778186ac033c18
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(developer_options, moz_fetches_dir)
212 def bootstrap_search_path_order(developer_options, moz_fetches_dir):
213     if moz_fetches_dir:
214         log.debug("Prioritizing MOZ_FETCHES_DIR in toolchain path.")
215         return "prepend"
217     if developer_options:
218         log.debug(
219             "Prioritizing mozbuild state dir in toolchain paths because "
220             "you are not building in release mode."
221         )
222         return "prepend"
224     log.debug(
225         "Prioritizing system over mozbuild state dir in "
226         "toolchain paths because you are building in "
227         "release mode."
228     )
229     return "append"
232 toolchains_base_dir = moz_fetches_dir | mozbuild_state_path
235 @dependable
236 @imports("os")
237 @imports(_from="os", _import="environ")
238 def original_path():
239     return environ["PATH"].split(os.pathsep)
242 option(
243     "--enable-bootstrap",
244     when=developer_options,
245     help="Automatically update/bootstrap some toolchains when they are present but out of date",
249 @depends("--enable-bootstrap", when=developer_options)
250 def bootstrap(value):
251     if value:
252         return True
255 @depends(host, when=bootstrap)
256 @imports("os")
257 @imports(_from="mozbuild.toolchains", _import="toolchain_task_definitions")
258 @imports(_from="__builtin__", _import="Exception")
259 def bootstrap_toolchain_tasks(host):
260     prefix = {
261         ("x86_64", "GNU", "Linux"): "linux64",
262         ("x86_64", "OSX", "Darwin"): "macosx64",
263         ("x86_64", "WINNT", "WINNT"): "win64",
264     }.get((host.cpu, host.os, host.kernel))
265     if prefix:
266         try:
267             return namespace(prefix=prefix, tasks=toolchain_task_definitions())
268         except Exception:
269             return None
272 @template
273 def bootstrap_search_path(*path_parts, **kwargs):
274     when = kwargs.pop("when", None)
275     if kwargs:
276         configure_error("bootstrap_search_path only takes `when` as keyword argument")
278     @depends(
279         bootstrap,
280         bootstrap_search_path_order,
281         original_path,
282         toolchains_base_dir,
283         bootstrap_toolchain_tasks,
284         shell,
285         check_build_environment,
286         when=when,
287     )
288     @imports("os")
289     @imports("subprocess")
290     @imports(_from="mozbuild.util", _import="ensureParentDir")
291     @imports(_from="__builtin__", _import="open")
292     @imports(_from="__builtin__", _import="Exception")
293     def bootstrap_search_path(
294         bootstrap, order, original_path, toolchains_base_dir, tasks, shell, build_env
295     ):
296         def try_bootstrap():
297             label = "toolchain-{}-{}".format(
298                 tasks.prefix, path_parts[0].replace("_", "-")
299             )
300             task = tasks.tasks.get(label)
301             if not task:
302                 return
303             task_index = task.optimization.get("index-search")
304             if not task_index:
305                 return
306             task_index = task_index[0].split(".")[-1]
307             artifact = task.attributes["toolchain-artifact"]
308             # `mach artifact toolchain` doesn't support authentication for
309             # private artifacts.
310             if not artifact.startswith("public/"):
311                 return
312             index_file = os.path.join(toolchains_base_dir, "indices", path_parts[0])
313             try:
314                 with open(index_file) as fh:
315                     index = fh.read().strip()
316             except Exception:
317                 index = None
318             if index == task_index:
319                 return
320             log.info(
321                 "Updating bootstrapped toolchain in %s",
322                 os.path.join(toolchains_base_dir, path_parts[0]),
323             )
324             subprocess.run(
325                 [
326                     shell,
327                     os.path.join(build_env.topsrcdir, "mach"),
328                     "--log-no-times",
329                     "artifact",
330                     "toolchain",
331                     "--from-build",
332                     label,
333                 ],
334                 cwd=toolchains_base_dir,
335                 check=True,
336             )
337             ensureParentDir(index_file)
338             with open(index_file, "w") as fh:
339                 fh.write(task_index)
341         path = os.path.join(toolchains_base_dir, *path_parts)
342         # Only bootstrap toolchains that have been bootstrapped at least once.
343         if bootstrap and tasks and os.path.exists(path):
344             try:
345                 try_bootstrap()
346             except Exception as e:
347                 log.error("%s", e)
348                 die("If you can't fix the above, retry with --disable-bootstrap.")
349         if order == "prepend":
350             return [path] + original_path
351         return original_path + [path]
353     return bootstrap_search_path
356 @depends(target, host)
357 def want_wine(target, host):
358     return target.kernel == "WINNT" and host.kernel != "WINNT"
361 wine = check_prog(
362     "WINE",
363     ["wine64", "wine"],
364     allow_missing=True,
365     when=want_wine,
366     paths=bootstrap_search_path("wine", "bin", when=want_wine),
368 check_prog("WGET", ("wget",), allow_missing=True)
371 include("build/moz.configure/toolchain.configure", when="--enable-compile-environment")
373 include("build/moz.configure/pkg.configure")
374 # Make this assignment here rather than in pkg.configure to avoid
375 # requiring this file in unit tests.
376 add_old_configure_assignment("PKG_CONFIG", pkg_config)
378 include("build/moz.configure/memory.configure", when="--enable-compile-environment")
379 include("build/moz.configure/headers.configure", when="--enable-compile-environment")
380 include("build/moz.configure/warnings.configure", when="--enable-compile-environment")
381 include("build/moz.configure/flags.configure", when="--enable-compile-environment")
382 include("build/moz.configure/lto-pgo.configure", when="--enable-compile-environment")
383 # rust.configure is included by js/moz.configure.
385 option("--enable-valgrind", help="Enable Valgrind integration hooks")
387 valgrind_h = check_header("valgrind/valgrind.h", when="--enable-valgrind")
390 @depends("--enable-valgrind", valgrind_h)
391 def check_valgrind(valgrind, valgrind_h):
392     if valgrind:
393         if not valgrind_h:
394             die("--enable-valgrind specified but Valgrind is not installed")
395         return True
398 set_define("MOZ_VALGRIND", check_valgrind)
399 set_config("MOZ_VALGRIND", check_valgrind)
402 @depends(target, host)
403 def is_openbsd(target, host):
404     return target.kernel == "OpenBSD" or host.kernel == "OpenBSD"
407 option(
408     env="SO_VERSION",
409     nargs=1,
410     default="1.0",
411     when=is_openbsd,
412     help="Shared library version for OpenBSD systems",
416 @depends("SO_VERSION", when=is_openbsd)
417 def so_version(value):
418     return value
421 @template
422 def library_name_info_template(host_or_target):
423     assert host_or_target in {host, target}
424     compiler = {
425         host: host_c_compiler,
426         target: c_compiler,
427     }[host_or_target]
429     @depends(host_or_target, compiler, so_version)
430     def library_name_info_impl(host_or_target, compiler, so_version):
431         if host_or_target.kernel == "WINNT":
432             # There aren't artifacts for mingw builds, so it's OK that the
433             # results are inaccurate in that case.
434             if compiler and compiler.type != "clang-cl":
435                 return namespace(
436                     dll=namespace(prefix="", suffix=".dll"),
437                     lib=namespace(prefix="lib", suffix="a"),
438                     import_lib=namespace(prefix="lib", suffix="a"),
439                     obj=namespace(prefix="", suffix="o"),
440                 )
442             return namespace(
443                 dll=namespace(prefix="", suffix=".dll"),
444                 lib=namespace(prefix="", suffix="lib"),
445                 import_lib=namespace(prefix="", suffix="lib"),
446                 obj=namespace(prefix="", suffix="obj"),
447             )
449         elif host_or_target.kernel == "Darwin":
450             return namespace(
451                 dll=namespace(prefix="lib", suffix=".dylib"),
452                 lib=namespace(prefix="lib", suffix="a"),
453                 import_lib=namespace(prefix=None, suffix=""),
454                 obj=namespace(prefix="", suffix="o"),
455             )
456         elif so_version:
457             so = ".so.%s" % so_version
458         else:
459             so = ".so"
461         return namespace(
462             dll=namespace(prefix="lib", suffix=so),
463             lib=namespace(prefix="lib", suffix="a"),
464             import_lib=namespace(prefix=None, suffix=""),
465             obj=namespace(prefix="", suffix="o"),
466         )
468     return library_name_info_impl
471 host_library_name_info = library_name_info_template(host)
472 library_name_info = library_name_info_template(target)
474 set_config("DLL_PREFIX", library_name_info.dll.prefix)
475 set_config("DLL_SUFFIX", library_name_info.dll.suffix)
476 set_config("HOST_DLL_PREFIX", host_library_name_info.dll.prefix)
477 set_config("HOST_DLL_SUFFIX", host_library_name_info.dll.suffix)
478 set_config("LIB_PREFIX", library_name_info.lib.prefix)
479 set_config("LIB_SUFFIX", library_name_info.lib.suffix)
480 set_config("OBJ_SUFFIX", library_name_info.obj.suffix)
481 # Lots of compilation tests depend on this variable being present.
482 add_old_configure_assignment("OBJ_SUFFIX", library_name_info.obj.suffix)
483 set_config("IMPORT_LIB_SUFFIX", library_name_info.import_lib.suffix)
484 set_define(
485     "MOZ_DLL_PREFIX", depends(library_name_info.dll.prefix)(lambda s: '"%s"' % s)
487 set_define(
488     "MOZ_DLL_SUFFIX", depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s)
490 set_config("WASM_OBJ_SUFFIX", "wasm")
492 # Make `profiling` available to this file even when js/moz.configure
493 # doesn't end up included.
494 profiling = dependable(False)
495 # Same for js_standalone
496 js_standalone = dependable(False)
497 # Same for fold_libs
498 fold_libs = dependable(False)
500 include(include_project_configure)
503 @depends("--help")
504 @imports(_from="mozbuild.backend", _import="backends")
505 def build_backends_choices(_):
506     return tuple(backends)
509 @deprecated_option("--enable-build-backend", nargs="+", choices=build_backends_choices)
510 def build_backend(backends):
511     if backends:
512         return tuple("+%s" % b for b in backends)
515 imply_option("--build-backends", build_backend)
518 @depends(
519     "--enable-artifact-builds",
520     "--disable-compile-environment",
521     "--enable-build-backend",
522     "--enable-project",
523     "--enable-application",
524     "--help",
526 @imports("sys")
527 def build_backend_defaults(
528     artifact_builds, compile_environment, requested_backends, project, application, _
530     if application:
531         project = application[0]
532     elif project:
533         project = project[0]
535     if "Tup" in requested_backends:
536         # As a special case, if Tup was requested, do not combine it with any
537         # Make based backend by default.
538         all_backends = []
539     elif artifact_builds:
540         all_backends = ["FasterMake+RecursiveMake"]
541     else:
542         all_backends = ["RecursiveMake", "FasterMake"]
543     # Normally, we'd use target.os == 'WINNT', but a dependency on target
544     # would require target to depend on --help, as well as host and shell,
545     # and this is not a can of worms we can open at the moment.
546     if sys.platform == "win32" and compile_environment and project != "mobile/android":
547         all_backends.append("VisualStudio")
548     return tuple(all_backends) or None
551 option(
552     "--build-backends",
553     nargs="+",
554     default=build_backend_defaults,
555     choices=build_backends_choices,
556     help="Build backends to generate",
560 @depends("--build-backends")
561 def build_backends(backends):
562     return backends
565 set_config("BUILD_BACKENDS", build_backends)
568 @depends(check_build_environment, build_backends)
569 @imports("glob")
570 def check_objdir_backend_reuse(build_env, backends):
571     # "Make based" might be RecursiveMake or a hybrid backend, so "Make" is
572     # intentionally vague for use with the substring match below.
573     incompatible_backends = (("Tup", "Make"), ("Make", "Tup"))
574     for backend_file in glob.iglob(
575         os.path.join(build_env.topobjdir, "backend.*Backend")
576     ):
577         for prev, curr in incompatible_backends:
578             if prev in backend_file and any(curr in b for b in backends):
579                 die(
580                     "The active objdir, %s, was previously "
581                     "used to build with a %s based backend. "
582                     "Change objdirs (by setting MOZ_OBJDIR in "
583                     "your mozconfig) or clobber to continue.\n",
584                     build_env.topobjdir,
585                     prev,
586                 )
589 option(
590     "--disable-gtest-in-build",
591     help="Force disable building the gtest libxul during the build.",
592     when="--enable-compile-environment",
595 # Determine whether to build the gtest xul. This happens in automation
596 # on Android and Desktop platforms with the exception of:
597 #  - Windows PGO, where linking xul-gtest.dll takes too long;
598 #  - Android other than x86_64, where gtest is not required.
599 @depends(
600     "MOZ_PGO",
601     build_project,
602     target,
603     "MOZ_AUTOMATION",
604     "--disable-gtest-in-build",
605     enable_tests,
606     when="--enable-compile-environment",
608 def build_gtest(pgo, build_project, target, automation, enabled, enable_tests):
609     if not enable_tests or not enabled:
610         return None
611     if (
612         automation
613         and build_project in ("browser", "comm/mail", "mobile/android")
614         and not (
615             (pgo and target.os == "WINNT")
616             or (target.os == "Android" and target.cpu != "x86_64")
617         )
618     ):
619         return True
622 set_config("LINK_GTEST_DURING_COMPILE", build_gtest)
624 # Localization
625 # ==============================================================
626 option(
627     "--enable-ui-locale",
628     default="en-US",
629     help="Select the user interface locale (default: en-US)",
632 set_config("MOZ_UI_LOCALE", depends("--enable-ui-locale")(lambda x: x))
634 # clang-plugin location
635 # ==============================================================
636 @depends(host_library_name_info, check_build_environment, when="--enable-clang-plugin")
637 def clang_plugin_path(library_name_info, build_env):
638     topobjdir = build_env.topobjdir
639     if topobjdir.endswith("/js/src"):
640         topobjdir = topobjdir[:-7]
641     return os.path.abspath(
642         os.path.join(
643             topobjdir,
644             "build",
645             "clang-plugin",
646             "%sclang-plugin%s"
647             % (library_name_info.dll.prefix, library_name_info.dll.suffix),
648         )
649     )
652 add_old_configure_assignment("CLANG_PLUGIN", clang_plugin_path)
655 # Awk detection
656 # ==============================================================
657 awk = check_prog("AWK", ("gawk", "mawk", "nawk", "awk"))
659 # Until the AWK variable is not necessary in old-configure
660 @depends(awk)
661 def awk_for_old_configure(value):
662     return value
665 add_old_configure_assignment("AWK", awk_for_old_configure)
668 # Perl detection
669 # ==============================================================
670 perl = check_prog("PERL", ("perl5", "perl"))
672 # Until the PERL variable is not necessary in old-configure
673 @depends(perl)
674 def perl_for_old_configure(value):
675     return value
678 add_old_configure_assignment("PERL", perl_for_old_configure)
681 @template
682 def perl_version_check(min_version):
683     @depends(perl)
684     @checking("for minimum required perl version >= %s" % min_version)
685     def get_perl_version(perl):
686         return Version(
687             check_cmd_output(
688                 perl,
689                 "-e",
690                 "print $]",
691                 onerror=lambda: die("Failed to get perl version."),
692             )
693         )
695     @depends(get_perl_version)
696     def check_perl_version(version):
697         if version < min_version:
698             die("Perl %s or higher is required.", min_version)
700     @depends(perl)
701     @checking("for full perl installation")
702     @imports("subprocess")
703     def has_full_perl_installation(perl):
704         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
705         return ret == 0
707     @depends(has_full_perl_installation)
708     def require_full_perl_installation(has_full_perl_installation):
709         if not has_full_perl_installation:
710             die(
711                 "Cannot find Config.pm or $Config{archlib}. "
712                 "A full perl installation is required."
713             )
716 perl_version_check("5.006")
719 # GNU make detection
720 # ==============================================================
721 option(env="MAKE", nargs=1, help="Path to GNU make")
724 @depends("MAKE", host)
725 def possible_makes(make, host):
726     candidates = []
727     if host.kernel == "WINNT":
728         candidates.append("mingw32-make")
729     if make:
730         candidates.append(make[0])
731     if host.kernel == "WINNT":
732         candidates.extend(("make", "gmake"))
733     else:
734         candidates.extend(("gmake", "make"))
735     return candidates
738 check_prog("GMAKE", possible_makes)
740 # watchman detection
741 # ==============================================================
743 option(env="WATCHMAN", nargs=1, help="Path to the watchman program")
746 @depends(host, "WATCHMAN")
747 @checking("for watchman", callback=lambda w: w.path if w else "not found")
748 def watchman(host, prog):
749     # On Windows, `watchman` is only supported on 64-bit hosts.
750     if host.os == "WINNT" and host.cpu != "x86_64":
751         return
753     if not prog:
754         prog = find_program("watchman")
756     if not prog:
757         return
759     # `watchman version` will talk to the Watchman daemon service.
760     # This can hang due to permissions problems. e.g.
761     # https://github.com/facebook/watchman/issues/376. So use
762     # `watchman --version` to prevent a class of failures.
763     out = check_cmd_output(prog, "--version", onerror=lambda: None)
764     if out is None:
765         return
767     return namespace(path=prog, version=Version(out.strip()))
770 @depends_if(watchman)
771 @checking("for watchman version")
772 def watchman_version(w):
773     return w.version
776 set_config("WATCHMAN", watchman.path)
779 @depends_all(hg_version, hg_config, watchman)
780 @checking("for watchman Mercurial integration")
781 @imports("os")
782 def watchman_hg(hg_version, hg_config, watchman):
783     if hg_version < Version("3.8"):
784         return "no (Mercurial 3.8+ required)"
786     ext_enabled = False
787     mode_disabled = False
789     for k in ("extensions.fsmonitor", "extensions.hgext.fsmonitor"):
790         if k in hg_config and hg_config[k] != "!":
791             ext_enabled = True
793     mode_disabled = hg_config.get("fsmonitor.mode") == "off"
795     if not ext_enabled:
796         return "no (fsmonitor extension not enabled)"
797     if mode_disabled:
798         return "no (fsmonitor.mode=off disables fsmonitor)"
800     return True
803 # Miscellaneous programs
804 # ==============================================================
805 check_prog("XARGS", ("xargs",))
808 @depends(target)
809 def extra_programs(target):
810     if target.kernel == "Darwin":
811         return namespace(
812             DSYMUTIL=("dsymutil", "llvm-dsymutil"),
813             MKFSHFS=("newfs_hfs", "mkfs.hfsplus"),
814             HFS_TOOL=("hfsplus",),
815         )
816     if target.os == "GNU" and target.kernel == "Linux":
817         return namespace(RPMBUILD=("rpmbuild",))
820 check_prog("DSYMUTIL", extra_programs.DSYMUTIL, allow_missing=True)
821 check_prog("MKFSHFS", extra_programs.MKFSHFS, allow_missing=True)
822 check_prog("HFS_TOOL", extra_programs.HFS_TOOL, allow_missing=True)
823 check_prog("RPMBUILD", extra_programs.RPMBUILD, allow_missing=True)
826 @depends(target)
827 @imports("os")
828 def makensis_progs(target):
829     if target.kernel != "WINNT":
830         return
832     candidates = [
833         "makensis-3.01",
834         "makensis-3.0b3",
835         "makensis-3.0b1",
836         "makensis",
837     ]
839     # Look for nsis installed by msys environment. But only the 32-bit version.
840     # We use an absolute path and insert as the first entry so it is preferred
841     # over a 64-bit exe that may be in PATH.
842     if "MSYSTEM_PREFIX" in os.environ:
843         prefix = os.path.dirname(os.environ["MSYSTEM_PREFIX"])
844         candidates.insert(0, os.path.join(prefix, "mingw32", "bin", "makensis.exe"))
846     return tuple(candidates)
849 nsis = check_prog("MAKENSISU", makensis_progs, allow_missing=True)
851 # Make sure the version of makensis is up to date.
852 @depends(nsis, wine)
853 @checking("for NSIS version")
854 @imports("re")
855 def nsis_version(nsis, wine):
856     if not nsis:
857         return None
858     nsis_min_version = "3.0b1"
859     onerror = lambda: die("Failed to get nsis version.")
860     if wine and nsis.lower().endswith(".exe"):
861         out = check_cmd_output(wine, nsis, "-version", onerror=onerror)
862     else:
863         out = check_cmd_output(nsis, "-version", onerror=onerror)
865     m = re.search(r"(?<=v)[0-9]+\.[0-9]+((a|b|rc)[0-9]+)?", out)
867     if not m:
868         raise FatalCheckError("Unknown version of makensis")
869     ver = Version(m.group(0))
871     # Versions comparisons don't quite work well with beta versions, so ensure
872     # it works for the non-beta version.
873     if ver < nsis_min_version and (ver >= "3.0a" or ver < "3"):
874         raise FatalCheckError(
875             "To build the installer you must have NSIS"
876             " version %s or greater in your path" % nsis_min_version
877         )
879     return ver
882 # And that makensis is 32-bit (but only on Windows).
883 @depends_if(nsis, when=depends(host)(lambda h: h.kernel == "WINNT"))
884 @checking("for 32-bit NSIS")
885 def nsis_binary_type(nsis):
886     bin_type = windows_binary_type(nsis)
887     if bin_type != "win32":
888         raise FatalCheckError("%s is not a 32-bit Windows application" % nsis)
890     return "yes"
893 # And any flags we have to give to makensis
894 @depends(host)
895 def nsis_flags(host):
896     if host.kernel != "WINNT":
897         return "-nocd"
898     return ""
901 set_config("MAKENSISU_FLAGS", nsis_flags)
903 check_prog("7Z", ("7z", "7za"), allow_missing=True, when=target_is_windows)
904 check_prog("UPX", ("upx",), allow_missing=True, when=target_is_windows)
907 @depends(host_c_compiler, c_compiler, bindgen_config_paths)
908 def llvm_objdump(host_c_compiler, c_compiler, bindgen_config_paths):
909     clang = None
910     for compiler in (host_c_compiler, c_compiler):
911         if compiler and compiler.type == "clang":
912             clang = compiler.compiler
913             break
914         elif compiler and compiler.type == "clang-cl":
915             clang = os.path.join(os.path.dirname(compiler.compiler), "clang")
916             break
918     if not clang and bindgen_config_paths:
919         clang = bindgen_config_paths.clang_path
920     llvm_objdump = "llvm-objdump"
921     if clang:
922         out = check_cmd_output(
923             clang, "--print-prog-name=llvm-objdump", onerror=lambda: None
924         )
925         if out:
926             llvm_objdump = out.rstrip()
927     return (llvm_objdump,)
930 llvm_objdump = check_prog(
931     "LLVM_OBJDUMP",
932     llvm_objdump,
933     what="llvm-objdump",
934     when="--enable-compile-environment",
935     paths=clang_search_path,
938 add_old_configure_assignment("LLVM_OBJDUMP", llvm_objdump)
941 option("--enable-dtrace", help="Build with dtrace support")
943 dtrace = check_header(
944     "sys/sdt.h",
945     when="--enable-dtrace",
946     onerror=lambda: die("dtrace enabled but sys/sdt.h not found"),
949 set_config("HAVE_DTRACE", True, when=dtrace)
950 set_define("INCLUDE_MOZILLA_DTRACE", True, when=dtrace)
951 add_old_configure_assignment("enable_dtrace", "yes", when=dtrace)
954 option("--disable-icf", help="Disable Identical Code Folding")
956 add_old_configure_assignment(
957     "MOZ_DISABLE_ICF", "1", when=depends("--enable-icf")(lambda x: not x)
961 option(
962     "--enable-strip",
963     when=compile_environment,
964     help="Enable stripping of libs & executables",
967 # This should be handled as a `when` once bug 1617793 is fixed.
968 @depends("--enable-strip", c_compiler, when=compile_environment)
969 def enable_strip(strip, c_compiler):
970     if strip and c_compiler.type != "clang-cl":
971         return True
974 set_config("ENABLE_STRIP", enable_strip)
976 option(
977     "--disable-install-strip",
978     when=compile_environment,
979     help="Enable stripping of libs & executables when packaging",
982 # This should be handled as a `when` once bug 1617793 is fixed.
983 @depends("--enable-install-strip", c_compiler, when=compile_environment)
984 def enable_install_strip(strip, c_compiler):
985     if strip and c_compiler.type != "clang-cl":
986         return True
989 set_config("PKG_STRIP", enable_install_strip)
992 @depends("--enable-strip", "--enable-install-strip", when=compile_environment)
993 def strip(strip, install_strip):
994     return strip or install_strip
997 option(env="STRIP_FLAGS", nargs=1, when=strip, help="Flags for the strip command")
1000 @depends("STRIP_FLAGS", profiling, target, when=strip)
1001 def strip_flags(flags, profiling, target):
1002     if flags:
1003         return flags[0].split()
1004     if profiling:
1005         # Only strip debug info and symbols when profiling is enabled, keeping
1006         # local symbols.
1007         if target.kernel == "Darwin":
1008             return ["-S"]
1009         elif target.os == "Android":
1010             # The tooling we use with Android supports detached symbols, and the
1011             # size increase caused by local symbols are too much for mobile. So,
1012             # don't restrict the amount of stripping with a flag.
1013             return
1014         else:
1015             return ["--strip-debug"]
1016     # Otherwise strip everything we can, which happens without flags on non-Darwin.
1017     # On Darwin, it tries to strip things it can't, so we need to limit its scope.
1018     elif target.kernel == "Darwin":
1019         return ["-x", "-S"]
1022 set_config("STRIP_FLAGS", strip_flags)
1025 @depends(js_standalone, target)
1026 def system_zlib_default(js_standalone, target):
1027     return js_standalone and target.kernel != "WINNT"
1030 option(
1031     "--with-system-zlib",
1032     nargs="?",
1033     default=system_zlib_default,
1034     help="{Use|Do not use} system libz",
1038 @depends("--with-system-zlib")
1039 def deprecated_system_zlib_path(value):
1040     if len(value) == 1:
1041         die(
1042             "--with-system-zlib=PATH is not supported anymore. Please use "
1043             "--with-system-zlib and set any necessary pkg-config environment variable."
1044         )
1047 pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when="--with-system-zlib")
1049 set_config("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1050 add_old_configure_assignment("MOZ_SYSTEM_ZLIB", True, when="--with-system-zlib")
1053 # Please do not add configure checks from here on.
1055 # Fallthrough to autoconf-based configure
1056 include("build/moz.configure/old.configure")
1058 # JS Subconfigure.
1059 include("js/sub.configure", when=compile_environment & toolkit)
1062 @depends(check_build_environment, build_project)
1063 @imports("__sandbox__")
1064 @imports("glob")
1065 @imports(_from="os.path", _import="exists")
1066 def config_status_deps(build_env, build_project):
1068     topsrcdir = build_env.topsrcdir
1069     topobjdir = build_env.topobjdir
1071     if not topobjdir.endswith("js/src"):
1072         extra_deps = [os.path.join(topobjdir, ".mozconfig.json")]
1073     else:
1074         # mozconfig changes may impact js configure.
1075         extra_deps = [os.path.join(topobjdir[:-7], ".mozconfig.json")]
1077     confvars = os.path.join(topsrcdir, build_project, "confvars.sh")
1078     if exists(confvars):
1079         extra_deps.append(confvars)
1081     return (
1082         list(__sandbox__._all_paths)
1083         + extra_deps
1084         + [
1085             os.path.join(topsrcdir, "CLOBBER"),
1086             os.path.join(topsrcdir, "configure.in"),
1087             os.path.join(topsrcdir, "js", "src", "configure.in"),
1088             os.path.join(topsrcdir, "nsprpub", "configure"),
1089             os.path.join(topsrcdir, "config", "milestone.txt"),
1090             os.path.join(topsrcdir, "browser", "config", "version.txt"),
1091             os.path.join(topsrcdir, "browser", "config", "version_display.txt"),
1092             os.path.join(topsrcdir, "build", "build_virtualenv_packages.txt"),
1093             os.path.join(topsrcdir, "build", "common_virtualenv_packages.txt"),
1094             os.path.join(topsrcdir, "build", "mach_virtualenv_packages.txt"),
1095             os.path.join(topsrcdir, "python", "mozbuild", "mozbuild", "virtualenv.py"),
1096             os.path.join(topsrcdir, "testing", "mozbase", "packages.txt"),
1097             os.path.join(topsrcdir, "aclocal.m4"),
1098             os.path.join(topsrcdir, "old-configure.in"),
1099             os.path.join(topsrcdir, "js", "src", "aclocal.m4"),
1100             os.path.join(topsrcdir, "js", "src", "old-configure.in"),
1101         ]
1102         + glob.glob(os.path.join(topsrcdir, "build", "autoconf", "*.m4"))
1103     )
1106 set_config("CONFIG_STATUS_DEPS", config_status_deps)
1107 # Please do not add anything after setting config_dep_paths.