Skip to content

Commit 7f5c207

Browse files
committed
[Web] Add memory64 option to setup the foundations of wasm64
1 parent 0ed1c19 commit 7f5c207

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

platform/web/detect.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_tools(env: "SConsEnvironment"):
3434

3535

3636
def get_opts():
37-
from SCons.Variables import BoolVariable
37+
from SCons.Variables import BoolVariable, EnumVariable
3838

3939
return [
4040
("initial_memory", "Initial WASM memory (in MiB)", 32),
@@ -57,6 +57,13 @@ def get_opts():
5757
"Use Emscripten PROXY_TO_PTHREAD option to run the main application code to a separate thread",
5858
False,
5959
),
60+
EnumVariable(
61+
"memory64",
62+
"Set Emscripten MEMORY64 mode",
63+
"wasm32",
64+
["wasm32", "wasm64", "wasm32+64bitptrs"],
65+
{"no": "wasm32", "yes": "wasm64", "0": "wasm32", "1": "wasm64", "2": "wasm32+64bitptrs"},
66+
),
6067
]
6168

6269

@@ -303,3 +310,16 @@ def configure(env: "SConsEnvironment"):
303310
# This workaround creates a closure that prevents the garbage collector from freeing the WebGL context.
304311
# We also only use WebGL2, and changing context version is not widely supported anyway.
305312
env.Append(LINKFLAGS=["-sGL_WORKAROUND_SAFARI_GETCONTEXT_BUG=0"])
313+
314+
# Set 32-bit or 64-bit pointers.
315+
if env["memory64"] == "wasm32":
316+
memory64_value = 0
317+
else:
318+
env.Append(CPPDEFINES=["WASM_MEMORY64_ENABLED"])
319+
if env["memory64"] == "wasm64":
320+
memory64_value = 1
321+
else:
322+
# "wasm32+64bitptrs"
323+
memory64_value = 2
324+
env.Append(CCFLAGS=[f"-sMEMORY64={memory64_value}"])
325+
env.Append(LINKFLAGS=[f"-sMEMORY64={memory64_value}"])

0 commit comments

Comments
 (0)