Bug 1855360 - Fix the skip-if syntax. a=bustage-fix
[gecko.git] / js / moz.configure
blob267b40cf587c3b5feea2f7bd1df09646114cd284
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 # Portable Baseline Intepreter
178 # =======================================================
179 option(
180     "--enable-portable-baseline-interp",
181     default=False,
182     help="{Enable|Disable} the portable baseline interpreter.",
184 set_define(
185     "ENABLE_PORTABLE_BASELINE_INTERP",
186     depends_if("--enable-portable-baseline-interp")(lambda _: True),
188 set_config(
189     "ENABLE_PORTABLE_BASELINE_INTERP",
190     depends_if("--enable-portable-baseline-interp")(lambda _: True),
193 # Option to always force PBL tier.
194 option(
195     "--enable-portable-baseline-interp-force",
196     default=False,
197     help="{Enable|Disable} forcing use of the portable baseline interpreter.",
200 set_define(
201     "ENABLE_PORTABLE_BASELINE_INTERP_FORCE",
202     depends_if("--enable-portable-baseline-interp-force")(lambda _: True),
204 set_config(
205     "ENABLE_PORTABLE_BASELINE_INTERP_FORCE",
206     depends_if("--enable-portable-baseline-interp-force")(lambda _: True),
210 # JIT support
211 # =======================================================
212 @depends(target, "--enable-record-tuple", "--enable-portable-baseline-interp")
213 def jit_default(target, enable_record_tuple, enable_portable_baseline_interp):
214     if enable_record_tuple:
215         return False
216     if enable_portable_baseline_interp:
217         return False
218     if target.cpu in (
219         "x86",
220         "x86_64",
221         "arm",
222         "aarch64",
223         "mips32",
224         "mips64",
225         "loongarch64",
226     ):
227         return True
228     return False
231 option("--enable-jit", default=jit_default, help="{Enable|Disable} use of the JITs")
234 @deprecated_option("--enable-ion")
235 def report_deprecated(value):
236     if value:
237         die("--enable-ion is deprecated, use --enable-jit instead")
238     else:
239         die("--disable-ion is deprecated, use --disable-jit instead")
242 # JIT code simulator for cross compiles
243 # =======================================================
244 option(
245     "--enable-simulator",
246     choices=("arm", "arm64", "mips32", "mips64", "loong64", "riscv64"),
247     nargs=1,
248     help="Enable a JIT code simulator for the specified architecture",
252 @depends("--enable-jit", "--enable-simulator", target)
253 def simulator(jit_enabled, simulator_enabled, target):
254     if not jit_enabled or not simulator_enabled:
255         return
257     sim_cpu = simulator_enabled[0]
259     if sim_cpu in ("arm", "mips32"):
260         if target.cpu != "x86":
261             die("The %s simulator only works on x86." % sim_cpu)
263     if sim_cpu in ("arm64", "mips64", "loong64", "riscv64"):
264         if target.cpu != "x86_64" and target.cpu != "aarch64":
265             die("The %s simulator only works on x86-64 or arm64." % sim_cpu)
267     return namespace(**{sim_cpu: True})
270 set_config("JS_SIMULATOR", depends_if(simulator)(lambda x: True))
271 set_config("JS_SIMULATOR_ARM", simulator.arm)
272 set_config("JS_SIMULATOR_ARM64", simulator.arm64)
273 set_config("JS_SIMULATOR_MIPS32", simulator.mips32)
274 set_config("JS_SIMULATOR_MIPS64", simulator.mips64)
275 set_config("JS_SIMULATOR_LOONG64", simulator.loong64)
276 set_config("JS_SIMULATOR_RISCV64", simulator.riscv64)
277 set_define("JS_SIMULATOR", depends_if(simulator)(lambda x: True))
278 set_define("JS_SIMULATOR_ARM", simulator.arm)
279 set_define("JS_SIMULATOR_ARM64", simulator.arm64)
280 set_define("JS_SIMULATOR_MIPS32", simulator.mips32)
281 set_define("JS_SIMULATOR_MIPS64", simulator.mips64)
282 set_define("JS_SIMULATOR_LOONG64", simulator.loong64)
283 set_define("JS_SIMULATOR_RISCV64", simulator.riscv64)
286 @depends("--enable-jit", simulator, target)
287 def jit_codegen(jit_enabled, simulator, target):
288     if not jit_enabled:
289         return namespace(none=True)
291     if simulator:
292         return simulator
294     if target.cpu == "aarch64":
295         return namespace(arm64=True)
296     elif target.cpu == "x86_64":
297         return namespace(x64=True)
298     elif target.cpu == "loongarch64":
299         return namespace(loong64=True)
300     elif target.cpu == "riscv64":
301         return namespace(riscv64=True)
303     return namespace(**{str(target.cpu): True})
306 set_config("JS_CODEGEN_NONE", jit_codegen.none)
307 set_config("JS_CODEGEN_ARM", jit_codegen.arm)
308 set_config("JS_CODEGEN_ARM64", jit_codegen.arm64)
309 set_config("JS_CODEGEN_MIPS32", jit_codegen.mips32)
310 set_config("JS_CODEGEN_MIPS64", jit_codegen.mips64)
311 set_config("JS_CODEGEN_LOONG64", jit_codegen.loong64)
312 set_config("JS_CODEGEN_RISCV64", jit_codegen.riscv64)
313 set_config("JS_CODEGEN_X86", jit_codegen.x86)
314 set_config("JS_CODEGEN_X64", jit_codegen.x64)
315 set_config("JS_CODEGEN_WASM32", jit_codegen.wasm32)
317 set_define("JS_CODEGEN_NONE", jit_codegen.none)
318 set_define("JS_CODEGEN_ARM", jit_codegen.arm)
319 set_define("JS_CODEGEN_ARM64", jit_codegen.arm64)
320 set_define("JS_CODEGEN_MIPS32", jit_codegen.mips32)
321 set_define("JS_CODEGEN_MIPS64", jit_codegen.mips64)
322 set_define("JS_CODEGEN_LOONG64", jit_codegen.loong64)
323 set_define("JS_CODEGEN_RISCV64", jit_codegen.riscv64)
324 set_define("JS_CODEGEN_X86", jit_codegen.x86)
325 set_define("JS_CODEGEN_X64", jit_codegen.x64)
326 set_define("JS_CODEGEN_WASM32", jit_codegen.wasm32)
329 # Profiling
330 # =======================================================
331 option(
332     "--enable-instruments",
333     env="MOZ_INSTRUMENTS",
334     help="Enable instruments remote profiling",
338 @depends("--enable-instruments", target)
339 def instruments(value, target):
340     if value and target.os != "OSX":
341         die("--enable-instruments cannot be used when targeting %s", target.os)
342     if value:
343         return True
346 set_config("MOZ_INSTRUMENTS", instruments)
347 set_define("MOZ_INSTRUMENTS", instruments)
348 add_old_configure_assignment("MOZ_INSTRUMENTS", instruments)
349 imply_option("--enable-profiling", instruments, reason="--enable-instruments")
351 option("--enable-callgrind", env="MOZ_CALLGRIND", help="Enable callgrind profiling")
354 @depends("--enable-callgrind")
355 def callgrind(value):
356     if value:
357         return True
360 set_define("MOZ_CALLGRIND", callgrind)
361 imply_option("--enable-profiling", callgrind)
364 @depends(milestone)
365 def enable_profiling(milestone):
366     return milestone.is_nightly
369 option(
370     "--enable-profiling",
371     env="MOZ_PROFILING",
372     default=enable_profiling,
373     help="{Set|Do not set} compile flags necessary for using sampling "
374     "profilers (e.g. shark, perf)",
378 @depends("--enable-profiling")
379 def profiling(value):
380     if value:
381         return True
384 with only_when("--enable-compile-environment"):
385     imply_option("--enable-frame-pointers", True, when=profiling)
388 @depends(profiling, target)
389 def imply_vtune(value, target):
390     ok_cpu = target.cpu in ["x86", "x86_64"]
391     ok_kernel = target.kernel == "WINNT" or (
392         target.kernel == "Linux" and target.os == "GNU"
393     )
395     if value and ok_cpu and ok_kernel:
396         return True
399 set_config("MOZ_PROFILING", profiling)
400 set_define("MOZ_PROFILING", profiling)
401 imply_option("--enable-vtune", imply_vtune, reason="--enable-profiling")
404 option("--enable-vtune", env="MOZ_VTUNE", help="Enable VTune profiling")
407 @depends("--enable-vtune")
408 def vtune(value):
409     if value:
410         return True
413 set_config("MOZ_VTUNE", vtune)
414 set_define("MOZ_VTUNE", vtune)
417 option(
418     "--enable-gc-probes",
419     env="JS_GC_PROBES",
420     help="Turn on probes for allocation and finalization",
424 @depends("--enable-gc-probes")
425 def gc_probes(value):
426     if value:
427         return True
430 set_define("JS_GC_PROBES", gc_probes)
433 option(
434     "--enable-gczeal",
435     default=depends(when=moz_debug)(lambda: True),
436     help="{Enable|Disable} zealous GCing",
439 set_define("JS_GC_ZEAL", depends_if("--enable-gczeal")(lambda _: True))
442 # Enable breakpoint for artificial OOMs
443 # =======================================================
444 option(
445     "--enable-oom-breakpoint", help="Enable a breakpoint function for artificial OOMs"
448 set_define("JS_OOM_BREAKPOINT", depends_if("--enable-oom-breakpoint")(lambda _: True))
451 option("--enable-perf", env="JS_ION_PERF", help="Enable Linux perf integration")
454 @depends("--enable-perf", target)
455 def ion_perf(value, target):
456     is_linux = target.kernel == "Linux"
457     is_mac = target.kernel == "Darwin" and target.os == "OSX"
459     if value and (is_linux or is_mac):
460         return True
463 set_define("JS_ION_PERF", ion_perf)
466 option(
467     "--enable-jitspew",
468     default=depends(when=moz_debug)(lambda: True),
469     help="{Enable|Disable} the Jit spew and IONFLAGS environment " "variable",
472 set_define("JS_JITSPEW", depends_if("--enable-jitspew")(lambda _: True))
473 set_config("JS_JITSPEW", depends_if("--enable-jitspew")(lambda _: True))
475 # Also enable the structured spewer
476 set_define("JS_STRUCTURED_SPEW", depends_if("--enable-jitspew")(lambda _: True))
477 set_config("JS_STRUCTURED_SPEW", depends_if("--enable-jitspew")(lambda _: True))
480 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
481 def jit_disasm_arm(jit_enabled, spew, simulator, target, debug):
482     if not jit_enabled:
483         return
485     if simulator and (debug or spew):
486         if getattr(simulator, "arm", None):
487             return True
489     if target.cpu == "arm" and (debug or spew):
490         return True
493 set_config("JS_DISASM_ARM", jit_disasm_arm)
494 set_define("JS_DISASM_ARM", jit_disasm_arm)
497 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
498 def jit_disasm_riscv(jit_enabled, spew, simulator, target, debug):
499     if not jit_enabled:
500         return
502     if simulator and (debug or spew):
503         if getattr(simulator, "riscv64", None):
504             return True
506     if target.cpu == "riscv64" and (debug or spew):
507         return True
510 set_config("JS_DISASM_RISCV64", jit_disasm_riscv)
511 set_define("JS_DISASM_RISCV64", jit_disasm_riscv)
514 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
515 def jit_disasm_arm64(jit_enabled, spew, simulator, target, debug):
516     if not jit_enabled:
517         return
519     if simulator and (debug or spew):
520         if getattr(simulator, "arm64", None):
521             return True
523     if target.cpu == "aarch64" and (debug or spew):
524         return True
527 set_config("JS_DISASM_ARM64", jit_disasm_arm64)
528 set_define("JS_DISASM_ARM64", jit_disasm_arm64)
530 # When enabled, masm will generate assumeUnreachable calls that act as
531 # assertions in the generated code. This option is worth disabling when you
532 # have to track mutated values through the generated code, to avoid constantly
533 # dumping registers on and off the stack.
534 option(
535     "--enable-masm-verbose",
536     default=depends(when=moz_debug)(lambda: True),
537     help="{Enable|Disable} MacroAssembler verbosity of generated code.",
539 set_define("JS_MASM_VERBOSE", depends_if("--enable-masm-verbose")(lambda _: True))
540 set_config("JS_MASM_VERBOSE", depends_if("--enable-masm-verbose")(lambda _: True))
542 # Architecture feature flags
543 # =======================================================
546 # Apple silicon does not seem to have any way to query the OS for the JSCVT
547 # flag stored in the ID_AA64ISAR1_EL1 system register. In the mean time, we
548 # hard code the value of the JSCVT flag which guards the implementation of
549 # FJCVTZS instruction as part of ARMv8.3-JSConv.
550 @depends(target)
551 def is_apple_silicon(target):
552     return target.os == "OSX" and target.kernel == "Darwin" and target.cpu == "aarch64"
555 option(
556     "--enable-arm64-fjcvtzs",
557     default=is_apple_silicon,
558     help="{Enable|Disable} static use of FJCVTZS instruction on Aarch64 targets.",
562 # The "ARM Architecture Reference Manual" for ARMv8 defines the JSCVT flag as
563 # being a 4 bit integer (D12.2.52) and it can be manipulated using >= operator
564 # (D12.1.4).
566 # The FJCVTZS instruction is implemented if ID_AA64ISAR1_EL1.JSCVT >= 1.
567 @depends("--enable-arm64-fjcvtzs", target, simulator)
568 def aarch64_jscvt(fjcvtzs, target, simulator):
569     if target.cpu == "aarch64" and fjcvtzs:
570         return 1
572     if simulator and getattr(simulator, "arm64", False) and fjcvtzs:
573         return 1
575     return 0
578 set_define("MOZ_AARCH64_JSCVT", aarch64_jscvt)
581 @depends(target)
582 def has_pthread_jit_write_protect_np(target):
583     return target.os == "OSX" and target.cpu == "aarch64"
586 # On Apple Silicon we use MAP_JIT with pthread_jit_write_protect_np to implement
587 # JIT code write protection.
588 set_define("JS_USE_APPLE_FAST_WX", True, when=has_pthread_jit_write_protect_np)
591 # CTypes
592 # =======================================================
593 @depends(js_standalone)
594 def ctypes_default(js_standalone):
595     return not js_standalone
598 option("--enable-ctypes", default=ctypes_default, help="{Enable|Disable} js-ctypes")
600 build_ctypes = depends_if("--enable-ctypes")(lambda _: True)
602 set_config("BUILD_CTYPES", build_ctypes)
603 set_define("BUILD_CTYPES", build_ctypes)
605 set_config("JS_HAS_CTYPES", build_ctypes)
606 set_define("JS_HAS_CTYPES", build_ctypes)
609 @depends("--enable-ctypes", "--enable-compile-environment")
610 def ctypes_and_compile_environment(ctypes, compile_environment):
611     return ctypes and compile_environment
614 include("ffi.configure", when=ctypes_and_compile_environment)
617 # Enable pipeline operator
618 # ===================================================
619 option("--enable-pipeline-operator", default=False, help="Enable pipeline operator")
622 @depends("--enable-pipeline-operator")
623 def enable_pipeline_operator(value):
624     if value:
625         return True
628 set_config("ENABLE_PIPELINE_OPERATOR", enable_pipeline_operator)
629 set_define("ENABLE_PIPELINE_OPERATOR", enable_pipeline_operator)
632 # SIMD acceleration for encoding_rs
633 # ==============================================================
635 option(
636     "--enable-rust-simd", env="MOZ_RUST_SIMD", help="Enable explicit SIMD in Rust code."
640 @depends("--enable-rust-simd", target)
641 def rust_simd(value, target):
642     # As of 2019-09-17, the simd-accel feature of encoding_rs has not
643     # been properly set up outside aarch64, armv7, x86 and x86_64.
644     if target.cpu in ("aarch64", "arm", "x86", "x86_64") and value:
645         return True
648 set_config("MOZ_RUST_SIMD", rust_simd)
649 set_define("MOZ_RUST_SIMD", rust_simd)
651 # Telemetry to measure compile time and generated-code runtime
652 # ============================================================
654 option(
655     "--enable-spidermonkey-telemetry",
656     default=milestone.is_nightly,
657     help="{Enable|Disable} performance telemetry for SpiderMonkey (e.g. compile and run times)",
660 set_define(
661     "ENABLE_SPIDERMONKEY_TELEMETRY",
662     depends_if("--enable-spidermonkey-telemetry")(lambda x: True),
665 # Support for debugging code generated by wasm backends
666 # =====================================================
668 option(
669     "--enable-wasm-codegen-debug",
670     default=depends(when=moz_debug)(lambda: True),
671     help="{Enable|Disable} debugging for wasm codegen",
674 set_config(
675     "WASM_CODEGEN_DEBUG", depends_if("--enable-wasm-codegen-debug")(lambda x: True)
677 set_define(
678     "WASM_CODEGEN_DEBUG", depends_if("--enable-wasm-codegen-debug")(lambda x: True)
681 # WebAssembly feature flags
682 # ==================================================
684 option(
685     "--wasm-no-experimental",
686     default=False,
687     help="Force disable all wasm experimental features for testing.",
690 # Support for WebAssembly function-references.
691 # ===========================
694 option(
695     "--disable-wasm-function-references",
696     default=True,
697     help="{Enable|Disable} WebAssembly function-references",
701 @depends("--disable-wasm-function-references", "--wasm-no-experimental")
702 def wasm_function_references(value, no_experimental):
703     if no_experimental:
704         return
706     if value:
707         return True
710 set_config("ENABLE_WASM_FUNCTION_REFERENCES", wasm_function_references)
711 set_define("ENABLE_WASM_FUNCTION_REFERENCES", wasm_function_references)
713 # Support for WebAssembly tail-calls.
714 # ===========================
717 @depends(target)
718 def default_wasm_tail_calls(target):
719     if target.cpu in ("x86", "x86_64", "arm", "aarch64", "loongarch64", "mips64"):
720         return True
723 option(
724     "--enable-wasm-tail-calls",
725     default=default_wasm_tail_calls,
726     help="{Enable|Disable} WebAssembly tail-calls",
730 @depends("--enable-wasm-tail-calls", target)
731 def wasm_tail_calls(value, target):
732     if not value:
733         return
735     if target.cpu in ("x86", "x86_64", "arm", "aarch64", "loongarch64", "mips64"):
736         return True
738     die(
739         "--enable-wasm-tail-calls only possible when targeting the x86_64/x86/arm64/arm/loongarch64/mips64 jits"
740     )
743 set_config("ENABLE_WASM_TAIL_CALLS", wasm_tail_calls)
744 set_define("ENABLE_WASM_TAIL_CALLS", wasm_tail_calls)
746 # Support for WebAssembly GC.
747 # ===========================
750 @depends("--disable-wasm-function-references")
751 def default_wasm_gc(function_references):
752     if function_references:
753         return True
756 option(
757     "--disable-wasm-gc", default=default_wasm_gc, help="{Enable|Disable} WebAssembly GC"
761 @depends(
762     "--disable-wasm-gc", "--disable-wasm-function-references", "--wasm-no-experimental"
764 def wasm_gc(value, function_references, no_experimental):
765     if no_experimental or not value:
766         return
768     if function_references:
769         return True
771     die("--disable-wasm-gc only possible with --disable-wasm-function-references")
774 set_config("ENABLE_WASM_GC", wasm_gc)
775 set_define("ENABLE_WASM_GC", wasm_gc)
777 # Support for WebAssembly JS String Builtins
778 # ==========================================
781 @depends(milestone.is_nightly)
782 def default_wasm_js_string_builtins(is_nightly):
783     if is_nightly:
784         return True
787 option(
788     "--enable-wasm-js-string-builtins",
789     default=default_wasm_js_string_builtins,
790     help="{Enable|Disable} WebAssembly JS String Builtins",
794 @depends("--enable-wasm-js-string-builtins", "--wasm-no-experimental")
795 def wasm_js_string_builtins(value, no_experimental):
796     if no_experimental or not value:
797         return
799     return True
802 set_config("ENABLE_WASM_JS_STRING_BUILTINS", wasm_js_string_builtins)
803 set_define("ENABLE_WASM_JS_STRING_BUILTINS", wasm_js_string_builtins)
805 # Support for WebAssembly shared memory and atomics.
807 # This affects the JS shell only.
808 # =====================================================
810 option(
811     "--disable-shared-memory", help="Disable JS/WebAssembly shared memory and atomics"
815 @depends("--disable-shared-memory")
816 def enable_shared_memory(value):
817     if value:
818         return True
821 set_config("ENABLE_SHARED_MEMORY", enable_shared_memory)
822 set_define("ENABLE_SHARED_MEMORY", enable_shared_memory)
824 # Support for WebAssembly extended constant expressions
825 # =====================================================
828 option(
829     "--disable-wasm-extended-const",
830     help="{Enable|Disable} WebAssembly extended constant expressions",
834 @depends("--disable-wasm-extended-const")
835 def wasm_extended_const(value):
836     if value:
837         return True
840 set_config("ENABLE_WASM_EXTENDED_CONST", wasm_extended_const)
841 set_define("ENABLE_WASM_EXTENDED_CONST", wasm_extended_const)
843 # Support for WebAssembly SIMD
844 # =====================================================
847 @depends("--enable-jit", "--enable-simulator", target)
848 def default_wasm_simd(jit_enabled, simulator, target):
849     if not jit_enabled:
850         return
852     if simulator and (simulator[0] != "arm64"):
853         return
855     if target.cpu in ("x86_64", "x86", "aarch64"):
856         return True
859 option(
860     "--enable-wasm-simd",
861     default=default_wasm_simd,
862     help="{Enable|Disable} WebAssembly SIMD",
866 @depends(
867     "--enable-wasm-simd",
868     "--enable-jit",
869     "--enable-simulator",
870     target,
871     "--wasm-no-experimental",
873 def wasm_simd(value, jit_enabled, simulator, target, no_experimental):
874     if no_experimental or not value:
875         return
877     if not jit_enabled:
878         die("--enable-wasm-simd requires --enable-jit")
880     if simulator and (simulator[0] != "arm64"):
881         die("--enable-wasm-simd is not supported for simulators, except arm64")
883     if target.cpu in ("x86_64", "x86", "aarch64"):
884         return True
886     die("--enable-wasm-simd only possible when targeting the x86_64/x86/arm64 jits")
889 set_config("ENABLE_WASM_SIMD", wasm_simd)
890 set_define("ENABLE_WASM_SIMD", wasm_simd)
892 # Whether to check for field changes in WebAssembly serialization
894 # See the comment for 'WASM_VERIFY_SERIALIZATION_FOR_SIZE' in WasmSerialize.cpp
895 # for more background.
896 # =====================================================================
899 @depends(
900     target,
901     c_compiler,
902     moz_debug,
903     milestone,
904     "--wasm-no-experimental",
906 def wasm_verify_serialization_for_size(
907     target, c_compiler, debug, milestone, no_experimental
909     if (
910         debug == True
911         and target.kernel == "Linux"
912         and target.cpu == "x86_64"
913         and c_compiler
914         and c_compiler.type == "clang"
915         and milestone.is_nightly
916         and not no_experimental
917     ):
918         return True
919     return
922 set_define(
923     "ENABLE_WASM_VERIFY_SERIALIZATION_FOR_SIZE", wasm_verify_serialization_for_size
926 # Support for Intel AVX instruction.
928 # AVX is exclusively used in WebAssembly SIMD instructions at the moment:
929 # set direct dependency on "--enable-wasm-simd".
930 # =====================================================
933 @depends("--enable-wasm-simd", "--enable-simulator", target)
934 def default_wasm_avx(wasm_simd_enabled, simulator, target):
935     if not wasm_simd_enabled:
936         return
938     if simulator:
939         return
941     if target.cpu in ("x86_64", "x86"):
942         return True
945 option(
946     "--enable-wasm-avx",
947     default=default_wasm_avx,
948     help="{Enable|Disable} AVX support for WebAssembly SIMD",
952 @depends(
953     "--enable-wasm-avx",
954     "--enable-wasm-simd",
955     "--enable-simulator",
956     target,
957     "--wasm-no-experimental",
959 def wasm_avx(value, wasm_simd_enabled, simulator, target, no_experimental):
960     if no_experimental or not value:
961         return
963     if not wasm_simd_enabled:
964         die("--enable-wasm-avx requires --enable-wasm-simd")
966     if simulator:
967         die("--enable-wasm-avx is not supported for simulators")
969     if target.cpu in ("x86_64", "x86"):
970         return True
972     die("--enable-wasm-avx only possible when targeting the x86_64/x86 jits")
975 set_config("ENABLE_WASM_AVX", wasm_avx)
976 set_define("ENABLE_WASM_AVX", wasm_avx)
978 # Support for WebAssembly relaxed SIMD
979 # =====================================================
982 @depends(milestone.is_nightly, "--enable-wasm-simd")
983 def default_wasm_relaxed_simd(is_nightly, wasm_simd):
984     if is_nightly and wasm_simd:
985         return True
988 option(
989     "--enable-wasm-relaxed-simd",
990     default=default_wasm_relaxed_simd,
991     help="{Enable|Disable} WebAssembly relaxed SIMD",
995 @depends("--enable-wasm-relaxed-simd", "--enable-wasm-simd", "--wasm-no-experimental")
996 def wasm_relaxed_simd(value, wasm_simd, no_experimental):
997     if no_experimental or not value:
998         return
1000     if not wasm_simd:
1001         die("relaxed SIMD requires SIMD")
1003     return True
1006 set_config("ENABLE_WASM_RELAXED_SIMD", wasm_relaxed_simd)
1007 set_define("ENABLE_WASM_RELAXED_SIMD", wasm_relaxed_simd)
1009 # Support for WebAssembly intgemm private intrinsics
1010 # =====================================================
1013 @depends(milestone.is_nightly)
1014 def default_wasm_moz_intgemm(is_nightly):
1015     if is_nightly:
1016         return True
1019 option(
1020     "--enable-wasm-moz-intgemm",
1021     default=default_wasm_moz_intgemm,
1022     help="{Enable|Disable} WebAssembly intgemm private intrinsics",
1026 @depends("--enable-wasm-moz-intgemm", target, "--wasm-no-experimental")
1027 def wasm_moz_intgemm(value, target, no_experimental):
1028     if no_experimental:
1029         return
1031     if value and target.cpu in ("x86", "x86_64", "aarch64"):
1032         return True
1035 set_config("ENABLE_WASM_MOZ_INTGEMM", wasm_moz_intgemm)
1036 set_define("ENABLE_WASM_MOZ_INTGEMM", wasm_moz_intgemm)
1038 # Support for WebAssembly Memory64.
1039 # ===========================
1042 @depends(milestone.is_nightly, "--enable-simulator", target)
1043 def default_wasm_memory64(is_nightly, simulator, target):
1044     if target.cpu == "mips32":
1045         return
1047     if simulator and simulator[0] == "mips32":
1048         return
1050     if is_nightly:
1051         return True
1054 option(
1055     "--enable-wasm-memory64",
1056     default=default_wasm_memory64,
1057     help="{Enable|Disable} WebAssembly Memory64",
1061 @depends(
1062     "--enable-wasm-memory64", "--enable-simulator", target, "--wasm-no-experimental"
1064 def wasm_memory64(value, simulator, target, no_experimental):
1065     if no_experimental or not value:
1066         return
1068     if target.cpu == "mips32":
1069         die("Memory64 is incompatible with MIPS32 target")
1071     if simulator and simulator[0] == "mips32":
1072         die("Memory64 is incompatible with MIPS32 simulator")
1074     return True
1077 set_config("ENABLE_WASM_MEMORY64", wasm_memory64)
1078 set_define("ENABLE_WASM_MEMORY64", wasm_memory64)
1081 # Support for WebAssembly memory control.
1082 # ===========================
1085 @depends(milestone.is_nightly)
1086 def default_wasm_memory_control(is_nightly):
1087     if is_nightly:
1088         return True
1091 option(
1092     "--enable-wasm-memory-control",
1093     default=default_wasm_memory_control,
1094     help="{Enable|Disable} WebAssembly fine-grained memory control instructions",
1098 @depends("--enable-wasm-memory-control", "--wasm-no-experimental")
1099 def wasm_memory_control(value, no_experimental):
1100     if no_experimental or not value:
1101         return
1103     return True
1106 set_config("ENABLE_WASM_MEMORY_CONTROL", wasm_memory_control)
1107 set_define("ENABLE_WASM_MEMORY_CONTROL", wasm_memory_control)
1110 # Support for WebAssembly Multi Memory.
1111 # =====================================
1114 @depends(milestone.is_nightly)
1115 def default_wasm_multi_memory(is_nightly):
1116     if is_nightly:
1117         return True
1120 option(
1121     "--enable-wasm-multi-memory",
1122     default=default_wasm_multi_memory,
1123     help="{Enable|Disable} WebAssembly multi-memory",
1127 @depends("--enable-wasm-multi-memory", "--wasm-no-experimental")
1128 def wasm_multi_memory(value, no_experimental):
1129     if no_experimental or not value:
1130         return
1132     return True
1135 set_config("ENABLE_WASM_MULTI_MEMORY", wasm_multi_memory)
1136 set_define("ENABLE_WASM_MULTI_MEMORY", wasm_multi_memory)
1138 # Options for generating the shell as a script
1139 # ============================================
1140 option("--with-qemu-exe", nargs=1, help="Use path as an arm emulator on host platforms")
1141 set_config("QEMU_EXE", depends_if("--with-qemu-exe")(lambda x: x))
1143 option(
1144     "--with-cross-lib",
1145     nargs=1,
1146     default=depends(target.alias)(lambda x: "/usr/%s" % x),
1147     help="Use dir as the location for arm libraries",
1149 set_config("CROSS_LIB", depends_if("--with-cross-lib")(lambda x: x))
1151 # Enable static checking using sixgill
1152 # ====================================
1154 option("--with-sixgill", nargs=1, help="Enable static checking of code using sixgill")
1157 @depends_if("--with-sixgill")
1158 @imports("os")
1159 def sixgill(value):
1160     for f in ("bin/xdbfind", "gcc/xgill.so", "scripts/wrap_gcc/g++"):
1161         if not os.path.exists(os.path.join(value[0], f)):
1162             die("The sixgill plugin and binaries are not at the specified path")
1163     return value[0]
1166 set_config("SIXGILL_PATH", sixgill)
1169 # Support for readline
1170 # =====================================================
1173 @depends("--enable-js-shell", target_is_windows, compile_environment, target)
1174 def editline(js_shell, is_windows, compile_environment, target):
1175     return js_shell and not is_windows and compile_environment and (target.os != "WASI")
1178 option(
1179     "--enable-readline", help="Link js shell to system readline library", when=editline
1182 has_readline = check_symbol(
1183     "readline",
1184     flags=["-lreadline"],
1185     when="--enable-readline",
1186     onerror=lambda: die("No system readline library found"),
1189 set_config("EDITLINE_LIBS", ["-lreadline"], when=has_readline)
1192 @depends("--enable-readline", editline, when=editline)
1193 def bundled_editline(readline, editline):
1194     return editline and not readline
1197 set_config("JS_BUNDLED_EDITLINE", bundled_editline)
1199 set_define("EDITLINE", True, when=editline)
1202 # JIT observers
1203 # =============
1205 option(
1206     "--with-jitreport-granularity",
1207     default="3",
1208     choices=("0", "1", "2", "3"),
1209     help="Default granularity at which to report JIT code to external tools "
1210     "(0 - no info, 1 - code ranges for while functions only, "
1211     "2 - per-line information, 3 - per-op information)",
1214 set_define(
1215     "JS_DEFAULT_JITREPORT_GRANULARITY",
1216     depends_if("--with-jitreport-granularity")(lambda value: value[0]),
1220 # ECMAScript Internationalization API Support (uses ICU)
1221 # ======================================================
1222 system_lib_option("--with-system-icu", help="Use system ICU")
1224 system_icu = pkg_check_modules("MOZ_ICU", "icu-i18n >= 73.1", when="--with-system-icu")
1227 @depends("--with-system-icu")
1228 def in_tree_icu(system_icu):
1229     return not system_icu
1232 # Set MOZ_ICU_CFLAGS to an explicit empty value when --with-system-icu is *not* used,
1233 # for layout/style/extra-bindgen-flags
1234 set_config("MOZ_ICU_CFLAGS", [], when=in_tree_icu)
1236 set_config("MOZ_SYSTEM_ICU", True, when=system_icu)
1237 set_define("MOZ_SYSTEM_ICU", True, when=system_icu)
1239 option("--without-intl-api", help="Disable ECMAScript Internationalization API")
1242 @depends("--with-intl-api", js_standalone)
1243 def check_intl_api(enabled, js_standalone):
1244     if not enabled and not js_standalone:
1245         die("--without-intl-api is not supported")
1248 set_config("JS_HAS_INTL_API", True, when="--with-intl-api")
1249 set_define("JS_HAS_INTL_API", True, when="--with-intl-api")
1252 @depends(build_environment, when="--with-intl-api")
1253 @imports(_from="__builtin__", _import="open")
1254 @imports(_from="__builtin__", _import="ValueError")
1255 def icu_version(build_env):
1256     path = os.path.join(
1257         build_env.topsrcdir, "intl", "icu", "source", "common", "unicode", "uvernum.h"
1258     )
1259     with open(path, encoding="utf-8") as fh:
1260         for line in fh:
1261             if line.startswith("#define"):
1262                 define = line.split(None, 3)
1263                 if len(define) == 3 and define[1] == "U_ICU_VERSION_MAJOR_NUM":
1264                     try:
1265                         return str(int(define[2]))
1266                     except ValueError:
1267                         pass
1268     die("Cannot determine ICU version number from uvernum.h header file")
1271 set_config("MOZ_ICU_VERSION", icu_version)
1273 # Source files that use ICU should have control over which parts of the ICU
1274 # namespace they want to use.
1275 set_define("U_USING_ICU_NAMESPACE", "0", when="--with-intl-api")
1277 # We build ICU as a static library.
1278 set_define("U_STATIC_IMPLEMENTATION", True, when=depends(system_icu)(lambda x: not x))
1281 # ECMAScript Temporal API Support (uses ICU)
1282 # ======================================================
1284 option("--with-temporal-api", default=False, help="Enable ECMAScript Temporal API")
1286 set_config("JS_HAS_TEMPORAL_API", True, when="--with-temporal-api")
1287 set_define("JS_HAS_TEMPORAL_API", True, when="--with-temporal-api")
1290 @depends("--with-temporal-api", "--with-intl-api")
1291 def check_temporal_api(temporal_enabled, intl_enabled):
1292     if temporal_enabled and not intl_enabled:
1293         die("Can't use both --with-temporal-api and --without-intl-api")
1296 # Initial support for WebAssembly JS-API Type Reflections
1297 # =======================================================
1300 @depends(milestone.is_nightly)
1301 def default_wasm_type_reflections(is_nightly):
1302     return is_nightly
1305 option(
1306     "--enable-wasm-type-reflections",
1307     default=default_wasm_type_reflections,
1308     help="{Enable|Disable} type reflection in WASM JS-API",
1311 set_config(
1312     "ENABLE_WASM_TYPE_REFLECTIONS",
1313     depends_if("--enable-wasm-type-reflections")(lambda x: True),
1315 set_define(
1316     "ENABLE_WASM_TYPE_REFLECTIONS",
1317     depends_if("--enable-wasm-type-reflections")(lambda x: True),
1320 # Wasi configuration
1321 # ===================================================
1324 @depends(target.os)
1325 def is_wasi_target(os):
1326     return os == "WASI"
1329 set_define("_WASI_EMULATED_PROCESS_CLOCKS", True, when=is_wasi_target)
1330 set_define("_WASI_EMULATED_GETPID", True, when=is_wasi_target)
1333 @depends(milestone.version)
1334 def js_version(version):
1335     return Version(version)
1338 set_config("MOZJS_MAJOR_VERSION", depends(js_version.major)(lambda m: str(m)))
1339 set_define("MOZJS_MAJOR_VERSION", js_version.major)
1340 set_config("MOZJS_MINOR_VERSION", depends(js_version.minor)(lambda m: str(m)))
1341 set_define("MOZJS_MINOR_VERSION", js_version.minor)
1342 set_config("MOZJS_PATCH_VERSION", depends(js_version.patch)(lambda p: str(p)))
1343 set_config(
1344     "MOZJS_ALPHA",
1345     depends(js_version)(
1346         lambda x: x.version[-2] if str(x.version[-2]) in "ab" else None
1347     ),
1351 # Some platforms have HeapReg, some don't
1352 # =====================================================
1354 # The ARM simulator runs on x86 and might be excluded by the first test,
1355 # so we special-case it.
1358 @depends("--enable-simulator", target)
1359 def wasm_has_heapreg(simulator, target):
1360     if target.cpu != "x86":
1361         return True
1363     if simulator and simulator[0] == "arm":
1364         return True
1367 set_define("WASM_HAS_HEAPREG", wasm_has_heapreg)
1369 # Check for tm_zone, tm_gmtoff in struct tm
1370 # ===================================================
1371 with only_when(compile_environment):
1372     set_define(
1373         "HAVE_TM_ZONE_TM_GMTOFF",
1374         c_compiler.try_compile(
1375             includes=["time.h"],
1376             body="struct tm tm; tm.tm_zone = 0; tm.tm_gmtoff = 1;",
1377             check_msg="for tm_zone and tm_gmtoff in struct tm",
1378         ),
1379     )
1382 # Checks for library functions
1383 # ==============================================================
1384 with only_when(compile_environment & depends(target.os)(lambda os: os != "WINNT")):
1385     set_define("HAVE_GETPAGESIZE", check_symbol("getpagesize"))
1386     set_define("HAVE_GMTIME_R", check_symbol("gmtime_r"))
1387     set_define("HAVE_LOCALTIME_R", check_symbol("localtime_r"))
1388     set_define("HAVE_GETTID", check_symbol("gettid"))
1389     set_define("HAVE_SETPRIORITY", check_symbol("setpriority"))
1390     set_define("HAVE_SYSCALL", check_symbol("syscall"))
1391     set_define("HAVE_GETC_UNLOCKED", check_symbol("getc_unlocked"))
1392     set_define("HAVE_PTHREAD_GETNAME_NP", check_symbol("pthread_getname_np"))
1393     set_define("HAVE_PTHREAD_GET_NAME_NP", check_symbol("pthread_get_name_np"))
1394     set_define("HAVE_STRERROR", check_symbol("strerror"))
1396     @depends(check_symbol("__cxa_demangle", language="C++"), moz_debug, dmd)
1397     def demangle_symbols(cxa_demangle, moz_debug, dmd):
1398         # Demangle only for debug or DMD builds
1399         if cxa_demangle and (moz_debug or dmd):
1400             return True
1402     set_define("MOZ_DEMANGLE_SYMBOLS", demangle_symbols)
1404     set_define("HAVE__UNWIND_BACKTRACE", True, when=have_unwind)
1406 with only_when(compile_environment):
1407     set_define("HAVE__GETC_NOLOCK", check_symbol("_getc_nolock"))
1408     set_define("HAVE_LOCALECONV", check_symbol("localeconv"))