Bug 1858921 - Part 2: Move WasmStructObject inlinable allocation methods to new inlin...
[gecko.git] / toolkit / moz.configure
blob9d5ee0ca9100d4206e8e0ef43f6ce5193acfa078
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/.
8 # Set the MOZ_CONFIGURE_OPTIONS variable with all the options that
9 # were passed somehow (environment, command line, mozconfig)
10 @dependable
11 @imports(_from="mozbuild.shellutil", _import="quote")
12 @imports(_from="mozbuild.util", _import="ensure_unicode")
13 @imports(_from="mozbuild.util", _import="system_encoding")
14 @imports("__sandbox__")
15 def all_configure_options():
16     result = []
17     previous = None
18     for option in __sandbox__._options.values():
19         # __sandbox__._options contains items for both option.name and
20         # option.env. But it's also an OrderedDict, meaning both are
21         # consecutive.
22         # Also ignore OLD_CONFIGURE and MOZCONFIG because they're not
23         # interesting.
24         if option == previous or option.env in ("OLD_CONFIGURE", "MOZCONFIG"):
25             continue
26         previous = option
27         value = __sandbox__._value_for(option)
28         # We only want options that were explicitly given on the command
29         # line, the environment, or mozconfig, and that differ from the
30         # defaults.
31         if (
32             value is not None
33             and value.origin not in ("default", "implied")
34             and value != option.default
35         ):
36             result.append(
37                 ensure_unicode(__sandbox__._raw_options[option], system_encoding)
38             )
39         # We however always include options that are sent to old configure
40         # because we don't know their actual defaults. (Keep the conditions
41         # separate for ease of understanding and ease of removal)
42         elif (
43             option.help == "Help missing for old configure options"
44             and option in __sandbox__._raw_options
45         ):
46             result.append(
47                 ensure_unicode(__sandbox__._raw_options[option], system_encoding)
48             )
50     # We shouldn't need this, but currently, quote will return a byte string
51     # if result is empty, and that's not wanted here.
52     if not result:
53         return ""
55     return quote(*result)
58 set_config("MOZ_CONFIGURE_OPTIONS", all_configure_options)
61 @depends(target)
62 def fold_libs(target):
63     return target.os in ("WINNT", "OSX", "Android")
66 set_config("MOZ_FOLD_LIBS", fold_libs)
68 # Profiling
69 # ==============================================================
70 # Some of the options here imply an option from js/moz.configure,
71 # so, need to be declared before the include.
73 option(
74     "--enable-jprof",
75     env="MOZ_JPROF",
76     help="Enable jprof profiling tool (needs mozilla/tools/jprof)",
80 @depends("--enable-jprof")
81 def jprof(value):
82     if value:
83         return True
86 set_config("MOZ_JPROF", jprof)
87 set_define("MOZ_JPROF", jprof)
88 imply_option("--enable-profiling", jprof)
91 @depends(target)
92 def gecko_profiler(target):
93     if target.os == "Android":
94         return target.cpu in ("aarch64", "arm", "x86", "x86_64")
95     elif target.kernel == "Linux":
96         return target.cpu in ("aarch64", "arm", "x86", "x86_64", "mips64")
97     elif target.kernel == "FreeBSD":
98         return target.cpu in ("aarch64", "x86_64")
99     return target.os in ("OSX", "WINNT")
102 @depends(gecko_profiler)
103 def gecko_profiler_define(value):
104     if value:
105         return True
108 set_config("MOZ_GECKO_PROFILER", gecko_profiler_define)
109 set_define("MOZ_GECKO_PROFILER", gecko_profiler_define)
112 # Whether code to parse ELF binaries should be compiled for the Gecko profiler
113 # (for symbol table dumping).
114 @depends(gecko_profiler, target)
115 def gecko_profiler_parse_elf(value, target):
116     # Currently we only want to build this code on Linux (including Android) and BSD.
117     # For Android, this is in order to dump symbols from Android system, where
118     # on other platforms there exist alternatives that don't require bloating
119     # up our binary size. For Linux more generally, we use this in profile
120     # pre-symbolication support, since MozDescribeCodeAddress doesn't do
121     # anything useful on that platform. (Ideally, we would update
122     # MozDescribeCodeAddress to call into some Rust crates that parse ELF and
123     # DWARF data, but build system issues currently prevent Rust from being
124     # used in mozglue.)
125     if value and (target.kernel == "Linux" or target.kernel == "FreeBSD"):
126         return True
129 set_config("MOZ_GECKO_PROFILER_PARSE_ELF", gecko_profiler_parse_elf)
130 set_define("MOZ_GECKO_PROFILER_PARSE_ELF", gecko_profiler_parse_elf)
132 # enable this by default if the profiler is enabled
133 # Note: also requires jemalloc
134 set_config("MOZ_PROFILER_MEMORY", gecko_profiler_define)
135 set_define("MOZ_PROFILER_MEMORY", gecko_profiler_define)
138 @depends(
139     "--enable-debug",
140     milestone,
141     build_project,
142     # Artifact builds are included because the downloaded artifacts can
143     # have DMD enabled.
144     when=artifact_builds | depends(when="--enable-replace-malloc")(lambda: True),
146 def dmd_default(debug, milestone, build_project):
147     return bool(build_project == "browser" and (debug or milestone.is_nightly))
150 option(
151     "--enable-dmd",
152     env="MOZ_DMD",
153     default=dmd_default,
154     help="{Enable|Disable} Dark Matter Detector (heap profiler). "
155     "Also enables jemalloc, replace-malloc and profiling",
159 @depends("--enable-dmd")
160 def dmd(value):
161     if value:
162         return True
165 set_config("MOZ_DMD", dmd)
166 set_define("MOZ_DMD", dmd)
167 imply_option("--enable-profiling", dmd)
168 imply_option("--enable-jemalloc", dmd, when=compile_environment)
169 imply_option("--enable-replace-malloc", dmd, when=compile_environment)
172 # midir-based Web MIDI support
173 # ==============================================================
174 @depends(target)
175 def midir_linux_support(target):
176     return (
177         target.kernel == "Linux" and target.os != "Android" and target.cpu != "riscv64"
178     )
181 @depends(target, midir_linux_support)
182 def midir_support(target, midir_linux_support):
183     if target.os in ("WINNT", "OSX") or midir_linux_support:
184         return True
187 set_config("MOZ_WEBMIDI_MIDIR_IMPL", midir_support)
190 # Enable various cubeb backends
191 # ==============================================================
192 @depends(target)
193 def audio_backends_default(target):
194     if target.os == "Android":
195         return (
196             "aaudio",
197             "opensl",
198         )
199     elif target.os in ("DragonFly", "FreeBSD", "SunOS"):
200         return ("oss",)
201     elif target.os == "OpenBSD":
202         return ("sndio",)
203     elif target.os == "OSX":
204         return ("audiounit",)
205     elif target.os == "NetBSD":
206         return ("sunaudio",)
207     elif target.os == "SunOS":
208         return ("sunaudio",)
209     elif target.os == "WINNT":
210         return ("wasapi",)
211     else:
212         return ("pulseaudio",)
215 option(
216     "--enable-audio-backends",
217     nargs="+",
218     choices=(
219         "aaudio",
220         "alsa",
221         "audiounit",
222         "jack",
223         "opensl",
224         "oss",
225         "pulseaudio",
226         "sndio",
227         "sunaudio",
228         "wasapi",
229     ),
230     default=audio_backends_default,
231     help="{Enable|Disable} various cubeb backends",
235 @depends("--enable-audio-backends", target)
236 def imply_aaudio(values, target):
237     if any("aaudio" in value for value in values) and target.os != "Android":
238         die("Cannot enable AAudio on %s", target.os)
239     return any("aaudio" in value for value in values) or None
242 @depends("--enable-audio-backends", target)
243 def imply_alsa(values, target):
244     if (
245         any("alsa" in value for value in values)
246         and target.kernel != "Linux"
247         and target.os != "FreeBSD"
248     ):
249         die("Cannot enable ALSA on %s", target.os)
250     return any("alsa" in value for value in values) or None
253 @depends("--enable-audio-backends", target)
254 def imply_audiounit(values, target):
255     if (
256         any("audiounit" in value for value in values)
257         and target.os != "OSX"
258         and target.kernel != "Darwin"
259     ):
260         die("Cannot enable AudioUnit on %s", target.os)
261     return any("audiounit" in value for value in values) or None
264 @depends("--enable-audio-backends")
265 def imply_jack(values):
266     return any("jack" in value for value in values) or None
269 @depends("--enable-audio-backends", target)
270 def imply_opensl(values, target):
271     if any("opensl" in value for value in values) and target.os != "Android":
272         die("Cannot enable OpenSL on %s", target.os)
273     return any("opensl" in value for value in values) or None
276 @depends("--enable-audio-backends", target)
277 def imply_oss(values, target):
278     if any("oss" in value for value in values) and (
279         target.os == "Android" or target.os == "OSX" or target.os == "WINNT"
280     ):
281         die("Cannot enable OSS on %s", target.os)
282     return any("oss" in value for value in values) or None
285 @depends("--enable-audio-backends", target)
286 def imply_pulseaudio(values, target):
287     if any("pulseaudio" in value for value in values) and (
288         target.os == "Android" or target.os == "OSX" or target.os == "WINNT"
289     ):
290         die("Cannot enable PulseAudio on %s", target.os)
291     return any("pulseaudio" in value for value in values) or None
294 @depends("--enable-audio-backends", target)
295 def imply_sndio(values, target):
296     if any("sndio" in value for value in values) and (
297         target.os == "Android" or target.os == "OSX" or target.os == "WINNT"
298     ):
299         die("Cannot enable sndio on %s", target.os)
300     return any("sndio" in value for value in values) or None
303 @depends("--enable-audio-backends", target)
304 def imply_sunaudio(values, target):
305     if any("sunaudio" in value for value in values) and (
306         target.os != "NetBSD" and target.os != "SunOS"
307     ):
308         die("Cannot enable sunaudio on %s", target.os)
309     return any("sunaudio" in value for value in values) or None
312 @depends("--enable-audio-backends", target)
313 def imply_wasapi(values, target):
314     if any("wasapi" in value for value in values) and target.os != "WINNT":
315         die("Cannot enable WASAPI on %s", target.os)
316     return any("wasapi" in value for value in values) or None
319 set_config("MOZ_AAUDIO", imply_aaudio, when="--enable-audio-backends")
321 imply_option("--enable-alsa", imply_alsa, reason="--enable-audio-backends")
323 set_config("MOZ_AUDIOUNIT_RUST", imply_audiounit, when="--enable-audio-backends")
325 imply_option("--enable-jack", imply_jack, reason="--enable-audio-backends")
327 set_config("MOZ_OPENSL", imply_opensl, when="--enable-audio-backends")
329 set_config("MOZ_OSS", imply_oss, when="--enable-audio-backends")
331 imply_option("--enable-pulseaudio", imply_pulseaudio, reason="--enable-audio-backends")
333 imply_option("--enable-sndio", imply_sndio, reason="--enable-audio-backends")
335 set_config("MOZ_SUNAUDIO", imply_sunaudio, when="--enable-audio-backends")
337 set_config("MOZ_WASAPI", imply_wasapi, when="--enable-audio-backends")
339 # ALSA cubeb backend
340 # ==============================================================
341 option("--enable-alsa", env="MOZ_ALSA", help="Enable ALSA audio backend.")
344 @depends("--enable-alsa", midir_linux_support)
345 def enable_alsa_or_midir_linux_support(alsa_enabled, midir_linux_support):
346     return alsa_enabled or midir_linux_support
349 pkg_check_modules("MOZ_ALSA", "alsa", when=enable_alsa_or_midir_linux_support)
351 set_config("MOZ_ALSA", True, when="--enable-alsa")
352 set_define("MOZ_ALSA", True, when="--enable-alsa")
354 # JACK cubeb backend
355 # ==============================================================
356 system_lib_option("--enable-jack", env="MOZ_JACK", help="Enable JACK audio backend.")
358 jack = pkg_check_modules("MOZ_JACK", "jack", when="--enable-jack")
360 set_config("MOZ_JACK", depends_if(jack)(lambda _: True))
362 # PulseAudio cubeb backend
363 # ==============================================================
364 option(
365     "--enable-pulseaudio",
366     env="MOZ_PULSEAUDIO",
367     help="{Enable|Disable} PulseAudio audio backend.",
370 pulseaudio = pkg_check_modules("MOZ_PULSEAUDIO", "libpulse", when="--enable-pulseaudio")
372 set_config("MOZ_PULSEAUDIO", depends_if(pulseaudio)(lambda _: True))
373 set_define("MOZ_PULSEAUDIO", depends_if(pulseaudio)(lambda _: True))
375 # sndio cubeb backend
376 # ==============================================================
377 system_lib_option("--enable-sndio", env="MOZ_SNDIO", help="Enable sndio audio backend.")
379 sndio = pkg_check_modules("MOZ_SNDIO", "sndio", when="--enable-sndio")
381 set_config("MOZ_SNDIO", depends_if(sndio)(lambda _: True))
383 # Javascript engine
384 # ==============================================================
385 include("../js/moz.configure")
388 # NodeJS
389 # ==============================================================
390 include("../build/moz.configure/node.configure")
392 # JsonCpp
393 # ==============================================================
394 set_define("JSON_USE_EXCEPTION", 0)
396 # L10N
397 # ==============================================================
398 option("--with-l10n-base", nargs=1, env="L10NBASEDIR", help="Path to l10n repositories")
401 @depends("--with-l10n-base", "MOZ_AUTOMATION", build_environment)
402 @imports(_from="os.path", _import="isdir")
403 @imports(_from="os.path", _import="expanduser")
404 @imports(_from="os", _import="environ")
405 def l10n_base(value, automation, build_env):
406     if value:
407         path = value[0]
408         if not isdir(path):
409             die("Invalid value --with-l10n-base, %s doesn't exist", path)
410     elif automation:
411         path = os.path.join(build_env.topsrcdir, "../l10n-central")
412     else:
413         path = os.path.join(
414             environ.get(
415                 "MOZBUILD_STATE_PATH", expanduser(os.path.join("~", ".mozbuild"))
416             ),
417             "l10n-central",
418         )
419     return os.path.realpath(os.path.abspath(path))
422 set_config("L10NBASEDIR", l10n_base)
425 # Default toolkit
426 # ==============================================================
427 @depends(target)
428 def toolkit_choices(target):
429     if target.os == "WINNT":
430         return ("cairo-windows",)
431     elif target.os == "OSX":
432         return ("cairo-cocoa",)
433     elif target.os == "Android":
434         return ("cairo-android",)
435     else:
436         # cairo-gtk3 - X11 backend with optional Wayland backend (auto detected)
437         # cairo-gtk3-wayland - Wayland backend with optional X11 backend (auto detected)
438         # cairo-gtk3-x11-wayland - builds explicitly with X11 & Wayland backends
439         return (
440             "cairo-gtk3",
441             "cairo-gtk3-wayland",
442             "cairo-gtk3-x11-wayland",
443             "cairo-gtk3-wayland-only",
444             "cairo-gtk3-x11-only",
445         )
448 @depends(toolkit_choices)
449 def toolkit_default(choices):
450     return choices[0]
453 option(
454     "--enable-default-toolkit",
455     nargs=1,
456     choices=toolkit_choices,
457     default=toolkit_default,
458     help="Select default toolkit",
462 @depends("--enable-default-toolkit")
463 def full_toolkit(value):
464     if value:
465         return value[0]
468 @depends(full_toolkit)
469 def toolkit(toolkit):
470     if toolkit.startswith("cairo-gtk3"):
471         widget_toolkit = "gtk"
472     else:
473         widget_toolkit = toolkit.replace("cairo-", "")
474     return widget_toolkit
477 set_config("MOZ_WIDGET_TOOLKIT", toolkit)
478 add_old_configure_assignment("MOZ_WIDGET_TOOLKIT", toolkit)
481 @depends(toolkit)
482 def toolkit_define(toolkit):
483     if toolkit != "windows":
484         return "MOZ_WIDGET_%s" % toolkit.upper()
487 set_define(toolkit_define, True)
490 @depends(toolkit)
491 def toolkit_gtk(toolkit):
492     return toolkit == "gtk"
495 @depends(toolkit_gtk, full_toolkit)
496 def toolkit_gtk_x11(toolkit_gtk, full_toolkit):
497     return toolkit_gtk and full_toolkit != "cairo-gtk3-wayland-only"
500 @depends(full_toolkit)
501 def toolkit_gtk_x11_optional(full_toolkit):
502     return full_toolkit == "cairo-gtk3-wayland"
505 @depends(toolkit_gtk, full_toolkit)
506 def toolkit_gtk_wayland(toolkit_gtk, full_toolkit):
507     return toolkit_gtk and full_toolkit != "cairo-gtk3-x11-only"
510 @depends(full_toolkit)
511 def toolkit_gtk_wayland_optional(full_toolkit):
512     return full_toolkit == "cairo-gtk3"
515 # Wayland support
516 # ==============================================================
517 wayland_headers = pkg_check_modules(
518     "MOZ_WAYLAND",
519     "gtk+-wayland-3.0 >= 3.14 xkbcommon >= 0.4.1",
520     allow_missing=toolkit_gtk_wayland_optional,
521     when=toolkit_gtk_wayland,
525 @depends(wayland_headers, toolkit_gtk, artifact_builds, toolkit_gtk_wayland)
526 def wayland_headers(wayland, toolkit_gtk, artifacts, toolkit_gtk_wayland):
527     if not toolkit_gtk_wayland:
528         return False
529     if toolkit_gtk and artifacts:
530         return True
531     return wayland
534 set_config("MOZ_WAYLAND", depends_if(wayland_headers)(lambda _: True))
535 set_define("MOZ_WAYLAND", depends_if(wayland_headers)(lambda _: True))
538 # Hardware-accelerated video decode with VAAPI and V4L2 on Linux
539 # ==============================================================
540 @depends(target, toolkit_gtk)
541 def vaapi(target, toolkit_gtk):
542     # VAAPI is mostly used on x86(-64) but is sometimes used on ARM/ARM64 SOCs.
543     if target.cpu in ("arm", "aarch64", "x86", "x86_64") and toolkit_gtk:
544         return True
547 @depends(target, toolkit_gtk)
548 def v4l2(target, toolkit_gtk):
549     # V4L2 decode is only used in GTK/Linux and generally only appears on
550     # embedded SOCs.
551     if target.cpu in ("arm", "aarch64", "riscv64") and toolkit_gtk:
552         return True
555 set_config("MOZ_ENABLE_VAAPI", True, when=vaapi)
556 set_config("MOZ_ENABLE_V4L2", True, when=v4l2)
557 set_define("MOZ_ENABLE_VAAPI", True, when=vaapi)
558 set_define("MOZ_ENABLE_V4L2", True, when=v4l2)
561 # GL Provider
562 # ==============================================================
563 option("--with-gl-provider", nargs=1, help="Set GL provider backend type")
566 @depends("--with-gl-provider")
567 def gl_provider(value):
568     if value:
569         return value[0]
572 @depends(gl_provider)
573 def gl_provider_define(provider):
574     if provider:
575         return "GLContextProvider%s" % provider
578 set_define("MOZ_GL_PROVIDER", gl_provider_define)
581 @depends(gl_provider, toolkit_gtk)
582 def gl_default_provider(value, toolkit_gtk):
583     if value:
584         return value
585     elif toolkit_gtk:
586         return "EGL"
589 set_config("MOZ_GL_PROVIDER", gl_provider)
590 set_config("MOZ_GL_DEFAULT_PROVIDER", gl_default_provider)
593 @depends(gl_default_provider)
594 def gl_provider_define(provider):
595     if provider:
596         return "GL_PROVIDER_%s" % provider
599 set_define(gl_provider_define, True)
602 # PDF printing
603 # ==============================================================
604 @depends(toolkit)
605 def pdf_printing(toolkit):
606     if toolkit in ("windows", "gtk", "android"):
607         return True
610 set_config("MOZ_PDF_PRINTING", pdf_printing)
611 set_define("MOZ_PDF_PRINTING", pdf_printing)
614 # Event loop instrumentation
615 # ==============================================================
616 option(env="MOZ_INSTRUMENT_EVENT_LOOP", help="Force-enable event loop instrumentation")
619 @depends("MOZ_INSTRUMENT_EVENT_LOOP", toolkit)
620 def instrument_event_loop(value, toolkit):
621     if value or (
622         toolkit in ("windows", "gtk", "cocoa", "android") and value.origin == "default"
623     ):
624         return True
627 set_config("MOZ_INSTRUMENT_EVENT_LOOP", instrument_event_loop)
628 set_define("MOZ_INSTRUMENT_EVENT_LOOP", instrument_event_loop)
631 # Fontconfig Freetype
632 # ==============================================================
633 option(env="USE_FC_FREETYPE", help="Force-enable the use of fontconfig freetype")
636 @depends("USE_FC_FREETYPE", toolkit)
637 def fc_freetype(value, toolkit):
638     if value or (toolkit == "gtk" and value.origin == "default"):
639         return True
642 set_define("USE_FC_FREETYPE", fc_freetype)
644 # Pango
645 # ==============================================================
646 pkg_check_modules("MOZ_PANGO", "pango >= 1.22.0", when=toolkit_gtk)
648 # Fontconfig
649 # ==============================================================
650 fontconfig_info = pkg_check_modules(
651     "_FONTCONFIG", "fontconfig >= 2.7.0", when=fc_freetype
655 @depends(fc_freetype)
656 def check_for_freetype2(fc_freetype):
657     if fc_freetype:
658         return True
661 # Check for freetype2. Flags are combined with fontconfig flags.
662 freetype2_info = pkg_check_modules(
663     "_FT2", "freetype2 >= 9.10.3", when=check_for_freetype2
667 @depends(fontconfig_info, freetype2_info)
668 def freetype2_combined_info(fontconfig_info, freetype2_info):
669     if not freetype2_info:
670         return
671     if not fontconfig_info:
672         return freetype2_info
673     return namespace(
674         cflags=freetype2_info.cflags + fontconfig_info.cflags,
675         libs=freetype2_info.libs + fontconfig_info.libs,
676     )
679 set_define("MOZ_HAVE_FREETYPE2", depends_if(freetype2_info)(lambda _: True))
682 # Apple platform decoder support
683 # ==============================================================
684 @depends(toolkit)
685 def applemedia(toolkit):
686     if toolkit in ("cocoa", "uikit"):
687         return True
690 set_config("MOZ_APPLEMEDIA", applemedia)
691 set_define("MOZ_APPLEMEDIA", applemedia)
693 # Windows Media Foundation support
694 # ==============================================================
695 option("--disable-wmf", help="Disable support for Windows Media Foundation")
698 @depends("--disable-wmf", target, "--help")
699 def wmf(value, target, _):
700     enabled = bool(value)
701     if value.origin == "default":
702         # Enable Windows Media Foundation support by default.
703         # Note our minimum SDK version is Windows 7 SDK, so we are (currently)
704         # guaranteed to have a recent-enough SDK to build WMF.
705         enabled = target.os == "WINNT"
706     if enabled and target.os != "WINNT":
707         die("Cannot enable Windows Media Foundation support on %s", target.os)
708     if enabled:
709         return True
712 @depends(c_compiler, when=wmf)
713 def wmfmediaengine(c_compiler):
714     return c_compiler and c_compiler.type == "clang-cl"
717 set_config("MOZ_WMF", wmf)
718 set_define("MOZ_WMF", wmf)
720 set_config("MOZ_WMF_MEDIA_ENGINE", True, when=wmfmediaengine)
721 set_define("MOZ_WMF_MEDIA_ENGINE", True, when=wmfmediaengine)
723 # FFmpeg H264/AAC Decoding Support
724 # ==============================================================
725 option("--disable-ffmpeg", help="Disable FFmpeg for fragmented H264/AAC decoding")
728 @depends("--disable-ffmpeg", target)
729 def ffmpeg(value, target):
730     enabled = bool(value)
731     if value.origin == "default":
732         enabled = target.os not in ("Android", "WINNT")
733     if enabled:
734         return True
737 set_config("MOZ_FFMPEG", ffmpeg)
738 set_define("MOZ_FFMPEG", ffmpeg)
740 # AV1 Video Codec Support
741 # ==============================================================
742 option("--disable-av1", help="Disable av1 video support")
745 @depends("--enable-av1")
746 def av1(value):
747     if value:
748         return True
751 @depends(target, when=av1 & compile_environment)
752 def dav1d_asm(target):
753     if target.cpu in ("aarch64", "x86", "x86_64"):
754         return True
757 @depends(target, when=av1 & compile_environment)
758 def dav1d_nasm(target):
759     if target.cpu in ("x86", "x86_64"):
760         return namespace(version="2.14", what="AV1")
763 set_config("MOZ_DAV1D_ASM", dav1d_asm)
764 set_define("MOZ_DAV1D_ASM", dav1d_asm)
765 set_config("MOZ_AV1", av1)
766 set_define("MOZ_AV1", av1)
768 # JXL Image Codec Support
769 # ==============================================================
770 option("--disable-jxl", help="Disable jxl image support")
773 @depends("--disable-jxl", milestone.is_nightly)
774 def jxl(value, is_nightly):
775     if is_nightly and value:
776         return True
779 set_config("MOZ_JXL", jxl)
780 set_define("MOZ_JXL", jxl)
782 set_config("MOZ_SAMPLE_TYPE_FLOAT32", True)
783 set_define("MOZ_SAMPLE_TYPE_FLOAT32", True)
785 set_define("MOZ_VORBIS", True)
786 set_config("MOZ_VORBIS", True)
788 option(
789     "--disable-real-time-tracing",
790     help="Disable tracing of real-time audio callbacks",
793 set_config("MOZ_REAL_TIME_TRACING", True, when="--enable-real-time-tracing")
794 set_define("MOZ_REAL_TIME_TRACING", True, when="--enable-real-time-tracing")
796 # OpenMAX IL Decoding Support
797 # ==============================================================
798 option("--enable-openmax", help="Enable OpenMAX IL for video/audio decoding")
801 @depends("--enable-openmax")
802 def openmax(value):
803     enabled = bool(value)
804     if enabled:
805         return True
808 set_config("MOZ_OMX", openmax)
809 set_define("MOZ_OMX", openmax)
812 # EME Support
813 # ==============================================================
814 @depends(target, wmf)
815 def eme_choices(target, wmf):
816     if (
817         target.kernel in ("WINNT", "Linux")
818         and target.os != "Android"
819         and target.cpu in ("x86", "x86_64")
820     ):
821         if wmf:
822             return ("widevine", "wmfcdm")
823         return ("widevine",)
824     if target.kernel == "WINNT" and target.cpu == "aarch64":
825         return ("widevine",)
826     if target.os in ("OSX"):
827         return ("widevine",)
830 # Widevine is enabled by default in desktop browser builds.
831 @depends(build_project, eme_choices)
832 def eme_default(build_project, choices):
833     if build_project == "browser":
834         return choices
837 option(
838     "--enable-eme",
839     nargs="+",
840     choices=eme_choices,
841     default=eme_default,
842     when=eme_choices,
843     help="{Enable|Disable} support for Encrypted Media Extensions",
847 @depends("--enable-eme", when=eme_choices)
848 def eme_modules(value):
849     return value
852 # Fallback to an empty list when eme_choices is empty, setting eme_modules to
853 # None.
854 set_config("MOZ_EME_MODULES", eme_modules | dependable([]))
857 # Media Foundation CDM support
858 # ==============================================================
859 @depends(eme_modules, when=wmfmediaengine)
860 def wmfcdm(modules):
861     if "wmfcdm" in modules:
862         return True
865 set_config("MOZ_WMF_CDM", True, when=wmfcdm)
866 set_define("MOZ_WMF_CDM", True, when=wmfcdm)
869 option(
870     name="--enable-chrome-format",
871     help="Select FORMAT of chrome files during packaging.",
872     nargs=1,
873     choices=("omni", "jar", "flat"),
874     default="omni",
878 @depends("--enable-chrome-format")
879 def packager_format(value):
880     return value[0]
883 set_config("MOZ_PACKAGER_FORMAT", packager_format)
885 # The packager minifies two different types of files: non-JS (mostly property
886 # files for l10n), and JS.  Setting MOZ_PACKAGER_MINIFY only minifies the
887 # former.  Firefox doesn't yet minify JS, due to concerns about debuggability.
889 # Also, the JS minification setup really only works correctly on Android:
890 # we need extra setup to use the newly-built shell for Linux and Windows,
891 # and cross-compilation for macOS requires some extra care.
894 @depends(target_is_android, "--enable-debug", milestone.is_nightly)
895 def enable_minify_default(is_android, debug, is_nightly):
896     if is_android and not debug and not is_nightly:
897         return ("properties", "js")
898     return ("properties",)
901 option(
902     name="--enable-minify",
903     help="Select types of files to minify during packaging.",
904     nargs="*",
905     choices=("properties", "js"),
906     default=enable_minify_default,
910 @depends("--enable-minify")
911 def enable_minify(value):
912     if "js" in value and "properties" not in value:
913         die("--enable-minify=js requires --enable-minify=properties.")
914     return namespace(
915         properties="properties" in value,
916         js="js" in value,
917     )
920 set_config("MOZ_PACKAGER_MINIFY", True, when=enable_minify.properties)
921 set_config("MOZ_PACKAGER_MINIFY_JS", True, when=enable_minify.js)
924 @depends(host, build_project)
925 def jar_maker_format(host, build_project):
926     # Multilocales for mobile/android use the same mergedirs for all locales,
927     # so we can't use symlinks for those builds.
928     if host.os == "WINNT" or build_project == "mobile/android":
929         return "flat"
930     return "symlink"
933 set_config("MOZ_JAR_MAKER_FILE_FORMAT", jar_maker_format)
936 @depends(toolkit)
937 def omnijar_name(toolkit):
938     # Fennec's static resources live in the assets/ folder of the
939     # APK.  Adding a path to the name here works because we only
940     # have one omnijar file in the final package (which is not the
941     # case on desktop).
942     return "assets/omni.ja" if toolkit == "android" else "omni.ja"
945 set_config("OMNIJAR_NAME", omnijar_name)
947 project_flag("MOZ_PLACES", help="Build Places if required", set_as_define=True)
949 project_flag(
950     "MOZ_SERVICES_HEALTHREPORT",
951     help="Build Firefox Health Reporter Service",
952     set_as_define=True,
955 project_flag(
956     "MOZ_NORMANDY",
957     help="Enable Normandy recipe runner",
958     set_as_define=True,
961 project_flag("MOZ_SERVICES_SYNC", help="Build Sync Services if required")
963 project_flag(
964     "MOZ_ANDROID_HISTORY",
965     help="Enable Android History instead of Places",
966     set_as_define=True,
969 project_flag(
970     "MOZ_DEDICATED_PROFILES",
971     help="Enable dedicated profiles per install",
972     set_as_define=True,
975 project_flag(
976     "MOZ_BLOCK_PROFILE_DOWNGRADE",
977     help="Block users from starting profiles last used by a newer build",
978     set_as_define=True,
982 @depends("MOZ_PLACES", "MOZ_ANDROID_HISTORY")
983 def check_places_and_android_history(places, android_history):
984     if places and android_history:
985         die("Cannot use MOZ_ANDROID_HISTORY alongside MOZ_PLACES.")
988 option(
989     env="MOZ_TELEMETRY_REPORTING",
990     default=mozilla_official,
991     help="Enable telemetry reporting",
994 set_define("MOZ_TELEMETRY_REPORTING", True, when="MOZ_TELEMETRY_REPORTING")
997 @depends("MOZ_TELEMETRY_REPORTING", milestone.is_nightly)
998 def telemetry_on_by_default(reporting, is_nightly):
999     return reporting and is_nightly
1002 set_define("MOZ_TELEMETRY_ON_BY_DEFAULT", True, when=telemetry_on_by_default)
1005 # gpsd support
1006 # ==============================================================
1007 system_lib_option("--enable-gpsd", env="MOZ_GPSD", help="Enable gpsd support")
1010 @depends("--enable-gpsd")
1011 def gpsd(value):
1012     return bool(value)
1015 system_gpsd = pkg_check_modules("MOZ_GPSD", "libgps >= 3.11", when=gpsd)
1017 set_config("MOZ_GPSD", depends_if(system_gpsd)(lambda _: True))
1019 # Miscellaneous programs
1020 # ==============================================================
1022 check_prog("TAR", ("gnutar", "gtar", "tar"))
1023 check_prog("UNZIP", ("unzip",))
1025 # Key files
1026 # ==============================================================
1027 include("../build/moz.configure/keyfiles.configure")
1029 simple_keyfile("Mozilla API")
1031 simple_keyfile("Google Location Service API")
1033 simple_keyfile("Google Safebrowsing API")
1035 id_and_secret_keyfile("Bing API")
1037 simple_keyfile("Adjust SDK")
1039 id_and_secret_keyfile("Leanplum SDK")
1041 simple_keyfile("Pocket API")
1044 # WebRender Debugger integration
1045 # ==============================================================
1047 option(
1048     "--enable-webrender-debugger", help="Build the websocket debug server in WebRender"
1051 set_config(
1052     "MOZ_WEBRENDER_DEBUGGER", depends_if("--enable-webrender-debugger")(lambda _: True)
1055 # Additional system headers defined at the application level
1056 # ==============================================================
1058 option(
1059     "--enable-app-system-headers",
1060     env="MOZ_APP_SYSTEM_HEADERS",
1061     help="Use additional system headers defined in $MOZ_BUILD_APP/app-system-headers.mozbuild",
1065 @depends("--enable-app-system-headers")
1066 def app_system_headers(value):
1067     if value:
1068         return True
1071 set_config("MOZ_APP_SYSTEM_HEADERS", app_system_headers)
1072 set_define("MOZ_APP_SYSTEM_HEADERS", app_system_headers)
1074 # Printing
1075 # ==============================================================
1076 option("--disable-printing", help="Disable printing support")
1079 @depends("--disable-printing")
1080 def printing(value):
1081     if value:
1082         return True
1085 set_config("NS_PRINTING", printing)
1086 set_define("NS_PRINTING", printing)
1087 set_define("NS_PRINT_PREVIEW", printing)
1090 # Speech-dispatcher support
1091 # ==============================================================
1092 @depends(toolkit)
1093 def no_speechd_on_non_gtk(toolkit):
1094     if toolkit != "gtk":
1095         return False
1098 imply_option(
1099     "--enable-synth-speechd", no_speechd_on_non_gtk, reason="--enable-default-toolkit"
1102 option("--disable-synth-speechd", help="Disable speech-dispatcher support")
1104 set_config("MOZ_SYNTH_SPEECHD", depends_if("--disable-synth-speechd")(lambda _: True))
1106 # Speech API
1107 # ==============================================================
1108 option("--disable-webspeech", help="Disable support for HTML Speech API")
1111 @depends("--disable-webspeech")
1112 def webspeech(value):
1113     if value:
1114         return True
1117 set_config("MOZ_WEBSPEECH", webspeech)
1118 set_define("MOZ_WEBSPEECH", webspeech)
1120 # Speech API test backend
1121 # ==============================================================
1122 option(
1123     "--enable-webspeechtestbackend",
1124     default=webspeech,
1125     help="{Enable|Disable} support for HTML Speech API Test Backend",
1129 @depends_if("--enable-webspeechtestbackend")
1130 def webspeech_test_backend(value):
1131     return True
1134 set_config("MOZ_WEBSPEECH_TEST_BACKEND", webspeech_test_backend)
1135 set_define("MOZ_WEBSPEECH_TEST_BACKEND", webspeech_test_backend)
1138 # Graphics
1139 # ==============================================================
1140 @depends(target, milestone)
1141 def skia_pdf_default(target, milestone):
1142     return milestone.is_nightly and target.os != "WINNT"
1145 option("--enable-skia-pdf", default=skia_pdf_default, help="{Enable|Disable} Skia PDF")
1147 set_config("MOZ_ENABLE_SKIA_PDF", True, when="--enable-skia-pdf")
1148 set_define("MOZ_ENABLE_SKIA_PDF", True, when="--enable-skia-pdf")
1150 set_config(
1151     "SKIA_INCLUDES",
1152     [
1153         "/gfx/skia",
1154         "/gfx/skia/skia",
1155     ],
1158 system_lib_option(
1159     "--with-system-webp", help="Use system libwebp (located with pkgconfig)"
1162 system_webp = pkg_check_modules(
1163     "MOZ_WEBP", "libwebp >= 1.0.2 libwebpdemux >= 1.0.2", when="--with-system-webp"
1166 set_config("MOZ_SYSTEM_WEBP", depends(when=system_webp)(lambda: True))
1169 # Build Freetype in the tree
1170 # ==============================================================
1171 @depends(target, "--enable-skia-pdf")
1172 def tree_freetype(target, skia_pdf):
1173     if target.os == "Android" or (skia_pdf and target.os == "WINNT"):
1174         return True
1177 set_define("MOZ_TREE_FREETYPE", tree_freetype)
1178 set_config("MOZ_TREE_FREETYPE", tree_freetype)
1180 set_define("HAVE_FT_BITMAP_SIZE_Y_PPEM", tree_freetype)
1181 set_define("HAVE_FT_GLYPHSLOT_EMBOLDEN", tree_freetype)
1182 set_define("HAVE_FT_LOAD_SFNT_TABLE", tree_freetype)
1185 @depends(freetype2_combined_info, tree_freetype, build_environment)
1186 def ft2_info(freetype2_combined_info, tree_freetype, build_env):
1187     if tree_freetype:
1188         return namespace(
1189             cflags=("-I%s/modules/freetype2/include" % build_env.topsrcdir,), libs=()
1190         )
1191     if freetype2_combined_info:
1192         return freetype2_combined_info
1195 set_config("FT2_LIBS", ft2_info.libs)
1198 @depends(target, tree_freetype, freetype2_info)
1199 def enable_cairo_ft(target, tree_freetype, freetype2_info):
1200     # Avoid defining MOZ_ENABLE_CAIRO_FT on Windows platforms because
1201     # "cairo-ft-font.c" includes <dlfcn.h>, which only exists on posix platforms
1202     return freetype2_info or (tree_freetype and target.os != "WINNT")
1205 set_config("MOZ_ENABLE_CAIRO_FT", True, when=enable_cairo_ft)
1206 set_config("CAIRO_FT_CFLAGS", ft2_info.cflags, when=enable_cairo_ft)
1209 # WebDriver (HTTP / BiDi)
1210 # ==============================================================
1212 # WebDriver is a remote control interface that enables introspection and
1213 # control of user agents. It provides a platform- and language-neutral wire
1214 # protocol as a way for out-of-process programs to remotely instruct the
1215 # behavior of web browsers.
1217 # The Gecko implementation is backed by Marionette and Remote Agent.
1218 # Both protocols are not really toolkit features, as much as Gecko engine
1219 # features. But they are enabled based on the toolkit, so here it lives.
1221 # Marionette remote protocol
1222 # -----------------------------------------------------------
1224 # Marionette is the Gecko remote protocol used for various remote control,
1225 # automation, and testing purposes throughout Gecko-based applications like
1226 # Firefox, Thunderbird, and any mobile browser built upon GeckoView.
1228 # It also backs ../testing/geckodriver, which is Mozilla's WebDriver
1229 # implementation.
1231 # The source of Marionette lives in ../remote/marionette.
1233 # For more information, see:
1234 # https://firefox-source-docs.mozilla.org/testing/marionette/index.html
1236 # Remote Agent (WebDriver BiDi / partial CDP)
1237 # -----------------------------------------------------------
1239 # The primary purpose is the implementation of the WebDriver BiDi specification.
1240 # But it also complements the existing Firefox Developer Tools Remote Debugging
1241 # Protocol (RDP) by implementing a subset of the Chrome DevTools Protocol (CDP).
1243 # The source of Remote Agent lives in ../remote.
1245 # For more information, see:
1246 # https://firefox-source-docs.mozilla.org/remote/index.html
1249 option(
1250     "--disable-webdriver",
1251     help="Disable support for WebDriver remote protocols",
1255 @depends("--disable-webdriver")
1256 def webdriver(enabled):
1257     if enabled:
1258         return True
1261 set_config("ENABLE_WEBDRIVER", webdriver)
1262 set_define("ENABLE_WEBDRIVER", webdriver)
1265 # geckodriver WebDriver implementation
1266 # ==============================================================
1268 # Turn off geckodriver for build configs we don't handle yet,
1269 # but allow --enable-geckodriver to override when compile environment is available.
1270 # --disable-tests implies disabling geckodriver.
1271 # Disable building in CI
1274 @depends(
1275     "--enable-tests", target, cross_compiling, hazard_analysis, asan, "MOZ_AUTOMATION"
1277 def geckodriver_default(enable_tests, target, cross_compile, hazard, asan, automation):
1278     if not enable_tests:
1279         return False
1280     if hazard or target.os == "Android" or (asan and cross_compile):
1281         return False
1282     if automation:
1283         return False
1284     return True
1287 option(
1288     "--enable-geckodriver",
1289     default=geckodriver_default,
1290     when="--enable-compile-environment",
1291     help="{Build|Do not build} geckodriver",
1295 @depends("--enable-geckodriver", when="--enable-compile-environment")
1296 def geckodriver(enabled):
1297     if enabled:
1298         return True
1301 set_config("MOZ_GECKODRIVER", geckodriver)
1304 # WebRTC
1305 # ========================================================
1306 @depends(target)
1307 def webrtc_default(target):
1308     # Turn off webrtc for OS's we don't handle yet, but allow
1309     # --enable-webrtc to override.
1310     os_match = target.kernel in (
1311         "Linux",
1312         "WINNT",
1313         "DragonFly",
1314         "FreeBSD",
1315         "kFreeBSD",
1316         "NetBSD",
1317         "OpenBSD",
1318     )
1320     if not os_match:
1321         os_match = target.os in ("OSX",)
1323     cpu_match = target.cpu in (
1324         "x86_64",
1325         "arm",
1326         "aarch64",
1327         "x86",
1328         "ia64",
1329         "mips32",
1330         "mips64",
1331         "ppc",
1332         "ppc64",
1333         "riscv64",
1334     )
1336     return os_match and cpu_match and target.endianness == "little"
1339 option(
1340     "--disable-webrtc",
1341     default=webrtc_default,
1342     help="{Enable|Disable} support for WebRTC",
1346 @depends("--disable-webrtc")
1347 def webrtc(enabled):
1348     if enabled:
1349         return True
1352 set_config("MOZ_WEBRTC", webrtc)
1353 set_define("MOZ_WEBRTC", webrtc)
1354 set_config("MOZ_SCTP", webrtc)
1355 set_define("MOZ_SCTP", webrtc)
1356 set_config("MOZ_SRTP", webrtc)
1357 set_define("MOZ_SRTP", webrtc)
1358 set_config("MOZ_WEBRTC_SIGNALING", webrtc)
1359 set_define("MOZ_WEBRTC_SIGNALING", webrtc)
1360 set_config("MOZ_PEERCONNECTION", webrtc)
1361 set_define("MOZ_PEERCONNECTION", webrtc)
1362 # MOZ_WEBRTC_ASSERT_ALWAYS turns on a number of safety asserts in
1363 # opt/production builds (via MOZ_CRASH())
1364 set_config("MOZ_WEBRTC_ASSERT_ALWAYS", webrtc)
1365 set_define("MOZ_WEBRTC_ASSERT_ALWAYS", webrtc)
1367 # RAW media
1368 # ==============================================================
1371 @depends(target, webrtc)
1372 def raw_media_default(target, webrtc):
1373     if target.os == "Android":
1374         return True
1375     if webrtc:
1376         return True
1379 option(
1380     "--enable-raw",
1381     default=raw_media_default,
1382     help="{Enable|Disable} support for RAW media",
1385 set_config("MOZ_RAW", depends_if("--enable-raw")(lambda _: True))
1386 set_define("MOZ_RAW", depends_if("--enable-raw")(lambda _: True))
1389 # X11
1390 # ==============================================================
1391 @depends(webrtc, when=toolkit_gtk)
1392 def x11_libs(webrtc):
1393     libs = [
1394         "x11",
1395         "xcb",
1396         "xcb-shm",
1397         "x11-xcb",
1398         "xext",
1399         "xrandr >= 1.4.0",
1400     ]
1401     if webrtc:
1402         # third_party/libwebrtc/webrtc/webrtc_gn/moz.build adds those
1403         # manually, ensure they're available.
1404         libs += [
1405             "xcomposite",
1406             "xcursor",
1407             "xdamage",
1408             "xfixes",
1409             "xi",
1410         ]
1411     return libs
1414 x11_headers = pkg_check_modules(
1415     "MOZ_X11",
1416     x11_libs,
1417     allow_missing=toolkit_gtk_x11_optional,
1418     when=toolkit_gtk_x11,
1422 set_config("MOZ_X11", True, when=x11_headers)
1423 set_define("MOZ_X11", True, when=x11_headers)
1425 pkg_check_modules(
1426     "MOZ_X11_SM",
1427     ["ice", "sm"],
1428     cflags_only=True,
1429     allow_missing=toolkit_gtk_x11_optional,
1430     when=toolkit_gtk_x11,
1434 # ASan Reporter Addon
1435 # ==============================================================
1436 option(
1437     "--enable-address-sanitizer-reporter",
1438     help="Enable Address Sanitizer Reporter Extension",
1442 @depends("--enable-address-sanitizer-reporter")
1443 def enable_asan_reporter(value):
1444     if value:
1445         return True
1448 set_config("MOZ_ASAN_REPORTER", enable_asan_reporter)
1449 set_define("MOZ_ASAN_REPORTER", enable_asan_reporter)
1451 # Checks for library functions
1452 # ==============================================================
1453 with only_when(compile_environment & depends(target.os)(lambda os: os != "WINNT")):
1454     set_define("HAVE_STAT64", check_symbol("stat64"))
1455     set_define("HAVE_LSTAT64", check_symbol("lstat64"))
1456     set_define("HAVE_TRUNCATE64", check_symbol("truncate64"))
1457     set_define("HAVE_STATVFS64", check_symbol("statvfs64"))
1458     set_define("HAVE_STATVFS", check_symbol("statvfs"))
1459     set_define("HAVE_STATFS64", check_symbol("statfs64"))
1460     set_define("HAVE_STATFS", check_symbol("statfs"))
1461     set_define("HAVE_LUTIMES", check_symbol("lutimes"))
1462     set_define("HAVE_POSIX_FADVISE", check_symbol("posix_fadvise"))
1463     set_define("HAVE_POSIX_FALLOCATE", check_symbol("posix_fallocate"))
1464     set_define("HAVE_EVENTFD", check_symbol("eventfd"))
1466     have_arc4random = check_symbol("arc4random")
1467     set_define("HAVE_ARC4RANDOM", have_arc4random)
1468     set_define("HAVE_ARC4RANDOM_BUF", check_symbol("arc4random_buf"))
1469     set_define("HAVE_MALLINFO", check_symbol("mallinfo"))
1471 # Checks for headers
1472 # ==============================================================
1473 with only_when(compile_environment & depends(target.os)(lambda os: os != "WINNT")):
1474     set_define("HAVE_SYSIOCCOM_H", check_header("sys/ioccom.h"))
1476 # Elfhack
1477 # ==============================================================
1478 with only_when("--enable-compile-environment"):
1480     @depends(host, target)
1481     def has_elfhack(host, target):
1482         return (
1483             target.kernel == "Linux"
1484             and host.kernel == "Linux"
1485             and target.cpu in ("arm", "aarch64", "x86", "x86_64")
1486         )
1488     option(
1489         "--disable-elf-hack",
1490         nargs="?",
1491         choices=("legacy", "relr"),
1492         help="{Enable|Disable} elf hacks",
1493         when=has_elfhack,
1494     )
1496     @depends("--enable-elf-hack", when=has_elfhack)
1497     def may_enable_legacy_elfhack(enable):
1498         if enable and enable != ("relr",):
1499             return enable
1501     @depends("--enable-elf-hack", when=has_elfhack)
1502     def may_enable_relrhack(enable):
1503         if enable and enable != ("legacy",):
1504             return enable
1506     @depends(
1507         have_arc4random,
1508         android_version,
1509         when=target_has_linux_kernel,
1510     )
1511     def may_use_pack_relative_relocs(have_arc4random, android_version):
1512         # Packed relative relocations are only supported on Android since
1513         # version 11 (API 30), and in glibc since version 2.36.
1514         # glibc 2.36 also added the arc4random function, which is our proxy
1515         # to detect this (or newer) version being used.
1516         # When targetting those newer versions, we allow ourselves to use
1517         # packed relative relocations rather than elfhack.
1518         if android_version:
1519             return android_version >= 30
1520         return have_arc4random
1522     @depends(
1523         c_compiler,
1524         extra_toolchain_flags,
1525         linker_ldflags,
1526         readelf,
1527         when=may_use_pack_relative_relocs | may_enable_relrhack,
1528     )
1529     @checking("for -z pack-relative-relocs option to ld", bool)
1530     @imports(_from="__builtin__", _import="FileNotFoundError")
1531     @imports("os")
1532     @imports(_from="tempfile", _import="mkstemp")
1533     @imports("textwrap")
1534     def has_pack_relative_relocs(
1535         c_compiler,
1536         extra_toolchain_flags,
1537         linker_ldflags,
1538         readelf,
1539     ):
1540         try:
1541             fd, path = mkstemp(prefix="conftest.")
1542             os.close(fd)
1544             pack_rel_relocs = ["-Wl,-z,pack-relative-relocs"]
1545             if (
1546                 try_invoke_compiler(
1547                     # No configure_cache because it would not create the
1548                     # expected output file.
1549                     None,
1550                     [c_compiler.compiler] + c_compiler.flags,
1551                     c_compiler.language,
1552                     # The resulting binary is expected to have relative
1553                     # relocations, the `ptr` variable attempts to ensure
1554                     # there is at least one. This requires the executable
1555                     # being built as position independent.
1556                     "int main() { return 0; }\nint (*ptr)() = main;",
1557                     pack_rel_relocs
1558                     + ["-pie", "-o", path]
1559                     + (extra_toolchain_flags or [])
1560                     + linker_ldflags,
1561                     wrapper=c_compiler.wrapper,
1562                     onerror=lambda: None,
1563                 )
1564                 is not None
1565             ):
1566                 # BFD ld ignores options it doesn't understand. So check
1567                 # that we did get packed relative relocations (DT_RELR).
1568                 env = os.environ.copy()
1569                 env["LANG"] = "C"
1570                 dyn = check_cmd_output(readelf, "-d", path, env=env).splitlines()
1571                 tags = [
1572                     int(l.split()[0], 16) for l in dyn if l.strip().startswith("0x")
1573                 ]
1574                 # Older versions of readelf don't know about DT_RELR but will
1575                 # still display the tag number.
1576                 if 0x23 in tags:
1577                     needed = [l for l in dyn if l.split()[1:2] == ["(NEEDED)"]]
1578                     is_glibc = any(l.endswith("[libc.so.6]") for l in needed)
1579                     # The mold linker doesn't add a GLIBC_ABI_DT_RELR version
1580                     # dependency, which ld.so doesn't like.
1581                     # https://github.com/rui314/mold/issues/653#issuecomment-1670274638
1582                     if is_glibc:
1583                         versions = check_cmd_output(readelf, "-V", path, env=env)
1584                         if "GLIBC_ABI_DT_RELR" in versions.split():
1585                             return pack_rel_relocs
1586                     else:
1587                         return pack_rel_relocs
1588         finally:
1589             try:
1590                 os.remove(path)
1591             except FileNotFoundError:
1592                 pass
1594     @depends(
1595         has_pack_relative_relocs,
1596         may_enable_legacy_elfhack,
1597         may_enable_relrhack,
1598         may_use_pack_relative_relocs,
1599         when=has_pack_relative_relocs,
1600     )
1601     def pack_relative_relocs_flags(
1602         flags,
1603         may_enable_legacy_elfhack,
1604         may_enable_relrhack,
1605         may_use_pack_relative_relocs,
1606     ):
1607         # When relrhack is enabled, we don't pass the flag to the linker because
1608         # relrhack will take care of it.
1609         if may_enable_relrhack and may_enable_relrhack.origin != "default":
1610             return None
1611         # if elfhack is explicitly enabled instead of relrhack, we prioritize it
1612         # over packed relative relocs.
1613         if may_enable_legacy_elfhack and may_enable_legacy_elfhack.origin != "default":
1614             return None
1615         if may_use_pack_relative_relocs:
1616             return flags
1618     add_old_configure_assignment("PACK_REL_RELOC_FLAGS", pack_relative_relocs_flags)
1620     @depends(
1621         select_linker,
1622         pack_relative_relocs_flags,
1623         has_pack_relative_relocs,
1624         may_enable_legacy_elfhack,
1625         may_enable_relrhack,
1626         when=has_elfhack,
1627     )
1628     def which_elf_hack(
1629         linker,
1630         pack_relative_relocs_flags,
1631         has_pack_relative_relocs,
1632         may_enable_legacy_elfhack,
1633         may_enable_relrhack,
1634     ):
1635         if pack_relative_relocs_flags:
1636             return
1637         if may_enable_relrhack:
1638             if has_pack_relative_relocs:
1639                 return "relr"
1640             elif (
1641                 may_enable_relrhack.origin != "default"
1642                 and not may_enable_legacy_elfhack
1643             ):
1644                 die(
1645                     "Cannot enable relrhack without linker support for -z pack-relative-relocs"
1646                 )
1647         if may_enable_legacy_elfhack:
1648             if linker and linker.KIND in ("lld", "mold"):
1649                 if may_enable_legacy_elfhack.origin != "default":
1650                     die(
1651                         f"Cannot enable elfhack with {linker.KIND}."
1652                         " Use --enable-linker=bfd, --enable-linker=gold, or --disable-elf-hack"
1653                     )
1654             else:
1655                 return "legacy"
1657     set_config(
1658         "USE_ELF_HACK", True, when=depends(which_elf_hack)(lambda x: x == "legacy")
1659     )
1661     use_relrhack = depends(which_elf_hack)(lambda x: x == "relr")
1662     set_config("RELRHACK", True, when=use_relrhack)
1664     @depends(c_compiler, linker_ldflags, when=use_relrhack)
1665     def relrhack_real_linker(c_compiler, linker_ldflags):
1666         ld = "ld"
1667         for flag in linker_ldflags:
1668             if flag.startswith("-fuse-ld="):
1669                 ld = "ld." + flag[len("-fuse-ld=") :]
1670         ld = check_cmd_output(
1671             c_compiler.compiler, f"--print-prog-name={ld}", *c_compiler.flags
1672         )
1673         return ld.rstrip()
1675     @depends(relrhack_real_linker, when=use_relrhack)
1676     def relrhack_linker(ld):
1677         return os.path.basename(ld)
1679     set_config("RELRHACK_LINKER", relrhack_linker)
1681     std_filesystem = host_cxx_compiler.try_run(
1682         header="#include <filesystem>",
1683         body='auto foo = std::filesystem::absolute("");',
1684         flags=host_linker_ldflags,
1685         when=use_relrhack,
1686         onerror=lambda: None,
1687     )
1689     stdcxxfs = host_cxx_compiler.try_run(
1690         header="#include <filesystem>",
1691         body='auto foo = std::filesystem::absolute("");',
1692         flags=depends(host_linker_ldflags)(
1693             lambda flags: (flags or []) + ["-lstdc++fs"]
1694         ),
1695         check_msg="whether std::filesystem requires -lstdc++fs",
1696         when=use_relrhack & depends(std_filesystem)(lambda x: not x),
1697         onerror=lambda: None,
1698     )
1700     set_config("RELRHACK_LIBS", ["stdc++fs"], when=stdcxxfs)
1702     @depends(build_environment, relrhack_real_linker, when=use_relrhack)
1703     def relrhack_ldflags(build_env, ld):
1704         flags = [
1705             "-B",
1706             os.path.join(build_env.topobjdir, "build", "unix", "elfhack"),
1707         ]
1708         if os.path.basename(ld) != ld:
1709             flags.append(f"-Wl,--real-linker,{ld}")
1710         return flags
1712     set_config("RELRHACK_LDFLAGS", relrhack_ldflags)
1715 @depends(build_environment)
1716 def idl_roots(build_env):
1717     return namespace(
1718         ipdl_root=os.path.join(build_env.topobjdir, "ipc", "ipdl"),
1719         webidl_root=os.path.join(build_env.topobjdir, "dom", "bindings"),
1720         xpcom_root=os.path.join(build_env.topobjdir, "xpcom", "components"),
1721     )
1724 set_config("WEBIDL_ROOT", idl_roots.webidl_root)
1725 set_config("IPDL_ROOT", idl_roots.ipdl_root)
1726 set_config("XPCOM_ROOT", idl_roots.xpcom_root)
1728 # Proxy bypass protection
1729 # ==============================================================
1731 option(
1732     "--enable-proxy-bypass-protection",
1733     help="Prevent suspected or confirmed proxy bypasses",
1737 @depends_if("--enable-proxy-bypass-protection")
1738 def proxy_bypass_protection(_):
1739     return True
1742 set_config("MOZ_PROXY_BYPASS_PROTECTION", proxy_bypass_protection)
1743 set_define("MOZ_PROXY_BYPASS_PROTECTION", proxy_bypass_protection)
1745 # Proxy direct failover
1746 # ==============================================================
1748 option(
1749     "--disable-proxy-direct-failover",
1750     help="Disable direct failover for system requests",
1754 @depends_if("--disable-proxy-direct-failover")
1755 def proxy_direct_failover(value):
1756     if value:
1757         return True
1760 set_config("MOZ_PROXY_DIRECT_FAILOVER", proxy_direct_failover)
1761 set_define("MOZ_PROXY_DIRECT_FAILOVER", proxy_direct_failover)
1763 # MIDL
1764 # ==============================================================
1767 @depends(c_compiler, toolchain_prefix)
1768 def midl_names(c_compiler, toolchain_prefix):
1769     if c_compiler and c_compiler.type in ["gcc", "clang"]:
1770         # mingw
1771         widl = ("widl",)
1772         if toolchain_prefix:
1773             prefixed = tuple("%s%s" % (p, "widl") for p in toolchain_prefix)
1774             widl = prefixed + widl
1775         return widl
1777     return ("midl.exe",)
1780 @depends(target, "--enable-compile-environment")
1781 def check_for_midl(target, compile_environment):
1782     if target.os != "WINNT":
1783         return
1785     if compile_environment:
1786         return True
1789 midl = check_prog(
1790     "MIDL",
1791     midl_names,
1792     when=check_for_midl,
1793     allow_missing=True,
1794     paths=sdk_bin_path,
1795     # MIDL being used from a python wrapper script, we can live with it
1796     # having spaces.
1797     allow_spaces=True,
1800 option(env="MIDL_FLAGS", nargs=1, help="Extra flags to pass to MIDL")
1803 @depends(
1804     "MIDL_FLAGS",
1805     target,
1806     midl,
1807     when=depends(midl, target)(lambda m, t: m and t.kernel == "WINNT"),
1809 def midl_flags(flags, target, midl):
1810     if flags:
1811         flags = flags[0].split()
1812     else:
1813         flags = []
1815     if not midl.endswith("widl"):
1816         env = {
1817             "x86": "win32",
1818             "x86_64": "x64",
1819             "aarch64": "arm64",
1820         }[target.cpu]
1821         return flags + ["-nologo", "-no_cpp", "-env", env]
1823     # widl
1824     return (
1825         flags
1826         + {
1827             "x86": ["--win32", "-m32"],
1828             "x86_64": ["--win64", "-m64"],
1829         }[target.cpu]
1830     )
1833 set_config("MIDL_FLAGS", midl_flags)
1835 # Accessibility
1836 # ==============================================================
1838 option("--disable-accessibility", help="Disable accessibility support")
1841 @depends("--enable-accessibility", check_for_midl, midl, c_compiler)
1842 def accessibility(value, check_for_midl, midl, c_compiler):
1843     enabled = bool(value)
1845     if not enabled:
1846         return
1848     if check_for_midl and not midl:
1849         if c_compiler and c_compiler.type in ("gcc", "clang"):
1850             die(
1851                 "You have accessibility enabled, but widl could not be found. "
1852                 "Add --disable-accessibility to your mozconfig or install widl. "
1853                 "See https://developer.mozilla.org/en-US/docs/Cross_Compile_Mozilla_for_Mingw32 for details."
1854             )
1855         else:
1856             die(
1857                 "MIDL could not be found. "
1858                 "Building accessibility without MIDL is not supported."
1859             )
1861     return enabled
1864 set_config("ACCESSIBILITY", accessibility)
1865 set_define("ACCESSIBILITY", accessibility)
1868 @depends(moz_debug, developer_options)
1869 def a11y_log(debug, developer_options):
1870     return debug or developer_options
1873 set_config("A11Y_LOG", True, when=a11y_log)
1874 set_define("A11Y_LOG", True, when=a11y_log)
1877 # Addon signing
1878 # ==============================================================
1879 @depends(milestone)
1880 def require_signing(milestone):
1881     return milestone.is_release_or_beta and not milestone.is_esr
1884 option(
1885     env="MOZ_REQUIRE_SIGNING",
1886     default=require_signing,
1887     help="Enforce that add-ons are signed by the trusted root",
1890 set_config("MOZ_REQUIRE_SIGNING", True, when="MOZ_REQUIRE_SIGNING")
1891 set_define("MOZ_REQUIRE_SIGNING", True, when="MOZ_REQUIRE_SIGNING")
1893 option(
1894     "--with-unsigned-addon-scopes",
1895     nargs="+",
1896     choices=("app", "system"),
1897     help="Addon scopes where signature is not required",
1901 @depends("--with-unsigned-addon-scopes")
1902 def unsigned_addon_scopes(scopes):
1903     return namespace(
1904         app="app" in scopes or None,
1905         system="system" in scopes or None,
1906     )
1909 set_config("MOZ_UNSIGNED_APP_SCOPE", unsigned_addon_scopes.app)
1910 set_config("MOZ_UNSIGNED_SYSTEM_SCOPE", unsigned_addon_scopes.system)
1913 # Addon sideloading
1914 # ==============================================================
1915 option(
1916     "--allow-addon-sideload",
1917     default=milestone.is_esr,
1918     help="Addon sideloading is allowed",
1922 set_config("MOZ_ALLOW_ADDON_SIDELOAD", True, when="--allow-addon-sideload")
1924 # WebExtensions API WebIDL bindings
1925 # ==============================================================
1928 @depends(milestone)
1929 def extensions_webidl_bindings_default(milestone):
1930     # Only enable the webidl bindings for the WebExtensions APIs
1931     # in Nightly.
1932     return milestone.is_nightly
1935 option(
1936     "--enable-extensions-webidl-bindings",
1937     default=extensions_webidl_bindings_default,
1938     help="{Enable|Disable} building experimental WebExtensions WebIDL bindings",
1942 @depends("--enable-extensions-webidl-bindings")
1943 def extensions_webidl_enabled(value):
1944     return bool(value)
1947 set_config("MOZ_WEBEXT_WEBIDL_ENABLED", extensions_webidl_enabled)
1949 # Launcher process (Windows only)
1950 # ==============================================================
1953 @depends(target)
1954 def launcher_process_default(target):
1955     return target.os == "WINNT"
1958 option(
1959     "--enable-launcher-process",
1960     default=launcher_process_default,
1961     help="{Enable|Disable} launcher process by default",
1965 @depends("--enable-launcher-process", target)
1966 def launcher(value, target):
1967     enabled = bool(value)
1968     if enabled and target.os != "WINNT":
1969         die("Cannot enable launcher process on %s", target.os)
1970     if enabled:
1971         return True
1974 set_config("MOZ_LAUNCHER_PROCESS", launcher)
1975 set_define("MOZ_LAUNCHER_PROCESS", launcher)
1977 # llvm-dlltool (Windows only)
1978 # ==============================================================
1981 @depends(build_project, target, "--enable-compile-environment")
1982 def check_for_llvm_dlltool(build_project, target, compile_environment):
1983     if build_project != "browser":
1984         return
1986     if target.os != "WINNT":
1987         return
1989     return compile_environment
1992 llvm_dlltool = check_prog(
1993     "LLVM_DLLTOOL",
1994     ("llvm-dlltool",),
1995     what="llvm-dlltool",
1996     when=check_for_llvm_dlltool,
1997     paths=clang_search_path,
2001 @depends(target, when=llvm_dlltool)
2002 def llvm_dlltool_flags(target):
2003     arch = {
2004         "x86": "i386",
2005         "x86_64": "i386:x86-64",
2006         "aarch64": "arm64",
2007     }[target.cpu]
2009     return ["-m", arch]
2012 set_config("LLVM_DLLTOOL_FLAGS", llvm_dlltool_flags)
2014 # BITS download (Windows only)
2015 # ==============================================================
2017 option(
2018     "--enable-bits-download",
2019     when=target_is_windows,
2020     default=target_is_windows,
2021     help="{Enable|Disable} building BITS download support",
2024 set_define(
2025     "MOZ_BITS_DOWNLOAD",
2026     depends_if("--enable-bits-download", when=target_is_windows)(lambda _: True),
2028 set_config(
2029     "MOZ_BITS_DOWNLOAD",
2030     depends_if("--enable-bits-download", when=target_is_windows)(lambda _: True),
2033 # Bundled fonts on desktop platform
2034 # ==============================================================
2037 @depends(target)
2038 def bundled_fonts_default(target):
2039     return target.os == "WINNT" or target.kernel == "Linux"
2042 @depends(build_project)
2043 def allow_bundled_fonts(project):
2044     return project == "browser" or project == "comm/mail"
2047 option(
2048     "--enable-bundled-fonts",
2049     default=bundled_fonts_default,
2050     when=allow_bundled_fonts,
2051     help="{Enable|Disable} support for bundled fonts on desktop platforms",
2054 set_define(
2055     "MOZ_BUNDLED_FONTS",
2056     depends_if("--enable-bundled-fonts", when=allow_bundled_fonts)(lambda _: True),
2059 # Reflow counting
2060 # ==============================================================
2063 @depends(moz_debug)
2064 def reflow_perf(debug):
2065     if debug:
2066         return True
2069 option(
2070     "--enable-reflow-perf",
2071     default=reflow_perf,
2072     help="{Enable|Disable} reflow performance tracing",
2075 # The difference in conditions here comes from the initial implementation
2076 # in old-configure, which was unexplained there as well.
2077 set_define("MOZ_REFLOW_PERF", depends_if("--enable-reflow-perf")(lambda _: True))
2078 set_define("MOZ_REFLOW_PERF_DSP", reflow_perf)
2080 # Layout debugger
2081 # ==============================================================
2084 @depends(moz_debug)
2085 def layout_debugger(debug):
2086     if debug:
2087         return True
2090 option(
2091     "--enable-layout-debugger",
2092     default=layout_debugger,
2093     help="{Enable|Disable} layout debugger",
2096 set_config("MOZ_LAYOUT_DEBUGGER", True, when="--enable-layout-debugger")
2097 set_define("MOZ_LAYOUT_DEBUGGER", True, when="--enable-layout-debugger")
2100 # Shader Compiler for Windows (and MinGW Cross Compile)
2101 # ==============================================================
2103 with only_when(compile_environment):
2104     fxc = check_prog(
2105         "FXC",
2106         ("fxc.exe", "fxc2.exe"),
2107         when=depends(target)(lambda t: t.kernel == "WINNT"),
2108         paths=sdk_bin_path,
2109         # FXC being used from a python wrapper script, we can live with it
2110         # having spaces.
2111         allow_spaces=True,
2112     )
2115 # VPX
2116 # ===
2118 with only_when(compile_environment):
2119     system_lib_option(
2120         "--with-system-libvpx", help="Use system libvpx (located with pkgconfig)"
2121     )
2123     with only_when("--with-system-libvpx"):
2124         vpx = pkg_check_modules("MOZ_LIBVPX", "vpx >= 1.10.0")
2126         check_header(
2127             "vpx/vpx_decoder.h",
2128             flags=vpx.cflags,
2129             onerror=lambda: die(
2130                 "Couldn't find vpx/vpx_decoder.h, which is required to build "
2131                 "with system libvpx. Use --without-system-libvpx to build "
2132                 "with in-tree libvpx."
2133             ),
2134         )
2136         check_symbol(
2137             "vpx_codec_dec_init_ver",
2138             flags=vpx.libs,
2139             onerror=lambda: die(
2140                 "--with-system-libvpx requested but symbol vpx_codec_dec_init_ver "
2141                 "not found"
2142             ),
2143         )
2145         set_config("MOZ_SYSTEM_LIBVPX", True)
2147     @depends("--with-system-libvpx", target)
2148     def in_tree_vpx(system_libvpx, target):
2149         if system_libvpx:
2150             return
2152         arm_asm = (target.cpu == "arm") or None
2153         return namespace(arm_asm=arm_asm)
2155     @depends(target, when=in_tree_vpx)
2156     def vpx_nasm(target):
2157         if target.cpu in ("x86", "x86_64"):
2158             if target.kernel == "WINNT":
2159                 # Version 2.03 is needed for automatic safeseh support.
2160                 return namespace(version="2.03", what="VPX")
2161             return namespace(what="VPX")
2163     @depends(in_tree_vpx, vpx_nasm, target, neon_flags)
2164     def vpx_as_flags(vpx, vpx_nasm, target, neon_flags):
2165         if vpx and vpx.arm_asm:
2166             # These flags are a lie; they're just used to enable the requisite
2167             # opcodes; actual arch detection is done at runtime.
2168             return neon_flags
2169         elif vpx and vpx_nasm and target.os != "WINNT" and target.cpu != "x86_64":
2170             return ("-DPIC",)
2172     set_config("VPX_USE_NASM", True, when=vpx_nasm)
2173     set_config("VPX_ASFLAGS", vpx_as_flags)
2176 # JPEG
2177 # ====
2179 with only_when(compile_environment):
2180     system_lib_option(
2181         "--with-system-jpeg",
2182         nargs="?",
2183         help="Use system libjpeg (installed at given prefix)",
2184     )
2186     @depends_if("--with-system-jpeg")
2187     def jpeg_flags(value):
2188         if len(value):
2189             return namespace(
2190                 cflags=("-I%s/include" % value[0],),
2191                 ldflags=("-L%s/lib" % value[0], "-ljpeg"),
2192             )
2193         return namespace(
2194             ldflags=("-ljpeg",),
2195         )
2197     with only_when("--with-system-jpeg"):
2198         check_symbol(
2199             "jpeg_destroy_compress",
2200             flags=jpeg_flags.ldflags,
2201             onerror=lambda: die(
2202                 "--with-system-jpeg requested but symbol "
2203                 "jpeg_destroy_compress not found."
2204             ),
2205         )
2207         c_compiler.try_compile(
2208             includes=[
2209                 "stdio.h",
2210                 "sys/types.h",
2211                 "jpeglib.h",
2212             ],
2213             body="""
2214                 #if JPEG_LIB_VERSION < 62
2215                 #error Insufficient JPEG library version
2216                 #endif
2217             """,
2218             flags=jpeg_flags.cflags,
2219             check_msg="for sufficient jpeg library version",
2220             onerror=lambda: die(
2221                 "Insufficient JPEG library version for "
2222                 "--with-system-jpeg (62 required)"
2223             ),
2224         )
2226         c_compiler.try_compile(
2227             includes=[
2228                 "stdio.h",
2229                 "sys/types.h",
2230                 "jpeglib.h",
2231             ],
2232             body="""
2233                 #ifndef JCS_EXTENSIONS
2234                 #error libjpeg-turbo JCS_EXTENSIONS required
2235                 #endif
2236             """,
2237             flags=jpeg_flags.cflags,
2238             check_msg="for sufficient libjpeg-turbo JCS_EXTENSIONS",
2239             onerror=lambda: die(
2240                 "libjpeg-turbo JCS_EXTENSIONS required for " "--with-system-jpeg"
2241             ),
2242         )
2244         set_config("MOZ_JPEG_CFLAGS", jpeg_flags.cflags)
2245         set_config("MOZ_JPEG_LIBS", jpeg_flags.ldflags)
2247     @depends("--with-system-jpeg", target, neon_flags)
2248     def in_tree_jpeg_arm(system_jpeg, target, neon_flags):
2249         if system_jpeg:
2250             return
2252         if target.cpu == "arm":
2253             return neon_flags
2254         elif target.cpu == "aarch64":
2255             return ("-march=armv8-a",)
2257     @depends("--with-system-jpeg", target)
2258     def in_tree_jpeg_mips64(system_jpeg, target):
2259         if system_jpeg:
2260             return
2262         if target.cpu == "mips64":
2263             return ("-Wa,-mloongson-mmi", "-mloongson-ext")
2265     # Compiler check from https://github.com/libjpeg-turbo/libjpeg-turbo/blob/57ba02a408a9a55ccff25aae8b164632a3a4f177/simd/CMakeLists.txt#L419
2266     jpeg_mips64_mmi = c_compiler.try_compile(
2267         body='int c = 0, a = 0, b = 0; asm("paddb %0, %1, %2" : "=f" (c) : "f" (a), "f" (b));',
2268         check_msg="for loongson mmi support",
2269         flags=in_tree_jpeg_mips64,
2270         when=in_tree_jpeg_mips64,
2271     )
2273     @depends(
2274         "--with-system-jpeg",
2275         target,
2276         in_tree_jpeg_arm,
2277         in_tree_jpeg_mips64,
2278         jpeg_mips64_mmi,
2279     )
2280     def in_tree_jpeg(
2281         system_jpeg, target, in_tree_jpeg_arm, in_tree_jpeg_mips64, jpeg_mips64_mmi
2282     ):
2283         if system_jpeg:
2284             return
2286         if target.cpu in ("arm", "aarch64"):
2287             return in_tree_jpeg_arm
2288         elif target.kernel == "Darwin":
2289             if target.cpu == "x86":
2290                 return ("-DPIC", "-DMACHO")
2291             elif target.cpu == "x86_64":
2292                 return ("-D__x86_64__", "-DPIC", "-DMACHO")
2293         elif target.kernel == "WINNT":
2294             if target.cpu == "x86":
2295                 return ("-DPIC", "-DWIN32")
2296             elif target.cpu == "x86_64":
2297                 return ("-D__x86_64__", "-DPIC", "-DWIN64", "-DMSVC")
2298         elif target.cpu == "mips32":
2299             return ("-mdspr2",)
2300         elif target.cpu == "mips64" and jpeg_mips64_mmi:
2301             return in_tree_jpeg_mips64
2302         elif target.cpu == "x86":
2303             return ("-DPIC", "-DELF")
2304         elif target.cpu == "x86_64":
2305             return ("-D__x86_64__", "-DPIC", "-DELF")
2307     @depends(target, when=depends("--with-system-jpeg")(lambda x: not x))
2308     def jpeg_nasm(target):
2309         if target.cpu in ("x86", "x86_64"):
2310             # libjpeg-turbo 2.0.6 requires nasm 2.10.
2311             return namespace(version="2.10", what="JPEG")
2313     # Compiler checks from https://github.com/libjpeg-turbo/libjpeg-turbo/blob/57ba02a408a9a55ccff25aae8b164632a3a4f177/simd/CMakeLists.txt#L258
2314     jpeg_arm_neon_vld1_s16_x3 = c_compiler.try_compile(
2315         includes=["arm_neon.h"],
2316         body="int16_t input[12] = {}; int16x4x3_t output = vld1_s16_x3(input);",
2317         check_msg="for vld1_s16_x3 in arm_neon.h",
2318         flags=in_tree_jpeg_arm,
2319         when=in_tree_jpeg_arm,
2320     )
2322     jpeg_arm_neon_vld1_u16_x2 = c_compiler.try_compile(
2323         includes=["arm_neon.h"],
2324         body="uint16_t input[8] = {}; uint16x4x2_t output = vld1_u16_x2(input);",
2325         check_msg="for vld1_u16_x2 in arm_neon.h",
2326         flags=in_tree_jpeg_arm,
2327         when=in_tree_jpeg_arm,
2328     )
2330     jpeg_arm_neon_vld1q_u8_x4 = c_compiler.try_compile(
2331         includes=["arm_neon.h"],
2332         body="uint8_t input[64] = {}; uint8x16x4_t output = vld1q_u8_x4(input);",
2333         check_msg="for vld1q_u8_x4 in arm_neon.h",
2334         flags=in_tree_jpeg_arm,
2335         when=in_tree_jpeg_arm,
2336     )
2338     set_config("LIBJPEG_TURBO_USE_NASM", True, when=jpeg_nasm)
2339     set_config("LIBJPEG_TURBO_SIMD_FLAGS", in_tree_jpeg)
2340     set_config("LIBJPEG_TURBO_HAVE_VLD1_S16_X3", jpeg_arm_neon_vld1_s16_x3)
2341     set_config("LIBJPEG_TURBO_HAVE_VLD1_U16_X2", jpeg_arm_neon_vld1_u16_x2)
2342     set_config("LIBJPEG_TURBO_HAVE_VLD1Q_U8_X4", jpeg_arm_neon_vld1q_u8_x4)
2343     set_config(
2344         "LIBJPEG_TURBO_NEON_INTRINSICS",
2345         jpeg_arm_neon_vld1_s16_x3
2346         & jpeg_arm_neon_vld1_u16_x2
2347         & jpeg_arm_neon_vld1q_u8_x4,
2348     )
2351 # PNG
2352 # ===
2353 with only_when(compile_environment):
2354     system_lib_option(
2355         "--with-system-png",
2356         nargs="?",
2357         help="Use system libpng",
2358     )
2360     @depends("--with-system-png")
2361     def deprecated_system_png_path(value):
2362         if len(value) == 1:
2363             die(
2364                 "--with-system-png=PATH is not supported anymore. Please use "
2365                 "--with-system-png and set any necessary pkg-config environment variable."
2366             )
2368     png = pkg_check_modules("MOZ_PNG", "libpng >= 1.6.35", when="--with-system-png")
2370     check_symbol(
2371         "png_get_acTL",
2372         flags=png.libs,
2373         onerror=lambda: die(
2374             "--with-system-png won't work because the system's libpng doesn't have APNG support"
2375         ),
2376         when="--with-system-png",
2377     )
2379     set_config("MOZ_SYSTEM_PNG", True, when="--with-system-png")
2382 # FFmpeg's ffvpx configuration
2383 # ==============================================================
2384 with only_when(compile_environment):
2386     @depends(target)
2387     def libav_fft(target):
2388         if target.os == "Android" and target.cpu != "arm":
2389             return True
2390         return target.kernel in ("WINNT", "Darwin") or target.cpu == "x86_64"
2392     set_config("MOZ_LIBAV_FFT", depends(when=libav_fft)(lambda: True))
2393     set_define("MOZ_LIBAV_FFT", depends(when=libav_fft)(lambda: True))
2396 # Artifact builds need MOZ_FFVPX defined as if compilation happened.
2397 with only_when(compile_environment | artifact_builds):
2399     @depends(target)
2400     def ffvpx(target):
2401         enable = use_nasm = True
2402         flac_only = False
2403         flags = []
2405         if target.kernel == "WINNT":
2406             if target.cpu == "x86":
2407                 # 32-bit windows need to prefix symbols with an underscore.
2408                 flags = ["-DPIC", "-DWIN32", "-DPREFIX", "-Pconfig_win32.asm"]
2409             elif target.cpu == "x86_64":
2410                 flags = [
2411                     "-D__x86_64__",
2412                     "-DPIC",
2413                     "-DWIN64",
2414                     "-DMSVC",
2415                     "-Pconfig_win64.asm",
2416                 ]
2417             elif target.cpu == "aarch64":
2418                 flags = ["-DPIC", "-DWIN64"]
2419                 use_nasm = False
2420         elif target.kernel == "Darwin":
2421             # 32/64-bit macosx assemblers need to prefix symbols with an
2422             # underscore.
2423             flags = ["-DPIC", "-DMACHO", "-DPREFIX"]
2424             if target.cpu == "x86_64":
2425                 flags += [
2426                     "-D__x86_64__",
2427                     "-Pconfig_darwin64.asm",
2428                 ]
2429             elif target.cpu == "aarch64":
2430                 use_nasm = False
2431         elif target.cpu == "x86_64":
2432             flags = ["-D__x86_64__", "-DPIC", "-DELF", "-Pconfig_unix64.asm"]
2433         elif target.cpu in ("x86", "arm", "aarch64"):
2434             flac_only = True
2435         else:
2436             enable = False
2438         if flac_only or not enable:
2439             use_nasm = False
2441         return namespace(
2442             enable=enable,
2443             use_nasm=use_nasm,
2444             flac_only=flac_only,
2445             flags=flags,
2446         )
2448     @depends(when=ffvpx.use_nasm)
2449     def ffvpx_nasm():
2450         # nasm 2.10 for AVX-2 support.
2451         return namespace(version="2.10", what="FFVPX")
2453     # ffvpx_nasm can't indirectly depend on vpx_as_flags, because it depends
2454     # on a compiler test, so we have to do a little bit of dance here.
2455     @depends(ffvpx, vpx_as_flags, target)
2456     def ffvpx(ffvpx, vpx_as_flags, target):
2457         if ffvpx and vpx_as_flags and target.cpu in ("arm", "aarch64"):
2458             ffvpx.flags.extend(vpx_as_flags)
2459         return ffvpx
2461     set_config("MOZ_FFVPX", True, when=ffvpx.enable)
2462     set_define("MOZ_FFVPX", True, when=ffvpx.enable)
2463     set_config("MOZ_FFVPX_AUDIOONLY", True, when=ffvpx.flac_only)
2464     set_define("MOZ_FFVPX_AUDIOONLY", True, when=ffvpx.flac_only)
2465     set_config("FFVPX_ASFLAGS", ffvpx.flags)
2466     set_config("FFVPX_USE_NASM", True, when=ffvpx.use_nasm)
2469 # nasm detection
2470 # ==============================================================
2471 @depends(dav1d_nasm, vpx_nasm, jpeg_nasm, ffvpx_nasm, when=compile_environment)
2472 def need_nasm(*requirements):
2473     requires = {
2474         x.what: x.version if hasattr(x, "version") else True for x in requirements if x
2475     }
2476     if requires:
2477         items = sorted(requires.keys())
2478         if len(items) > 1:
2479             what = " and ".join((", ".join(items[:-1]), items[-1]))
2480         else:
2481             what = items[0]
2482         versioned = {k: v for (k, v) in requires.items() if v is not True}
2483         return namespace(what=what, versioned=versioned)
2486 nasm = check_prog(
2487     "NASM",
2488     ["nasm"],
2489     allow_missing=True,
2490     bootstrap="nasm",
2491     when=need_nasm,
2495 @depends(nasm, need_nasm.what)
2496 def check_nasm(nasm, what):
2497     if not nasm and what:
2498         die("Nasm is required to build with %s, but it was not found." % what)
2499     return nasm
2502 @depends_if(check_nasm)
2503 @checking("nasm version")
2504 def nasm_version(nasm):
2505     version = (
2506         check_cmd_output(nasm, "-v", onerror=lambda: die("Failed to get nasm version."))
2507         .splitlines()[0]
2508         .split()[2]
2509     )
2510     return Version(version)
2513 @depends(nasm_version, need_nasm.versioned, when=need_nasm.versioned)
2514 def check_nasm_version(nasm_version, versioned):
2515     by_version = sorted(versioned.items(), key=lambda x: x[1])
2516     what, version = by_version[-1]
2517     if nasm_version < version:
2518         die(
2519             "Nasm version %s or greater is required to build with %s." % (version, what)
2520         )
2521     return nasm_version
2524 @depends(target, when=check_nasm_version)
2525 def nasm_asflags(target):
2526     asflags = {
2527         ("OSX", "x86"): ["-f", "macho32"],
2528         ("OSX", "x86_64"): ["-f", "macho64"],
2529         ("WINNT", "x86"): ["-f", "win32"],
2530         ("WINNT", "x86_64"): ["-f", "win64"],
2531     }.get((target.os, target.cpu), None)
2532     if asflags is None:
2533         # We're assuming every x86 platform we support that's
2534         # not Windows or Mac is ELF.
2535         if target.cpu == "x86":
2536             asflags = ["-f", "elf32"]
2537         elif target.cpu == "x86_64":
2538             asflags = ["-f", "elf64"]
2539     return asflags
2542 set_config("NASM_ASFLAGS", nasm_asflags)
2545 # ANGLE OpenGL->D3D translator for WebGL
2546 # ==============================================================
2548 with only_when(compile_environment & target_is_windows):
2549     set_config("MOZ_ANGLE_RENDERER", True)
2551 # Remoting protocol support
2552 # ==============================================================
2555 @depends(toolkit)
2556 def has_remote(toolkit):
2557     if toolkit in ("gtk", "windows", "cocoa"):
2558         return True
2561 set_config("MOZ_HAS_REMOTE", has_remote)
2562 set_define("MOZ_HAS_REMOTE", has_remote)
2564 # RLBox Library Sandboxing wasm support
2565 # ==============================================================
2568 def wasm_sandboxing_libraries():
2569     return (
2570         "graphite",
2571         "ogg",
2572         "hunspell",
2573         "expat",
2574         "woff2",
2575         "soundtouch",
2576     )
2579 @depends(dependable(wasm_sandboxing_libraries), build_project)
2580 def default_wasm_sandboxing_libraries(libraries, build_project):
2581     if build_project != "tools/rusttests":
2582         non_default_libs = {}
2584         return tuple(l for l in libraries if l not in non_default_libs)
2587 option(
2588     "--with-wasm-sandboxed-libraries",
2589     env="WASM_SANDBOXED_LIBRARIES",
2590     help="{Enable wasm sandboxing for the selected libraries|Disable wasm sandboxing}",
2591     nargs="+",
2592     choices=dependable(wasm_sandboxing_libraries),
2593     default=default_wasm_sandboxing_libraries,
2597 @depends("--with-wasm-sandboxed-libraries")
2598 def requires_wasm_sandboxing(libraries):
2599     if libraries:
2600         return True
2603 set_config("MOZ_USING_WASM_SANDBOXING", requires_wasm_sandboxing)
2604 set_define("MOZ_USING_WASM_SANDBOXING", requires_wasm_sandboxing)
2606 with only_when(requires_wasm_sandboxing & compile_environment):
2607     option(
2608         "--with-wasi-sysroot",
2609         env="WASI_SYSROOT",
2610         nargs=1,
2611         help="Path to wasi sysroot for wasm sandboxing",
2612     )
2614     @depends("--with-wasi-sysroot", requires_wasm_sandboxing)
2615     def bootstrap_wasi_sysroot(wasi_sysroot, requires_wasm_sandboxing):
2616         return requires_wasm_sandboxing and not wasi_sysroot
2618     @depends(
2619         "--with-wasi-sysroot",
2620         bootstrap_path("sysroot-wasm32-wasi", when=bootstrap_wasi_sysroot),
2621     )
2622     @imports("os")
2623     def wasi_sysroot(wasi_sysroot, bootstrapped_sysroot):
2624         if not wasi_sysroot:
2625             return bootstrapped_sysroot
2627         wasi_sysroot = wasi_sysroot[0]
2628         if not os.path.isdir(wasi_sysroot):
2629             die("Argument to --with-wasi-sysroot must be a directory")
2630         if not os.path.isabs(wasi_sysroot):
2631             die("Argument to --with-wasi-sysroot must be an absolute path")
2633         return wasi_sysroot
2635     @depends(wasi_sysroot)
2636     def wasi_sysroot_flags(wasi_sysroot):
2637         if wasi_sysroot:
2638             log.info("Using wasi sysroot in %s", wasi_sysroot)
2639             return ["--sysroot=%s" % wasi_sysroot]
2640         return []
2642     set_config("WASI_SYSROOT", wasi_sysroot)
2644     def wasm_compiler_with_flags(compiler, sysroot_flags):
2645         if compiler:
2646             return (
2647                 compiler.wrapper + [compiler.compiler] + compiler.flags + sysroot_flags
2648             )
2650     @template
2651     def wasm_compiler_error(msg):
2652         @depends("--with-wasm-sandboxed-libraries")
2653         def wasm_compiler_error(sandboxed_libs):
2654             suggest_disable = ""
2655             if sandboxed_libs.origin == "default":
2656                 suggest_disable = " Or build with --without-wasm-sandboxed-libraries."
2657             return lambda: die(msg + suggest_disable)
2659         return wasm_compiler_error
2661     @template
2662     def check_wasm_compiler(compiler, language):
2663         compiler.try_compile(
2664             includes=["cstring" if language == "C++" else "string.h"],
2665             flags=wasi_sysroot_flags,
2666             check_msg="the wasm %s compiler can find wasi headers" % language,
2667             onerror=wasm_compiler_error(
2668                 "Cannot find wasi headers or problem with the wasm compiler. "
2669                 "Please fix the problem."
2670             ),
2671         )
2673         compiler.try_run(
2674             flags=wasi_sysroot_flags,
2675             check_msg="the wasm %s linker can find wasi libraries" % language,
2676             onerror=wasm_compiler_error(
2677                 "Cannot find wasi libraries or problem with the wasm linker. "
2678                 "Please fix the problem."
2679             ),
2680         )
2682     wasm_cc = compiler("C", wasm, other_compiler=c_compiler)
2683     check_wasm_compiler(wasm_cc, "C")
2685     @depends(wasm_cc, wasi_sysroot_flags)
2686     def wasm_cc_with_flags(wasm_cc, wasi_sysroot_flags):
2687         return wasm_compiler_with_flags(wasm_cc, wasi_sysroot_flags)
2689     set_config("WASM_CC", wasm_cc_with_flags)
2691     wasm_cxx = compiler(
2692         "C++",
2693         wasm,
2694         c_compiler=wasm_cc,
2695         other_compiler=cxx_compiler,
2696         other_c_compiler=c_compiler,
2697     )
2698     check_wasm_compiler(wasm_cxx, "C++")
2700     @depends(wasm_cxx, wasi_sysroot_flags)
2701     def wasm_cxx_with_flags(wasm_cxx, wasi_sysroot_flags):
2702         return wasm_compiler_with_flags(wasm_cxx, wasi_sysroot_flags)
2704     set_config("WASM_CXX", wasm_cxx_with_flags)
2706     wasm_compile_flags = dependable(["-fno-exceptions", "-fno-strict-aliasing"])
2707     option(env="WASM_CFLAGS", nargs=1, help="Options to pass to WASM_CC")
2709     @depends("WASM_CFLAGS", wasm_compile_flags)
2710     def wasm_cflags(value, wasm_compile_flags):
2711         if value:
2712             return wasm_compile_flags + value
2713         else:
2714             return wasm_compile_flags
2716     set_config("WASM_CFLAGS", wasm_cflags)
2718     option(env="WASM_CXXFLAGS", nargs=1, help="Options to pass to WASM_CXX")
2720     @depends("WASM_CXXFLAGS", wasm_compile_flags)
2721     def wasm_cxxflags(value, wasm_compile_flags):
2722         if value:
2723             return wasm_compile_flags + value
2724         else:
2725             return wasm_compile_flags
2727     set_config("WASM_CXXFLAGS", wasm_cxxflags)
2730 @depends("--with-wasm-sandboxed-libraries")
2731 def wasm_sandboxing(libraries):
2732     if not libraries:
2733         return
2735     return namespace(**{name: True for name in libraries})
2738 @template
2739 def wasm_sandboxing_config_defines():
2740     for lib in wasm_sandboxing_libraries():
2741         set_config(
2742             "MOZ_WASM_SANDBOXING_%s" % lib.upper(), getattr(wasm_sandboxing, lib)
2743         )
2744         set_define(
2745             "MOZ_WASM_SANDBOXING_%s" % lib.upper(), getattr(wasm_sandboxing, lib)
2746         )
2749 wasm_sandboxing_config_defines()
2752 with only_when(compile_environment & wasm_sandboxing.hunspell):
2753     clock_in_wasi_sysroot = wasm_cc.try_run(
2754         header="#include <time.h>",
2755         body="clock();",
2756         check_msg="for clock() in wasi sysroot",
2757         flags=depends(wasi_sysroot_flags)(
2758             lambda sysroot_flags: ["-Werror"] + sysroot_flags
2759         ),
2760     )
2762     wasi_emulated_clock = wasm_cc.try_run(
2763         header="#include <time.h>",
2764         body="clock();",
2765         check_msg="for emulated clock() in wasi sysroot",
2766         flags=depends(wasi_sysroot_flags)(
2767             lambda sysroot_flags: [
2768                 "-Werror",
2769                 "-D_WASI_EMULATED_PROCESS_CLOCKS",
2770                 "-lwasi-emulated-process-clocks",
2771             ]
2772             + sysroot_flags
2773         ),
2774         when=depends(clock_in_wasi_sysroot)(lambda x: not x),
2775         onerror=lambda: die("Can't find clock() in wasi sysroot."),
2776     )
2778     set_config("MOZ_WASI_EMULATED_CLOCK", True, when=wasi_emulated_clock)
2781 # new Notification Store implementation
2782 # ==============================================================
2785 @depends(milestone)
2786 def new_notification_store(milestone):
2787     if milestone.is_nightly:
2788         return True
2791 set_config("MOZ_NEW_NOTIFICATION_STORE", True, when=new_notification_store)
2792 set_define("MOZ_NEW_NOTIFICATION_STORE", True, when=new_notification_store)
2795 # Auxiliary files persistence on application close
2796 # ==============================================================
2798 option(
2799     "--enable-disk-remnant-avoidance",
2800     help="Prevent persistence of auxiliary files on application close",
2804 set_config(
2805     "MOZ_AVOID_DISK_REMNANT_ON_CLOSE",
2806     True,
2807     when="--enable-disk-remnant-avoidance",
2811 # Glean SDK Integration Crate
2812 # ==============================================================
2815 @depends(target)
2816 def glean_android(target):
2817     return target.os == "Android"
2820 set_config("MOZ_GLEAN_ANDROID", True, when=glean_android)
2821 set_define("MOZ_GLEAN_ANDROID", True, when=glean_android)
2824 # dump_syms
2825 # ==============================================================
2827 check_prog(
2828     "DUMP_SYMS",
2829     ["dump_syms"],
2830     allow_missing=True,
2831     bootstrap="dump_syms",
2832     when=compile_environment,
2836 @depends(valid_windows_sdk_dir, host)
2837 @imports(_from="os", _import="environ")
2838 def pdbstr_paths(valid_windows_sdk_dir, host):
2839     if not valid_windows_sdk_dir:
2840         return
2842     vc_host = {
2843         "x86": "x86",
2844         "x86_64": "x64",
2845     }.get(host.cpu)
2847     return [
2848         environ["PATH"],
2849         os.path.join(valid_windows_sdk_dir.path, "Debuggers", vc_host, "srcsrv"),
2850     ]
2853 check_prog(
2854     "PDBSTR",
2855     ["pdbstr.exe"],
2856     allow_missing=True,
2857     when=compile_environment & target_is_windows,
2858     paths=pdbstr_paths,
2859     allow_spaces=True,
2863 @depends("MOZ_AUTOMATION", c_compiler)
2864 def allow_missing_winchecksec(automation, c_compiler):
2865     if not automation:
2866         return True
2867     if c_compiler and c_compiler.type != "clang-cl":
2868         return True
2871 check_prog(
2872     "WINCHECKSEC",
2873     ["winchecksec.exe", "winchecksec"],
2874     bootstrap="winchecksec",
2875     allow_missing=allow_missing_winchecksec,
2876     when=compile_environment & target_is_windows,
2880 # Fork server
2881 @depends(target, build_project)
2882 def forkserver_default(target, build_project):
2883     return build_project == "browser" and (
2884         (target.os == "GNU" and target.kernel == "Linux")
2885         or target.os == "FreeBSD"
2886         or target.os == "OpenBSD"
2887     )
2890 option(
2891     "--enable-forkserver",
2892     default=forkserver_default,
2893     env="MOZ_ENABLE_FORKSERVER",
2894     help="{Enable|Disable} fork server",
2898 @depends("--enable-forkserver", target)
2899 def forkserver_flag(value, target):
2900     if (
2901         target.os == "Android"
2902         or (target.os == "GNU" and target.kernel == "Linux")
2903         or target.os == "FreeBSD"
2904         or target.os == "OpenBSD"
2905     ):
2906         return bool(value)
2907     pass
2910 set_config("MOZ_ENABLE_FORKSERVER", forkserver_flag)
2911 set_define("MOZ_ENABLE_FORKSERVER", forkserver_flag, forkserver_flag)
2913 # Crash Reporter
2914 # ==============================================================
2916 with only_when(compile_environment & target_has_linux_kernel):
2917     # Check if we need to use the breakpad_getcontext fallback.
2918     getcontext = check_symbol("getcontext")
2919     set_config("HAVE_GETCONTEXT", getcontext)
2920     set_define("HAVE_GETCONTEXT", getcontext)
2922 # NSS
2923 # ==============================================================
2924 include("../build/moz.configure/nss.configure")
2927 # Enable or disable running in background task mode: headless for
2928 # periodic, short-lived, maintenance tasks.
2929 # ==============================================================================
2930 option(
2931     "--disable-backgroundtasks",
2932     help="Disable running in background task mode",
2934 set_config("MOZ_BACKGROUNDTASKS", True, when="--enable-backgroundtasks")
2935 set_define("MOZ_BACKGROUNDTASKS", True, when="--enable-backgroundtasks")
2938 # Update-related programs: updater, maintenance service, update agent,
2939 # default browser agent.
2940 # ==============================================================
2941 include("../build/moz.configure/update-programs.configure")
2944 # Mobile optimizations
2945 # ==============================================================
2946 option(
2947     "--enable-mobile-optimize",
2948     default=target_is_android,
2949     help="{Enable|Disable} mobile optimizations",
2952 set_define("MOZ_GFX_OPTIMIZE_MOBILE", True, when="--enable-mobile-optimize")
2953 # We ignore "paint will resample" on mobile for performance.
2954 # We may want to revisit this later.
2955 set_define("MOZ_IGNORE_PAINT_WILL_RESAMPLE", True, when="--enable-mobile-optimize")
2957 # Pref extensions
2958 # ==============================================================
2959 option("--disable-pref-extensions", help="Disable pref extensions such as autoconfig")
2960 set_config("MOZ_PREF_EXTENSIONS", True, when="--enable-pref-extensions")
2962 # Offer a way to disable the startup cache
2963 # ==============================================================
2964 option("--disable-startupcache", help="Disable startup cache")
2967 @depends("--enable-startupcache")
2968 def enable_startupcache(value):
2969     if value:
2970         return True
2973 set_define(
2974     "MOZ_DISABLE_STARTUPCACHE", True, when=depends(enable_startupcache)(lambda x: not x)
2978 # Branding
2979 # ==============================================================
2980 option(
2981     env="MOZ_APP_REMOTINGNAME",
2982     nargs=1,
2983     help="Used for the internal program name, which affects profile name "
2984     "and remoting. If not set, defaults to MOZ_APP_NAME if the update channel "
2985     "is release, and MOZ_APP_NAME-MOZ_UPDATE_CHANNEL otherwise.",
2989 @depends("MOZ_APP_REMOTINGNAME", moz_app_name, update_channel)
2990 def moz_app_remotingname(value, moz_app_name, update_channel):
2991     if value:
2992         return value[0]
2993     if update_channel == "release":
2994         return moz_app_name
2995     return moz_app_name + "-" + update_channel
2998 set_config("MOZ_APP_REMOTINGNAME", moz_app_remotingname)
3000 option(
3001     env="ANDROID_PACKAGE_NAME",
3002     nargs=1,
3003     help="Name of the Android package (default org.mozilla.$MOZ_APP_NAME)",
3007 @depends("ANDROID_PACKAGE_NAME", moz_app_name)
3008 def android_package_name(value, moz_app_name):
3009     if value:
3010         return value[0]
3011     if moz_app_name == "fennec":
3012         return "org.mozilla.fennec_aurora"
3013     return "org.mozilla.%s" % moz_app_name
3016 set_config("ANDROID_PACKAGE_NAME", android_package_name)
3019 # Miscellaneous options
3020 # ==============================================================
3021 option(env="MOZ_WINCONSOLE", nargs="?", help="Whether we can create a console window.")
3022 set_define("MOZ_WINCONSOLE", True, when=depends("MOZ_WINCONSOLE")(lambda x: x))
3025 # Alternative Crashreporter setting
3026 option(
3027     "--with-crashreporter-url",
3028     env="MOZ_CRASHREPORTER_URL",
3029     default="https://crash-reports.mozilla.com/",
3030     nargs=1,
3031     help="Set an alternative crashreporter url",
3034 set_config(
3035     "MOZ_CRASHREPORTER_URL",
3036     depends("--with-crashreporter-url")(lambda x: x[0].rstrip("/")),
3040 # Crash reporter options
3041 # ==============================================================
3042 @depends(target)
3043 def oxidized_breakpad(target):
3044     if target.kernel == "Linux":
3045         return target.cpu in ("aarch64", "arm", "x86", "x86_64")
3046     return False
3049 set_config("MOZ_OXIDIZED_BREAKPAD", True, when=oxidized_breakpad)
3050 set_define("MOZ_OXIDIZED_BREAKPAD", True, when=oxidized_breakpad)
3053 # Wine
3054 # ==============================================================
3055 @depends(target, host)
3056 def want_wine(target, host):
3057     return target.kernel == "WINNT" and host.kernel != "WINNT"
3060 wine = check_prog(
3061     "WINE",
3062     ["wine64", "wine"],
3063     when=want_wine,
3064     bootstrap="wine/bin",
3067 # DOM Streams
3068 # ==============================================================
3069 # Set this to true so the JS engine knows we're doing a browser build.
3070 set_config("MOZ_DOM_STREAMS", True)
3071 set_define("MOZ_DOM_STREAMS", True)
3073 # libevent
3074 # ==============================================================
3075 with only_when(compile_environment):
3076     system_lib_option(
3077         "--with-system-libevent",
3078         nargs="?",
3079         help="Use system libevent",
3080     )
3082     @depends("--with-system-libevent")
3083     def deprecated_system_libevent_path(value):
3084         if len(value) == 1:
3085             die(
3086                 "--with-system-libevent=PATH is not supported anymore. Please use "
3087                 "--with-system-libevent and set any necessary pkg-config environment variable."
3088             )
3090     pkg_check_modules("MOZ_LIBEVENT", "libevent", when="--with-system-libevent")
3092     set_config("MOZ_SYSTEM_LIBEVENT", True, when="--with-system-libevent")
3095 # Crash reporting
3096 # ==============================================================
3097 @depends(target, developer_options, artifact_builds)
3098 def crashreporter_default(target, developer_options, artifacts):
3099     if target.kernel in ("WINNT", "Darwin"):
3100         return True
3101     if target.kernel == "Linux" and target.cpu in ("x86", "x86_64", "arm", "aarch64"):
3102         # The crash reporter prevents crash stacktraces to be logged in the
3103         # logs on Android, so we leave it out by default in developer builds.
3104         return target.os != "Android" or not developer_options or artifacts
3107 option(
3108     "--enable-crashreporter",
3109     default=crashreporter_default,
3110     help="{Enable|Disable} crash reporting",
3114 set_config("MOZ_CRASHREPORTER", True, when="--enable-crashreporter")
3115 set_define("MOZ_CRASHREPORTER", True, when="--enable-crashreporter")
3117 with only_when(compile_environment):
3118     with only_when("--enable-crashreporter"):
3119         pkg_check_modules(
3120             "MOZ_GTHREAD",
3121             "gthread-2.0",
3122             when=depends(target)(lambda t: t.os == "GNU" and t.kernel == "Linux"),
3123         )
3125         set_config(
3126             "MOZ_CRASHREPORTER_INJECTOR",
3127             True,
3128             when=depends(target)(lambda t: t.os == "WINNT" and t.bitness == 32),
3129         )
3130         set_define(
3131             "MOZ_CRASHREPORTER_INJECTOR",
3132             True,
3133             when=depends(target)(lambda t: t.os == "WINNT" and t.bitness == 32),
3134         )
3137 # If we have any service that uploads data (and requires data submission
3138 # policy alert), set MOZ_DATA_REPORTING.
3139 # ==============================================================
3140 @depends(
3141     "MOZ_TELEMETRY_REPORTING",
3142     "MOZ_SERVICES_HEALTHREPORT",
3143     "--enable-crashreporter",
3144     "MOZ_NORMANDY",
3146 def data_reporting(telemetry, healthreport, crashreporter, normandy):
3147     return telemetry or healthreport or crashreporter or normandy
3150 set_config("MOZ_DATA_REPORTING", True, when=data_reporting)
3151 set_define("MOZ_DATA_REPORTING", True, when=data_reporting)
3154 # Gtk+
3155 # ==============================================================
3156 with only_when(toolkit_gtk):
3157     pkg_check_modules(
3158         "MOZ_GTK3",
3159         "gtk+-3.0 >= 3.14.0 gtk+-unix-print-3.0 glib-2.0 gobject-2.0 gio-unix-2.0",
3160     )
3162     set_define("GDK_VERSION_MIN_REQUIRED", "GDK_VERSION_3_14")
3163     set_define("GDK_VERSION_MAX_ALLOWED", "GDK_VERSION_3_14")
3165     pkg_check_modules("GLIB", "glib-2.0 >= 2.42 gobject-2.0")
3167     set_define("GLIB_VERSION_MIN_REQUIRED", "GLIB_VERSION_2_42")
3168     set_define("GLIB_VERSION_MAX_ALLOWED", "GLIB_VERSION_2_42")
3170     set_define("MOZ_ACCESSIBILITY_ATK", True, when=accessibility)
3172 # DBus
3173 # ==============================================================
3174 with only_when(toolkit_gtk):
3175     option("--disable-dbus", help="Disable dbus support")
3177     with only_when("--enable-dbus"):
3178         pkg_check_modules("MOZ_DBUS", "dbus-1 >= 0.60")
3180         set_config("MOZ_ENABLE_DBUS", True)
3181         set_define("MOZ_ENABLE_DBUS", True)
3184 # Necko's wifi scanner
3185 # ==============================================================
3186 @depends(target)
3187 def necko_wifi_when(target):
3188     return target.os in ("WINNT", "OSX", "DragonFly", "FreeBSD") or (
3189         target.kernel == "Linux" and target.os == "GNU"
3190     )
3193 option("--disable-necko-wifi", help="Disable necko wifi scanner", when=necko_wifi_when)
3195 set_config("NECKO_WIFI", True, when="--enable-necko-wifi")
3196 set_define("NECKO_WIFI", True, when="--enable-necko-wifi")
3199 @depends(
3200     depends("--enable-necko-wifi", when=necko_wifi_when)(lambda x: x),
3201     depends("--enable-dbus", when=toolkit_gtk)(lambda x: x),
3202     when=depends(target)(lambda t: t.os == "GNU" and t.kernel == "Linux"),
3204 def necko_wifi_dbus(necko_wifi, dbus):
3205     if necko_wifi and not dbus:
3206         die(
3207             "Necko WiFi scanning needs DBus on your platform, remove --disable-dbus"
3208             " or use --disable-necko-wifi"
3209         )
3210     return necko_wifi and dbus
3213 set_config("NECKO_WIFI_DBUS", True, when=necko_wifi_dbus)
3214 set_define("NECKO_WIFI_DBUS", True, when=necko_wifi_dbus)
3217 # Frontend JS debug mode
3218 # ==============================================================
3219 option("--enable-debug-js-modules", help="Enable debug mode for frontend JS libraries")
3221 set_config("DEBUG_JS_MODULES", True, when="--enable-debug-js-modules")
3224 # moz_dump_painting
3225 # ==============================================================
3226 option("--enable-dump-painting", help="Enable paint debugging")
3228 set_define(
3229     "MOZ_DUMP_PAINTING",
3230     True,
3231     when=depends("--enable-dump-painting", "--enable-debug")(
3232         lambda painting, debug: painting or debug
3233     ),
3235 set_define("MOZ_LAYERS_HAVE_LOG", True, when="--enable-dump-painting")
3238 # libproxy support
3239 # ==============================================================
3240 with only_when(toolkit_gtk):
3241     system_lib_option("--enable-libproxy", help="Enable libproxy support")
3243     with only_when("--enable-libproxy"):
3244         pkg_check_modules("MOZ_LIBPROXY", "libproxy-1.0")
3246         set_config("MOZ_ENABLE_LIBPROXY", True)
3247         set_define("MOZ_ENABLE_LIBPROXY", True)
3250 # Enable runtime logging
3251 # ==============================================================
3252 set_define("MOZ_LOGGING", True)
3253 set_define("FORCE_PR_LOG", True)
3255 # This will enable logging of addref, release, ctor, dtor.
3256 # ==============================================================
3257 option(
3258     "--enable-logrefcnt",
3259     default=moz_debug,
3260     help="{Enable|Disable} logging of refcounts",
3263 set_define("NS_BUILD_REFCNT_LOGGING", True, when="--enable-logrefcnt")
3266 # NegotiateAuth
3267 # ==============================================================
3268 option("--disable-negotiateauth", help="Disable GSS-API negotiation")
3270 set_config("MOZ_AUTH_EXTENSION", True, when="--enable-negotiateauth")
3271 set_define("MOZ_AUTH_EXTENSION", True, when="--enable-negotiateauth")
3274 # Parental control
3275 # ==============================================================
3276 option("--disable-parental-controls", help="Do not build parental controls")
3278 set_config(
3279     "MOZ_DISABLE_PARENTAL_CONTROLS",
3280     True,
3281     when=depends("--enable-parental-controls")(lambda x: not x),
3283 set_define(
3284     "MOZ_DISABLE_PARENTAL_CONTROLS",
3285     True,
3286     when=depends("--enable-parental-controls")(lambda x: not x),
3290 # Sandboxing support
3291 # ==============================================================
3292 @depends(target, tsan, asan)
3293 def sandbox_default(target, tsan, asan):
3294     # Only enable the sandbox by default on Linux, OpenBSD, macOS, and Windows
3295     if target.kernel == "Linux" and target.os == "GNU":
3296         # Bug 1182565: TSan conflicts with sandboxing on Linux.
3297         # Bug 1287971: LSan also conflicts with sandboxing on Linux.
3298         if tsan or asan:
3299             return False
3300         # Linux sandbox is only available on x86{,_64} and arm{,64}.
3301         return target.cpu in ("x86", "x86_64", "arm", "aarch64")
3302     return target.kernel in ("WINNT", "Darwin", "OpenBSD")
3305 option(
3306     "--enable-sandbox",
3307     default=sandbox_default,
3308     help="{Enable|Disable} sandboxing support",
3311 set_config("MOZ_SANDBOX", True, when="--enable-sandbox")
3312 set_define("MOZ_SANDBOX", True, when="--enable-sandbox")
3314 with only_when(depends(target.kernel)(lambda k: k not in ("Darwin", "WINNT"))):
3315     set_define("MOZ_CONTENT_TEMP_DIR", True, when="--enable-sandbox")
3317 # Searching of system directories for extensions.
3318 # ==============================================================
3319 # Note: this switch is meant to be used for test builds whose behavior should
3320 # not depend on what happens to be installed on the local machine.
3321 option(
3322     "--disable-system-extension-dirs",
3323     help="Disable searching system- and account-global directories for extensions"
3324     " of any kind; use only profile-specific extension directories",
3327 set_define("ENABLE_SYSTEM_EXTENSION_DIRS", True, when="--enable-system-extension-dirs")
3330 # Pixman
3331 # ==============================================================
3332 with only_when(compile_environment):
3333     system_lib_option(
3334         "--enable-system-pixman", help="Use system pixman (located with pkgconfig)"
3335     )
3337     @depends("--enable-system-pixman")
3338     def in_tree_pixman(pixman):
3339         return not pixman
3341     set_config("MOZ_TREE_PIXMAN", True, when=in_tree_pixman)
3342     set_define("MOZ_TREE_PIXMAN", True, when=in_tree_pixman)
3344     pkg_check_modules("MOZ_PIXMAN", "pixman-1 >= 0.36.0", when="--enable-system-pixman")
3345     # Set MOZ_PIXMAN_CFLAGS to an explicit empty value when --enable-system-pixman is *not* used,
3346     # for layout/style/extra-bindgen-flags
3347     set_config("MOZ_PIXMAN_CFLAGS", [], when=in_tree_pixman)
3350 # Universalchardet
3351 # ==============================================================
3352 with only_when(compile_environment):
3353     option("--disable-universalchardet", help="Disable universal encoding detection")
3355     set_config("MOZ_UNIVERSALCHARDET", True, when="--enable-universalchardet")
3358 # Disable zipwriter
3359 # ==============================================================
3360 with only_when(compile_environment):
3361     option("--disable-zipwriter", help="Disable zipwriter component")
3363     set_config("MOZ_ZIPWRITER", True, when="--enable-zipwriter")
3366 # Location of the mozilla user directory
3367 # ==============================================================
3368 with only_when(compile_environment):
3370     @depends(target)
3371     def default_user_appdir(target):
3372         if target.kernel in ("WINNT", "Darwin"):
3373             return "Mozilla"
3374         return ".mozilla"
3376     option(
3377         "--with-user-appdir",
3378         nargs=1,
3379         default=default_user_appdir,
3380         help="Set user-specific appdir",
3381     )
3383     @depends("--with-user-appdir")
3384     def user_appdir(appdir):
3385         if not appdir:
3386             die("--without-user-appdir is not a valid option.")
3387         if "/" in appdir[0]:
3388             die("--with-user-appdir must be a single relative path.")
3389         return '"{}"'.format(appdir[0])
3391     set_define("MOZ_USER_DIR", user_appdir)
3394 # Check for sin_len and sin6_len - used by SCTP; only appears in Mac/*BSD generally
3395 # ==============================================================
3396 with only_when(compile_environment):
3397     have_sin_len = c_compiler.try_compile(
3398         includes=["netinet/in.h"],
3399         body="struct sockaddr_in x; void *foo = (void*) &x.sin_len;",
3400         check_msg="for sin_len in struct sockaddr_in",
3401     )
3402     have_sin6_len = c_compiler.try_compile(
3403         includes=["netinet/in.h"],
3404         body="struct sockaddr_in6 x; void *foo = (void*) &x.sin6_len;",
3405         check_msg="for sin_len6 in struct sockaddr_in6",
3406     )
3407     set_define("HAVE_SIN_LEN", have_sin_len)
3408     set_define("HAVE_SIN6_LEN", have_sin6_len)
3409     # HAVE_CONN_LEN must be the same as HAVE_SIN_LEN and HAVE_SIN6_LEN
3410     set_define("HAVE_SCONN_LEN", have_sin_len & have_sin6_len)
3411     set_define(
3412         "HAVE_SA_LEN",
3413         c_compiler.try_compile(
3414             includes=["netinet/in.h"],
3415             body="struct sockaddr x; void *foo = (void*) &x.sa_len;",
3416             check_msg="for sa_len in struct sockaddr",
3417         ),
3418     )
3421 # Check for pthread_cond_timedwait_monotonic_np
3422 # ==============================================================
3423 with only_when(compile_environment):
3424     set_define(
3425         "HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC",
3426         c_compiler.try_compile(
3427             includes=["pthread.h"],
3428             body="pthread_cond_timedwait_monotonic_np(0, 0, 0);",
3429             # -Werror to catch any "implicit declaration" warning that means the function
3430             # is not supported.
3431             flags=["-Werror=implicit-function-declaration"],
3432             check_msg="for pthread_cond_timedwait_monotonic_np",
3433         ),
3434     )
3437 # Custom dynamic linker for Android
3438 # ==============================================================
3439 with only_when(target_has_linux_kernel & compile_environment):
3440     option(
3441         env="MOZ_LINKER",
3442         default=depends(target.os, when="--enable-jemalloc")(
3443             lambda os: os == "Android"
3444         ),
3445         help="{Enable|Disable} custom dynamic linker",
3446     )
3448     set_config("MOZ_LINKER", True, when="MOZ_LINKER")
3449     set_define("MOZ_LINKER", True, when="MOZ_LINKER")
3450     add_old_configure_assignment("MOZ_LINKER", True, when="MOZ_LINKER")
3452     moz_linker = depends(when="MOZ_LINKER")(lambda: True)
3455 # 32-bits ethtool_cmd.speed
3456 # ==============================================================
3457 with only_when(target_has_linux_kernel & compile_environment):
3458     set_config(
3459         "MOZ_WEBRTC_HAVE_ETHTOOL_SPEED_HI",
3460         c_compiler.try_compile(
3461             includes=["linux/ethtool.h"],
3462             body="struct ethtool_cmd cmd; cmd.speed_hi = 0;",
3463             check_msg="for 32-bits ethtool_cmd.speed",
3464         ),
3465     )
3467 # Gamepad support
3468 # ==============================================================
3469 check_header(
3470     "linux/joystick.h",
3471     onerror=lambda: die(
3472         "Can't find header linux/joystick.h, needed for gamepad support."
3473         " Please install Linux kernel headers."
3474     ),
3475     when=target_has_linux_kernel & compile_environment,
3479 # Smart card support
3480 # ==============================================================
3481 @depends(build_project)
3482 def disable_smart_cards(build_project):
3483     return build_project == "mobile/android"
3486 set_config("MOZ_NO_SMART_CARDS", True, when=disable_smart_cards)
3487 set_define("MOZ_NO_SMART_CARDS", True, when=disable_smart_cards)
3489 # Enable UniFFI fixtures
3490 # ==============================================================
3491 # These are used to test the uniffi-bindgen-gecko-js code generation.  They
3492 # should not be enabled in release builds.
3494 option(
3495     "--enable-uniffi-fixtures",
3496     help="Enable UniFFI Fixtures/Examples",
3499 set_config("MOZ_UNIFFI_FIXTURES", True, when="--enable-uniffi-fixtures")
3501 # System policies
3502 # ==============================================================
3504 option(
3505     "--disable-system-policies",
3506     help="Disable reading policies from Windows registry, macOS's file system attributes, and /etc/firefox",
3509 set_config("MOZ_SYSTEM_POLICIES", True, when="--enable-system-policies")
3511 # Allow disabling the creation a legacy profile
3512 # ==============================================================
3514 option(
3515     "--disable-legacy-profile-creation",
3516     help="Disable the creation a legacy profile, to be used by old versions "
3517     "of Firefox, when no profiles exist.",
3520 set_config("MOZ_CREATE_LEGACY_PROFILE", True, when="--enable-legacy-profile-creation")
3523 # STL wrapping
3524 # ==============================================================
3525 set_config("WRAP_STL_INCLUDES", True)
3526 set_config(
3527     "STL_FLAGS",
3528     depends(build_environment.dist)(lambda dist: [f"-I{dist}/stl_wrappers"]),
3532 # Perl detection
3533 # ==============================================================
3534 @depends(target)
3535 def need_perl(target):
3536     # Ideally, we'd also depend on gnu_as here, but that adds complications.
3537     return target.cpu == "arm"
3540 perl = check_prog("PERL", ("perl5", "perl"), when=need_perl)
3543 @template
3544 def perl_version_check(min_version):
3545     @depends(perl)
3546     @checking("for minimum required perl version >= %s" % min_version)
3547     def get_perl_version(perl):
3548         return Version(
3549             check_cmd_output(
3550                 perl,
3551                 "-e",
3552                 "print $]",
3553                 onerror=lambda: die("Failed to get perl version."),
3554             )
3555         )
3557     @depends(get_perl_version)
3558     def check_perl_version(version):
3559         if version < min_version:
3560             die("Perl %s or higher is required.", min_version)
3562     @depends(perl)
3563     @checking("for full perl installation")
3564     @imports("subprocess")
3565     def has_full_perl_installation(perl):
3566         ret = subprocess.call([perl, "-e", "use Config; exit(!-d $Config{archlib})"])
3567         return ret == 0
3569     @depends(has_full_perl_installation)
3570     def require_full_perl_installation(has_full_perl_installation):
3571         if not has_full_perl_installation:
3572             die(
3573                 "Cannot find Config.pm or $Config{archlib}. "
3574                 "A full perl installation is required."
3575             )
3578 with only_when(need_perl):
3579     perl_version_check("5.006")