Bug 1883706: part 3) Implement `createHTML`, `createScript` and `createScriptURL...
[gecko.git] / js / moz.configure
blobcbcaf38f01c9dc156f2df72197b04627174f480a
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 # Enable JSON.parse with source
177 # ===================================================
178 option(
179     "--enable-json-parse-with-source",
180     default=False,
181     help="Enable experimental JS JSON.parse with source support",
185 @depends("--enable-json-parse-with-source")
186 def enable_json_parse_with_source(value):
187     if value:
188         return True
191 set_config("ENABLE_JSON_PARSE_WITH_SOURCE", enable_json_parse_with_source)
192 set_define("ENABLE_JSON_PARSE_WITH_SOURCE", enable_json_parse_with_source)
195 # Portable Baseline Intepreter
196 # =======================================================
197 option(
198     "--enable-portable-baseline-interp",
199     default=False,
200     help="{Enable|Disable} the portable baseline interpreter.",
202 set_define(
203     "ENABLE_PORTABLE_BASELINE_INTERP",
204     depends_if("--enable-portable-baseline-interp")(lambda _: True),
206 set_config(
207     "ENABLE_PORTABLE_BASELINE_INTERP",
208     depends_if("--enable-portable-baseline-interp")(lambda _: True),
211 # Option to always force PBL tier.
212 option(
213     "--enable-portable-baseline-interp-force",
214     default=False,
215     help="{Enable|Disable} forcing use of the portable baseline interpreter.",
218 set_define(
219     "ENABLE_PORTABLE_BASELINE_INTERP_FORCE",
220     depends_if("--enable-portable-baseline-interp-force")(lambda _: True),
222 set_config(
223     "ENABLE_PORTABLE_BASELINE_INTERP_FORCE",
224     depends_if("--enable-portable-baseline-interp-force")(lambda _: True),
228 # JIT support
229 # =======================================================
230 @depends(target, "--enable-record-tuple", "--enable-portable-baseline-interp")
231 def jit_default(target, enable_record_tuple, enable_portable_baseline_interp):
232     if enable_record_tuple:
233         return False
234     if enable_portable_baseline_interp:
235         return False
236     if target.cpu in (
237         "x86",
238         "x86_64",
239         "arm",
240         "aarch64",
241         "mips32",
242         "mips64",
243         "loongarch64",
244     ):
245         return True
246     return False
249 option("--enable-jit", default=jit_default, help="{Enable|Disable} use of the JITs")
252 @deprecated_option("--enable-ion")
253 def report_deprecated(value):
254     if value:
255         die("--enable-ion is deprecated, use --enable-jit instead")
256     else:
257         die("--disable-ion is deprecated, use --disable-jit instead")
260 # JIT code simulator for cross compiles
261 # =======================================================
262 option(
263     "--enable-simulator",
264     choices=("arm", "arm64", "mips32", "mips64", "loong64", "riscv64"),
265     nargs=1,
266     help="Enable a JIT code simulator for the specified architecture",
270 @depends("--enable-jit", "--enable-simulator", target)
271 def simulator(jit_enabled, simulator_enabled, target):
272     if not jit_enabled or not simulator_enabled:
273         return
275     sim_cpu = simulator_enabled[0]
277     if sim_cpu in ("arm", "mips32"):
278         if target.cpu != "x86":
279             die("The %s simulator only works on x86." % sim_cpu)
281     if sim_cpu in ("arm64", "mips64", "loong64", "riscv64"):
282         if target.cpu != "x86_64" and target.cpu != "aarch64":
283             die("The %s simulator only works on x86-64 or arm64." % sim_cpu)
285     return namespace(**{sim_cpu: True})
288 set_config("JS_SIMULATOR", depends_if(simulator)(lambda x: True))
289 set_config("JS_SIMULATOR_ARM", simulator.arm)
290 set_config("JS_SIMULATOR_ARM64", simulator.arm64)
291 set_config("JS_SIMULATOR_MIPS32", simulator.mips32)
292 set_config("JS_SIMULATOR_MIPS64", simulator.mips64)
293 set_config("JS_SIMULATOR_LOONG64", simulator.loong64)
294 set_config("JS_SIMULATOR_RISCV64", simulator.riscv64)
295 set_define("JS_SIMULATOR", depends_if(simulator)(lambda x: True))
296 set_define("JS_SIMULATOR_ARM", simulator.arm)
297 set_define("JS_SIMULATOR_ARM64", simulator.arm64)
298 set_define("JS_SIMULATOR_MIPS32", simulator.mips32)
299 set_define("JS_SIMULATOR_MIPS64", simulator.mips64)
300 set_define("JS_SIMULATOR_LOONG64", simulator.loong64)
301 set_define("JS_SIMULATOR_RISCV64", simulator.riscv64)
304 @depends("--enable-jit", simulator, target)
305 def jit_codegen(jit_enabled, simulator, target):
306     if not jit_enabled:
307         return namespace(none=True)
309     if simulator:
310         return simulator
312     if target.cpu == "aarch64":
313         return namespace(arm64=True)
314     elif target.cpu == "x86_64":
315         return namespace(x64=True)
316     elif target.cpu == "loongarch64":
317         return namespace(loong64=True)
318     elif target.cpu == "riscv64":
319         return namespace(riscv64=True)
321     return namespace(**{str(target.cpu): True})
324 set_config("JS_CODEGEN_NONE", jit_codegen.none)
325 set_config("JS_CODEGEN_ARM", jit_codegen.arm)
326 set_config("JS_CODEGEN_ARM64", jit_codegen.arm64)
327 set_config("JS_CODEGEN_MIPS32", jit_codegen.mips32)
328 set_config("JS_CODEGEN_MIPS64", jit_codegen.mips64)
329 set_config("JS_CODEGEN_LOONG64", jit_codegen.loong64)
330 set_config("JS_CODEGEN_RISCV64", jit_codegen.riscv64)
331 set_config("JS_CODEGEN_X86", jit_codegen.x86)
332 set_config("JS_CODEGEN_X64", jit_codegen.x64)
333 set_config("JS_CODEGEN_WASM32", jit_codegen.wasm32)
335 set_define("JS_CODEGEN_NONE", jit_codegen.none)
336 set_define("JS_CODEGEN_ARM", jit_codegen.arm)
337 set_define("JS_CODEGEN_ARM64", jit_codegen.arm64)
338 set_define("JS_CODEGEN_MIPS32", jit_codegen.mips32)
339 set_define("JS_CODEGEN_MIPS64", jit_codegen.mips64)
340 set_define("JS_CODEGEN_LOONG64", jit_codegen.loong64)
341 set_define("JS_CODEGEN_RISCV64", jit_codegen.riscv64)
342 set_define("JS_CODEGEN_X86", jit_codegen.x86)
343 set_define("JS_CODEGEN_X64", jit_codegen.x64)
344 set_define("JS_CODEGEN_WASM32", jit_codegen.wasm32)
347 # Profiling
348 # =======================================================
349 option(
350     "--enable-instruments",
351     env="MOZ_INSTRUMENTS",
352     help="Enable instruments remote profiling",
356 @depends("--enable-instruments", target)
357 def instruments(value, target):
358     if value and target.os != "OSX":
359         die("--enable-instruments cannot be used when targeting %s", target.os)
360     if value:
361         return True
364 set_config("MOZ_INSTRUMENTS", instruments)
365 set_define("MOZ_INSTRUMENTS", instruments)
366 add_old_configure_assignment("MOZ_INSTRUMENTS", instruments)
367 imply_option("--enable-profiling", instruments, reason="--enable-instruments")
369 option("--enable-callgrind", env="MOZ_CALLGRIND", help="Enable callgrind profiling")
372 @depends("--enable-callgrind")
373 def callgrind(value):
374     if value:
375         return True
378 set_define("MOZ_CALLGRIND", callgrind)
379 imply_option("--enable-profiling", callgrind)
382 @depends(milestone)
383 def enable_profiling(milestone):
384     return milestone.is_nightly
387 option(
388     "--enable-profiling",
389     env="MOZ_PROFILING",
390     default=enable_profiling,
391     help="{Set|Do not set} compile flags necessary for using sampling "
392     "profilers (e.g. shark, perf)",
396 @depends("--enable-profiling")
397 def profiling(value):
398     if value:
399         return True
402 with only_when("--enable-compile-environment"):
403     imply_option("--enable-frame-pointers", True, when=profiling)
406 @depends(profiling, target)
407 def imply_vtune(value, target):
408     ok_cpu = target.cpu in ["x86", "x86_64"]
409     ok_kernel = target.kernel == "WINNT" or (
410         target.kernel == "Linux" and target.os == "GNU"
411     )
413     if value and ok_cpu and ok_kernel:
414         return True
417 set_config("MOZ_PROFILING", profiling)
418 set_define("MOZ_PROFILING", profiling)
419 imply_option("--enable-vtune", imply_vtune, reason="--enable-profiling")
422 option("--enable-vtune", env="MOZ_VTUNE", help="Enable VTune profiling")
425 @depends("--enable-vtune")
426 def vtune(value):
427     if value:
428         return True
431 set_config("MOZ_VTUNE", vtune)
432 set_define("MOZ_VTUNE", vtune)
435 option(
436     "--enable-gc-probes",
437     env="JS_GC_PROBES",
438     help="Turn on probes for allocation and finalization",
442 @depends("--enable-gc-probes")
443 def gc_probes(value):
444     if value:
445         return True
448 set_define("JS_GC_PROBES", gc_probes)
451 option(
452     "--enable-gczeal",
453     default=depends(when=moz_debug)(lambda: True),
454     help="{Enable|Disable} zealous GCing",
457 set_define("JS_GC_ZEAL", depends_if("--enable-gczeal")(lambda _: True))
460 # Enable breakpoint for artificial OOMs
461 # =======================================================
462 option(
463     "--enable-oom-breakpoint", help="Enable a breakpoint function for artificial OOMs"
466 set_define("JS_OOM_BREAKPOINT", depends_if("--enable-oom-breakpoint")(lambda _: True))
469 option("--enable-perf", env="JS_ION_PERF", help="Enable Linux perf integration")
472 @depends("--enable-perf", target)
473 def ion_perf(value, target):
474     is_linux = target.kernel == "Linux"
475     is_mac = target.kernel == "Darwin" and target.os == "OSX"
477     if value and (is_linux or is_mac):
478         return True
481 set_define("JS_ION_PERF", ion_perf)
484 option(
485     "--enable-jitspew",
486     default=depends(when=moz_debug)(lambda: True),
487     help="{Enable|Disable} the Jit spew and IONFLAGS environment " "variable",
490 set_define("JS_JITSPEW", depends_if("--enable-jitspew")(lambda _: True))
491 set_config("JS_JITSPEW", depends_if("--enable-jitspew")(lambda _: True))
493 # Also enable the structured spewer
494 set_define("JS_STRUCTURED_SPEW", depends_if("--enable-jitspew")(lambda _: True))
495 set_config("JS_STRUCTURED_SPEW", depends_if("--enable-jitspew")(lambda _: True))
498 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
499 def jit_disasm_arm(jit_enabled, spew, simulator, target, debug):
500     if not jit_enabled:
501         return
503     if simulator and (debug or spew):
504         if getattr(simulator, "arm", None):
505             return True
507     if target.cpu == "arm" and (debug or spew):
508         return True
511 set_config("JS_DISASM_ARM", jit_disasm_arm)
512 set_define("JS_DISASM_ARM", jit_disasm_arm)
515 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
516 def jit_disasm_riscv(jit_enabled, spew, simulator, target, debug):
517     if not jit_enabled:
518         return
520     if simulator and (debug or spew):
521         if getattr(simulator, "riscv64", None):
522             return True
524     if target.cpu == "riscv64" and (debug or spew):
525         return True
528 set_config("JS_DISASM_RISCV64", jit_disasm_riscv)
529 set_define("JS_DISASM_RISCV64", jit_disasm_riscv)
532 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
533 def jit_disasm_arm64(jit_enabled, spew, simulator, target, debug):
534     if not jit_enabled:
535         return
537     if simulator and (debug or spew):
538         if getattr(simulator, "arm64", None):
539             return True
541     if target.cpu == "aarch64" and (debug or spew):
542         return True
545 set_config("JS_DISASM_ARM64", jit_disasm_arm64)
546 set_define("JS_DISASM_ARM64", jit_disasm_arm64)
548 # When enabled, masm will generate assumeUnreachable calls that act as
549 # assertions in the generated code. This option is worth disabling when you
550 # have to track mutated values through the generated code, to avoid constantly
551 # dumping registers on and off the stack.
552 option(
553     "--enable-masm-verbose",
554     default=depends(when=moz_debug)(lambda: True),
555     help="{Enable|Disable} MacroAssembler verbosity of generated code.",
557 set_define("JS_MASM_VERBOSE", depends_if("--enable-masm-verbose")(lambda _: True))
558 set_config("JS_MASM_VERBOSE", depends_if("--enable-masm-verbose")(lambda _: True))
560 # Architecture feature flags
561 # =======================================================
564 # Apple silicon does not seem to have any way to query the OS for the JSCVT
565 # flag stored in the ID_AA64ISAR1_EL1 system register. In the mean time, we
566 # hard code the value of the JSCVT flag which guards the implementation of
567 # FJCVTZS instruction as part of ARMv8.3-JSConv.
568 @depends(target)
569 def is_apple_silicon(target):
570     return target.kernel == "Darwin" and target.cpu == "aarch64"
573 option(
574     "--enable-arm64-fjcvtzs",
575     default=is_apple_silicon,
576     help="{Enable|Disable} static use of FJCVTZS instruction on Aarch64 targets.",
580 # The "ARM Architecture Reference Manual" for ARMv8 defines the JSCVT flag as
581 # being a 4 bit integer (D12.2.52) and it can be manipulated using >= operator
582 # (D12.1.4).
584 # The FJCVTZS instruction is implemented if ID_AA64ISAR1_EL1.JSCVT >= 1.
585 @depends("--enable-arm64-fjcvtzs", target, simulator)
586 def aarch64_jscvt(fjcvtzs, target, simulator):
587     if target.cpu == "aarch64" and fjcvtzs:
588         return 1
590     if simulator and getattr(simulator, "arm64", False) and fjcvtzs:
591         return 1
593     return 0
596 set_define("MOZ_AARCH64_JSCVT", aarch64_jscvt)
599 @depends(target)
600 def has_pthread_jit_write_protect_np(target):
601     return target.os == "OSX" and target.cpu == "aarch64"
604 # On Apple Silicon we use MAP_JIT with pthread_jit_write_protect_np to implement
605 # JIT code write protection.
606 set_define("JS_USE_APPLE_FAST_WX", True, when=has_pthread_jit_write_protect_np)
609 # CTypes
610 # =======================================================
611 @depends(js_standalone)
612 def ctypes_default(js_standalone):
613     return not js_standalone
616 option("--enable-ctypes", default=ctypes_default, help="{Enable|Disable} js-ctypes")
618 build_ctypes = depends_if("--enable-ctypes")(lambda _: True)
620 set_config("BUILD_CTYPES", build_ctypes)
621 set_define("BUILD_CTYPES", build_ctypes)
623 set_config("JS_HAS_CTYPES", build_ctypes)
624 set_define("JS_HAS_CTYPES", build_ctypes)
627 @depends("--enable-ctypes", "--enable-compile-environment")
628 def ctypes_and_compile_environment(ctypes, compile_environment):
629     return ctypes and compile_environment
632 include("ffi.configure", when=ctypes_and_compile_environment)
635 # Enable pipeline operator
636 # ===================================================
637 option("--enable-pipeline-operator", default=False, help="Enable pipeline operator")
640 @depends("--enable-pipeline-operator")
641 def enable_pipeline_operator(value):
642     if value:
643         return True
646 set_config("ENABLE_PIPELINE_OPERATOR", enable_pipeline_operator)
647 set_define("ENABLE_PIPELINE_OPERATOR", enable_pipeline_operator)
650 # SIMD acceleration for encoding_rs
651 # ==============================================================
653 option(
654     "--enable-rust-simd", env="MOZ_RUST_SIMD", help="Enable explicit SIMD in Rust code."
658 @depends("--enable-rust-simd", target)
659 def rust_simd(value, target):
660     # As of 2019-09-17, the simd-accel feature of encoding_rs has not
661     # been properly set up outside aarch64, armv7, x86 and x86_64.
662     if target.cpu in ("aarch64", "arm", "x86", "x86_64") and value:
663         return True
666 set_config("MOZ_RUST_SIMD", rust_simd)
667 set_define("MOZ_RUST_SIMD", rust_simd)
669 # Telemetry to measure compile time and generated-code runtime
670 # ============================================================
672 option(
673     "--enable-spidermonkey-telemetry",
674     default=milestone.is_nightly,
675     help="{Enable|Disable} performance telemetry for SpiderMonkey (e.g. compile and run times)",
678 set_define(
679     "ENABLE_SPIDERMONKEY_TELEMETRY",
680     depends_if("--enable-spidermonkey-telemetry")(lambda x: True),
683 # Support for debugging code generated by wasm backends
684 # =====================================================
686 option(
687     "--enable-wasm-codegen-debug",
688     default=depends(when=moz_debug)(lambda: True),
689     help="{Enable|Disable} debugging for wasm codegen",
692 set_config(
693     "WASM_CODEGEN_DEBUG", depends_if("--enable-wasm-codegen-debug")(lambda x: True)
695 set_define(
696     "WASM_CODEGEN_DEBUG", depends_if("--enable-wasm-codegen-debug")(lambda x: True)
699 # WebAssembly feature flags
700 # ==================================================
702 option(
703     "--wasm-no-experimental",
704     default=False,
705     help="Force disable all wasm experimental features for testing.",
708 # Support for WebAssembly tail-calls.
709 # ===========================
712 @depends(target)
713 def default_wasm_tail_calls(target):
714     if target.cpu in ("x86", "x86_64", "arm", "aarch64", "loongarch64", "mips64"):
715         return True
718 option(
719     "--enable-wasm-tail-calls",
720     default=default_wasm_tail_calls,
721     help="{Enable|Disable} WebAssembly tail-calls",
725 @depends("--enable-wasm-tail-calls", target)
726 def wasm_tail_calls(value, target):
727     if not value:
728         return
730     if target.cpu in ("x86", "x86_64", "arm", "aarch64", "loongarch64", "mips64"):
731         return True
733     die(
734         "--enable-wasm-tail-calls only possible when targeting the x86_64/x86/arm64/arm/loongarch64/mips64 jits"
735     )
738 set_config("ENABLE_WASM_TAIL_CALLS", wasm_tail_calls)
739 set_define("ENABLE_WASM_TAIL_CALLS", wasm_tail_calls)
741 # Support for WebAssembly GC.
742 # ===========================
745 option("--disable-wasm-gc", default=True, help="{Enable|Disable} WebAssembly GC")
748 @depends("--disable-wasm-gc")
749 def wasm_gc(value):
750     if not value:
751         return
752     return True
755 set_config("ENABLE_WASM_GC", wasm_gc)
756 set_define("ENABLE_WASM_GC", wasm_gc)
758 # Support for WebAssembly JS String Builtins
759 # ==========================================
762 option(
763     "--disable-wasm-js-string-builtins",
764     default=True,
765     help="{Enable|Disable} WebAssembly JS String Builtins",
769 @depends("--disable-wasm-js-string-builtins", "--wasm-no-experimental")
770 def wasm_js_string_builtins(value, no_experimental):
771     if no_experimental or not value:
772         return
774     return True
777 set_config("ENABLE_WASM_JS_STRING_BUILTINS", wasm_js_string_builtins)
778 set_define("ENABLE_WASM_JS_STRING_BUILTINS", wasm_js_string_builtins)
780 # Support for WebAssembly shared memory and atomics.
782 # This affects the JS shell only.
783 # =====================================================
785 option(
786     "--disable-shared-memory", help="Disable JS/WebAssembly shared memory and atomics"
790 @depends("--disable-shared-memory")
791 def enable_shared_memory(value):
792     if value:
793         return True
796 set_config("ENABLE_SHARED_MEMORY", enable_shared_memory)
797 set_define("ENABLE_SHARED_MEMORY", enable_shared_memory)
799 # Support for WebAssembly SIMD
800 # =====================================================
803 @depends("--enable-jit", "--enable-simulator", target)
804 def default_wasm_simd(jit_enabled, simulator, target):
805     if not jit_enabled:
806         return
808     if simulator and (simulator[0] != "arm64"):
809         return
811     if target.cpu in ("x86_64", "x86", "aarch64"):
812         return True
815 option(
816     "--enable-wasm-simd",
817     default=default_wasm_simd,
818     help="{Enable|Disable} WebAssembly SIMD",
822 @depends(
823     "--enable-wasm-simd",
824     "--enable-jit",
825     "--enable-simulator",
826     target,
827     "--wasm-no-experimental",
829 def wasm_simd(value, jit_enabled, simulator, target, no_experimental):
830     if no_experimental or not value:
831         return
833     if not jit_enabled:
834         die("--enable-wasm-simd requires --enable-jit")
836     if simulator and (simulator[0] != "arm64"):
837         die("--enable-wasm-simd is not supported for simulators, except arm64")
839     if target.cpu in ("x86_64", "x86", "aarch64"):
840         return True
842     die("--enable-wasm-simd only possible when targeting the x86_64/x86/arm64 jits")
845 set_config("ENABLE_WASM_SIMD", wasm_simd)
846 set_define("ENABLE_WASM_SIMD", wasm_simd)
848 # Whether to check for field changes in WebAssembly serialization
850 # See the comment for 'WASM_VERIFY_SERIALIZATION_FOR_SIZE' in WasmSerialize.cpp
851 # for more background.
852 # =====================================================================
855 @depends(
856     target,
857     c_compiler,
858     moz_debug,
859     milestone,
860     "--wasm-no-experimental",
862 def wasm_verify_serialization_for_size(
863     target, c_compiler, debug, milestone, no_experimental
865     if (
866         debug == True
867         and target.kernel == "Linux"
868         and target.cpu == "x86_64"
869         and c_compiler
870         and c_compiler.type == "clang"
871         and milestone.is_nightly
872         and not no_experimental
873     ):
874         return True
875     return
878 set_define(
879     "ENABLE_WASM_VERIFY_SERIALIZATION_FOR_SIZE", wasm_verify_serialization_for_size
882 # Support for Intel AVX instruction.
884 # AVX is exclusively used in WebAssembly SIMD instructions at the moment:
885 # set direct dependency on "--enable-wasm-simd".
886 # =====================================================
889 @depends("--enable-wasm-simd", "--enable-simulator", target)
890 def default_wasm_avx(wasm_simd_enabled, simulator, target):
891     if not wasm_simd_enabled:
892         return
894     if simulator:
895         return
897     if target.cpu in ("x86_64", "x86"):
898         return True
901 option(
902     "--enable-wasm-avx",
903     default=default_wasm_avx,
904     help="{Enable|Disable} AVX support for WebAssembly SIMD",
908 @depends(
909     "--enable-wasm-avx",
910     "--enable-wasm-simd",
911     "--enable-simulator",
912     target,
913     "--wasm-no-experimental",
915 def wasm_avx(value, wasm_simd_enabled, simulator, target, no_experimental):
916     if no_experimental or not value:
917         return
919     if not wasm_simd_enabled:
920         die("--enable-wasm-avx requires --enable-wasm-simd")
922     if simulator:
923         die("--enable-wasm-avx is not supported for simulators")
925     if target.cpu in ("x86_64", "x86"):
926         return True
928     die("--enable-wasm-avx only possible when targeting the x86_64/x86 jits")
931 set_config("ENABLE_WASM_AVX", wasm_avx)
932 set_define("ENABLE_WASM_AVX", wasm_avx)
934 # Support for WebAssembly relaxed SIMD
935 # =====================================================
938 @depends(milestone.is_nightly, "--enable-wasm-simd")
939 def default_wasm_relaxed_simd(is_nightly, wasm_simd):
940     if is_nightly and wasm_simd:
941         return True
944 option(
945     "--enable-wasm-relaxed-simd",
946     default=default_wasm_relaxed_simd,
947     help="{Enable|Disable} WebAssembly relaxed SIMD",
951 @depends("--enable-wasm-relaxed-simd", "--enable-wasm-simd", "--wasm-no-experimental")
952 def wasm_relaxed_simd(value, wasm_simd, no_experimental):
953     if no_experimental or not value:
954         return
956     if not wasm_simd:
957         die("relaxed SIMD requires SIMD")
959     return True
962 set_config("ENABLE_WASM_RELAXED_SIMD", wasm_relaxed_simd)
963 set_define("ENABLE_WASM_RELAXED_SIMD", wasm_relaxed_simd)
965 # Support for WebAssembly intgemm private intrinsics
966 # =====================================================
969 @depends(target)
970 def default_wasm_moz_intgemm(target):
971     return target.cpu in ("x86", "x86_64", "aarch64")
974 option(
975     "--enable-wasm-moz-intgemm",
976     default=default_wasm_moz_intgemm,
977     help="{Enable|Disable} WebAssembly intgemm private intrinsics",
981 @depends("--enable-wasm-moz-intgemm", "--wasm-no-experimental")
982 def wasm_moz_intgemm(value, no_experimental):
983     if no_experimental:
984         return
986     if value:
987         return True
990 set_config("ENABLE_WASM_MOZ_INTGEMM", wasm_moz_intgemm)
991 set_define("ENABLE_WASM_MOZ_INTGEMM", wasm_moz_intgemm)
993 # Support for WebAssembly Memory64.
994 # ===========================
997 @depends(milestone.is_nightly, "--enable-simulator", target)
998 def default_wasm_memory64(is_nightly, simulator, target):
999     if target.cpu == "mips32":
1000         return
1002     if simulator and simulator[0] == "mips32":
1003         return
1005     if is_nightly:
1006         return True
1009 option(
1010     "--enable-wasm-memory64",
1011     default=default_wasm_memory64,
1012     help="{Enable|Disable} WebAssembly Memory64",
1016 @depends(
1017     "--enable-wasm-memory64", "--enable-simulator", target, "--wasm-no-experimental"
1019 def wasm_memory64(value, simulator, target, no_experimental):
1020     if no_experimental or not value:
1021         return
1023     if target.cpu == "mips32":
1024         die("Memory64 is incompatible with MIPS32 target")
1026     if simulator and simulator[0] == "mips32":
1027         die("Memory64 is incompatible with MIPS32 simulator")
1029     return True
1032 set_config("ENABLE_WASM_MEMORY64", wasm_memory64)
1033 set_define("ENABLE_WASM_MEMORY64", wasm_memory64)
1036 # Support for WebAssembly memory control.
1037 # ===========================
1040 @depends(milestone.is_nightly)
1041 def default_wasm_memory_control(is_nightly):
1042     if is_nightly:
1043         return True
1046 option(
1047     "--enable-wasm-memory-control",
1048     default=default_wasm_memory_control,
1049     help="{Enable|Disable} WebAssembly fine-grained memory control instructions",
1053 @depends("--enable-wasm-memory-control", "--wasm-no-experimental")
1054 def wasm_memory_control(value, no_experimental):
1055     if no_experimental or not value:
1056         return
1058     return True
1061 set_config("ENABLE_WASM_MEMORY_CONTROL", wasm_memory_control)
1062 set_define("ENABLE_WASM_MEMORY_CONTROL", wasm_memory_control)
1065 # Support for WebAssembly Multi Memory.
1066 # =====================================
1069 option(
1070     "--disable-wasm-multi-memory",
1071     help="{Enable|Disable} WebAssembly multi-memory",
1075 @depends("--disable-wasm-multi-memory")
1076 def wasm_multi_memory(value):
1077     if value:
1078         return True
1081 set_config("ENABLE_WASM_MULTI_MEMORY", wasm_multi_memory)
1082 set_define("ENABLE_WASM_MULTI_MEMORY", wasm_multi_memory)
1084 # Options for generating the shell as a script
1085 # ============================================
1086 option("--with-qemu-exe", nargs=1, help="Use path as an arm emulator on host platforms")
1087 set_config("QEMU_EXE", depends_if("--with-qemu-exe")(lambda x: x))
1089 option(
1090     "--with-cross-lib",
1091     nargs=1,
1092     default=depends(target.alias)(lambda x: "/usr/%s" % x),
1093     help="Use dir as the location for arm libraries",
1095 set_config("CROSS_LIB", depends_if("--with-cross-lib")(lambda x: x))
1097 # Enable static checking using sixgill
1098 # ====================================
1100 option("--with-sixgill", nargs=1, help="Enable static checking of code using sixgill")
1103 @depends_if("--with-sixgill")
1104 @imports("os")
1105 def sixgill(value):
1106     for f in ("bin/xdbfind", "gcc/xgill.so", "scripts/wrap_gcc/g++"):
1107         if not os.path.exists(os.path.join(value[0], f)):
1108             die("The sixgill plugin and binaries are not at the specified path")
1109     return value[0]
1112 set_config("SIXGILL_PATH", sixgill)
1115 # Support for readline
1116 # =====================================================
1119 @depends("--enable-js-shell", target_is_windows, compile_environment, target)
1120 def editline(js_shell, is_windows, compile_environment, target):
1121     return js_shell and not is_windows and compile_environment and (target.os != "WASI")
1124 option(
1125     "--enable-readline", help="Link js shell to system readline library", when=editline
1128 has_readline = check_symbol(
1129     "readline",
1130     flags=["-lreadline"],
1131     when="--enable-readline",
1132     onerror=lambda: die("No system readline library found"),
1135 set_config("EDITLINE_LIBS", ["-lreadline"], when=has_readline)
1138 @depends("--enable-readline", editline, when=editline)
1139 def bundled_editline(readline, editline):
1140     return editline and not readline
1143 set_config("JS_BUNDLED_EDITLINE", bundled_editline)
1145 set_define("EDITLINE", True, when=editline)
1148 # JIT observers
1149 # =============
1151 option(
1152     "--with-jitreport-granularity",
1153     default="3",
1154     choices=("0", "1", "2", "3"),
1155     help="Default granularity at which to report JIT code to external tools "
1156     "(0 - no info, 1 - code ranges for while functions only, "
1157     "2 - per-line information, 3 - per-op information)",
1160 set_define(
1161     "JS_DEFAULT_JITREPORT_GRANULARITY",
1162     depends_if("--with-jitreport-granularity")(lambda value: value[0]),
1166 # ECMAScript Internationalization API Support (uses ICU)
1167 # ======================================================
1168 system_lib_option("--with-system-icu", help="Use system ICU")
1170 system_icu = pkg_check_modules("MOZ_ICU", "icu-i18n >= 73.1", when="--with-system-icu")
1173 @depends("--with-system-icu")
1174 def in_tree_icu(system_icu):
1175     return not system_icu
1178 # Set MOZ_ICU_CFLAGS to an explicit empty value when --with-system-icu is *not* used,
1179 # for layout/style/extra-bindgen-flags
1180 set_config("MOZ_ICU_CFLAGS", [], when=in_tree_icu)
1182 set_config("MOZ_SYSTEM_ICU", True, when=system_icu)
1183 set_define("MOZ_SYSTEM_ICU", True, when=system_icu)
1185 option("--without-intl-api", help="Disable ECMAScript Internationalization API")
1188 @depends("--with-intl-api", js_standalone)
1189 def check_intl_api(enabled, js_standalone):
1190     if not enabled and not js_standalone:
1191         die("--without-intl-api is not supported")
1194 set_config("JS_HAS_INTL_API", True, when="--with-intl-api")
1195 set_define("JS_HAS_INTL_API", True, when="--with-intl-api")
1198 @depends(build_environment, when="--with-intl-api")
1199 @imports(_from="__builtin__", _import="open")
1200 @imports(_from="__builtin__", _import="ValueError")
1201 def icu_version(build_env):
1202     path = os.path.join(
1203         build_env.topsrcdir, "intl", "icu", "source", "common", "unicode", "uvernum.h"
1204     )
1205     with open(path, encoding="utf-8") as fh:
1206         for line in fh:
1207             if line.startswith("#define"):
1208                 define = line.split(None, 3)
1209                 if len(define) == 3 and define[1] == "U_ICU_VERSION_MAJOR_NUM":
1210                     try:
1211                         return str(int(define[2]))
1212                     except ValueError:
1213                         pass
1214     die("Cannot determine ICU version number from uvernum.h header file")
1217 set_config("MOZ_ICU_VERSION", icu_version)
1219 # Source files that use ICU should have control over which parts of the ICU
1220 # namespace they want to use.
1221 set_define("U_USING_ICU_NAMESPACE", "0", when="--with-intl-api")
1223 # We build ICU as a static library.
1224 set_define("U_STATIC_IMPLEMENTATION", True, when=depends(system_icu)(lambda x: not x))
1227 # ECMAScript Temporal API Support (uses ICU)
1228 # ======================================================
1230 option("--with-temporal-api", default=False, help="Enable ECMAScript Temporal API")
1232 set_config("JS_HAS_TEMPORAL_API", True, when="--with-temporal-api")
1233 set_define("JS_HAS_TEMPORAL_API", True, when="--with-temporal-api")
1236 @depends("--with-temporal-api", "--with-intl-api")
1237 def check_temporal_api(temporal_enabled, intl_enabled):
1238     if temporal_enabled and not intl_enabled:
1239         die("Can't use both --with-temporal-api and --without-intl-api")
1242 # Initial support for WebAssembly JS-API Type Reflections
1243 # =======================================================
1246 @depends(milestone.is_nightly)
1247 def default_wasm_type_reflections(is_nightly):
1248     return is_nightly
1251 option(
1252     "--enable-wasm-type-reflections",
1253     default=default_wasm_type_reflections,
1254     help="{Enable|Disable} type reflection in WASM JS-API",
1257 set_config(
1258     "ENABLE_WASM_TYPE_REFLECTIONS",
1259     depends_if("--enable-wasm-type-reflections")(lambda x: True),
1261 set_define(
1262     "ENABLE_WASM_TYPE_REFLECTIONS",
1263     depends_if("--enable-wasm-type-reflections")(lambda x: True),
1266 # Wasi configuration
1267 # ===================================================
1270 @depends(target.os)
1271 def is_wasi_target(os):
1272     return os == "WASI"
1275 set_define("_WASI_EMULATED_PROCESS_CLOCKS", True, when=is_wasi_target)
1276 set_define("_WASI_EMULATED_GETPID", True, when=is_wasi_target)
1279 @depends(milestone.version)
1280 def js_version(version):
1281     return Version(version)
1284 set_config("MOZJS_MAJOR_VERSION", depends(js_version.major)(lambda m: str(m)))
1285 set_define("MOZJS_MAJOR_VERSION", js_version.major)
1286 set_config("MOZJS_MINOR_VERSION", depends(js_version.minor)(lambda m: str(m)))
1287 set_define("MOZJS_MINOR_VERSION", js_version.minor)
1288 set_config("MOZJS_PATCH_VERSION", depends(js_version.patch)(lambda p: str(p)))
1289 set_config(
1290     "MOZJS_ALPHA",
1291     depends(js_version)(
1292         lambda x: x.version[-2] if str(x.version[-2]) in "ab" else None
1293     ),
1297 # Some platforms have HeapReg, some don't
1298 # =====================================================
1300 # The ARM simulator runs on x86 and might be excluded by the first test,
1301 # so we special-case it.
1304 @depends("--enable-simulator", target)
1305 def wasm_has_heapreg(simulator, target):
1306     if target.cpu != "x86":
1307         return True
1309     if simulator and simulator[0] == "arm":
1310         return True
1313 set_define("WASM_HAS_HEAPREG", wasm_has_heapreg)
1315 # Check for tm_zone, tm_gmtoff in struct tm
1316 # ===================================================
1317 with only_when(compile_environment):
1318     set_define(
1319         "HAVE_TM_ZONE_TM_GMTOFF",
1320         c_compiler.try_compile(
1321             includes=["time.h"],
1322             body="struct tm tm; tm.tm_zone = 0; tm.tm_gmtoff = 1;",
1323             check_msg="for tm_zone and tm_gmtoff in struct tm",
1324         ),
1325     )
1328 # Checks for library functions
1329 # ==============================================================
1330 with only_when(compile_environment & depends(target.os)(lambda os: os != "WINNT")):
1331     set_define("HAVE_GETPAGESIZE", check_symbol("getpagesize"))
1332     set_define("HAVE_GMTIME_R", check_symbol("gmtime_r"))
1333     set_define("HAVE_LOCALTIME_R", check_symbol("localtime_r"))
1334     set_define("HAVE_GETTID", check_symbol("gettid"))
1335     set_define("HAVE_SETPRIORITY", check_symbol("setpriority"))
1336     set_define("HAVE_SYSCALL", check_symbol("syscall"))
1337     set_define("HAVE_GETC_UNLOCKED", check_symbol("getc_unlocked"))
1338     set_define("HAVE_PTHREAD_GETNAME_NP", check_symbol("pthread_getname_np"))
1339     set_define("HAVE_PTHREAD_GET_NAME_NP", check_symbol("pthread_get_name_np"))
1340     set_define("HAVE_STRERROR", check_symbol("strerror"))
1342     set_config(
1343         "HAVE_LANGINFO_CODESET",
1344         try_link(
1345             includes=["langinfo.h"],
1346             body="char* cs = nl_langinfo(CODESET);",
1347             check_msg="for nl_langinfo and CODESET",
1348             when=building_with_gnu_cc,
1349         ),
1350     )
1352     @depends(check_symbol("__cxa_demangle", language="C++"), moz_debug, dmd)
1353     def demangle_symbols(cxa_demangle, moz_debug, dmd):
1354         # Demangle only for debug or DMD builds
1355         if cxa_demangle and (moz_debug or dmd):
1356             return True
1358     set_define("MOZ_DEMANGLE_SYMBOLS", demangle_symbols)
1360     set_define("HAVE__UNWIND_BACKTRACE", True, when=have_unwind)
1362 with only_when(compile_environment):
1363     set_define("HAVE__GETC_NOLOCK", check_symbol("_getc_nolock"))
1364     set_define("HAVE_LOCALECONV", check_symbol("localeconv"))