diff --git a/build.zig b/build.zig index 3e7f285214..4f97e019f8 100644 --- a/build.zig +++ b/build.zig @@ -570,6 +570,7 @@ pub fn build(b: *std.Build) !void { if (is_windows) "-DWIN32_LEAN_AND_MEAN" else "", if (is_windows) "-DUTF8PROC_STATIC" else "", if (use_unibilium) "-DHAVE_UNIBILIUM" else "", + if (is_wasm) "-flto" else "", }; nvim_mod.addCSourceFiles(.{ .files = src_paths, .flags = &flags }); @@ -610,14 +611,28 @@ pub fn build(b: *std.Build) !void { emcc.addArgs(&.{ b.fmt("--sysroot={s}", .{s}), "-sALLOW_MEMORY_GROWTH=1", - "-sEXPORT_ALL=1", - "-sINITIAL_MEMORY=67108864", + "--profiling-funcs", + "-sEXPORTED_FUNCTIONS=_main,_malloc,_free", + "-sEXPORTED_RUNTIME_METHODS=stringToUTF8,lengthBytesUTF8,setValue,getValue,UTF8ToString,callMain,ENV,FS", + "-sSTACK_SIZE=134217728", // 64MB — emscripten's own flag, overrides its 65536 + "-sINITIAL_MEMORY=536870912", // 256MB — stack(64MB) + data(12MB) + heap room + "-sMAXIMUM_MEMORY=2147483648", "-sFORCE_FILESYSTEM=1", + "-sNODERAWFS=0", "-sERROR_ON_UNDEFINED_SYMBOLS=0", + "-sEXIT_RUNTIME=0", + "-sINVOKE_RUN=0", + "-sGLOBAL_BASE=134217728", + "-sMODULARIZE=1", + "-sEXPORT_NAME=createNvim", + "-Wl,--unresolved-symbols=ignore-all", "--no-entry", - "-Wl,--export-all", - "-Wl,--no-gc-sections", + "-fexceptions", + "-flto", + "-sSTACK_OVERFLOW_CHECK=2", + "-sASSERTIONS=1", }); + emcc.addArg("-o"); const nvim_js = emcc.addOutputFileArg("nvim.js"); nvim_exe_step.dependOn(&b.addInstallFileWithDir(nvim_js, .bin, "nvim.js").step);