Bug 1886451: Add missing ifdef Nightly guards. r=dminor
[gecko.git] / js / moz.configure
blob9629d6eea6bd219df7e62d92d8e742264577b8c9
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 # Enable JSON.parse with source
178 # ===================================================
179 @depends(milestone.is_nightly)
180 def enable_json_parse_with_source(is_nightly):
181     if is_nightly:
182         return True
185 set_config("ENABLE_JSON_PARSE_WITH_SOURCE", enable_json_parse_with_source)
186 set_define("ENABLE_JSON_PARSE_WITH_SOURCE", enable_json_parse_with_source)
189 # Portable Baseline Intepreter
190 # =======================================================
191 option(
192     "--enable-portable-baseline-interp",
193     default=False,
194     help="{Enable|Disable} the portable baseline interpreter.",
196 set_define(
197     "ENABLE_PORTABLE_BASELINE_INTERP",
198     depends_if("--enable-portable-baseline-interp")(lambda _: True),
200 set_config(
201     "ENABLE_PORTABLE_BASELINE_INTERP",
202     depends_if("--enable-portable-baseline-interp")(lambda _: True),
205 # Option to always force PBL tier.
206 option(
207     "--enable-portable-baseline-interp-force",
208     default=False,
209     help="{Enable|Disable} forcing use of the portable baseline interpreter.",
212 set_define(
213     "ENABLE_PORTABLE_BASELINE_INTERP_FORCE",
214     depends_if("--enable-portable-baseline-interp-force")(lambda _: True),
216 set_config(
217     "ENABLE_PORTABLE_BASELINE_INTERP_FORCE",
218     depends_if("--enable-portable-baseline-interp-force")(lambda _: True),
222 # JIT support
223 # =======================================================
224 @depends(target, "--enable-record-tuple", "--enable-portable-baseline-interp")
225 def jit_default(target, enable_record_tuple, enable_portable_baseline_interp):
226     if enable_record_tuple:
227         return False
228     if enable_portable_baseline_interp:
229         return False
230     if target.cpu in (
231         "x86",
232         "x86_64",
233         "arm",
234         "aarch64",
235         "mips32",
236         "mips64",
237         "loongarch64",
238     ):
239         return True
240     return False
243 option("--enable-jit", default=jit_default, help="{Enable|Disable} use of the JITs")
246 @deprecated_option("--enable-ion")
247 def report_deprecated(value):
248     if value:
249         die("--enable-ion is deprecated, use --enable-jit instead")
250     else:
251         die("--disable-ion is deprecated, use --disable-jit instead")
254 # JIT code simulator for cross compiles
255 # =======================================================
256 option(
257     "--enable-simulator",
258     choices=("arm", "arm64", "mips32", "mips64", "loong64", "riscv64"),
259     nargs=1,
260     help="Enable a JIT code simulator for the specified architecture",
264 @depends("--enable-jit", "--enable-simulator", target)
265 def simulator(jit_enabled, simulator_enabled, target):
266     if not jit_enabled or not simulator_enabled:
267         return
269     sim_cpu = simulator_enabled[0]
271     if sim_cpu in ("arm", "mips32"):
272         if target.cpu != "x86":
273             die("The %s simulator only works on x86." % sim_cpu)
275     if sim_cpu in ("arm64", "mips64", "loong64", "riscv64"):
276         if target.cpu != "x86_64" and target.cpu != "aarch64":
277             die("The %s simulator only works on x86-64 or arm64." % sim_cpu)
279     return namespace(**{sim_cpu: True})
282 set_config("JS_SIMULATOR", depends_if(simulator)(lambda x: True))
283 set_config("JS_SIMULATOR_ARM", simulator.arm)
284 set_config("JS_SIMULATOR_ARM64", simulator.arm64)
285 set_config("JS_SIMULATOR_MIPS32", simulator.mips32)
286 set_config("JS_SIMULATOR_MIPS64", simulator.mips64)
287 set_config("JS_SIMULATOR_LOONG64", simulator.loong64)
288 set_config("JS_SIMULATOR_RISCV64", simulator.riscv64)
289 set_define("JS_SIMULATOR", depends_if(simulator)(lambda x: True))
290 set_define("JS_SIMULATOR_ARM", simulator.arm)
291 set_define("JS_SIMULATOR_ARM64", simulator.arm64)
292 set_define("JS_SIMULATOR_MIPS32", simulator.mips32)
293 set_define("JS_SIMULATOR_MIPS64", simulator.mips64)
294 set_define("JS_SIMULATOR_LOONG64", simulator.loong64)
295 set_define("JS_SIMULATOR_RISCV64", simulator.riscv64)
298 @depends("--enable-jit", simulator, target)
299 def jit_codegen(jit_enabled, simulator, target):
300     if not jit_enabled:
301         return namespace(none=True)
303     if simulator:
304         return simulator
306     if target.cpu == "aarch64":
307         return namespace(arm64=True)
308     elif target.cpu == "x86_64":
309         return namespace(x64=True)
310     elif target.cpu == "loongarch64":
311         return namespace(loong64=True)
312     elif target.cpu == "riscv64":
313         return namespace(riscv64=True)
315     return namespace(**{str(target.cpu): True})
318 set_config("JS_CODEGEN_NONE", jit_codegen.none)
319 set_config("JS_CODEGEN_ARM", jit_codegen.arm)
320 set_config("JS_CODEGEN_ARM64", jit_codegen.arm64)
321 set_config("JS_CODEGEN_MIPS32", jit_codegen.mips32)
322 set_config("JS_CODEGEN_MIPS64", jit_codegen.mips64)
323 set_config("JS_CODEGEN_LOONG64", jit_codegen.loong64)
324 set_config("JS_CODEGEN_RISCV64", jit_codegen.riscv64)
325 set_config("JS_CODEGEN_X86", jit_codegen.x86)
326 set_config("JS_CODEGEN_X64", jit_codegen.x64)
327 set_config("JS_CODEGEN_WASM32", jit_codegen.wasm32)
329 set_define("JS_CODEGEN_NONE", jit_codegen.none)
330 set_define("JS_CODEGEN_ARM", jit_codegen.arm)
331 set_define("JS_CODEGEN_ARM64", jit_codegen.arm64)
332 set_define("JS_CODEGEN_MIPS32", jit_codegen.mips32)
333 set_define("JS_CODEGEN_MIPS64", jit_codegen.mips64)
334 set_define("JS_CODEGEN_LOONG64", jit_codegen.loong64)
335 set_define("JS_CODEGEN_RISCV64", jit_codegen.riscv64)
336 set_define("JS_CODEGEN_X86", jit_codegen.x86)
337 set_define("JS_CODEGEN_X64", jit_codegen.x64)
338 set_define("JS_CODEGEN_WASM32", jit_codegen.wasm32)
341 # Profiling
342 # =======================================================
343 option(
344     "--enable-instruments",
345     env="MOZ_INSTRUMENTS",
346     help="Enable instruments remote profiling",
350 @depends("--enable-instruments", target)
351 def instruments(value, target):
352     if value and target.os != "OSX":
353         die("--enable-instruments cannot be used when targeting %s", target.os)
354     if value:
355         return True
358 set_config("MOZ_INSTRUMENTS", instruments)
359 set_define("MOZ_INSTRUMENTS", instruments)
360 add_old_configure_assignment("MOZ_INSTRUMENTS", instruments)
361 imply_option("--enable-profiling", instruments, reason="--enable-instruments")
363 option("--enable-callgrind", env="MOZ_CALLGRIND", help="Enable callgrind profiling")
366 @depends("--enable-callgrind")
367 def callgrind(value):
368     if value:
369         return True
372 set_define("MOZ_CALLGRIND", callgrind)
373 imply_option("--enable-profiling", callgrind)
376 @depends(milestone)
377 def enable_profiling(milestone):
378     return milestone.is_nightly
381 option(
382     "--enable-profiling",
383     env="MOZ_PROFILING",
384     default=enable_profiling,
385     help="{Set|Do not set} compile flags necessary for using sampling "
386     "profilers (e.g. shark, perf)",
390 @depends("--enable-profiling")
391 def profiling(value):
392     if value:
393         return True
396 with only_when("--enable-compile-environment"):
397     imply_option("--enable-frame-pointers", True, when=profiling)
400 @depends(profiling, target)
401 def imply_vtune(value, target):
402     ok_cpu = target.cpu in ["x86", "x86_64"]
403     ok_kernel = target.kernel == "WINNT" or (
404         target.kernel == "Linux" and target.os == "GNU"
405     )
407     if value and ok_cpu and ok_kernel:
408         return True
411 set_config("MOZ_PROFILING", profiling)
412 set_define("MOZ_PROFILING", profiling)
413 imply_option("--enable-vtune", imply_vtune, reason="--enable-profiling")
416 option("--enable-vtune", env="MOZ_VTUNE", help="Enable VTune profiling")
419 @depends("--enable-vtune")
420 def vtune(value):
421     if value:
422         return True
425 set_config("MOZ_VTUNE", vtune)
426 set_define("MOZ_VTUNE", vtune)
429 option(
430     "--enable-gc-probes",
431     env="JS_GC_PROBES",
432     help="Turn on probes for allocation and finalization",
436 @depends("--enable-gc-probes")
437 def gc_probes(value):
438     if value:
439         return True
442 set_define("JS_GC_PROBES", gc_probes)
445 option(
446     "--enable-gczeal",
447     default=depends(when=moz_debug)(lambda: True),
448     help="{Enable|Disable} zealous GCing",
451 set_define("JS_GC_ZEAL", depends_if("--enable-gczeal")(lambda _: True))
454 # Enable breakpoint for artificial OOMs
455 # =======================================================
456 option(
457     "--enable-oom-breakpoint", help="Enable a breakpoint function for artificial OOMs"
460 set_define("JS_OOM_BREAKPOINT", depends_if("--enable-oom-breakpoint")(lambda _: True))
463 option("--enable-perf", env="JS_ION_PERF", help="Enable Linux perf integration")
466 @depends("--enable-perf", target)
467 def ion_perf(value, target):
468     is_linux = target.kernel == "Linux"
469     is_mac = target.kernel == "Darwin" and target.os == "OSX"
471     if value and (is_linux or is_mac):
472         return True
475 set_define("JS_ION_PERF", ion_perf)
478 option(
479     "--enable-jitspew",
480     default=depends(when=moz_debug)(lambda: True),
481     help="{Enable|Disable} the Jit spew and IONFLAGS environment " "variable",
484 set_define("JS_JITSPEW", depends_if("--enable-jitspew")(lambda _: True))
485 set_config("JS_JITSPEW", depends_if("--enable-jitspew")(lambda _: True))
487 # Also enable the structured spewer
488 set_define("JS_STRUCTURED_SPEW", depends_if("--enable-jitspew")(lambda _: True))
489 set_config("JS_STRUCTURED_SPEW", depends_if("--enable-jitspew")(lambda _: True))
492 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
493 def jit_disasm_arm(jit_enabled, spew, simulator, target, debug):
494     if not jit_enabled:
495         return
497     if simulator and (debug or spew):
498         if getattr(simulator, "arm", None):
499             return True
501     if target.cpu == "arm" and (debug or spew):
502         return True
505 set_config("JS_DISASM_ARM", jit_disasm_arm)
506 set_define("JS_DISASM_ARM", jit_disasm_arm)
509 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
510 def jit_disasm_riscv(jit_enabled, spew, simulator, target, debug):
511     if not jit_enabled:
512         return
514     if simulator and (debug or spew):
515         if getattr(simulator, "riscv64", None):
516             return True
518     if target.cpu == "riscv64" and (debug or spew):
519         return True
522 set_config("JS_DISASM_RISCV64", jit_disasm_riscv)
523 set_define("JS_DISASM_RISCV64", jit_disasm_riscv)
526 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
527 def jit_disasm_arm64(jit_enabled, spew, simulator, target, debug):
528     if not jit_enabled:
529         return
531     if simulator and (debug or spew):
532         if getattr(simulator, "arm64", None):
533             return True
535     if target.cpu == "aarch64" and (debug or spew):
536         return True
539 set_config("JS_DISASM_ARM64", jit_disasm_arm64)
540 set_define("JS_DISASM_ARM64", jit_disasm_arm64)
542 # When enabled, masm will generate assumeUnreachable calls that act as
543 # assertions in the generated code. This option is worth disabling when you
544 # have to track mutated values through the generated code, to avoid constantly
545 # dumping registers on and off the stack.
546 option(
547     "--enable-masm-verbose",
548     default=depends(when=moz_debug)(lambda: True),
549     help="{Enable|Disable} MacroAssembler verbosity of generated code.",
551 set_define("JS_MASM_VERBOSE", depends_if("--enable-masm-verbose")(lambda _: True))
552 set_config("JS_MASM_VERBOSE", depends_if("--enable-masm-verbose")(lambda _: True))
554 # Architecture feature flags
555 # =======================================================
558 # Apple silicon does not seem to have any way to query the OS for the JSCVT
559 # flag stored in the ID_AA64ISAR1_EL1 system register. In the mean time, we
560 # hard code the value of the JSCVT flag which guards the implementation of
561 # FJCVTZS instruction as part of ARMv8.3-JSConv.
562 @depends(target)
563 def is_apple_silicon(target):
564     return target.kernel == "Darwin" and target.cpu == "aarch64"
567 option(
568     "--enable-arm64-fjcvtzs",
569     default=is_apple_silicon,
570     help="{Enable|Disable} static use of FJCVTZS instruction on Aarch64 targets.",
574 # The "ARM Architecture Reference Manual" for ARMv8 defines the JSCVT flag as
575 # being a 4 bit integer (D12.2.52) and it can be manipulated using >= operator
576 # (D12.1.4).
578 # The FJCVTZS instruction is implemented if ID_AA64ISAR1_EL1.JSCVT >= 1.
579 @depends("--enable-arm64-fjcvtzs", target, simulator)
580 def aarch64_jscvt(fjcvtzs, target, simulator):
581     if target.cpu == "aarch64" and fjcvtzs:
582         return 1
584     if simulator and getattr(simulator, "arm64", False) and fjcvtzs:
585         return 1
587     return 0
590 set_define("MOZ_AARCH64_JSCVT", aarch64_jscvt)
593 @depends(target)
594 def has_pthread_jit_write_protect_np(target):
595     return target.os == "OSX" and target.cpu == "aarch64"
598 # On Apple Silicon we use MAP_JIT with pthread_jit_write_protect_np to implement
599 # JIT code write protection.
600 set_define("JS_USE_APPLE_FAST_WX", True, when=has_pthread_jit_write_protect_np)
603 # CTypes
604 # =======================================================
605 @depends(js_standalone)
606 def ctypes_default(js_standalone):
607     return not js_standalone
610 option("--enable-ctypes", default=ctypes_default, help="{Enable|Disable} js-ctypes")
612 build_ctypes = depends_if("--enable-ctypes")(lambda _: True)
614 set_config("BUILD_CTYPES", build_ctypes)
615 set_define("BUILD_CTYPES", build_ctypes)
617 set_config("JS_HAS_CTYPES", build_ctypes)
618 set_define("JS_HAS_CTYPES", build_ctypes)
621 @depends("--enable-ctypes", "--enable-compile-environment")
622 def ctypes_and_compile_environment(ctypes, compile_environment):
623     return ctypes and compile_environment
626 include("ffi.configure", when=ctypes_and_compile_environment)
629 # Enable pipeline operator
630 # ===================================================
631 option("--enable-pipeline-operator", default=False, help="Enable pipeline operator")
634 @depends("--enable-pipeline-operator")
635 def enable_pipeline_operator(value):
636     if value:
637         return True
640 set_config("ENABLE_PIPELINE_OPERATOR", enable_pipeline_operator)
641 set_define("ENABLE_PIPELINE_OPERATOR", enable_pipeline_operator)
644 # SIMD acceleration for encoding_rs
645 # ==============================================================
647 option(
648     "--enable-rust-simd", env="MOZ_RUST_SIMD", help="Enable explicit SIMD in Rust code."
652 @depends("--enable-rust-simd", target)
653 def rust_simd(value, target):
654     # As of 2019-09-17, the simd-accel feature of encoding_rs has not
655     # been properly set up outside aarch64, armv7, x86 and x86_64.
656     if target.cpu in ("aarch64", "arm", "x86", "x86_64") and value:
657         return True
660 set_config("MOZ_RUST_SIMD", rust_simd)
661 set_define("MOZ_RUST_SIMD", rust_simd)
663 # Telemetry to measure compile time and generated-code runtime
664 # ============================================================
666 option(
667     "--enable-spidermonkey-telemetry",
668     default=milestone.is_nightly,
669     help="{Enable|Disable} performance telemetry for SpiderMonkey (e.g. compile and run times)",
672 set_define(
673     "ENABLE_SPIDERMONKEY_TELEMETRY",
674     depends_if("--enable-spidermonkey-telemetry")(lambda x: True),
677 # Support for debugging code generated by wasm backends
678 # =====================================================
680 option(
681     "--enable-wasm-codegen-debug",
682     default=depends(when=moz_debug)(lambda: True),
683     help="{Enable|Disable} debugging for wasm codegen",
686 set_config(
687     "WASM_CODEGEN_DEBUG", depends_if("--enable-wasm-codegen-debug")(lambda x: True)
689 set_define(
690     "WASM_CODEGEN_DEBUG", depends_if("--enable-wasm-codegen-debug")(lambda x: True)
693 # WebAssembly feature flags
694 # ==================================================
696 option(
697     "--wasm-no-experimental",
698     default=False,
699     help="Force disable all wasm experimental features for testing.",
702 # Support for WebAssembly tail-calls.
703 # ===========================
706 @depends(target)
707 def default_wasm_tail_calls(target):
708     if target.cpu in ("x86", "x86_64", "arm", "aarch64", "loongarch64", "mips64"):
709         return True
712 option(
713     "--enable-wasm-tail-calls",
714     default=default_wasm_tail_calls,
715     help="{Enable|Disable} WebAssembly tail-calls",
719 @depends("--enable-wasm-tail-calls", target)
720 def wasm_tail_calls(value, target):
721     if not value:
722         return
724     if target.cpu in ("x86", "x86_64", "arm", "aarch64", "loongarch64", "mips64"):
725         return True
727     die(
728         "--enable-wasm-tail-calls only possible when targeting the x86_64/x86/arm64/arm/loongarch64/mips64 jits"
729     )
732 set_config("ENABLE_WASM_TAIL_CALLS", wasm_tail_calls)
733 set_define("ENABLE_WASM_TAIL_CALLS", wasm_tail_calls)
735 # Support for WebAssembly GC.
736 # ===========================
739 option("--disable-wasm-gc", default=True, help="{Enable|Disable} WebAssembly GC")
742 @depends("--disable-wasm-gc")
743 def wasm_gc(value):
744     if not value:
745         return
746     return True
749 set_config("ENABLE_WASM_GC", wasm_gc)
750 set_define("ENABLE_WASM_GC", wasm_gc)
752 # Support for WebAssembly JS String Builtins
753 # ==========================================
756 option(
757     "--disable-wasm-js-string-builtins",
758     default=True,
759     help="{Enable|Disable} WebAssembly JS String Builtins",
763 @depends("--disable-wasm-js-string-builtins", "--wasm-no-experimental")
764 def wasm_js_string_builtins(value, no_experimental):
765     if no_experimental or not value:
766         return
768     return True
771 set_config("ENABLE_WASM_JS_STRING_BUILTINS", wasm_js_string_builtins)
772 set_define("ENABLE_WASM_JS_STRING_BUILTINS", wasm_js_string_builtins)
774 # Support for WebAssembly shared memory and atomics.
776 # This affects the JS shell only.
777 # =====================================================
779 option(
780     "--disable-shared-memory", help="Disable JS/WebAssembly shared memory and atomics"
784 @depends("--disable-shared-memory")
785 def enable_shared_memory(value):
786     if value:
787         return True
790 set_config("ENABLE_SHARED_MEMORY", enable_shared_memory)
791 set_define("ENABLE_SHARED_MEMORY", enable_shared_memory)
793 # Support for WebAssembly SIMD
794 # =====================================================
797 @depends("--enable-jit", "--enable-simulator", target)
798 def default_wasm_simd(jit_enabled, simulator, target):
799     if not jit_enabled:
800         return
802     if simulator and (simulator[0] != "arm64"):
803         return
805     if target.cpu in ("x86_64", "x86", "aarch64"):
806         return True
809 option(
810     "--enable-wasm-simd",
811     default=default_wasm_simd,
812     help="{Enable|Disable} WebAssembly SIMD",
816 @depends(
817     "--enable-wasm-simd",
818     "--enable-jit",
819     "--enable-simulator",
820     target,
821     "--wasm-no-experimental",
823 def wasm_simd(value, jit_enabled, simulator, target, no_experimental):
824     if no_experimental or not value:
825         return
827     if not jit_enabled:
828         die("--enable-wasm-simd requires --enable-jit")
830     if simulator and (simulator[0] != "arm64"):
831         die("--enable-wasm-simd is not supported for simulators, except arm64")
833     if target.cpu in ("x86_64", "x86", "aarch64"):
834         return True
836     die("--enable-wasm-simd only possible when targeting the x86_64/x86/arm64 jits")
839 set_config("ENABLE_WASM_SIMD", wasm_simd)
840 set_define("ENABLE_WASM_SIMD", wasm_simd)
842 # Whether to check for field changes in WebAssembly serialization
844 # See the comment for 'WASM_VERIFY_SERIALIZATION_FOR_SIZE' in WasmSerialize.cpp
845 # for more background.
846 # =====================================================================
849 @depends(
850     target,
851     c_compiler,
852     moz_debug,
853     milestone,
854     "--wasm-no-experimental",
856 def wasm_verify_serialization_for_size(
857     target, c_compiler, debug, milestone, no_experimental
859     if (
860         debug == True
861         and target.kernel == "Linux"
862         and target.cpu == "x86_64"
863         and c_compiler
864         and c_compiler.type == "clang"
865         and milestone.is_nightly
866         and not no_experimental
867     ):
868         return True
869     return
872 set_define(
873     "ENABLE_WASM_VERIFY_SERIALIZATION_FOR_SIZE", wasm_verify_serialization_for_size
876 # Support for Intel AVX instruction.
878 # AVX is exclusively used in WebAssembly SIMD instructions at the moment:
879 # set direct dependency on "--enable-wasm-simd".
880 # =====================================================
883 @depends("--enable-wasm-simd", "--enable-simulator", target)
884 def default_wasm_avx(wasm_simd_enabled, simulator, target):
885     if not wasm_simd_enabled:
886         return
888     if simulator:
889         return
891     if target.cpu in ("x86_64", "x86"):
892         return True
895 option(
896     "--enable-wasm-avx",
897     default=default_wasm_avx,
898     help="{Enable|Disable} AVX support for WebAssembly SIMD",
902 @depends(
903     "--enable-wasm-avx",
904     "--enable-wasm-simd",
905     "--enable-simulator",
906     target,
907     "--wasm-no-experimental",
909 def wasm_avx(value, wasm_simd_enabled, simulator, target, no_experimental):
910     if no_experimental or not value:
911         return
913     if not wasm_simd_enabled:
914         die("--enable-wasm-avx requires --enable-wasm-simd")
916     if simulator:
917         die("--enable-wasm-avx is not supported for simulators")
919     if target.cpu in ("x86_64", "x86"):
920         return True
922     die("--enable-wasm-avx only possible when targeting the x86_64/x86 jits")
925 set_config("ENABLE_WASM_AVX", wasm_avx)
926 set_define("ENABLE_WASM_AVX", wasm_avx)
928 # Support for WebAssembly relaxed SIMD
929 # =====================================================
932 @depends(milestone.is_nightly, "--enable-wasm-simd")
933 def default_wasm_relaxed_simd(is_nightly, wasm_simd):
934     if is_nightly and wasm_simd:
935         return True
938 option(
939     "--enable-wasm-relaxed-simd",
940     default=default_wasm_relaxed_simd,
941     help="{Enable|Disable} WebAssembly relaxed SIMD",
945 @depends("--enable-wasm-relaxed-simd", "--enable-wasm-simd", "--wasm-no-experimental")
946 def wasm_relaxed_simd(value, wasm_simd, no_experimental):
947     if no_experimental or not value:
948         return
950     if not wasm_simd:
951         die("relaxed SIMD requires SIMD")
953     return True
956 set_config("ENABLE_WASM_RELAXED_SIMD", wasm_relaxed_simd)
957 set_define("ENABLE_WASM_RELAXED_SIMD", wasm_relaxed_simd)
959 # Support for WebAssembly intgemm private intrinsics
960 # =====================================================
963 @depends(target)
964 def default_wasm_moz_intgemm(target):
965     return target.cpu in ("x86", "x86_64", "aarch64")
968 option(
969     "--enable-wasm-moz-intgemm",
970     default=default_wasm_moz_intgemm,
971     help="{Enable|Disable} WebAssembly intgemm private intrinsics",
975 @depends("--enable-wasm-moz-intgemm", "--wasm-no-experimental")
976 def wasm_moz_intgemm(value, no_experimental):
977     if no_experimental:
978         return
980     if value:
981         return True
984 set_config("ENABLE_WASM_MOZ_INTGEMM", wasm_moz_intgemm)
985 set_define("ENABLE_WASM_MOZ_INTGEMM", wasm_moz_intgemm)
987 # Support for WebAssembly Memory64.
988 # ===========================
991 @depends(milestone.is_nightly, "--enable-simulator", target)
992 def default_wasm_memory64(is_nightly, simulator, target):
993     if target.cpu == "mips32":
994         return
996     if simulator and simulator[0] == "mips32":
997         return
999     if is_nightly:
1000         return True
1003 option(
1004     "--enable-wasm-memory64",
1005     default=default_wasm_memory64,
1006     help="{Enable|Disable} WebAssembly Memory64",
1010 @depends(
1011     "--enable-wasm-memory64", "--enable-simulator", target, "--wasm-no-experimental"
1013 def wasm_memory64(value, simulator, target, no_experimental):
1014     if no_experimental or not value:
1015         return
1017     if target.cpu == "mips32":
1018         die("Memory64 is incompatible with MIPS32 target")
1020     if simulator and simulator[0] == "mips32":
1021         die("Memory64 is incompatible with MIPS32 simulator")
1023     return True
1026 set_config("ENABLE_WASM_MEMORY64", wasm_memory64)
1027 set_define("ENABLE_WASM_MEMORY64", wasm_memory64)
1030 # Support for WebAssembly memory control.
1031 # ===========================
1034 @depends(milestone.is_nightly)
1035 def default_wasm_memory_control(is_nightly):
1036     if is_nightly:
1037         return True
1040 option(
1041     "--enable-wasm-memory-control",
1042     default=default_wasm_memory_control,
1043     help="{Enable|Disable} WebAssembly fine-grained memory control instructions",
1047 @depends("--enable-wasm-memory-control", "--wasm-no-experimental")
1048 def wasm_memory_control(value, no_experimental):
1049     if no_experimental or not value:
1050         return
1052     return True
1055 set_config("ENABLE_WASM_MEMORY_CONTROL", wasm_memory_control)
1056 set_define("ENABLE_WASM_MEMORY_CONTROL", wasm_memory_control)
1059 # Support for WebAssembly Multi Memory.
1060 # =====================================
1063 option(
1064     "--disable-wasm-multi-memory",
1065     help="{Enable|Disable} WebAssembly multi-memory",
1069 @depends("--disable-wasm-multi-memory")
1070 def wasm_multi_memory(value):
1071     if value:
1072         return True
1075 set_config("ENABLE_WASM_MULTI_MEMORY", wasm_multi_memory)
1076 set_define("ENABLE_WASM_MULTI_MEMORY", wasm_multi_memory)
1078 # Options for generating the shell as a script
1079 # ============================================
1080 option("--with-qemu-exe", nargs=1, help="Use path as an arm emulator on host platforms")
1081 set_config("QEMU_EXE", depends_if("--with-qemu-exe")(lambda x: x))
1083 option(
1084     "--with-cross-lib",
1085     nargs=1,
1086     default=depends(target.alias)(lambda x: "/usr/%s" % x),
1087     help="Use dir as the location for arm libraries",
1089 set_config("CROSS_LIB", depends_if("--with-cross-lib")(lambda x: x))
1091 # Enable static checking using sixgill
1092 # ====================================
1094 option("--with-sixgill", nargs=1, help="Enable static checking of code using sixgill")
1097 @depends_if("--with-sixgill")
1098 @imports("os")
1099 def sixgill(value):
1100     for f in ("bin/xdbfind", "gcc/xgill.so", "scripts/wrap_gcc/g++"):
1101         if not os.path.exists(os.path.join(value[0], f)):
1102             die("The sixgill plugin and binaries are not at the specified path")
1103     return value[0]
1106 set_config("SIXGILL_PATH", sixgill)
1109 # Support for readline
1110 # =====================================================
1113 @depends("--enable-js-shell", target_is_windows, compile_environment, target)
1114 def editline(js_shell, is_windows, compile_environment, target):
1115     return js_shell and not is_windows and compile_environment and (target.os != "WASI")
1118 option(
1119     "--enable-readline", help="Link js shell to system readline library", when=editline
1122 has_readline = check_symbol(
1123     "readline",
1124     flags=["-lreadline"],
1125     when="--enable-readline",
1126     onerror=lambda: die("No system readline library found"),
1129 set_config("EDITLINE_LIBS", ["-lreadline"], when=has_readline)
1132 @depends("--enable-readline", editline, when=editline)
1133 def bundled_editline(readline, editline):
1134     return editline and not readline
1137 set_config("JS_BUNDLED_EDITLINE", bundled_editline)
1139 set_define("EDITLINE", True, when=editline)
1142 # JIT observers
1143 # =============
1145 option(
1146     "--with-jitreport-granularity",
1147     default="3",
1148     choices=("0", "1", "2", "3"),
1149     help="Default granularity at which to report JIT code to external tools "
1150     "(0 - no info, 1 - code ranges for while functions only, "
1151     "2 - per-line information, 3 - per-op information)",
1154 set_define(
1155     "JS_DEFAULT_JITREPORT_GRANULARITY",
1156     depends_if("--with-jitreport-granularity")(lambda value: value[0]),
1160 # ECMAScript Internationalization API Support (uses ICU)
1161 # ======================================================
1162 system_lib_option("--with-system-icu", help="Use system ICU")
1164 system_icu = pkg_check_modules("MOZ_ICU", "icu-i18n >= 73.1", when="--with-system-icu")
1167 @depends("--with-system-icu")
1168 def in_tree_icu(system_icu):
1169     return not system_icu
1172 # Set MOZ_ICU_CFLAGS to an explicit empty value when --with-system-icu is *not* used,
1173 # for layout/style/extra-bindgen-flags
1174 set_config("MOZ_ICU_CFLAGS", [], when=in_tree_icu)
1176 set_config("MOZ_SYSTEM_ICU", True, when=system_icu)
1177 set_define("MOZ_SYSTEM_ICU", True, when=system_icu)
1179 option("--without-intl-api", help="Disable ECMAScript Internationalization API")
1182 @depends("--with-intl-api", js_standalone)
1183 def check_intl_api(enabled, js_standalone):
1184     if not enabled and not js_standalone:
1185         die("--without-intl-api is not supported")
1188 set_config("JS_HAS_INTL_API", True, when="--with-intl-api")
1189 set_define("JS_HAS_INTL_API", True, when="--with-intl-api")
1192 @depends(build_environment, when="--with-intl-api")
1193 @imports(_from="__builtin__", _import="open")
1194 @imports(_from="__builtin__", _import="ValueError")
1195 def icu_version(build_env):
1196     path = os.path.join(
1197         build_env.topsrcdir, "intl", "icu", "source", "common", "unicode", "uvernum.h"
1198     )
1199     with open(path, encoding="utf-8") as fh:
1200         for line in fh:
1201             if line.startswith("#define"):
1202                 define = line.split(None, 3)
1203                 if len(define) == 3 and define[1] == "U_ICU_VERSION_MAJOR_NUM":
1204                     try:
1205                         return str(int(define[2]))
1206                     except ValueError:
1207                         pass
1208     die("Cannot determine ICU version number from uvernum.h header file")
1211 set_config("MOZ_ICU_VERSION", icu_version)
1213 # Source files that use ICU should have control over which parts of the ICU
1214 # namespace they want to use.
1215 set_define("U_USING_ICU_NAMESPACE", "0", when="--with-intl-api")
1217 # We build ICU as a static library.
1218 set_define("U_STATIC_IMPLEMENTATION", True, when=depends(system_icu)(lambda x: not x))
1221 # ECMAScript Temporal API Support (uses ICU)
1222 # ======================================================
1224 option("--with-temporal-api", default=False, help="Enable ECMAScript Temporal API")
1226 set_config("JS_HAS_TEMPORAL_API", True, when="--with-temporal-api")
1227 set_define("JS_HAS_TEMPORAL_API", True, when="--with-temporal-api")
1230 @depends("--with-temporal-api", "--with-intl-api")
1231 def check_temporal_api(temporal_enabled, intl_enabled):
1232     if temporal_enabled and not intl_enabled:
1233         die("Can't use both --with-temporal-api and --without-intl-api")
1236 # Initial support for WebAssembly JS-API Type Reflections
1237 # =======================================================
1240 @depends(milestone.is_nightly)
1241 def default_wasm_type_reflections(is_nightly):
1242     return is_nightly
1245 option(
1246     "--enable-wasm-type-reflections",
1247     default=default_wasm_type_reflections,
1248     help="{Enable|Disable} type reflection in WASM JS-API",
1251 set_config(
1252     "ENABLE_WASM_TYPE_REFLECTIONS",
1253     depends_if("--enable-wasm-type-reflections")(lambda x: True),
1255 set_define(
1256     "ENABLE_WASM_TYPE_REFLECTIONS",
1257     depends_if("--enable-wasm-type-reflections")(lambda x: True),
1260 # Wasi configuration
1261 # ===================================================
1264 @depends(target.os)
1265 def is_wasi_target(os):
1266     return os == "WASI"
1269 set_define("_WASI_EMULATED_PROCESS_CLOCKS", True, when=is_wasi_target)
1270 set_define("_WASI_EMULATED_GETPID", True, when=is_wasi_target)
1273 @depends(milestone.version)
1274 def js_version(version):
1275     return Version(version)
1278 set_config("MOZJS_MAJOR_VERSION", depends(js_version.major)(lambda m: str(m)))
1279 set_define("MOZJS_MAJOR_VERSION", js_version.major)
1280 set_config("MOZJS_MINOR_VERSION", depends(js_version.minor)(lambda m: str(m)))
1281 set_define("MOZJS_MINOR_VERSION", js_version.minor)
1282 set_config("MOZJS_PATCH_VERSION", depends(js_version.patch)(lambda p: str(p)))
1283 set_config(
1284     "MOZJS_ALPHA",
1285     depends(js_version)(
1286         lambda x: x.version[-2] if str(x.version[-2]) in "ab" else None
1287     ),
1291 # Some platforms have HeapReg, some don't
1292 # =====================================================
1294 # The ARM simulator runs on x86 and might be excluded by the first test,
1295 # so we special-case it.
1298 @depends("--enable-simulator", target)
1299 def wasm_has_heapreg(simulator, target):
1300     if target.cpu != "x86":
1301         return True
1303     if simulator and simulator[0] == "arm":
1304         return True
1307 set_define("WASM_HAS_HEAPREG", wasm_has_heapreg)
1309 # Check for tm_zone, tm_gmtoff in struct tm
1310 # ===================================================
1311 with only_when(compile_environment):
1312     set_define(
1313         "HAVE_TM_ZONE_TM_GMTOFF",
1314         c_compiler.try_compile(
1315             includes=["time.h"],
1316             body="struct tm tm; tm.tm_zone = 0; tm.tm_gmtoff = 1;",
1317             check_msg="for tm_zone and tm_gmtoff in struct tm",
1318         ),
1319     )
1322 # Checks for library functions
1323 # ==============================================================
1324 with only_when(compile_environment & depends(target.os)(lambda os: os != "WINNT")):
1325     set_define("HAVE_GETPAGESIZE", check_symbol("getpagesize"))
1326     set_define("HAVE_GMTIME_R", check_symbol("gmtime_r"))
1327     set_define("HAVE_LOCALTIME_R", check_symbol("localtime_r"))
1328     set_define("HAVE_GETTID", check_symbol("gettid"))
1329     set_define("HAVE_SETPRIORITY", check_symbol("setpriority"))
1330     set_define("HAVE_SYSCALL", check_symbol("syscall"))
1331     set_define("HAVE_GETC_UNLOCKED", check_symbol("getc_unlocked"))
1332     set_define("HAVE_PTHREAD_GETNAME_NP", check_symbol("pthread_getname_np"))
1333     set_define("HAVE_PTHREAD_GET_NAME_NP", check_symbol("pthread_get_name_np"))
1334     set_define("HAVE_STRERROR", check_symbol("strerror"))
1336     set_config(
1337         "HAVE_LANGINFO_CODESET",
1338         try_link(
1339             includes=["langinfo.h"],
1340             body="char* cs = nl_langinfo(CODESET);",
1341             check_msg="for nl_langinfo and CODESET",
1342             when=building_with_gnu_cc,
1343         ),
1344     )
1346     @depends(check_symbol("__cxa_demangle", language="C++"), moz_debug, dmd)
1347     def demangle_symbols(cxa_demangle, moz_debug, dmd):
1348         # Demangle only for debug or DMD builds
1349         if cxa_demangle and (moz_debug or dmd):
1350             return True
1352     set_define("MOZ_DEMANGLE_SYMBOLS", demangle_symbols)
1354     set_define("HAVE__UNWIND_BACKTRACE", True, when=have_unwind)
1356 with only_when(compile_environment):
1357     set_define("HAVE__GETC_NOLOCK", check_symbol("_getc_nolock"))
1358     set_define("HAVE_LOCALECONV", check_symbol("localeconv"))