Skip to content

Commit dcad5ac

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

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

platform/web/detect.py

Lines changed: 19 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,14 @@ 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+
elif env["memory64"] == "wasm64":
318+
memory64_value = 1
319+
else:
320+
# "wasm32+64bitptrs"
321+
memory64_value = 2
322+
env.Append(CCFLAGS=[f"-sMEMORY64={memory64_value}"])
323+
env.Append(LINKFLAGS=[f"-sMEMORY64={memory64_value}"])

platform/web/os_web.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class OS_Web : public OS_Unix {
7373
// Override return type to make writing static callbacks less tedious.
7474
static OS_Web *get_singleton();
7575

76+
_FORCE_INLINE_ bool is_memory64() const { return sizeof(size_t) == sizeof(uint64_t); }
77+
7678
bool pwa_needs_update() const { return pwa_is_waiting; }
7779
Error pwa_update();
7880
void force_fs_sync();

0 commit comments

Comments
 (0)