Skip to content

Bump emsdk to 7.0.1 #537

Todo
Todo

Description

@Tchips46

Which package or utils is this feature request for?

ecs

Feature

The CI builds the ECS with Emscripten 4.0.23 (January 2026). Locally, everyone uses whatever version they installed. Emscripten is now at 7.0.1. Let's move both to 7.0.1, and use what the new versions give us when we write code.

What we get, in short:

  • C++ containers can be looped over in TS like normal JS arrays.
  • A C++ error shows up in TS as a real error with its message, instead of a number.
  • The generated ECS JS no longer uses eval.

Ideal solution or implementation

1. Loop over C++ containers from TS

Since 5.0.0, embind can make a C++ class iterable. JS then gets Symbol.iterator, and the generated .d.ts says Iterable<...>. So for...of, [...x] and Array.from(x) work, with types and autocomplete. register_vector does it by itself. Any std::vector we expose is iterable for free.

For SparseArray, which is the one we use everywhere, we add one line in SparseArray.cpp:

.iterable<std::optional<emscripten::val>>("size", "getConst")

Then in a game:

const positions = registry.getComponents(Position);

// Today: index loop by hand. And Array.from(positions) silently returns [].
for (let id = 0; id < positions.size(); id++) {
  const p = positions.get(id);
  if (p) p.x += 1;
}

// After:
for (const p of positions) if (p) p.x += 1;
const all = Array.from(positions).filter(Boolean);

Why it matters:

  • It removes a silent trap. Today Array.from(sparseArray) returns [] with no error.
  • It makes ECS objects feel like normal JS, which is what game devs expect.
  • It is handy in tests, debug tools and the editor, when you need to list components.

Limits:

  • Empty slots come out as undefined.
  • Elements are still typed any, so the as Position cast stays.
  • for...of gives no entity id. Systems should keep using getZipper / getIndexedZipper.

2. Readable C++ errors in TS

Today, when the C++ throws (e.g. registry.entityFromIndex(999)), TS receives a plain number like 90952, with no message. Since 5.0.5 it is a CppException object. That is still not an Error and still has no message, unless we link with -sEXCEPTION_STACK_TRACES. With that flag, game devs get:

try {
  registry.entityFromIndex(id);
} catch (e) {
  console.error((e as Error).message); // "Entity index out of range."
}

The cost is about 1 KB gzipped. We must touch this line anyway: -sEXPORT_EXCEPTION_HANDLING_HELPERS does nothing since 5.0.4. So the Makefile line becomes:

LDFLAGS = -O3 --no-entry --bind -sNO_DISABLE_EXCEPTION_CATCHING -sEXCEPTION_STACK_TRACES

3. No more eval in the ECS JS

Before 7.0.1, the generated libecs.js builds its embind wrappers at runtime with new Function, so the page needs 'unsafe-eval' in its CSP. In 7.0.1 they are generated at build time. The ECS then runs under a strict CSP, and startup is a bit faster. The editor can only drop 'unsafe-eval' for games once every project it runs uses a new ECS. That is a follow-up, not part of this issue.

4. Newer C++ (libc++ 23)

Nothing big for our code. For example, std::flat_set (C++23) could replace the _dead_entities vector, giving no duplicates and a faster lookup. That needs -std=c++23.

What the bump PR must also do (or it breaks)

  • Build: libc++ 23 no longer pulls in headers for us. SparseArray.hpp:229 (std::ranges::all_of) stops compiling. Add #include <algorithm> and #include <vector> to SparseArray.hpp. This works on 4.0.23 too.
  • CI cache: in .github/actions/emsdk-install/action.yml, the restore-keys have no version in them. On a new version, they restore this month's 4.0.23 folder, setup-emsdk skips the install, and emsdk activate 7.0.1 fails on every run. Remove restore-keys along with the bump. pyodide/setup-emsdk is archived and runs on node20; emscripten-core/setup-emsdk@v16 takes the same inputs.
  • --emit-tsd: 7.0.1 generates the types with TypeScript 7 (4.0.23 used 5.9). In CI, emsdk sits under the engine's tsconfig.json, and TS 6+ can refuse to run with error TS5112. Check that the base target still works in CI.
  • Locally: update the emsdk checkout (git pull), run ./emsdk install 7.0.1 && ./emsdk activate 7.0.1, then pnpm clean once. Old .o files make the module fail at load (invokerFactory is not a function). Write the version in .github/CONTRIBUTING.md.

Alternative solutions or implementations

No response

Other context

No response

Activity

  1. added
    enhancement
    on Dec 3, 2026
  2. self-assigned this
    on Dec 3, 2026
  3. added
    modules:ecs
    on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementmodules:ecs

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions