Bug 1705532 use async/await instead of callbacks r=annyG
[gecko.git] / js / moz.configure
blob7a261c9f02581e0048857cc964a7ad9dfa4b788e
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 # Branding
15 # ==============================================================
16 option(
17     "--with-app-name",
18     env="MOZ_APP_NAME",
19     nargs=1,
20     help="Used for e.g. the binary program file name. If not set, "
21     "defaults to a lowercase form of MOZ_APP_BASENAME.",
25 @depends("--with-app-name", js_standalone, moz_app_basename)
26 def moz_app_name(value, js_standalone, moz_app_basename):
27     if value:
28         return value[0]
29     if js_standalone:
30         return "js"
31     return moz_app_basename.lower()
34 set_config("MOZ_APP_NAME", moz_app_name)
36 # SmooshMonkey (new frontend)
37 # ==================================================
39 # Define here in order to use the option from bindgen.configure.
40 option(
41     "--enable-smoosh",
42     default=False,
43     help="Enable SmooshMonkey (new JS engine frontend)",
47 @depends("--enable-smoosh")
48 def enable_smoosh(value):
49     if value:
50         return True
53 set_config("JS_ENABLE_SMOOSH", enable_smoosh)
54 set_define("JS_ENABLE_SMOOSH", enable_smoosh)
56 include("../build/moz.configure/nspr.configure", when="--enable-compile-environment")
57 include("../build/moz.configure/rust.configure", when="--enable-compile-environment")
58 include("../build/moz.configure/bindgen.configure", when="--enable-compile-environment")
60 set_config("JS_STANDALONE", js_standalone)
61 set_define("JS_STANDALONE", js_standalone)
62 add_old_configure_assignment("JS_STANDALONE", js_standalone)
63 option(
64     "--enable-js-shell", default=js_standalone, help="{Build|Do not build} the JS shell"
68 @depends("--enable-js-shell")
69 def js_disable_shell(value):
70     if not value:
71         return True
74 set_config("JS_DISABLE_SHELL", js_disable_shell)
76 set_define("JS_64BIT", depends(target)(lambda t: t.bitness == 64 or None))
78 set_define("JS_PUNBOX64", depends(target)(lambda t: t.bitness == 64 or None))
79 set_define("JS_NUNBOX32", depends(target)(lambda t: t.bitness == 32 or None))
82 # SpiderMonkey as a shared library, and how its symbols are exported
83 # ==================================================================
84 option(
85     "--disable-shared-js",
86     when=js_standalone,
87     help="{Create|Do not create} a shared library",
90 option(
91     "--disable-export-js",
92     when=js_standalone,
93     help="{Mark|Do not mark} JS symbols as DLL exported/visible",
97 @depends("--disable-shared-js", "--disable-export-js", when=js_standalone)
98 def shared_js(shared_js, export_js):
99     if shared_js:
100         if not export_js:
101             die("Must export JS symbols when building a shared library.")
102         return True
105 set_config("JS_SHARED_LIBRARY", shared_js)
106 add_old_configure_assignment("JS_SHARED_LIBRARY", shared_js)
109 @depends(shared_js, "--disable-export-js", when=js_standalone)
110 def exportable_js_api(shared_js, export_js):
111     if not shared_js and export_js:
112         return True
115 set_define("STATIC_EXPORTABLE_JS_API", exportable_js_api)
118 @depends(shared_js, exportable_js_api)
119 def static_js_api(shared_js, export_js):
120     if not shared_js and not export_js:
121         return True
124 set_define("STATIC_JS_API", static_js_api)
127 @depends(shared_js)
128 def static_js(value):
129     if not value:
130         return True
133 set_define("MOZ_STATIC_JS", static_js)
136 # Enable records and tuples
137 # ===================================================
138 option(
139     "--enable-record-tuple",
140     default=False,
141     help="Enable records and tuples (and disables JIT)",
145 @depends("--enable-record-tuple")
146 def enable_record_tuple(value):
147     if value:
148         return True
151 set_config("ENABLE_RECORD_TUPLE", enable_record_tuple)
152 set_define("ENABLE_RECORD_TUPLE", enable_record_tuple)
154 # JIT support
155 # =======================================================
156 @depends(target, "--enable-record-tuple")
157 def jit_default(target, enable_record_tuple):
158     if enable_record_tuple:
159         return False
160     if target.cpu in ("x86", "x86_64", "arm", "aarch64", "mips32", "mips64"):
161         return True
162     return False
165 option("--enable-jit", default=jit_default, help="{Enable|Disable} use of the JITs")
168 @deprecated_option("--enable-ion")
169 def report_deprecated(value):
170     if value:
171         die("--enable-ion is deprecated, use --enable-jit instead")
172     else:
173         die("--disable-ion is deprecated, use --disable-jit instead")
176 # JIT code simulator for cross compiles
177 # =======================================================
178 option(
179     "--enable-simulator",
180     choices=("arm", "arm64", "mips32", "mips64"),
181     nargs=1,
182     help="Enable a JIT code simulator for the specified architecture",
186 @depends("--enable-jit", "--enable-simulator", target)
187 def simulator(jit_enabled, simulator_enabled, target):
188     if not jit_enabled or not simulator_enabled:
189         return
191     sim_cpu = simulator_enabled[0]
193     if sim_cpu in ("arm", "mips32"):
194         if target.cpu != "x86":
195             die("The %s simulator only works on x86." % sim_cpu)
197     if sim_cpu in ("arm64", "mips64"):
198         if target.cpu != "x86_64":
199             die("The %s simulator only works on x86-64." % sim_cpu)
201     return namespace(**{sim_cpu: True})
204 set_config("JS_SIMULATOR", depends_if(simulator)(lambda x: True))
205 set_config("JS_SIMULATOR_ARM", simulator.arm)
206 set_config("JS_SIMULATOR_ARM64", simulator.arm64)
207 set_config("JS_SIMULATOR_MIPS32", simulator.mips32)
208 set_config("JS_SIMULATOR_MIPS64", simulator.mips64)
209 set_define("JS_SIMULATOR", depends_if(simulator)(lambda x: True))
210 set_define("JS_SIMULATOR_ARM", simulator.arm)
211 set_define("JS_SIMULATOR_ARM64", simulator.arm64)
212 set_define("JS_SIMULATOR_MIPS32", simulator.mips32)
213 set_define("JS_SIMULATOR_MIPS64", simulator.mips64)
216 @depends("--enable-jit", simulator, target)
217 def jit_codegen(jit_enabled, simulator, target):
218     if not jit_enabled:
219         return namespace(none=True)
221     if simulator:
222         return simulator
224     if target.cpu == "aarch64":
225         return namespace(arm64=True)
226     elif target.cpu == "x86_64":
227         return namespace(x64=True)
229     return namespace(**{str(target.cpu): True})
232 set_config("JS_CODEGEN_NONE", jit_codegen.none)
233 set_config("JS_CODEGEN_ARM", jit_codegen.arm)
234 set_config("JS_CODEGEN_ARM64", jit_codegen.arm64)
235 set_config("JS_CODEGEN_MIPS32", jit_codegen.mips32)
236 set_config("JS_CODEGEN_MIPS64", jit_codegen.mips64)
237 set_config("JS_CODEGEN_X86", jit_codegen.x86)
238 set_config("JS_CODEGEN_X64", jit_codegen.x64)
239 set_define("JS_CODEGEN_NONE", jit_codegen.none)
240 set_define("JS_CODEGEN_ARM", jit_codegen.arm)
241 set_define("JS_CODEGEN_ARM64", jit_codegen.arm64)
242 set_define("JS_CODEGEN_MIPS32", jit_codegen.mips32)
243 set_define("JS_CODEGEN_MIPS64", jit_codegen.mips64)
244 set_define("JS_CODEGEN_X86", jit_codegen.x86)
245 set_define("JS_CODEGEN_X64", jit_codegen.x64)
247 # Profiling
248 # =======================================================
249 option(
250     "--enable-instruments",
251     env="MOZ_INSTRUMENTS",
252     help="Enable instruments remote profiling",
256 @depends("--enable-instruments", target)
257 def instruments(value, target):
258     if value and target.os != "OSX":
259         die("--enable-instruments cannot be used when targeting %s", target.os)
260     if value:
261         return True
264 set_config("MOZ_INSTRUMENTS", instruments)
265 set_define("MOZ_INSTRUMENTS", instruments)
266 add_old_configure_assignment("MOZ_INSTRUMENTS", instruments)
267 imply_option("--enable-profiling", instruments, reason="--enable-instruments")
269 option("--enable-callgrind", env="MOZ_CALLGRIND", help="Enable callgrind profiling")
272 @depends("--enable-callgrind")
273 def callgrind(value):
274     if value:
275         return True
278 set_define("MOZ_CALLGRIND", callgrind)
279 imply_option("--enable-profiling", callgrind)
282 @depends(milestone)
283 def enable_profiling(milestone):
284     return milestone.is_nightly
287 option(
288     "--enable-profiling",
289     env="MOZ_PROFILING",
290     default=enable_profiling,
291     help="{Set|Do not set} compile flags necessary for using sampling "
292     "profilers (e.g. shark, perf)",
296 @depends("--enable-profiling")
297 def profiling(value):
298     if value:
299         return True
302 add_old_configure_assignment("MOZ_PROFILING", profiling)
304 with only_when("--enable-compile-environment"):
305     imply_option("--enable-frame-pointers", True, when=profiling)
308 @depends(profiling, target)
309 def imply_vtune(value, target):
310     ok_cpu = target.cpu in ["x86", "x86_64"]
311     ok_kernel = target.kernel == "WINNT" or (
312         target.kernel == "Linux" and target.os == "GNU"
313     )
315     if value and ok_cpu and ok_kernel:
316         return True
319 set_config("MOZ_PROFILING", profiling)
320 set_define("MOZ_PROFILING", profiling)
321 imply_option("--enable-vtune", imply_vtune, reason="--enable-profiling")
324 option("--enable-vtune", env="MOZ_VTUNE", help="Enable VTune profiling")
327 @depends("--enable-vtune")
328 def vtune(value):
329     if value:
330         return True
333 set_config("MOZ_VTUNE", vtune)
334 set_define("MOZ_VTUNE", vtune)
337 option(
338     "--enable-gc-probes",
339     env="JS_GC_PROBES",
340     help="Turn on probes for allocation and finalization",
344 @depends("--enable-gc-probes")
345 def gc_probes(value):
346     if value:
347         return True
350 set_define("JS_GC_PROBES", gc_probes)
353 option(
354     "--enable-gczeal",
355     default=depends(when=moz_debug)(lambda: True),
356     help="{Enable|Disable} zealous GCing",
359 set_define("JS_GC_ZEAL", depends_if("--enable-gczeal")(lambda _: True))
362 # Use a smaller chunk size for GC chunks
363 # ========================================================
364 # Use large (1MB) chunks by default.  This option can be used to give
365 # smaller (currently 256K) chunks.
366 option(
367     "--enable-small-chunk-size",
368     help="Allocate memory for JS GC things in smaller chunks",
371 set_define(
372     "JS_GC_SMALL_CHUNK_SIZE", depends(when="--enable-small-chunk-size")(lambda: True)
376 # Trace logging.
377 # =======================================================
378 @depends(milestone)
379 def default_trace_logging(milestone):
380     return milestone.is_nightly
383 option(
384     "--enable-trace-logging",
385     default=default_trace_logging,
386     help="{Enable|Disable} trace logging",
389 set_config("ENABLE_TRACE_LOGGING", depends_if("--enable-trace-logging")(lambda x: True))
390 set_define("JS_TRACE_LOGGING", depends_if("--enable-trace-logging")(lambda x: True))
393 # Enable breakpoint for artificial OOMs
394 # =======================================================
395 option(
396     "--enable-oom-breakpoint", help="Enable a breakpoint function for artificial OOMs"
399 set_define("JS_OOM_BREAKPOINT", depends_if("--enable-oom-breakpoint")(lambda _: True))
402 option("--enable-perf", env="JS_ION_PERF", help="Enable Linux perf integration")
405 @depends("--enable-perf")
406 def ion_perf(value):
407     if value:
408         return True
411 set_define("JS_ION_PERF", ion_perf)
414 option(
415     "--enable-jitspew",
416     default=depends(when=moz_debug)(lambda: True),
417     help="{Enable|Disable} the Jit spew and IONFLAGS environment " "variable",
420 set_define("JS_JITSPEW", depends_if("--enable-jitspew")(lambda _: True))
421 set_config("JS_JITSPEW", depends_if("--enable-jitspew")(lambda _: True))
423 # Also enable the structured spewer
424 set_define("JS_STRUCTURED_SPEW", depends_if("--enable-jitspew")(lambda _: True))
425 set_config("JS_STRUCTURED_SPEW", depends_if("--enable-jitspew")(lambda _: True))
428 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
429 def jit_disasm_arm(jit_enabled, spew, simulator, target, debug):
430     if not jit_enabled:
431         return
433     if simulator and (debug or spew):
434         if getattr(simulator, "arm", None):
435             return True
437     if target.cpu == "arm" and (debug or spew):
438         return True
441 set_config("JS_DISASM_ARM", jit_disasm_arm)
442 set_define("JS_DISASM_ARM", jit_disasm_arm)
445 @depends("--enable-jit", "--enable-jitspew", simulator, target, moz_debug)
446 def jit_disasm_arm64(jit_enabled, spew, simulator, target, debug):
447     if not jit_enabled:
448         return
450     if simulator and (debug or spew):
451         if getattr(simulator, "arm64", None):
452             return True
454     if target.cpu == "aarch64" and (debug or spew):
455         return True
458 set_config("JS_DISASM_ARM64", jit_disasm_arm64)
459 set_define("JS_DISASM_ARM64", jit_disasm_arm64)
461 # When enabled, masm will generate assumeUnreachable calls that act as
462 # assertions in the generated code. This option is worth disabling when you
463 # have to track mutated values through the generated code, to avoid constantly
464 # dumping registers on and off the stack.
465 option(
466     "--enable-masm-verbose",
467     default=depends(when=moz_debug)(lambda: True),
468     help="{Enable|Disable} MacroAssembler verbosity of generated code.",
470 set_define("JS_MASM_VERBOSE", depends_if("--enable-masm-verbose")(lambda _: True))
471 set_config("JS_MASM_VERBOSE", depends_if("--enable-masm-verbose")(lambda _: True))
473 # Architecture feature flags
474 # =======================================================
476 # Apple silicon does not seem to have any way to query the OS for the JSCVT
477 # flag stored in the ID_AA64ISAR1_EL1 system register. In the mean time, we
478 # hard code the value of the JSCVT flag which guards the implementation of
479 # FJCVTZS instruction as part of ARMv8.3-JSConv.
480 @depends(target)
481 def is_apple_silicon(target):
482     return target.os == "OSX" and target.kernel == "Darwin" and target.cpu == "aarch64"
485 option(
486     "--enable-arm64-fjcvtzs",
487     default=is_apple_silicon,
488     help="{Enable|Disable} static use of FJCVTZS instruction on Aarch64 targets.",
491 # The "ARM Architecture Reference Manual" for ARMv8 defines the JSCVT flag as
492 # being a 4 bit integer (D12.2.52) and it can be manipulated using >= operator
493 # (D12.1.4).
495 # The FJCVTZS instruction is implemented if ID_AA64ISAR1_EL1.JSCVT >= 1.
496 @depends("--enable-arm64-fjcvtzs", target, simulator)
497 def aarch64_jscvt(fjcvtzs, target, simulator):
498     if target.cpu == "aarch64" and fjcvtzs:
499         return 1
501     if simulator and getattr(simulator, "arm64", False) and fjcvtzs:
502         return 1
504     return 0
507 set_define("MOZ_AARCH64_JSCVT", aarch64_jscvt)
509 # CTypes
510 # =======================================================
511 @depends(js_standalone)
512 def ctypes_default(js_standalone):
513     return not js_standalone
516 option("--enable-ctypes", default=ctypes_default, help="{Enable|Disable} js-ctypes")
518 build_ctypes = depends_if("--enable-ctypes")(lambda _: True)
520 set_config("BUILD_CTYPES", build_ctypes)
521 set_define("BUILD_CTYPES", build_ctypes)
523 set_config("JS_HAS_CTYPES", build_ctypes)
524 set_define("JS_HAS_CTYPES", build_ctypes)
527 @depends("--enable-ctypes", "--enable-compile-environment")
528 def ctypes_and_compile_environment(ctypes, compile_environment):
529     return ctypes and compile_environment
532 include("ffi.configure", when=ctypes_and_compile_environment)
535 # Enable pipeline operator
536 # ===================================================
537 option("--enable-pipeline-operator", default=False, help="Enable pipeline operator")
540 @depends("--enable-pipeline-operator")
541 def enable_pipeline_operator(value):
542     if value:
543         return True
546 set_config("ENABLE_PIPELINE_OPERATOR", enable_pipeline_operator)
547 set_define("ENABLE_PIPELINE_OPERATOR", enable_pipeline_operator)
550 # SIMD acceleration for encoding_rs
551 # ==============================================================
553 option(
554     "--enable-rust-simd", env="MOZ_RUST_SIMD", help="Enable explicit SIMD in Rust code."
558 @depends("--enable-rust-simd", target)
559 def rust_simd(value, target):
560     # As of 2019-09-17, the simd-accel feature of encoding_rs has not
561     # been properly set up outside aarch64, armv7, x86 and x86_64.
562     if target.cpu in ("aarch64", "arm", "x86", "x86_64") and value:
563         return True
566 set_config("MOZ_RUST_SIMD", rust_simd)
567 set_define("MOZ_RUST_SIMD", rust_simd)
570 # Support for wasm code generation with Cranelift
571 # ==============================================================
573 option(
574     "--enable-cranelift",
575     default=False,
576     help="{Enable|Disable} Cranelift code generator for wasm",
580 @depends(
581     "--enable-cranelift",
582     "--enable-jit",
583     "--enable-simulator",
584     target,
585     target_is_windows,
587 def enable_cranelift(value, jit_enabled, simulator, target, is_windows):
588     if not value:
589         return
591     if not jit_enabled:
592         die("--enable-cranelift requires --enable-jit")
594     if not (
595         target.cpu == "aarch64"
596         or (target.cpu == "x86_64" and simulator and simulator[0] == "arm64")
597     ):
598         die("--enable-cranelift is only supported on arm64")
600     if is_windows:
601         die("--enable-cranelift is not supported on windows")
603     return True
606 set_config("ENABLE_WASM_CRANELIFT", enable_cranelift)
607 set_define("ENABLE_WASM_CRANELIFT", enable_cranelift)
610 # Telemetry to measure compile time and generated-code runtime
611 # ============================================================
613 option(
614     "--enable-spidermonkey-telemetry",
615     default=milestone.is_nightly,
616     help="{Enable|Disable} performance telemetry for SpiderMonkey (e.g. compile and run times)",
619 set_define(
620     "ENABLE_SPIDERMONKEY_TELEMETRY",
621     depends_if("--enable-spidermonkey-telemetry")(lambda x: True),
624 # Support for debugging code generated by wasm backends
625 # =====================================================
627 option(
628     "--enable-wasm-codegen-debug",
629     default=depends(when=moz_debug)(lambda: True),
630     help="{Enable|Disable} debugging for wasm codegen",
633 set_config(
634     "WASM_CODEGEN_DEBUG", depends_if("--enable-wasm-codegen-debug")(lambda x: True)
636 set_define(
637     "WASM_CODEGEN_DEBUG", depends_if("--enable-wasm-codegen-debug")(lambda x: True)
640 # Support for WebAssembly function-references.
641 # ===========================
644 @depends(milestone.is_nightly)
645 def default_wasm_function_references(is_nightly):
646     if is_nightly:
647         return True
650 option(
651     "--enable-wasm-function-references",
652     default=default_wasm_function_references,
653     help="{Enable|Disable} WebAssembly function-references",
657 @depends("--enable-wasm-function-references")
658 def wasm_function_references(value):
659     if value:
660         return True
663 set_config("ENABLE_WASM_FUNCTION_REFERENCES", wasm_function_references)
664 set_define("ENABLE_WASM_FUNCTION_REFERENCES", wasm_function_references)
666 # Support for WebAssembly GC.
667 # ===========================
670 @depends(milestone.is_nightly, "--enable-wasm-function-references")
671 def default_wasm_gc(is_nightly, function_references):
672     if is_nightly and function_references:
673         return True
676 option(
677     "--enable-wasm-gc", default=default_wasm_gc, help="{Enable|Disable} WebAssembly GC"
681 @depends("--enable-wasm-gc", "--enable-wasm-function-references")
682 def wasm_gc(value, function_references):
683     if not value:
684         return
686     if function_references:
687         return True
689     die("--enable-wasm-gc only possible with --enable-wasm-function-references")
692 set_config("ENABLE_WASM_GC", wasm_gc)
693 set_define("ENABLE_WASM_GC", wasm_gc)
696 # Support for WebAssembly private ref types.
697 # Prevent (ref T) types from being exposed to JS content so that wasm need do
698 # no typechecking at the JS/wasm boundary
699 # ===========================================================================
702 @depends(milestone.is_nightly, "--enable-wasm-gc")
703 def default_wasm_private_reftypes(is_nightly, gc):
704     if gc and is_nightly:
705         return True
708 option(
709     "--enable-wasm-private-reftypes",
710     default=default_wasm_private_reftypes,
711     help="{Enable|Disable} WebAssembly private reference types",
714 set_config(
715     "WASM_PRIVATE_REFTYPES",
716     depends_if("--enable-wasm-private-reftypes")(lambda x: True),
718 set_define(
719     "WASM_PRIVATE_REFTYPES",
720     depends_if("--enable-wasm-private-reftypes")(lambda x: True),
723 # Support for WebAssembly shared memory and atomics.
725 # This affects the JS shell only and here to allow the use of
726 # Cranelift in the shell.  Once Cranelift supports shared memory
727 # and atomics it can go away.
728 # =====================================================
730 option(
731     "--disable-shared-memory", help="Disable JS/WebAssembly shared memory and atomics"
735 @depends("--disable-shared-memory")
736 def enable_shared_memory(value):
737     if value:
738         return True
741 set_config("ENABLE_SHARED_MEMORY", enable_shared_memory)
742 set_define("ENABLE_SHARED_MEMORY", enable_shared_memory)
744 # Support for WebAssembly extended constant expressions
745 # =====================================================
748 @depends(milestone.is_nightly)
749 def default_wasm_extended_const(is_nightly):
750     if is_nightly:
751         return True
754 option(
755     "--enable-wasm-extended-const",
756     default=default_wasm_extended_const,
757     help="{Enable|Disable} WebAssembly extended constant expressions",
761 @depends("--enable-wasm-extended-const")
762 def wasm_extended_const(value):
763     if value:
764         return True
767 set_config("ENABLE_WASM_EXTENDED_CONST", wasm_extended_const)
768 set_define("ENABLE_WASM_EXTENDED_CONST", wasm_extended_const)
770 # Support for WebAssembly SIMD
771 # =====================================================
774 @depends("--enable-jit", "--enable-simulator", "--enable-cranelift", target)
775 def default_wasm_simd(jit_enabled, simulator, cranelift_enabled, target):
776     if not jit_enabled:
777         return
779     if cranelift_enabled:
780         return
782     if simulator and (simulator[0] != "arm64"):
783         return
785     if target.cpu in ("x86_64", "x86", "aarch64"):
786         return True
789 option(
790     "--enable-wasm-simd",
791     default=default_wasm_simd,
792     help="{Enable|Disable} WebAssembly SIMD",
796 @depends(
797     "--enable-wasm-simd",
798     "--enable-jit",
799     "--enable-simulator",
800     "--enable-cranelift",
801     target,
803 def wasm_simd(value, jit_enabled, simulator, cranelift_enabled, target):
804     if not value:
805         return
807     if not jit_enabled:
808         die("--enable-wasm-simd requires --enable-jit")
810     if cranelift_enabled:
811         die("--enable-wasm-simd is not supported for --enable-cranelift")
813     if simulator and (simulator[0] != "arm64"):
814         die("--enable-wasm-simd is not supported for simulators, except arm64")
816     if target.cpu in ("x86_64", "x86", "aarch64"):
817         return True
819     die("--enable-wasm-simd only possible when targeting the x86_64/x86/arm64 jits")
822 set_config("ENABLE_WASM_SIMD", wasm_simd)
823 set_define("ENABLE_WASM_SIMD", wasm_simd)
825 # Wormhole opcodes are Intel-only.  They are private to Firefox, but we need them for some
826 # experiments on release and so they ride the trains.
829 @depends("--enable-simulator", "--enable-wasm-simd", target)
830 def default_wasm_simd_wormhole(simulator, wasm_simd, target):
831     if wasm_simd and target.cpu in ("x86", "x86_64") and not simulator:
832         return True
835 option(
836     "--enable-wasm-simd-wormhole",
837     default=default_wasm_simd_wormhole,
838     help="{Enable|Disable} WebAssembly SIMD wormhole opcodes",
842 @depends(
843     "--enable-wasm-simd-wormhole", "--enable-wasm-simd", "--enable-simulator", target
845 def wasm_simd_wormhole(value, wasm_simd, simulator, target):
846     if not value:
847         return
849     if wasm_simd and target.cpu in ("x86", "x86_64") and not simulator:
850         return True
852     die("SIMD wormhole currently supported on native x86/x64 only, with --wasm-simd")
855 set_config("ENABLE_WASM_SIMD_WORMHOLE", wasm_simd_wormhole)
856 set_define("ENABLE_WASM_SIMD_WORMHOLE", wasm_simd_wormhole)
859 # Support for WebAssembly relaxed SIMD
860 # =====================================================
863 @depends(milestone.is_nightly, "--enable-wasm-simd")
864 def default_wasm_relaxed_simd(is_nightly, wasm_simd):
865     if is_nightly and wasm_simd:
866         return True
869 option(
870     "--enable-wasm-relaxed-simd",
871     default=default_wasm_relaxed_simd,
872     help="{Enable|Disable} WebAssembly relaxed SIMD",
876 @depends("--enable-wasm-relaxed-simd", "--enable-wasm-simd")
877 def wasm_relaxed_simd(value, wasm_simd):
878     if not value:
879         return
881     if not wasm_simd:
882         die("relaxed SIMD requires SIMD")
884     return True
887 set_config("ENABLE_WASM_RELAXED_SIMD", wasm_relaxed_simd)
888 set_define("ENABLE_WASM_RELAXED_SIMD", wasm_relaxed_simd)
890 # Support for WebAssembly intgemm private intrinsics
891 # =====================================================
894 @depends(milestone.is_nightly)
895 def default_wasm_moz_intgemm(is_nightly):
896     if is_nightly:
897         return True
900 option(
901     "--enable-wasm-moz-intgemm",
902     default=default_wasm_moz_intgemm,
903     help="{Enable|Disable} WebAssembly intgemm private intrinsics",
907 @depends("--enable-wasm-moz-intgemm")
908 def wasm_moz_intgemm(value):
909     if not value:
910         return
912     return True
915 set_config("ENABLE_WASM_MOZ_INTGEMM", wasm_moz_intgemm)
916 set_define("ENABLE_WASM_MOZ_INTGEMM", wasm_moz_intgemm)
918 # Support for WebAssembly Memory64.
919 # ===========================
922 @depends(milestone.is_nightly, "--enable-cranelift", "--enable-simulator", target)
923 def default_wasm_memory64(is_nightly, cranelift, simulator, target):
924     if cranelift:
925         return
927     if target.cpu == "mips32":
928         return
930     if simulator and simulator[0] == "mips32":
931         return
933     if is_nightly:
934         return True
937 option(
938     "--enable-wasm-memory64",
939     default=default_wasm_memory64,
940     help="{Enable|Disable} WebAssembly Memory64",
944 @depends("--enable-wasm-memory64", "--enable-cranelift", "--enable-simulator", target)
945 def wasm_memory64(value, cranelift, simulator, target):
946     if not value:
947         return
949     if cranelift:
950         die("Memory64 is incompatible with Cranelift")
952     if target.cpu == "mips32":
953         die("Memory64 is incompatible with MIPS32 target")
955     if simulator and simulator[0] == "mips32":
956         die("Memory64 is incompatible with MIPS32 simulator")
958     return True
961 set_config("ENABLE_WASM_MEMORY64", wasm_memory64)
962 set_define("ENABLE_WASM_MEMORY64", wasm_memory64)
964 # Support for checking for indirect call to null via traps
965 # =====================================================
968 @depends(milestone.is_nightly, "--enable-jit", "--enable-simulator")
969 def default_wasm_call_indirect_null(is_nightly, enable_jit, simulator):
970     if not enable_jit:
971         return
973     if simulator:
974         return
976     if is_nightly:
977         return True
980 option(
981     "--enable-wasm-call-indirect-null",
982     default=default_wasm_call_indirect_null,
983     help="{Enable|Disable} WebAssembly call-indirect-to-null optimization",
987 @depends("--enable-wasm-call-indirect-null", "--enable-jit", "--enable-simulator")
988 def wasm_call_indirect_null(value, enable_jit, simulator):
989     if not value:
990         return
992     if not enable_jit:
993         return
995     if simulator:
996         return
998     return True
1001 set_config("ENABLE_WASM_CALL_INDIRECT_NULL", wasm_call_indirect_null)
1002 set_define("ENABLE_WASM_CALL_INDIRECT_NULL", wasm_call_indirect_null)
1004 # Options for generating the shell as a script
1005 # ============================================
1006 option("--with-qemu-exe", nargs=1, help="Use path as an arm emulator on host platforms")
1007 set_config("QEMU_EXE", depends_if("--with-qemu-exe")(lambda x: x))
1009 option(
1010     "--with-cross-lib",
1011     nargs=1,
1012     default=depends(target.alias)(lambda x: "/usr/%s" % x),
1013     help="Use dir as the location for arm libraries",
1015 set_config("CROSS_LIB", depends_if("--with-cross-lib")(lambda x: x))
1017 # Enable static checking using sixgill
1018 # ====================================
1020 option("--with-sixgill", nargs=1, help="Enable static checking of code using sixgill")
1023 @depends_if("--with-sixgill")
1024 @imports("os")
1025 def sixgill(value):
1026     for f in ("bin/xdbfind", "gcc/xgill.so", "scripts/wrap_gcc/g++"):
1027         if not os.path.exists(os.path.join(value[0], f)):
1028             die("The sixgill plugin and binaries are not at the specified path")
1029     return value[0]
1032 set_config("SIXGILL_PATH", sixgill)
1035 # Support for readline
1036 # =====================================================
1039 @depends("--enable-js-shell", target_is_windows, compile_environment, target)
1040 def editline(js_shell, is_windows, compile_environment, target):
1041     return js_shell and not is_windows and compile_environment and (target.os != "WASI")
1044 option(
1045     "--enable-readline", help="Link js shell to system readline library", when=editline
1048 has_readline = check_symbol(
1049     "readline",
1050     flags=["-lreadline"],
1051     when="--enable-readline",
1052     onerror=lambda: die("No system readline library found"),
1055 set_config("EDITLINE_LIBS", ["-lreadline"], when=has_readline)
1058 @depends("--enable-readline", editline, when=editline)
1059 def bundled_editline(readline, editline):
1060     return editline and not readline
1063 set_config("JS_BUNDLED_EDITLINE", bundled_editline)
1065 set_define("EDITLINE", True, when=editline)
1068 # JIT observers
1069 # =============
1071 option(
1072     "--with-jitreport-granularity",
1073     default="3",
1074     choices=("0", "1", "2", "3"),
1075     help="Default granularity at which to report JIT code to external tools "
1076     "(0 - no info, 1 - code ranges for while functions only, "
1077     "2 - per-line information, 3 - per-op information)",
1080 set_define(
1081     "JS_DEFAULT_JITREPORT_GRANULARITY",
1082     depends_if("--with-jitreport-granularity")(lambda value: value[0]),
1086 # ECMAScript Internationalization API Support (uses ICU)
1087 # ======================================================
1088 system_lib_option("--with-system-icu", help="Use system ICU")
1090 system_icu = pkg_check_modules("MOZ_ICU", "icu-i18n >= 70.1", when="--with-system-icu")
1093 @depends("--with-system-icu")
1094 def in_tree_icu(system_icu):
1095     return not system_icu
1098 # Set MOZ_ICU_CFLAGS to an explicit empty value when --with-system-icu is *not* used,
1099 # for layout/style/extra-bindgen-flags
1100 set_config("MOZ_ICU_CFLAGS", [], when=in_tree_icu)
1102 set_config("MOZ_SYSTEM_ICU", True, when=system_icu)
1103 set_define("MOZ_SYSTEM_ICU", True, when=system_icu)
1105 option("--without-intl-api", help="Disable ECMAScript Internationalization API")
1108 @depends("--with-intl-api", js_standalone)
1109 def check_intl_api(enabled, js_standalone):
1110     if not enabled and not js_standalone:
1111         die("--without-intl-api is not supported")
1114 set_config("JS_HAS_INTL_API", True, when="--with-intl-api")
1115 set_define("JS_HAS_INTL_API", True, when="--with-intl-api")
1118 @depends(build_environment, when="--with-intl-api")
1119 @imports(_from="__builtin__", _import="open")
1120 @imports(_from="__builtin__", _import="ValueError")
1121 def icu_version(build_env):
1122     path = os.path.join(
1123         build_env.topsrcdir, "intl", "icu", "source", "common", "unicode", "uvernum.h"
1124     )
1125     with open(path, encoding="utf-8") as fh:
1126         for line in fh:
1127             if line.startswith("#define"):
1128                 define = line.split(None, 3)
1129                 if len(define) == 3 and define[1] == "U_ICU_VERSION_MAJOR_NUM":
1130                     try:
1131                         return str(int(define[2]))
1132                     except ValueError:
1133                         pass
1134     die("Cannot determine ICU version number from uvernum.h header file")
1137 set_config("MOZ_ICU_VERSION", icu_version)
1139 # Source files that use ICU should have control over which parts of the ICU
1140 # namespace they want to use.
1141 set_define("U_USING_ICU_NAMESPACE", "0", when="--with-intl-api")
1143 # We build ICU as a static library.
1144 set_define("U_STATIC_IMPLEMENTATION", True, when=depends(system_icu)(lambda x: not x))
1147 # Initial support for WebAssembly JS-API Type Reflections
1148 # =======================================================
1151 @depends(milestone.is_nightly)
1152 def default_wasm_type_reflections(is_nightly):
1153     return is_nightly
1156 option(
1157     "--enable-wasm-type-reflections",
1158     default=default_wasm_type_reflections,
1159     help="{Enable|Disable} type reflection in WASM JS-API",
1162 set_config(
1163     "ENABLE_WASM_TYPE_REFLECTIONS",
1164     depends_if("--enable-wasm-type-reflections")(lambda x: True),
1166 set_define(
1167     "ENABLE_WASM_TYPE_REFLECTIONS",
1168     depends_if("--enable-wasm-type-reflections")(lambda x: True),
1171 # Support for WebAssembly exceptions
1172 # ==================================
1175 @depends(milestone.is_nightly)
1176 def default_wasm_exceptions(is_nightly):
1177     if is_nightly:
1178         return True
1181 option(
1182     "--enable-wasm-exceptions",
1183     default=default_wasm_exceptions,
1184     help="{Enable|Disable} WebAssembly exceptions",
1187 set_config(
1188     "ENABLE_WASM_EXCEPTIONS", depends_if("--enable-wasm-exceptions")(lambda x: True)
1190 set_define(
1191     "ENABLE_WASM_EXCEPTIONS", depends_if("--enable-wasm-exceptions")(lambda x: True)
1194 set_define(
1195     "_WASI_EMULATED_PROCESS_CLOCKS",
1196     True,
1197     when=depends(target)(lambda t: t.os == "WASI"),
1200 # Enable change-array-by-copy
1201 # ===================================================
1202 def use_change_array_by_copy():
1203     return False
1206 option(
1207     "--enable-change-array-by-copy",
1208     default=use_change_array_by_copy(),
1209     help="{Enable|Disable} change-array-by-copy method pref/command-line option (disabled by default)",
1213 @depends("--enable-change-array-by-copy")
1214 def enable_change_array_by_copy(value):
1215     if value:
1216         return True
1219 set_config("ENABLE_CHANGE_ARRAY_BY_COPY", enable_change_array_by_copy)
1220 set_define("ENABLE_CHANGE_ARRAY_BY_COPY", enable_change_array_by_copy)
1222 # Enable New Set methods
1223 # ===================================================
1224 def use_new_set_methods():
1225     return False
1228 option(
1229     "--enable-new-set-methods",
1230     default=use_new_set_methods(),
1231     help="{Enable|Disable} New Set methods pref/command-line option (disabled by default)",
1235 @depends("--enable-new-set-methods")
1236 def enable_new_set_methods(value):
1237     if value:
1238         return True
1241 set_config("ENABLE_NEW_SET_METHODS", enable_new_set_methods)
1242 set_define("ENABLE_NEW_SET_METHODS", enable_new_set_methods)
1245 @depends(milestone.version)
1246 def js_version(version):
1247     return Version(version)
1250 set_config("MOZJS_MAJOR_VERSION", depends(js_version.major)(lambda m: str(m)))
1251 set_define("MOZJS_MAJOR_VERSION", js_version.major)
1252 set_config("MOZJS_MINOR_VERSION", depends(js_version.minor)(lambda m: str(m)))
1253 set_define("MOZJS_MINOR_VERSION", js_version.minor)
1254 set_config("MOZJS_PATCH_VERSION", depends(js_version.patch)(lambda p: str(p)))
1255 set_config(
1256     "MOZJS_ALPHA",
1257     depends(js_version)(
1258         lambda x: x.version[-2] if str(x.version[-2]) in "ab" else None
1259     ),
1263 # Check for tm_zone, tm_gmtoff in struct tm
1264 # ===================================================
1265 with only_when(compile_environment):
1266     set_define(
1267         "HAVE_TM_ZONE_TM_GMTOFF",
1268         c_compiler.try_compile(
1269             includes=["time.h"],
1270             body="struct tm tm; tm.tm_zone = 0; tm.tm_gmtoff = 1;",
1271             check_msg="for tm_zone and tm_gmtoff in struct tm",
1272         ),
1273     )