emscripten-core / emscripten-core/emscripten

EMSCRIPTEN_VERSION macro in JS libraries

Open
#19,469 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

When working on [wasm_webgpu bindings library](https://github.com/juj/wasm_webgpu), I realized that after #19097 which landed for Emscripten 3.1.35, I needed to add these directives

https://github.com/juj/wasm_webgpu/commit/a1cc82dc445512f3acc2bf044a699531b8e4d944

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:

https://github.com/juj/wasm_webgpu/commit/5460a0d8c71343b5a1984da11f46a606cec3c9e3

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)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.