Bug 1814798 - pt 1. Add bool to enable/disable PHC at runtime r=glandium
[gecko.git] / js / moz.configure
blobf4a1f0dea5cd858e3464eb01d2371589d3946fb1
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)
177 # JIT support
178 # =======================================================
179 @depends(target, "--enable-record-tuple")
180 def jit_default(target, enable_record_tuple):
181     if enable_record_tuple:
182         return False
183     if target.cpu in (
184         "x86",
185         "x86_64",
186         "arm",
187         "aarch64",
188         "mips32",
189         "mips64",
190         "loongarch64",
191     ):
192         return True
193     return False
196 option("--enable-jit", default=jit_default, help="{Enable|Disable} use of the JITs")
199 @deprecated_option("--enable-ion")
200 def report_deprecated(value):
201     if value:
202         die("--enable-ion is deprecated, use --enable-jit instead")
203     else:
204         die("--disable-ion is deprecated, use --disable-jit instead")
207 # JIT code simulator for cross compiles
208 # =======================================================
209 option(
210     "--enable-simulator",
211     choices=("arm", "arm64", "mips32", "mips64", "loong64", "riscv64"),
212     nargs=1,
213     help="Enable a JIT code simulator for the specified architecture",
217 @depends("--enable-jit", "--enable-simulator", target)
218 def simulator(jit_enabled, simulator_enabled, target):
219     if not jit_enabled or not simulator_enabled:
220         return
222     sim_cpu = simulator_enabled[0]
224     if sim_cpu in ("arm", "mips32"):
225         if target.cpu != "x86":
226             die("The %s simulator only works on x86." % sim_cpu)
228     if sim_cpu in ("arm64", "mips64", "loong64", "riscv64"):
229         if target.cpu != "x86_64" and target.cpu != "aarch64":
230             die("The %s simulator only works on x86-64 or arm64." % sim_cpu)
232     return namespace(**{sim_cpu: True})
235 set_config("JS_SIMULATOR", depends_if(simulator)(lambda x: True))
236 set_config("JS_SIMULATOR_ARM", simulator.arm)
237 set_config("JS_SIMULATOR_ARM64", simulator.arm64)
238 set_config("JS_SIMULATOR_MIPS32", simulator.mips32)
239 set_config("JS_SIMULATOR_MIPS64", simulator.mips64)
240 set_config("JS_SIMULATOR_LOONG64", simulator.loong64)
241 set_config("JS_SIMULATOR_RISCV64", simulator.riscv64)
242 set_define("JS_SIMULATOR", depends_if(simulator)(lambda x: True))
243 set_define("JS_SIMULATOR_ARM", simulator.arm)
244 set_define("JS_SIMULATOR_ARM64", simulator.arm64)
245 set_define("JS_SIMULATOR_MIPS32", simulator.mips32)
246 set_define("JS_SIMULATOR_MIPS64", simulator.mips64)
247 set_define("JS_SIMULATOR_LOONG64", simulator.loong64)
248 set_define("JS_SIMULATOR_RISCV64", simulator.riscv64)
251 @depends("--enable-jit", simulator, target)
252 def jit_codegen(jit_enabled, simulator, target):
253     if not jit_enabled:
254         return namespace(none=True)
256     if simulator:
257         return simulator
259     if target.cpu == "aarch64":
260         return namespace(arm64=True)
261     elif target.cpu == "x86_64":
262         return namespace(x64=True)
263     elif target.cpu == "loongarch64":
264         return namespace(loong64=True)
265     elif target.cpu == "riscv64":
266         return namespace(riscv64=True)
268     return namespace(**{str(target.cpu): True})
271 set_config("JS_CODEGEN_NONE", jit_codegen.none)
272 set_config("JS_CODEGEN_ARM", jit_codegen.arm)
273 set_config("JS_CODEGEN_ARM64", jit_codegen.arm64)
274 set_config("JS_CODEGEN_MIPS32", jit_codegen.mips32)
275 set_config("JS_CODEGEN_MIPS64", jit_codegen.mips64)
276 set_config("JS_CODEGEN_LOONG64", jit_codegen.loong64)
277 set_config("JS_CODEGEN_RISCV64", jit_codegen.riscv64)
278 set_config("JS_CODEGEN_X86", jit_codegen.x86)
279 set_config("JS_CODEGEN_X64", jit_codegen.x64)
280 set_config("JS_CODEGEN_WASM32", jit_codegen.wasm32)
282 set_define("JS_CODEGEN_NONE", jit_codegen.none)
283 set_define("JS_CODEGEN_ARM", jit_codegen.arm)
284 set_define("JS_CODEGEN_ARM64", jit_codegen.arm64)
285 set_define("JS_CODEGEN_MIPS32", jit_codegen.mips32)
286 set_define("JS_CODEGEN_MIPS64", jit_codegen.mips64)
287 set_define("JS_CODEGEN_LOONG64", jit_codegen.loong64)
288 set_define("JS_CODEGEN_RISCV64", jit_codegen.riscv64)
289 set_define("JS_CODEGEN_X86", jit_codegen.x86)
290 set_define("JS_CODEGEN_X64", jit_codegen.x64)
291 set_define("JS_CODEGEN_WASM32", jit_codegen.wasm32)
294 # Profiling
295 # =======================================================
296 option(
297     "--enable-instruments",
298     env="MOZ_INSTRUMENTS",
299     help="Enable instruments remote profiling",
303 @depends("--enable-instruments", target)
304 def instruments(value, target):
305     if value and target.os != "OSX":
306         die("--enable-instruments cannot be used when targeting %s", target.os)
307     if value:
308         return True
311 set_config("MOZ_INSTRUMENTS", instruments)
312 set_define("MOZ_INSTRUMENTS", instruments)
313 add_old_configure_assignment("MOZ_INSTRUMENTS", instruments)
314 imply_option("--enable-profiling", instruments, reason="--enable-instruments")
316 option("--enable-callgrind", env="MOZ_CALLGRIND", help="Enable callgrind profiling")
319 @depends("--enable-callgrind")
320 def callgrind(value):
321     if value:
322         return True
325 set_define("MOZ_CALLGRIND", callgrind)
326 imply_option("--enable-profiling", callgrind)
329 @depends(milestone)
330 def enable_profiling(milestone):
331     return milestone.is_nightly
334 option(
335     "--enable-profiling",
336     env="MOZ_PROFILING",
337     default=enable_profiling,
338     help="{Set|Do not set} compile flags necessary for using sampling "
339     "profilers (e.g. shark, perf)",
343 @depends("--enable-profiling")
344 def profiling(value):
345     if value:
346         return True
349 with only_when("--enable-compile-environment"):
350     imply_option("--enable-frame-pointers", True, when=profiling)
353 @depends(profiling, target)
354 def imply_vtune(value, target):
355     ok_cpu = target.cpu in ["x86", "x86_64"]
356     ok_kernel = target.kernel == "WINNT" or (
357         target.kernel == "Linux" and target.os == "GNU"
358     )
360     if value and ok_cpu and ok_kernel:
361         return True
364 set_config("MOZ_PROFILING", profiling)
365 set_define("MOZ_PROFILING", profiling)
366 imply_option("--enable-vtune", imply_vtune, reason="--enable-profiling")
369 option("--enable-vtune", env="MOZ_VTUNE", help="Enable VTune profiling")
372 @depends("--enable-vtune")
373 def vtune(value):
374     if value:
375         return True
378 set_config("MOZ_VTUNE", vtune)
379 set_define("MOZ_VTUNE", vtune)
382 option(
383     "--enable-gc-probes",
384     env="JS_GC_PROBES",
385     help="Turn on probes for allocation and finalization",
389 @depends("--enable-gc-probes")
390 def gc_probes(value):
391     if value:
392         return True
395 set_define("JS_GC_PROBES", gc_probes)
398 option(
399     "--enable-gczeal",
400     default=depends(when=moz_debug)(lambda: True),
401     help="{Enable|Disable} zealous GCing",
404 set_define("JS_GC_ZEAL", depends_if("--enable-gczeal")(lambda _: True))
407 # Enable breakpoint for artificial OOMs
408 # =======================================================
409 option(
410     "--enable-oom-breakpoint", help="Enable a breakpoint function for artificial OOMs"
413 set_define("JS_OOM_BREAKPOINT", depends_if("--enable-oom-breakpoint")(lambda _: True))
416 option("--enable-perf", env="JS_ION_PERF", help="Enable Linux perf integration")
419 @depends("--enable-perf", target)
420 def ion_perf(value, target):
421     is_linux = target.kernel == "Linux"
422     is_mac = target.kernel == "Darwin" and target.os == "OSX"
424     if value and (is_linux or is_mac):
425         return True
428 set_define("JS_ION_PERF", ion_perf)
431 option(
432     "--enable-jitspew",
433     default=depends(when=moz_debug)(lambda: True),
434     help="{Enable|Disable} the Jit spew and IONFLAGS environment " "variable",
437 set_define("JS_JITSPEW", depends_if("--enable-jitspew")(lambda _: True))
438 set_config("JS_JITSPEW", depends_if("--enable-jitspew")(lambda _: True))
440 # Also enable the structured spewer
441 set_define("JS_STRUCTURED_SPEW", depends_if("--enable-jitspew")(lambda _: True))
442 set_config("JS_STRUCTURED_SPEW", depends_if("--enable-jitspew")(lambda _: True))
445 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
446 def jit_disasm_arm(jit_enabled, spew, simulator, target, debug):
447     if not jit_enabled:
448         return
450     if simulator and (debug or spew):
451         if getattr(simulator, "arm", None):
452             return True
454     if target.cpu == "arm" and (debug or spew):
455         return True
458 set_config("JS_DISASM_ARM", jit_disasm_arm)
459 set_define("JS_DISASM_ARM", jit_disasm_arm)
462 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
463 def jit_disasm_riscv(jit_enabled, spew, simulator, target, debug):
464     if not jit_enabled:
465         return
467     if simulator and (debug or spew):
468         if getattr(simulator, "riscv64", None):
469             return True
471     if target.cpu == "riscv64" and (debug or spew):
472         return True
475 set_config("JS_DISASM_RISCV64", jit_disasm_riscv)
476 set_define("JS_DISASM_RISCV64", jit_disasm_riscv)
479 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
480 def jit_disasm_arm64(jit_enabled, spew, simulator, target, debug):
481     if not jit_enabled:
482         return
484     if simulator and (debug or spew):
485         if getattr(simulator, "arm64", None):
486             return True
488     if target.cpu == "aarch64" and (debug or spew):
489         return True
492 set_config("JS_DISASM_ARM64", jit_disasm_arm64)
493 set_define("JS_DISASM_ARM64", jit_disasm_arm64)
495 # When enabled, masm will generate assumeUnreachable calls that act as
496 # assertions in the generated code. This option is worth disabling when you
497 # have to track mutated values through the generated code, to avoid constantly
498 # dumping registers on and off the stack.
499 option(
500     "--enable-masm-verbose",
501     default=depends(when=moz_debug)(lambda: True),
502     help="{Enable|Disable} MacroAssembler verbosity of generated code.",
504 set_define("JS_MASM_VERBOSE", depends_if("--enable-masm-verbose")(lambda _: True))
505 set_config("JS_MASM_VERBOSE", depends_if("--enable-masm-verbose")(lambda _: True))
507 # Architecture feature flags
508 # =======================================================
511 # Apple silicon does not seem to have any way to query the OS for the JSCVT
512 # flag stored in the ID_AA64ISAR1_EL1 system register. In the mean time, we
513 # hard code the value of the JSCVT flag which guards the implementation of
514 # FJCVTZS instruction as part of ARMv8.3-JSConv.
515 @depends(target)
516 def is_apple_silicon(target):
517     return target.os == "OSX" and target.kernel == "Darwin" and target.cpu == "aarch64"
520 option(
521     "--enable-arm64-fjcvtzs",
522     default=is_apple_silicon,
523     help="{Enable|Disable} static use of FJCVTZS instruction on Aarch64 targets.",
527 # The "ARM Architecture Reference Manual" for ARMv8 defines the JSCVT flag as
528 # being a 4 bit integer (D12.2.52) and it can be manipulated using >= operator
529 # (D12.1.4).
531 # The FJCVTZS instruction is implemented if ID_AA64ISAR1_EL1.JSCVT >= 1.
532 @depends("--enable-arm64-fjcvtzs", target, simulator)
533 def aarch64_jscvt(fjcvtzs, target, simulator):
534     if target.cpu == "aarch64" and fjcvtzs:
535         return 1
537     if simulator and getattr(simulator, "arm64", False) and fjcvtzs:
538         return 1
540     return 0
543 set_define("MOZ_AARCH64_JSCVT", aarch64_jscvt)
546 @depends(target)
547 def has_pthread_jit_write_protect_np(target):
548     return target.os == "OSX" and target.cpu == "aarch64"
551 # On Apple Silicon we use MAP_JIT with pthread_jit_write_protect_np to implement
552 # JIT code write protection.
553 set_define("JS_USE_APPLE_FAST_WX", True, when=has_pthread_jit_write_protect_np)
556 # CTypes
557 # =======================================================
558 @depends(js_standalone)
559 def ctypes_default(js_standalone):
560     return not js_standalone
563 option("--enable-ctypes", default=ctypes_default, help="{Enable|Disable} js-ctypes")
565 build_ctypes = depends_if("--enable-ctypes")(lambda _: True)
567 set_config("BUILD_CTYPES", build_ctypes)
568 set_define("BUILD_CTYPES", build_ctypes)
570 set_config("JS_HAS_CTYPES", build_ctypes)
571 set_define("JS_HAS_CTYPES", build_ctypes)
574 @depends("--enable-ctypes", "--enable-compile-environment")
575 def ctypes_and_compile_environment(ctypes, compile_environment):
576     return ctypes and compile_environment
579 include("ffi.configure", when=ctypes_and_compile_environment)
582 # Enable pipeline operator
583 # ===================================================
584 option("--enable-pipeline-operator", default=False, help="Enable pipeline operator")
587 @depends("--enable-pipeline-operator")
588 def enable_pipeline_operator(value):
589     if value:
590         return True
593 set_config("ENABLE_PIPELINE_OPERATOR", enable_pipeline_operator)
594 set_define("ENABLE_PIPELINE_OPERATOR", enable_pipeline_operator)
597 # SIMD acceleration for encoding_rs
598 # ==============================================================
600 option(
601     "--enable-rust-simd", env="MOZ_RUST_SIMD", help="Enable explicit SIMD in Rust code."
605 @depends("--enable-rust-simd", target)
606 def rust_simd(value, target):
607     # As of 2019-09-17, the simd-accel feature of encoding_rs has not
608     # been properly set up outside aarch64, armv7, x86 and x86_64.
609     if target.cpu in ("aarch64", "arm", "x86", "x86_64") and value:
610         return True
613 set_config("MOZ_RUST_SIMD", rust_simd)
614 set_define("MOZ_RUST_SIMD", rust_simd)
616 # Telemetry to measure compile time and generated-code runtime
617 # ============================================================
619 option(
620     "--enable-spidermonkey-telemetry",
621     default=milestone.is_nightly,
622     help="{Enable|Disable} performance telemetry for SpiderMonkey (e.g. compile and run times)",
625 set_define(
626     "ENABLE_SPIDERMONKEY_TELEMETRY",
627     depends_if("--enable-spidermonkey-telemetry")(lambda x: True),
630 # Support for debugging code generated by wasm backends
631 # =====================================================
633 option(
634     "--enable-wasm-codegen-debug",
635     default=depends(when=moz_debug)(lambda: True),
636     help="{Enable|Disable} debugging for wasm codegen",
639 set_config(
640     "WASM_CODEGEN_DEBUG", depends_if("--enable-wasm-codegen-debug")(lambda x: True)
642 set_define(
643     "WASM_CODEGEN_DEBUG", depends_if("--enable-wasm-codegen-debug")(lambda x: True)
646 # WebAssembly feature flags
647 # ==================================================
649 option(
650     "--wasm-no-experimental",
651     default=False,
652     help="Force disable all wasm experimental features for testing.",
655 # Support for WebAssembly function-references.
656 # ===========================
659 option(
660     "--disable-wasm-function-references",
661     default=True,
662     help="{Enable|Disable} WebAssembly function-references",
666 @depends("--disable-wasm-function-references", "--wasm-no-experimental")
667 def wasm_function_references(value, no_experimental):
668     if no_experimental:
669         return
671     if value:
672         return True
675 set_config("ENABLE_WASM_FUNCTION_REFERENCES", wasm_function_references)
676 set_define("ENABLE_WASM_FUNCTION_REFERENCES", wasm_function_references)
678 # Support for WebAssembly tail-calls.
679 # ===========================
682 @depends(milestone.is_nightly)
683 def default_wasm_tail_calls(is_nightly):
684     if is_nightly:
685         return True
688 option(
689     "--enable-wasm-tail-calls",
690     default=default_wasm_tail_calls,
691     help="{Enable|Disable} WebAssembly tail-calls",
695 @depends("--enable-wasm-tail-calls", target)
696 def wasm_tail_calls(value, target):
697     if not value:
698         return
700     if target.cpu in ("x86", "x86_64", "arm", "aarch64", "loongarch64", "mips64"):
701         return True
704 set_config("ENABLE_WASM_TAIL_CALLS", wasm_tail_calls)
705 set_define("ENABLE_WASM_TAIL_CALLS", wasm_tail_calls)
707 # Support for WebAssembly GC.
708 # ===========================
711 @depends("--disable-wasm-function-references")
712 def default_wasm_gc(function_references):
713     if function_references:
714         return True
717 option(
718     "--disable-wasm-gc", default=default_wasm_gc, help="{Enable|Disable} WebAssembly GC"
722 @depends(
723     "--disable-wasm-gc", "--disable-wasm-function-references", "--wasm-no-experimental"
725 def wasm_gc(value, function_references, no_experimental):
726     if no_experimental or not value:
727         return
729     if function_references:
730         return True
732     die("--disable-wasm-gc only possible with --disable-wasm-function-references")
735 set_config("ENABLE_WASM_GC", wasm_gc)
736 set_define("ENABLE_WASM_GC", wasm_gc)
739 # Support for WebAssembly shared memory and atomics.
741 # This affects the JS shell only.
742 # =====================================================
744 option(
745     "--disable-shared-memory", help="Disable JS/WebAssembly shared memory and atomics"
749 @depends("--disable-shared-memory")
750 def enable_shared_memory(value):
751     if value:
752         return True
755 set_config("ENABLE_SHARED_MEMORY", enable_shared_memory)
756 set_define("ENABLE_SHARED_MEMORY", enable_shared_memory)
758 # Support for WebAssembly extended constant expressions
759 # =====================================================
762 option(
763     "--disable-wasm-extended-const",
764     help="{Enable|Disable} WebAssembly extended constant expressions",
768 @depends("--disable-wasm-extended-const")
769 def wasm_extended_const(value):
770     if value:
771         return True
774 set_config("ENABLE_WASM_EXTENDED_CONST", wasm_extended_const)
775 set_define("ENABLE_WASM_EXTENDED_CONST", wasm_extended_const)
777 # Support for WebAssembly SIMD
778 # =====================================================
781 @depends("--enable-jit", "--enable-simulator", target)
782 def default_wasm_simd(jit_enabled, simulator, target):
783     if not jit_enabled:
784         return
786     if simulator and (simulator[0] != "arm64"):
787         return
789     if target.cpu in ("x86_64", "x86", "aarch64"):
790         return True
793 option(
794     "--enable-wasm-simd",
795     default=default_wasm_simd,
796     help="{Enable|Disable} WebAssembly SIMD",
800 @depends(
801     "--enable-wasm-simd",
802     "--enable-jit",
803     "--enable-simulator",
804     target,
805     "--wasm-no-experimental",
807 def wasm_simd(value, jit_enabled, simulator, target, no_experimental):
808     if no_experimental or not value:
809         return
811     if not jit_enabled:
812         die("--enable-wasm-simd requires --enable-jit")
814     if simulator and (simulator[0] != "arm64"):
815         die("--enable-wasm-simd is not supported for simulators, except arm64")
817     if target.cpu in ("x86_64", "x86", "aarch64"):
818         return True
820     die("--enable-wasm-simd only possible when targeting the x86_64/x86/arm64 jits")
823 set_config("ENABLE_WASM_SIMD", wasm_simd)
824 set_define("ENABLE_WASM_SIMD", wasm_simd)
826 # Whether to check for field changes in WebAssembly serialization
828 # See the comment for 'WASM_VERIFY_SERIALIZATION_FOR_SIZE' in WasmSerialize.cpp
829 # for more background.
830 # =====================================================================
833 @depends(
834     target,
835     c_compiler,
836     moz_debug,
837     milestone,
838     "--wasm-no-experimental",
840 def wasm_verify_serialization_for_size(
841     target, c_compiler, debug, milestone, no_experimental
843     if (
844         debug == True
845         and target.kernel == "Linux"
846         and target.cpu == "x86_64"
847         and c_compiler
848         and c_compiler.type == "clang"
849         and milestone.is_nightly
850         and not no_experimental
851     ):
852         return True
853     return
856 set_define(
857     "ENABLE_WASM_VERIFY_SERIALIZATION_FOR_SIZE", wasm_verify_serialization_for_size
860 # Support for Intel AVX instruction.
862 # AVX is exclusively used in WebAssembly SIMD instructions at the moment:
863 # set direct dependency on "--enable-wasm-simd".
864 # =====================================================
867 @depends("--enable-wasm-simd", "--enable-simulator", target)
868 def default_wasm_avx(wasm_simd_enabled, simulator, target):
869     if not wasm_simd_enabled:
870         return
872     if simulator:
873         return
875     if target.cpu in ("x86_64", "x86"):
876         return True
879 option(
880     "--enable-wasm-avx",
881     default=default_wasm_avx,
882     help="{Enable|Disable} AVX support for WebAssembly SIMD",
886 @depends(
887     "--enable-wasm-avx",
888     "--enable-wasm-simd",
889     "--enable-simulator",
890     target,
891     "--wasm-no-experimental",
893 def wasm_avx(value, wasm_simd_enabled, simulator, target, no_experimental):
894     if no_experimental or not value:
895         return
897     if not wasm_simd_enabled:
898         die("--enable-wasm-avx requires --enable-wasm-simd")
900     if simulator:
901         die("--enable-wasm-avx is not supported for simulators")
903     if target.cpu in ("x86_64", "x86"):
904         return True
906     die("--enable-wasm-avx only possible when targeting the x86_64/x86 jits")
909 set_config("ENABLE_WASM_AVX", wasm_avx)
910 set_define("ENABLE_WASM_AVX", wasm_avx)
912 # Support for WebAssembly relaxed SIMD
913 # =====================================================
916 @depends(milestone.is_nightly, "--enable-wasm-simd")
917 def default_wasm_relaxed_simd(is_nightly, wasm_simd):
918     if is_nightly and wasm_simd:
919         return True
922 option(
923     "--enable-wasm-relaxed-simd",
924     default=default_wasm_relaxed_simd,
925     help="{Enable|Disable} WebAssembly relaxed SIMD",
929 @depends("--enable-wasm-relaxed-simd", "--enable-wasm-simd", "--wasm-no-experimental")
930 def wasm_relaxed_simd(value, wasm_simd, no_experimental):
931     if no_experimental or not value:
932         return
934     if not wasm_simd:
935         die("relaxed SIMD requires SIMD")
937     return True
940 set_config("ENABLE_WASM_RELAXED_SIMD", wasm_relaxed_simd)
941 set_define("ENABLE_WASM_RELAXED_SIMD", wasm_relaxed_simd)
943 # Support for WebAssembly intgemm private intrinsics
944 # =====================================================
947 @depends(milestone.is_nightly)
948 def default_wasm_moz_intgemm(is_nightly):
949     if is_nightly:
950         return True
953 option(
954     "--enable-wasm-moz-intgemm",
955     default=default_wasm_moz_intgemm,
956     help="{Enable|Disable} WebAssembly intgemm private intrinsics",
960 @depends("--enable-wasm-moz-intgemm", target, "--wasm-no-experimental")
961 def wasm_moz_intgemm(value, target, no_experimental):
962     if no_experimental:
963         return
965     if value and target.cpu in ("x86", "x86_64", "aarch64"):
966         return True
969 set_config("ENABLE_WASM_MOZ_INTGEMM", wasm_moz_intgemm)
970 set_define("ENABLE_WASM_MOZ_INTGEMM", wasm_moz_intgemm)
972 # Support for WebAssembly Memory64.
973 # ===========================
976 @depends(milestone.is_nightly, "--enable-simulator", target)
977 def default_wasm_memory64(is_nightly, simulator, target):
978     if target.cpu == "mips32":
979         return
981     if simulator and simulator[0] == "mips32":
982         return
984     if is_nightly:
985         return True
988 option(
989     "--enable-wasm-memory64",
990     default=default_wasm_memory64,
991     help="{Enable|Disable} WebAssembly Memory64",
995 @depends(
996     "--enable-wasm-memory64", "--enable-simulator", target, "--wasm-no-experimental"
998 def wasm_memory64(value, simulator, target, no_experimental):
999     if no_experimental or not value:
1000         return
1002     if target.cpu == "mips32":
1003         die("Memory64 is incompatible with MIPS32 target")
1005     if simulator and simulator[0] == "mips32":
1006         die("Memory64 is incompatible with MIPS32 simulator")
1008     return True
1011 set_config("ENABLE_WASM_MEMORY64", wasm_memory64)
1012 set_define("ENABLE_WASM_MEMORY64", wasm_memory64)
1015 # Support for WebAssembly memory control.
1016 # ===========================
1019 @depends(milestone.is_nightly)
1020 def default_wasm_memory_control(is_nightly):
1021     if is_nightly:
1022         return True
1025 option(
1026     "--enable-wasm-memory-control",
1027     default=default_wasm_memory_control,
1028     help="{Enable|Disable} WebAssembly fine-grained memory control instructions",
1032 @depends("--enable-wasm-memory-control", "--wasm-no-experimental")
1033 def wasm_memory_control(value, no_experimental):
1034     if no_experimental or not value:
1035         return
1037     return True
1040 set_config("ENABLE_WASM_MEMORY_CONTROL", wasm_memory_control)
1041 set_define("ENABLE_WASM_MEMORY_CONTROL", wasm_memory_control)
1044 # Support for WebAssembly Multi Memory.
1045 # =====================================
1048 @depends(milestone.is_nightly)
1049 def default_wasm_multi_memory(is_nightly):
1050     if is_nightly:
1051         return True
1054 option(
1055     "--enable-wasm-multi-memory",
1056     default=default_wasm_multi_memory,
1057     help="{Enable|Disable} WebAssembly multi-memory",
1061 @depends("--enable-wasm-multi-memory", "--wasm-no-experimental")
1062 def wasm_multi_memory(value, no_experimental):
1063     if no_experimental or not value:
1064         return
1066     return True
1069 set_config("ENABLE_WASM_MULTI_MEMORY", wasm_multi_memory)
1070 set_define("ENABLE_WASM_MULTI_MEMORY", wasm_multi_memory)
1072 # Options for generating the shell as a script
1073 # ============================================
1074 option("--with-qemu-exe", nargs=1, help="Use path as an arm emulator on host platforms")
1075 set_config("QEMU_EXE", depends_if("--with-qemu-exe")(lambda x: x))
1077 option(
1078     "--with-cross-lib",
1079     nargs=1,
1080     default=depends(target.alias)(lambda x: "/usr/%s" % x),
1081     help="Use dir as the location for arm libraries",
1083 set_config("CROSS_LIB", depends_if("--with-cross-lib")(lambda x: x))
1085 # Enable static checking using sixgill
1086 # ====================================
1088 option("--with-sixgill", nargs=1, help="Enable static checking of code using sixgill")
1091 @depends_if("--with-sixgill")
1092 @imports("os")
1093 def sixgill(value):
1094     for f in ("bin/xdbfind", "gcc/xgill.so", "scripts/wrap_gcc/g++"):
1095         if not os.path.exists(os.path.join(value[0], f)):
1096             die("The sixgill plugin and binaries are not at the specified path")
1097     return value[0]
1100 set_config("SIXGILL_PATH", sixgill)
1103 # Support for readline
1104 # =====================================================
1107 @depends("--enable-js-shell", target_is_windows, compile_environment, target)
1108 def editline(js_shell, is_windows, compile_environment, target):
1109     return js_shell and not is_windows and compile_environment and (target.os != "WASI")
1112 option(
1113     "--enable-readline", help="Link js shell to system readline library", when=editline
1116 has_readline = check_symbol(
1117     "readline",
1118     flags=["-lreadline"],
1119     when="--enable-readline",
1120     onerror=lambda: die("No system readline library found"),
1123 set_config("EDITLINE_LIBS", ["-lreadline"], when=has_readline)
1126 @depends("--enable-readline", editline, when=editline)
1127 def bundled_editline(readline, editline):
1128     return editline and not readline
1131 set_config("JS_BUNDLED_EDITLINE", bundled_editline)
1133 set_define("EDITLINE", True, when=editline)
1136 # JIT observers
1137 # =============
1139 option(
1140     "--with-jitreport-granularity",
1141     default="3",
1142     choices=("0", "1", "2", "3"),
1143     help="Default granularity at which to report JIT code to external tools "
1144     "(0 - no info, 1 - code ranges for while functions only, "
1145     "2 - per-line information, 3 - per-op information)",
1148 set_define(
1149     "JS_DEFAULT_JITREPORT_GRANULARITY",
1150     depends_if("--with-jitreport-granularity")(lambda value: value[0]),
1154 # ECMAScript Internationalization API Support (uses ICU)
1155 # ======================================================
1156 system_lib_option("--with-system-icu", help="Use system ICU")
1158 system_icu = pkg_check_modules("MOZ_ICU", "icu-i18n >= 73.1", when="--with-system-icu")
1161 @depends("--with-system-icu")
1162 def in_tree_icu(system_icu):
1163     return not system_icu
1166 # Set MOZ_ICU_CFLAGS to an explicit empty value when --with-system-icu is *not* used,
1167 # for layout/style/extra-bindgen-flags
1168 set_config("MOZ_ICU_CFLAGS", [], when=in_tree_icu)
1170 set_config("MOZ_SYSTEM_ICU", True, when=system_icu)
1171 set_define("MOZ_SYSTEM_ICU", True, when=system_icu)
1173 option("--without-intl-api", help="Disable ECMAScript Internationalization API")
1176 @depends("--with-intl-api", js_standalone)
1177 def check_intl_api(enabled, js_standalone):
1178     if not enabled and not js_standalone:
1179         die("--without-intl-api is not supported")
1182 set_config("JS_HAS_INTL_API", True, when="--with-intl-api")
1183 set_define("JS_HAS_INTL_API", True, when="--with-intl-api")
1186 @depends(build_environment, when="--with-intl-api")
1187 @imports(_from="__builtin__", _import="open")
1188 @imports(_from="__builtin__", _import="ValueError")
1189 def icu_version(build_env):
1190     path = os.path.join(
1191         build_env.topsrcdir, "intl", "icu", "source", "common", "unicode", "uvernum.h"
1192     )
1193     with open(path, encoding="utf-8") as fh:
1194         for line in fh:
1195             if line.startswith("#define"):
1196                 define = line.split(None, 3)
1197                 if len(define) == 3 and define[1] == "U_ICU_VERSION_MAJOR_NUM":
1198                     try:
1199                         return str(int(define[2]))
1200                     except ValueError:
1201                         pass
1202     die("Cannot determine ICU version number from uvernum.h header file")
1205 set_config("MOZ_ICU_VERSION", icu_version)
1207 # Source files that use ICU should have control over which parts of the ICU
1208 # namespace they want to use.
1209 set_define("U_USING_ICU_NAMESPACE", "0", when="--with-intl-api")
1211 # We build ICU as a static library.
1212 set_define("U_STATIC_IMPLEMENTATION", True, when=depends(system_icu)(lambda x: not x))
1215 # ECMAScript Temporal API Support (uses ICU)
1216 # ======================================================
1218 option("--with-temporal-api", default=False, help="Enable ECMAScript Temporal API")
1220 set_config("JS_HAS_TEMPORAL_API", True, when="--with-temporal-api")
1221 set_define("JS_HAS_TEMPORAL_API", True, when="--with-temporal-api")
1224 @depends("--with-temporal-api", "--with-intl-api")
1225 def check_temporal_api(temporal_enabled, intl_enabled):
1226     if temporal_enabled and not intl_enabled:
1227         die("Can't use both --with-temporal-api and --without-intl-api")
1230 # Initial support for WebAssembly JS-API Type Reflections
1231 # =======================================================
1234 @depends(milestone.is_nightly)
1235 def default_wasm_type_reflections(is_nightly):
1236     return is_nightly
1239 option(
1240     "--enable-wasm-type-reflections",
1241     default=default_wasm_type_reflections,
1242     help="{Enable|Disable} type reflection in WASM JS-API",
1245 set_config(
1246     "ENABLE_WASM_TYPE_REFLECTIONS",
1247     depends_if("--enable-wasm-type-reflections")(lambda x: True),
1249 set_define(
1250     "ENABLE_WASM_TYPE_REFLECTIONS",
1251     depends_if("--enable-wasm-type-reflections")(lambda x: True),
1254 # Wasi configuration
1255 # ===================================================
1258 @depends(target.os)
1259 def is_wasi_target(os):
1260     return os == "WASI"
1263 set_define("_WASI_EMULATED_PROCESS_CLOCKS", True, when=is_wasi_target)
1264 set_define("_WASI_EMULATED_GETPID", True, when=is_wasi_target)
1267 @depends(milestone.version)
1268 def js_version(version):
1269     return Version(version)
1272 set_config("MOZJS_MAJOR_VERSION", depends(js_version.major)(lambda m: str(m)))
1273 set_define("MOZJS_MAJOR_VERSION", js_version.major)
1274 set_config("MOZJS_MINOR_VERSION", depends(js_version.minor)(lambda m: str(m)))
1275 set_define("MOZJS_MINOR_VERSION", js_version.minor)
1276 set_config("MOZJS_PATCH_VERSION", depends(js_version.patch)(lambda p: str(p)))
1277 set_config(
1278     "MOZJS_ALPHA",
1279     depends(js_version)(
1280         lambda x: x.version[-2] if str(x.version[-2]) in "ab" else None
1281     ),
1285 # Some platforms have HeapReg, some don't
1286 # =====================================================
1288 # The ARM simulator runs on x86 and might be excluded by the first test,
1289 # so we special-case it.
1292 @depends("--enable-simulator", target)
1293 def wasm_has_heapreg(simulator, target):
1294     if target.cpu != "x86":
1295         return True
1297     if simulator and simulator[0] == "arm":
1298         return True
1301 set_define("WASM_HAS_HEAPREG", wasm_has_heapreg)
1303 # Check for tm_zone, tm_gmtoff in struct tm
1304 # ===================================================
1305 with only_when(compile_environment):
1306     set_define(
1307         "HAVE_TM_ZONE_TM_GMTOFF",
1308         c_compiler.try_compile(
1309             includes=["time.h"],
1310             body="struct tm tm; tm.tm_zone = 0; tm.tm_gmtoff = 1;",
1311             check_msg="for tm_zone and tm_gmtoff in struct tm",
1312         ),
1313     )
1316 # Checks for library functions
1317 # ==============================================================
1318 with only_when(compile_environment & depends(target.os)(lambda os: os != "WINNT")):
1319     set_define("HAVE_GETPAGESIZE", check_symbol("getpagesize"))
1320     set_define("HAVE_GMTIME_R", check_symbol("gmtime_r"))
1321     set_define("HAVE_LOCALTIME_R", check_symbol("localtime_r"))
1322     set_define("HAVE_GETTID", check_symbol("gettid"))
1323     set_define("HAVE_SETPRIORITY", check_symbol("setpriority"))
1324     set_define("HAVE_SYSCALL", check_symbol("syscall"))
1325     set_define("HAVE_GETC_UNLOCKED", check_symbol("getc_unlocked"))
1326     set_define("HAVE_PTHREAD_GETNAME_NP", check_symbol("pthread_getname_np"))
1327     set_define("HAVE_PTHREAD_GET_NAME_NP", check_symbol("pthread_get_name_np"))
1328     set_define("HAVE_STRERROR", check_symbol("strerror"))
1330     @depends(check_symbol("__cxa_demangle", language="C++"), moz_debug, dmd)
1331     def demangle_symbols(cxa_demangle, moz_debug, dmd):
1332         # Demangle only for debug or DMD builds
1333         if cxa_demangle and (moz_debug or dmd):
1334             return True
1336     set_define("MOZ_DEMANGLE_SYMBOLS", demangle_symbols)
1338     set_define(
1339         "HAVE__UNWIND_BACKTRACE",
1340         check_symbol("_Unwind_Backtrace", when=check_header("unwind.h")),
1341     )
1343 with only_when(compile_environment):
1344     set_define("HAVE__GETC_NOLOCK", check_symbol("_getc_nolock"))
1345     set_define("HAVE_LOCALECONV", check_symbol("localeconv"))