Bug 1842798 - Part 1: Remove use of MozPromise to wait for module fetch r=smaug
[gecko.git] / js / moz.configure
blobb592db0f77ba305161b5872a97d74dfbd2817cb0
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 @depends(build_project)
9 def js_standalone(build_project):
10     if build_project == "js":
11         return True
14 # Debug (see Bug 939505)
15 # ==============================================================
16 set_define("JS_DEBUG", True, when=moz_debug)
19 # Branding
20 # ==============================================================
21 option(
22     "--with-app-name",
23     env="MOZ_APP_NAME",
24     nargs=1,
25     help="Used for e.g. the binary program file name. If not set, "
26     "defaults to a lowercase form of MOZ_APP_BASENAME.",
30 @depends("--with-app-name", js_standalone, moz_app_basename)
31 def moz_app_name(value, js_standalone, moz_app_basename):
32     if value:
33         return value[0]
34     if js_standalone:
35         return "js"
36     return moz_app_basename.lower()
39 set_config("MOZ_APP_NAME", moz_app_name)
41 # SmooshMonkey (new frontend)
42 # ==================================================
44 # Define here in order to use the option from bindgen.configure.
45 option(
46     "--enable-smoosh",
47     default=False,
48     help="Enable SmooshMonkey (new JS engine frontend)",
52 @depends("--enable-smoosh")
53 def enable_smoosh(value):
54     if value:
55         return True
58 set_config("JS_ENABLE_SMOOSH", enable_smoosh)
59 set_define("JS_ENABLE_SMOOSH", enable_smoosh)
61 include("../build/moz.configure/nspr.configure", when="--enable-compile-environment")
62 include("../build/moz.configure/rust.configure", when="--enable-compile-environment")
63 include("../build/moz.configure/bindgen.configure", when="--enable-compile-environment")
65 set_config("JS_STANDALONE", js_standalone)
66 set_define("JS_STANDALONE", js_standalone)
67 add_old_configure_assignment("JS_STANDALONE", js_standalone)
68 option(
69     "--enable-js-shell", default=js_standalone, help="{Build|Do not build} the JS shell"
73 @depends("--enable-js-shell")
74 def js_disable_shell(value):
75     if not value:
76         return True
79 set_config("JS_DISABLE_SHELL", js_disable_shell)
81 set_define("JS_64BIT", depends(target)(lambda t: t.bitness == 64 or None))
83 set_define("JS_PUNBOX64", depends(target)(lambda t: t.bitness == 64 or None))
84 set_define("JS_NUNBOX32", depends(target)(lambda t: t.bitness == 32 or None))
87 # SpiderMonkey as a shared library, and how its symbols are exported
88 # ==================================================================
89 option(
90     "--disable-shared-js",
91     when=js_standalone,
92     help="{Create|Do not create} a shared library",
95 option(
96     "--disable-export-js",
97     when=js_standalone,
98     help="{Mark|Do not mark} JS symbols as DLL exported/visible",
102 @depends("--disable-shared-js", "--disable-export-js", when=js_standalone)
103 def shared_js(shared_js, export_js):
104     if shared_js:
105         if not export_js:
106             die("Must export JS symbols when building a shared library.")
107         return True
110 set_config("JS_SHARED_LIBRARY", shared_js)
113 @depends(shared_js, "--disable-export-js", when=js_standalone)
114 def exportable_js_api(shared_js, export_js):
115     if not shared_js and export_js:
116         return True
119 set_define("STATIC_EXPORTABLE_JS_API", exportable_js_api)
122 @depends(shared_js, exportable_js_api)
123 def static_js_api(shared_js, export_js):
124     if not shared_js and not export_js:
125         return True
128 set_define("STATIC_JS_API", static_js_api)
131 @depends(shared_js)
132 def static_js(value):
133     if not value:
134         return True
137 set_define("MOZ_STATIC_JS", static_js)
140 # Enable records and tuples
141 # ===================================================
142 option(
143     "--enable-record-tuple",
144     default=False,
145     help="Enable records and tuples (and disables JIT)",
149 @depends("--enable-record-tuple")
150 def enable_record_tuple(value):
151     if value:
152         return True
155 set_config("ENABLE_RECORD_TUPLE", enable_record_tuple)
156 set_define("ENABLE_RECORD_TUPLE", enable_record_tuple)
158 # Enable decorators
159 # ===================================================
160 option(
161     "--enable-decorators",
162     default=False,
163     help="Enable experimental JS Decorators support",
167 @depends("--enable-decorators")
168 def enable_decorators(value):
169     if value:
170         return True
173 set_config("ENABLE_DECORATORS", enable_decorators)
174 set_define("ENABLE_DECORATORS", enable_decorators)
176 # JIT support
177 # =======================================================
178 @depends(target, "--enable-record-tuple")
179 def jit_default(target, enable_record_tuple):
180     if enable_record_tuple:
181         return False
182     if target.cpu in (
183         "x86",
184         "x86_64",
185         "arm",
186         "aarch64",
187         "mips32",
188         "mips64",
189         "loongarch64",
190     ):
191         return True
192     return False
195 option("--enable-jit", default=jit_default, help="{Enable|Disable} use of the JITs")
198 @deprecated_option("--enable-ion")
199 def report_deprecated(value):
200     if value:
201         die("--enable-ion is deprecated, use --enable-jit instead")
202     else:
203         die("--disable-ion is deprecated, use --disable-jit instead")
206 # JIT code simulator for cross compiles
207 # =======================================================
208 option(
209     "--enable-simulator",
210     choices=("arm", "arm64", "mips32", "mips64", "loong64", "riscv64"),
211     nargs=1,
212     help="Enable a JIT code simulator for the specified architecture",
216 @depends("--enable-jit", "--enable-simulator", target)
217 def simulator(jit_enabled, simulator_enabled, target):
218     if not jit_enabled or not simulator_enabled:
219         return
221     sim_cpu = simulator_enabled[0]
223     if sim_cpu in ("arm", "mips32"):
224         if target.cpu != "x86":
225             die("The %s simulator only works on x86." % sim_cpu)
227     if sim_cpu in ("arm64", "mips64", "loong64", "riscv64"):
228         if target.cpu != "x86_64" and target.cpu != "aarch64":
229             die("The %s simulator only works on x86-64 or arm64." % sim_cpu)
231     return namespace(**{sim_cpu: True})
234 set_config("JS_SIMULATOR", depends_if(simulator)(lambda x: True))
235 set_config("JS_SIMULATOR_ARM", simulator.arm)
236 set_config("JS_SIMULATOR_ARM64", simulator.arm64)
237 set_config("JS_SIMULATOR_MIPS32", simulator.mips32)
238 set_config("JS_SIMULATOR_MIPS64", simulator.mips64)
239 set_config("JS_SIMULATOR_LOONG64", simulator.loong64)
240 set_config("JS_SIMULATOR_RISCV64", simulator.riscv64)
241 set_define("JS_SIMULATOR", depends_if(simulator)(lambda x: True))
242 set_define("JS_SIMULATOR_ARM", simulator.arm)
243 set_define("JS_SIMULATOR_ARM64", simulator.arm64)
244 set_define("JS_SIMULATOR_MIPS32", simulator.mips32)
245 set_define("JS_SIMULATOR_MIPS64", simulator.mips64)
246 set_define("JS_SIMULATOR_LOONG64", simulator.loong64)
247 set_define("JS_SIMULATOR_RISCV64", simulator.riscv64)
250 @depends("--enable-jit", simulator, target)
251 def jit_codegen(jit_enabled, simulator, target):
252     if not jit_enabled:
253         return namespace(none=True)
255     if simulator:
256         return simulator
258     if target.cpu == "aarch64":
259         return namespace(arm64=True)
260     elif target.cpu == "x86_64":
261         return namespace(x64=True)
262     elif target.cpu == "loongarch64":
263         return namespace(loong64=True)
264     elif target.cpu == "riscv64":
265         return namespace(riscv64=True)
267     return namespace(**{str(target.cpu): True})
270 set_config("JS_CODEGEN_NONE", jit_codegen.none)
271 set_config("JS_CODEGEN_ARM", jit_codegen.arm)
272 set_config("JS_CODEGEN_ARM64", jit_codegen.arm64)
273 set_config("JS_CODEGEN_MIPS32", jit_codegen.mips32)
274 set_config("JS_CODEGEN_MIPS64", jit_codegen.mips64)
275 set_config("JS_CODEGEN_LOONG64", jit_codegen.loong64)
276 set_config("JS_CODEGEN_RISCV64", jit_codegen.riscv64)
277 set_config("JS_CODEGEN_X86", jit_codegen.x86)
278 set_config("JS_CODEGEN_X64", jit_codegen.x64)
279 set_config("JS_CODEGEN_WASM32", jit_codegen.wasm32)
281 set_define("JS_CODEGEN_NONE", jit_codegen.none)
282 set_define("JS_CODEGEN_ARM", jit_codegen.arm)
283 set_define("JS_CODEGEN_ARM64", jit_codegen.arm64)
284 set_define("JS_CODEGEN_MIPS32", jit_codegen.mips32)
285 set_define("JS_CODEGEN_MIPS64", jit_codegen.mips64)
286 set_define("JS_CODEGEN_LOONG64", jit_codegen.loong64)
287 set_define("JS_CODEGEN_RISCV64", jit_codegen.riscv64)
288 set_define("JS_CODEGEN_X86", jit_codegen.x86)
289 set_define("JS_CODEGEN_X64", jit_codegen.x64)
290 set_define("JS_CODEGEN_WASM32", jit_codegen.wasm32)
293 # Profiling
294 # =======================================================
295 option(
296     "--enable-instruments",
297     env="MOZ_INSTRUMENTS",
298     help="Enable instruments remote profiling",
302 @depends("--enable-instruments", target)
303 def instruments(value, target):
304     if value and target.os != "OSX":
305         die("--enable-instruments cannot be used when targeting %s", target.os)
306     if value:
307         return True
310 set_config("MOZ_INSTRUMENTS", instruments)
311 set_define("MOZ_INSTRUMENTS", instruments)
312 add_old_configure_assignment("MOZ_INSTRUMENTS", instruments)
313 imply_option("--enable-profiling", instruments, reason="--enable-instruments")
315 option("--enable-callgrind", env="MOZ_CALLGRIND", help="Enable callgrind profiling")
318 @depends("--enable-callgrind")
319 def callgrind(value):
320     if value:
321         return True
324 set_define("MOZ_CALLGRIND", callgrind)
325 imply_option("--enable-profiling", callgrind)
328 @depends(milestone)
329 def enable_profiling(milestone):
330     return milestone.is_nightly
333 option(
334     "--enable-profiling",
335     env="MOZ_PROFILING",
336     default=enable_profiling,
337     help="{Set|Do not set} compile flags necessary for using sampling "
338     "profilers (e.g. shark, perf)",
342 @depends("--enable-profiling")
343 def profiling(value):
344     if value:
345         return True
348 with only_when("--enable-compile-environment"):
349     imply_option("--enable-frame-pointers", True, when=profiling)
352 @depends(profiling, target)
353 def imply_vtune(value, target):
354     ok_cpu = target.cpu in ["x86", "x86_64"]
355     ok_kernel = target.kernel == "WINNT" or (
356         target.kernel == "Linux" and target.os == "GNU"
357     )
359     if value and ok_cpu and ok_kernel:
360         return True
363 set_config("MOZ_PROFILING", profiling)
364 set_define("MOZ_PROFILING", profiling)
365 imply_option("--enable-vtune", imply_vtune, reason="--enable-profiling")
368 option("--enable-vtune", env="MOZ_VTUNE", help="Enable VTune profiling")
371 @depends("--enable-vtune")
372 def vtune(value):
373     if value:
374         return True
377 set_config("MOZ_VTUNE", vtune)
378 set_define("MOZ_VTUNE", vtune)
381 option(
382     "--enable-gc-probes",
383     env="JS_GC_PROBES",
384     help="Turn on probes for allocation and finalization",
388 @depends("--enable-gc-probes")
389 def gc_probes(value):
390     if value:
391         return True
394 set_define("JS_GC_PROBES", gc_probes)
397 option(
398     "--enable-gczeal",
399     default=depends(when=moz_debug)(lambda: True),
400     help="{Enable|Disable} zealous GCing",
403 set_define("JS_GC_ZEAL", depends_if("--enable-gczeal")(lambda _: True))
406 # Enable breakpoint for artificial OOMs
407 # =======================================================
408 option(
409     "--enable-oom-breakpoint", help="Enable a breakpoint function for artificial OOMs"
412 set_define("JS_OOM_BREAKPOINT", depends_if("--enable-oom-breakpoint")(lambda _: True))
415 option("--enable-perf", env="JS_ION_PERF", help="Enable Linux perf integration")
418 @depends("--enable-perf", target)
419 def ion_perf(value, target):
420     is_linux = target.kernel == "Linux"
421     is_mac = target.kernel == "Darwin" and target.os == "OSX"
423     if value and (is_linux or is_mac):
424         return True
427 set_define("JS_ION_PERF", ion_perf)
430 option(
431     "--enable-jitspew",
432     default=depends(when=moz_debug)(lambda: True),
433     help="{Enable|Disable} the Jit spew and IONFLAGS environment " "variable",
436 set_define("JS_JITSPEW", depends_if("--enable-jitspew")(lambda _: True))
437 set_config("JS_JITSPEW", depends_if("--enable-jitspew")(lambda _: True))
439 # Also enable the structured spewer
440 set_define("JS_STRUCTURED_SPEW", depends_if("--enable-jitspew")(lambda _: True))
441 set_config("JS_STRUCTURED_SPEW", depends_if("--enable-jitspew")(lambda _: True))
444 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
445 def jit_disasm_arm(jit_enabled, spew, simulator, target, debug):
446     if not jit_enabled:
447         return
449     if simulator and (debug or spew):
450         if getattr(simulator, "arm", None):
451             return True
453     if target.cpu == "arm" and (debug or spew):
454         return True
457 set_config("JS_DISASM_ARM", jit_disasm_arm)
458 set_define("JS_DISASM_ARM", jit_disasm_arm)
461 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
462 def jit_disasm_riscv(jit_enabled, spew, simulator, target, debug):
463     if not jit_enabled:
464         return
466     if simulator and (debug or spew):
467         if getattr(simulator, "riscv64", None):
468             return True
470     if target.cpu == "riscv64" and (debug or spew):
471         return True
474 set_config("JS_DISASM_RISCV64", jit_disasm_riscv)
475 set_define("JS_DISASM_RISCV64", jit_disasm_riscv)
478 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
479 def jit_disasm_arm64(jit_enabled, spew, simulator, target, debug):
480     if not jit_enabled:
481         return
483     if simulator and (debug or spew):
484         if getattr(simulator, "arm64", None):
485             return True
487     if target.cpu == "aarch64" and (debug or spew):
488         return True
491 set_config("JS_DISASM_ARM64", jit_disasm_arm64)
492 set_define("JS_DISASM_ARM64", jit_disasm_arm64)
494 # When enabled, masm will generate assumeUnreachable calls that act as
495 # assertions in the generated code. This option is worth disabling when you
496 # have to track mutated values through the generated code, to avoid constantly
497 # dumping registers on and off the stack.
498 option(
499     "--enable-masm-verbose",
500     default=depends(when=moz_debug)(lambda: True),
501     help="{Enable|Disable} MacroAssembler verbosity of generated code.",
503 set_define("JS_MASM_VERBOSE", depends_if("--enable-masm-verbose")(lambda _: True))
504 set_config("JS_MASM_VERBOSE", depends_if("--enable-masm-verbose")(lambda _: True))
506 # Architecture feature flags
507 # =======================================================
509 # Apple silicon does not seem to have any way to query the OS for the JSCVT
510 # flag stored in the ID_AA64ISAR1_EL1 system register. In the mean time, we
511 # hard code the value of the JSCVT flag which guards the implementation of
512 # FJCVTZS instruction as part of ARMv8.3-JSConv.
513 @depends(target)
514 def is_apple_silicon(target):
515     return target.os == "OSX" and target.kernel == "Darwin" and target.cpu == "aarch64"
518 option(
519     "--enable-arm64-fjcvtzs",
520     default=is_apple_silicon,
521     help="{Enable|Disable} static use of FJCVTZS instruction on Aarch64 targets.",
524 # The "ARM Architecture Reference Manual" for ARMv8 defines the JSCVT flag as
525 # being a 4 bit integer (D12.2.52) and it can be manipulated using >= operator
526 # (D12.1.4).
528 # The FJCVTZS instruction is implemented if ID_AA64ISAR1_EL1.JSCVT >= 1.
529 @depends("--enable-arm64-fjcvtzs", target, simulator)
530 def aarch64_jscvt(fjcvtzs, target, simulator):
531     if target.cpu == "aarch64" and fjcvtzs:
532         return 1
534     if simulator and getattr(simulator, "arm64", False) and fjcvtzs:
535         return 1
537     return 0
540 set_define("MOZ_AARCH64_JSCVT", aarch64_jscvt)
543 @depends(target)
544 def has_pthread_jit_write_protect_np(target):
545     return target.os == "OSX" and target.cpu == "aarch64"
548 # On Apple Silicon we use MAP_JIT with pthread_jit_write_protect_np to implement
549 # JIT code write protection.
550 set_define("JS_USE_APPLE_FAST_WX", True, when=has_pthread_jit_write_protect_np)
552 # CTypes
553 # =======================================================
554 @depends(js_standalone)
555 def ctypes_default(js_standalone):
556     return not js_standalone
559 option("--enable-ctypes", default=ctypes_default, help="{Enable|Disable} js-ctypes")
561 build_ctypes = depends_if("--enable-ctypes")(lambda _: True)
563 set_config("BUILD_CTYPES", build_ctypes)
564 set_define("BUILD_CTYPES", build_ctypes)
566 set_config("JS_HAS_CTYPES", build_ctypes)
567 set_define("JS_HAS_CTYPES", build_ctypes)
570 @depends("--enable-ctypes", "--enable-compile-environment")
571 def ctypes_and_compile_environment(ctypes, compile_environment):
572     return ctypes and compile_environment
575 include("ffi.configure", when=ctypes_and_compile_environment)
578 # Enable pipeline operator
579 # ===================================================
580 option("--enable-pipeline-operator", default=False, help="Enable pipeline operator")
583 @depends("--enable-pipeline-operator")
584 def enable_pipeline_operator(value):
585     if value:
586         return True
589 set_config("ENABLE_PIPELINE_OPERATOR", enable_pipeline_operator)
590 set_define("ENABLE_PIPELINE_OPERATOR", enable_pipeline_operator)
593 # SIMD acceleration for encoding_rs
594 # ==============================================================
596 option(
597     "--enable-rust-simd", env="MOZ_RUST_SIMD", help="Enable explicit SIMD in Rust code."
601 @depends("--enable-rust-simd", target)
602 def rust_simd(value, target):
603     # As of 2019-09-17, the simd-accel feature of encoding_rs has not
604     # been properly set up outside aarch64, armv7, x86 and x86_64.
605     if target.cpu in ("aarch64", "arm", "x86", "x86_64") and value:
606         return True
609 set_config("MOZ_RUST_SIMD", rust_simd)
610 set_define("MOZ_RUST_SIMD", rust_simd)
612 # Telemetry to measure compile time and generated-code runtime
613 # ============================================================
615 option(
616     "--enable-spidermonkey-telemetry",
617     default=milestone.is_nightly,
618     help="{Enable|Disable} performance telemetry for SpiderMonkey (e.g. compile and run times)",
621 set_define(
622     "ENABLE_SPIDERMONKEY_TELEMETRY",
623     depends_if("--enable-spidermonkey-telemetry")(lambda x: True),
626 # Support for debugging code generated by wasm backends
627 # =====================================================
629 option(
630     "--enable-wasm-codegen-debug",
631     default=depends(when=moz_debug)(lambda: True),
632     help="{Enable|Disable} debugging for wasm codegen",
635 set_config(
636     "WASM_CODEGEN_DEBUG", depends_if("--enable-wasm-codegen-debug")(lambda x: True)
638 set_define(
639     "WASM_CODEGEN_DEBUG", depends_if("--enable-wasm-codegen-debug")(lambda x: True)
642 # WebAssembly feature flags
643 # ==================================================
645 option(
646     "--wasm-no-experimental",
647     default=False,
648     help="Force disable all wasm experimental features for testing.",
651 # Support for WebAssembly function-references.
652 # ===========================
655 option(
656     "--disable-wasm-function-references",
657     default=True,
658     help="{Enable|Disable} WebAssembly function-references",
662 @depends("--disable-wasm-function-references", "--wasm-no-experimental")
663 def wasm_function_references(value, no_experimental):
664     if no_experimental:
665         return
667     if value:
668         return True
671 set_config("ENABLE_WASM_FUNCTION_REFERENCES", wasm_function_references)
672 set_define("ENABLE_WASM_FUNCTION_REFERENCES", wasm_function_references)
674 # Support for WebAssembly tail-calls.
675 # ===========================
678 @depends(milestone.is_nightly)
679 def default_wasm_tail_calls(is_nightly):
680     if is_nightly:
681         return True
684 option(
685     "--enable-wasm-tail-calls",
686     default=default_wasm_tail_calls,
687     help="{Enable|Disable} WebAssembly tail-calls",
691 @depends("--enable-wasm-tail-calls", target)
692 def wasm_tail_calls(value, target):
693     if not value:
694         return
696     if target.cpu in ("x86", "x86_64", "arm", "aarch64"):
697         return True
700 set_config("ENABLE_WASM_TAIL_CALLS", wasm_tail_calls)
701 set_define("ENABLE_WASM_TAIL_CALLS", wasm_tail_calls)
703 # Support for WebAssembly GC.
704 # ===========================
707 @depends("--disable-wasm-function-references")
708 def default_wasm_gc(function_references):
709     if function_references:
710         return True
713 option(
714     "--disable-wasm-gc", default=default_wasm_gc, help="{Enable|Disable} WebAssembly GC"
718 @depends(
719     "--disable-wasm-gc", "--disable-wasm-function-references", "--wasm-no-experimental"
721 def wasm_gc(value, function_references, no_experimental):
722     if no_experimental or not value:
723         return
725     if function_references:
726         return True
728     die("--disable-wasm-gc only possible with --disable-wasm-function-references")
731 set_config("ENABLE_WASM_GC", wasm_gc)
732 set_define("ENABLE_WASM_GC", wasm_gc)
735 # Support for WebAssembly shared memory and atomics.
737 # This affects the JS shell only.
738 # =====================================================
740 option(
741     "--disable-shared-memory", help="Disable JS/WebAssembly shared memory and atomics"
745 @depends("--disable-shared-memory")
746 def enable_shared_memory(value):
747     if value:
748         return True
751 set_config("ENABLE_SHARED_MEMORY", enable_shared_memory)
752 set_define("ENABLE_SHARED_MEMORY", enable_shared_memory)
754 # Support for WebAssembly extended constant expressions
755 # =====================================================
758 option(
759     "--disable-wasm-extended-const",
760     help="{Enable|Disable} WebAssembly extended constant expressions",
764 @depends("--disable-wasm-extended-const")
765 def wasm_extended_const(value):
766     if value:
767         return True
770 set_config("ENABLE_WASM_EXTENDED_CONST", wasm_extended_const)
771 set_define("ENABLE_WASM_EXTENDED_CONST", wasm_extended_const)
773 # Support for WebAssembly SIMD
774 # =====================================================
777 @depends("--enable-jit", "--enable-simulator", target)
778 def default_wasm_simd(jit_enabled, simulator, target):
779     if not jit_enabled:
780         return
782     if simulator and (simulator[0] != "arm64"):
783         return
785     if target.cpu in ("x86_64", "x86", "aarch64"):
786         return True
789 option(
790     "--enable-wasm-simd",
791     default=default_wasm_simd,
792     help="{Enable|Disable} WebAssembly SIMD",
796 @depends(
797     "--enable-wasm-simd",
798     "--enable-jit",
799     "--enable-simulator",
800     target,
801     "--wasm-no-experimental",
803 def wasm_simd(value, jit_enabled, simulator, target, no_experimental):
804     if no_experimental or not value:
805         return
807     if not jit_enabled:
808         die("--enable-wasm-simd requires --enable-jit")
810     if simulator and (simulator[0] != "arm64"):
811         die("--enable-wasm-simd is not supported for simulators, except arm64")
813     if target.cpu in ("x86_64", "x86", "aarch64"):
814         return True
816     die("--enable-wasm-simd only possible when targeting the x86_64/x86/arm64 jits")
819 set_config("ENABLE_WASM_SIMD", wasm_simd)
820 set_define("ENABLE_WASM_SIMD", wasm_simd)
822 # Whether to check for field changes in WebAssembly serialization
824 # See the comment for 'WASM_VERIFY_SERIALIZATION_FOR_SIZE' in WasmSerialize.cpp
825 # for more background.
826 # =====================================================================
829 @depends(
830     target,
831     c_compiler,
832     moz_debug,
833     milestone,
834     "--wasm-no-experimental",
836 def wasm_verify_serialization_for_size(
837     target, c_compiler, debug, milestone, no_experimental
839     if (
840         debug == True
841         and target.kernel == "Linux"
842         and target.cpu == "x86_64"
843         and c_compiler
844         and c_compiler.type == "clang"
845         and milestone.is_nightly
846         and not no_experimental
847     ):
848         return True
849     return
852 set_define(
853     "ENABLE_WASM_VERIFY_SERIALIZATION_FOR_SIZE", wasm_verify_serialization_for_size
856 # Support for Intel AVX instruction.
858 # AVX is exclusively used in WebAssembly SIMD instructions at the moment:
859 # set direct dependency on "--enable-wasm-simd".
860 # =====================================================
863 @depends("--enable-wasm-simd", "--enable-simulator", target)
864 def default_wasm_avx(wasm_simd_enabled, simulator, target):
865     if not wasm_simd_enabled:
866         return
868     if simulator:
869         return
871     if target.cpu in ("x86_64", "x86"):
872         return True
875 option(
876     "--enable-wasm-avx",
877     default=default_wasm_avx,
878     help="{Enable|Disable} AVX support for WebAssembly SIMD",
882 @depends(
883     "--enable-wasm-avx",
884     "--enable-wasm-simd",
885     "--enable-simulator",
886     target,
887     "--wasm-no-experimental",
889 def wasm_avx(value, wasm_simd_enabled, simulator, target, no_experimental):
890     if no_experimental or not value:
891         return
893     if not wasm_simd_enabled:
894         die("--enable-wasm-avx requires --enable-wasm-simd")
896     if simulator:
897         die("--enable-wasm-avx is not supported for simulators")
899     if target.cpu in ("x86_64", "x86"):
900         return True
902     die("--enable-wasm-avx only possible when targeting the x86_64/x86 jits")
905 set_config("ENABLE_WASM_AVX", wasm_avx)
906 set_define("ENABLE_WASM_AVX", wasm_avx)
908 # Support for WebAssembly relaxed SIMD
909 # =====================================================
912 @depends(milestone.is_nightly, "--enable-wasm-simd")
913 def default_wasm_relaxed_simd(is_nightly, wasm_simd):
914     if is_nightly and wasm_simd:
915         return True
918 option(
919     "--enable-wasm-relaxed-simd",
920     default=default_wasm_relaxed_simd,
921     help="{Enable|Disable} WebAssembly relaxed SIMD",
925 @depends("--enable-wasm-relaxed-simd", "--enable-wasm-simd", "--wasm-no-experimental")
926 def wasm_relaxed_simd(value, wasm_simd, no_experimental):
927     if no_experimental or not value:
928         return
930     if not wasm_simd:
931         die("relaxed SIMD requires SIMD")
933     return True
936 set_config("ENABLE_WASM_RELAXED_SIMD", wasm_relaxed_simd)
937 set_define("ENABLE_WASM_RELAXED_SIMD", wasm_relaxed_simd)
939 # Support for WebAssembly intgemm private intrinsics
940 # =====================================================
943 @depends(milestone.is_nightly)
944 def default_wasm_moz_intgemm(is_nightly):
945     if is_nightly:
946         return True
949 option(
950     "--enable-wasm-moz-intgemm",
951     default=default_wasm_moz_intgemm,
952     help="{Enable|Disable} WebAssembly intgemm private intrinsics",
956 @depends("--enable-wasm-moz-intgemm", target, "--wasm-no-experimental")
957 def wasm_moz_intgemm(value, target, no_experimental):
958     if no_experimental:
959         return
961     if value and target.cpu in ("x86", "x86_64", "aarch64"):
962         return True
965 set_config("ENABLE_WASM_MOZ_INTGEMM", wasm_moz_intgemm)
966 set_define("ENABLE_WASM_MOZ_INTGEMM", wasm_moz_intgemm)
968 # Support for WebAssembly Memory64.
969 # ===========================
972 @depends(milestone.is_nightly, "--enable-simulator", target)
973 def default_wasm_memory64(is_nightly, simulator, target):
974     if target.cpu == "mips32":
975         return
977     if simulator and simulator[0] == "mips32":
978         return
980     if is_nightly:
981         return True
984 option(
985     "--enable-wasm-memory64",
986     default=default_wasm_memory64,
987     help="{Enable|Disable} WebAssembly Memory64",
991 @depends(
992     "--enable-wasm-memory64", "--enable-simulator", target, "--wasm-no-experimental"
994 def wasm_memory64(value, simulator, target, no_experimental):
995     if no_experimental or not value:
996         return
998     if target.cpu == "mips32":
999         die("Memory64 is incompatible with MIPS32 target")
1001     if simulator and simulator[0] == "mips32":
1002         die("Memory64 is incompatible with MIPS32 simulator")
1004     return True
1007 set_config("ENABLE_WASM_MEMORY64", wasm_memory64)
1008 set_define("ENABLE_WASM_MEMORY64", wasm_memory64)
1011 # Support for WebAssembly memory control.
1012 # ===========================
1015 @depends(milestone.is_nightly)
1016 def default_wasm_memory_control(is_nightly):
1017     if is_nightly:
1018         return True
1021 option(
1022     "--enable-wasm-memory-control",
1023     default=default_wasm_memory_control,
1024     help="{Enable|Disable} WebAssembly fine-grained memory control instructions",
1028 @depends("--enable-wasm-memory-control", "--wasm-no-experimental")
1029 def wasm_memory_control(value, no_experimental):
1030     if no_experimental or not value:
1031         return
1033     return True
1036 set_config("ENABLE_WASM_MEMORY_CONTROL", wasm_memory_control)
1037 set_define("ENABLE_WASM_MEMORY_CONTROL", wasm_memory_control)
1040 # Support for WebAssembly Multi Memory.
1041 # =====================================
1044 @depends(milestone.is_nightly)
1045 def default_wasm_multi_memory(is_nightly):
1046     if is_nightly:
1047         return True
1050 option(
1051     "--enable-wasm-multi-memory",
1052     default=default_wasm_multi_memory,
1053     help="{Enable|Disable} WebAssembly multi-memory",
1057 @depends("--enable-wasm-multi-memory", "--wasm-no-experimental")
1058 def wasm_multi_memory(value, no_experimental):
1059     if no_experimental or not value:
1060         return
1062     return True
1065 set_config("ENABLE_WASM_MULTI_MEMORY", wasm_multi_memory)
1066 set_define("ENABLE_WASM_MULTI_MEMORY", wasm_multi_memory)
1068 # Options for generating the shell as a script
1069 # ============================================
1070 option("--with-qemu-exe", nargs=1, help="Use path as an arm emulator on host platforms")
1071 set_config("QEMU_EXE", depends_if("--with-qemu-exe")(lambda x: x))
1073 option(
1074     "--with-cross-lib",
1075     nargs=1,
1076     default=depends(target.alias)(lambda x: "/usr/%s" % x),
1077     help="Use dir as the location for arm libraries",
1079 set_config("CROSS_LIB", depends_if("--with-cross-lib")(lambda x: x))
1081 # Enable static checking using sixgill
1082 # ====================================
1084 option("--with-sixgill", nargs=1, help="Enable static checking of code using sixgill")
1087 @depends_if("--with-sixgill")
1088 @imports("os")
1089 def sixgill(value):
1090     for f in ("bin/xdbfind", "gcc/xgill.so", "scripts/wrap_gcc/g++"):
1091         if not os.path.exists(os.path.join(value[0], f)):
1092             die("The sixgill plugin and binaries are not at the specified path")
1093     return value[0]
1096 set_config("SIXGILL_PATH", sixgill)
1099 # Support for readline
1100 # =====================================================
1103 @depends("--enable-js-shell", target_is_windows, compile_environment, target)
1104 def editline(js_shell, is_windows, compile_environment, target):
1105     return js_shell and not is_windows and compile_environment and (target.os != "WASI")
1108 option(
1109     "--enable-readline", help="Link js shell to system readline library", when=editline
1112 has_readline = check_symbol(
1113     "readline",
1114     flags=["-lreadline"],
1115     when="--enable-readline",
1116     onerror=lambda: die("No system readline library found"),
1119 set_config("EDITLINE_LIBS", ["-lreadline"], when=has_readline)
1122 @depends("--enable-readline", editline, when=editline)
1123 def bundled_editline(readline, editline):
1124     return editline and not readline
1127 set_config("JS_BUNDLED_EDITLINE", bundled_editline)
1129 set_define("EDITLINE", True, when=editline)
1132 # JIT observers
1133 # =============
1135 option(
1136     "--with-jitreport-granularity",
1137     default="3",
1138     choices=("0", "1", "2", "3"),
1139     help="Default granularity at which to report JIT code to external tools "
1140     "(0 - no info, 1 - code ranges for while functions only, "
1141     "2 - per-line information, 3 - per-op information)",
1144 set_define(
1145     "JS_DEFAULT_JITREPORT_GRANULARITY",
1146     depends_if("--with-jitreport-granularity")(lambda value: value[0]),
1150 # ECMAScript Internationalization API Support (uses ICU)
1151 # ======================================================
1152 system_lib_option("--with-system-icu", help="Use system ICU")
1154 system_icu = pkg_check_modules("MOZ_ICU", "icu-i18n >= 73.1", when="--with-system-icu")
1157 @depends("--with-system-icu")
1158 def in_tree_icu(system_icu):
1159     return not system_icu
1162 # Set MOZ_ICU_CFLAGS to an explicit empty value when --with-system-icu is *not* used,
1163 # for layout/style/extra-bindgen-flags
1164 set_config("MOZ_ICU_CFLAGS", [], when=in_tree_icu)
1166 set_config("MOZ_SYSTEM_ICU", True, when=system_icu)
1167 set_define("MOZ_SYSTEM_ICU", True, when=system_icu)
1169 option("--without-intl-api", help="Disable ECMAScript Internationalization API")
1172 @depends("--with-intl-api", js_standalone)
1173 def check_intl_api(enabled, js_standalone):
1174     if not enabled and not js_standalone:
1175         die("--without-intl-api is not supported")
1178 set_config("JS_HAS_INTL_API", True, when="--with-intl-api")
1179 set_define("JS_HAS_INTL_API", True, when="--with-intl-api")
1182 @depends(build_environment, when="--with-intl-api")
1183 @imports(_from="__builtin__", _import="open")
1184 @imports(_from="__builtin__", _import="ValueError")
1185 def icu_version(build_env):
1186     path = os.path.join(
1187         build_env.topsrcdir, "intl", "icu", "source", "common", "unicode", "uvernum.h"
1188     )
1189     with open(path, encoding="utf-8") as fh:
1190         for line in fh:
1191             if line.startswith("#define"):
1192                 define = line.split(None, 3)
1193                 if len(define) == 3 and define[1] == "U_ICU_VERSION_MAJOR_NUM":
1194                     try:
1195                         return str(int(define[2]))
1196                     except ValueError:
1197                         pass
1198     die("Cannot determine ICU version number from uvernum.h header file")
1201 set_config("MOZ_ICU_VERSION", icu_version)
1203 # Source files that use ICU should have control over which parts of the ICU
1204 # namespace they want to use.
1205 set_define("U_USING_ICU_NAMESPACE", "0", when="--with-intl-api")
1207 # We build ICU as a static library.
1208 set_define("U_STATIC_IMPLEMENTATION", True, when=depends(system_icu)(lambda x: not x))
1211 # ECMAScript Temporal API Support (uses ICU)
1212 # ======================================================
1214 option("--with-temporal-api", default=False, help="Enable ECMAScript Temporal API")
1216 set_config("JS_HAS_TEMPORAL_API", True, when="--with-temporal-api")
1217 set_define("JS_HAS_TEMPORAL_API", True, when="--with-temporal-api")
1220 @depends("--with-temporal-api", "--with-intl-api")
1221 def check_temporal_api(temporal_enabled, intl_enabled):
1222     if temporal_enabled and not intl_enabled:
1223         die("Can't use both --with-temporal-api and --without-intl-api")
1226 # Initial support for WebAssembly JS-API Type Reflections
1227 # =======================================================
1230 @depends(milestone.is_nightly)
1231 def default_wasm_type_reflections(is_nightly):
1232     return is_nightly
1235 option(
1236     "--enable-wasm-type-reflections",
1237     default=default_wasm_type_reflections,
1238     help="{Enable|Disable} type reflection in WASM JS-API",
1241 set_config(
1242     "ENABLE_WASM_TYPE_REFLECTIONS",
1243     depends_if("--enable-wasm-type-reflections")(lambda x: True),
1245 set_define(
1246     "ENABLE_WASM_TYPE_REFLECTIONS",
1247     depends_if("--enable-wasm-type-reflections")(lambda x: True),
1250 # Wasi configuration
1251 # ===================================================
1254 @depends(target.os)
1255 def is_wasi_target(os):
1256     return os == "WASI"
1259 set_define("_WASI_EMULATED_PROCESS_CLOCKS", True, when=is_wasi_target)
1260 set_define("_WASI_EMULATED_GETPID", True, when=is_wasi_target)
1262 # Enable New Set methods
1263 # ===================================================
1264 def use_new_set_methods():
1265     return False
1268 option(
1269     "--enable-new-set-methods",
1270     default=use_new_set_methods(),
1271     help="{Enable|Disable} New Set methods pref/command-line option (disabled by default)",
1275 @depends("--enable-new-set-methods")
1276 def enable_new_set_methods(value):
1277     if value:
1278         return True
1281 set_config("ENABLE_NEW_SET_METHODS", enable_new_set_methods)
1282 set_define("ENABLE_NEW_SET_METHODS", enable_new_set_methods)
1285 @depends(milestone.version)
1286 def js_version(version):
1287     return Version(version)
1290 set_config("MOZJS_MAJOR_VERSION", depends(js_version.major)(lambda m: str(m)))
1291 set_define("MOZJS_MAJOR_VERSION", js_version.major)
1292 set_config("MOZJS_MINOR_VERSION", depends(js_version.minor)(lambda m: str(m)))
1293 set_define("MOZJS_MINOR_VERSION", js_version.minor)
1294 set_config("MOZJS_PATCH_VERSION", depends(js_version.patch)(lambda p: str(p)))
1295 set_config(
1296     "MOZJS_ALPHA",
1297     depends(js_version)(
1298         lambda x: x.version[-2] if str(x.version[-2]) in "ab" else None
1299     ),
1303 # Some platforms have HeapReg, some don't
1304 # =====================================================
1306 # The ARM simulator runs on x86 and might be excluded by the first test,
1307 # so we special-case it.
1310 @depends("--enable-simulator", target)
1311 def wasm_has_heapreg(simulator, target):
1312     if target.cpu != "x86":
1313         return True
1315     if simulator and simulator[0] == "arm":
1316         return True
1319 set_define("WASM_HAS_HEAPREG", wasm_has_heapreg)
1321 # Check for tm_zone, tm_gmtoff in struct tm
1322 # ===================================================
1323 with only_when(compile_environment):
1324     set_define(
1325         "HAVE_TM_ZONE_TM_GMTOFF",
1326         c_compiler.try_compile(
1327             includes=["time.h"],
1328             body="struct tm tm; tm.tm_zone = 0; tm.tm_gmtoff = 1;",
1329             check_msg="for tm_zone and tm_gmtoff in struct tm",
1330         ),
1331     )
1334 # Checks for library functions
1335 # ==============================================================
1336 with only_when(compile_environment & depends(target.os)(lambda os: os != "WINNT")):
1337     set_define("HAVE_GETPAGESIZE", check_symbol("getpagesize"))
1338     set_define("HAVE_GMTIME_R", check_symbol("gmtime_r"))
1339     set_define("HAVE_LOCALTIME_R", check_symbol("localtime_r"))
1340     set_define("HAVE_GETTID", check_symbol("gettid"))
1341     set_define("HAVE_SETPRIORITY", check_symbol("setpriority"))
1342     set_define("HAVE_SYSCALL", check_symbol("syscall"))
1343     set_define("HAVE_GETC_UNLOCKED", check_symbol("getc_unlocked"))
1344     set_define("HAVE_PTHREAD_GETNAME_NP", check_symbol("pthread_getname_np"))
1345     set_define("HAVE_PTHREAD_GET_NAME_NP", check_symbol("pthread_get_name_np"))
1346     set_define("HAVE_STRERROR", check_symbol("strerror"))
1348     @depends(check_symbol("__cxa_demangle", language="C++"), moz_debug, dmd)
1349     def demangle_symbols(cxa_demangle, moz_debug, dmd):
1350         # Demangle only for debug or DMD builds
1351         if cxa_demangle and (moz_debug or dmd):
1352             return True
1354     set_define("MOZ_DEMANGLE_SYMBOLS", demangle_symbols)
1356     set_define(
1357         "HAVE__UNWIND_BACKTRACE",
1358         check_symbol("_Unwind_Backtrace", when=check_header("unwind.h")),
1359     )
1361 with only_when(compile_environment):
1362     set_define("HAVE__GETC_NOLOCK", check_symbol("_getc_nolock"))
1363     set_define("HAVE_LOCALECONV", check_symbol("localeconv"))