Skip to content

EMSCRIPTEN_VERSION macro in JS libraries #19469

@juj

Description

@juj

When working on wasm_webgpu bindings library, I realized that after #19097 which landed for Emscripten 3.1.35, I needed to add these directives

juj/wasm_webgpu@a1cc82d

which broke the JS library from working on Emscripten < 3.1.35, so in order to make the JS library work for different versions, I had to a backwards compatibility item to the library, that looks like this:

juj/wasm_webgpu@5460a0d

Maintaining that kind of backwards compatibility item is brittle and difficult, since if the upstream code changes in the future, the change won't appear for users who use the wasm_webgpu library.

So instead, what I would like to do is write something like

#if EMSCRIPTEN_VERSION >= 3.1.35
wgpu_object_get_label__deps: ['$stringToUTF8'],
#endif

to make the needed deps appear only for old Emscripten versions, or simply

#if EMSCRIPTEN_VERSION < 3.1.35
#error "lib_webgpu.js requires Emscripten 3.1.35 or newer"
#endif

to require developers to update to a newer version.

However looks like we don't have a construct that would allow implementing a EMSCRIPTEN_VERSION < 3.1.35 yet - seems like we should add one.

Any preferences on how the syntax would like to look?

Use the same kind of compacted version number like the MIN_xxx_VERSION fields?

#if EMSCRIPTEN_VERSION < 30135

or use the same names as C/C++ code gets as preprocessor:

#if __EMSCRIPTEN_major__*10000 + __EMSCRIPTEN_minor__*100 + __EMSCRIPTEN_tiny__ < 30135

or use function syntax?

#if EMSCRIPTEN_VERSION_LESS_THAN(3,1,35)
#if EMSCRIPTEN_VERSION_LESS_OR_EQUAL(3,1,35)
#if EMSCRIPTEN_VERSION_GREATER_THAN(3,1,35)
#if EMSCRIPTEN_VERSION_GREATER_OR_EQUAL(3,1,35)

or something else?

(I think I'd prefer the very first one)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions