From 4eb6f8ebb23daabb6c77c396fd276ca2029a7041 Mon Sep 17 00:00:00 2001 From: ShuangLiu1992 Date: Sat, 23 May 2026 01:36:01 +0200 Subject: [PATCH] platform: bridge legacy lowercase emscripten version macros (#397) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit emscripten <= 4.0.23 only defined the lowercase forms (`__EMSCRIPTEN_major__`, `__EMSCRIPTEN_minor__`, `__EMSCRIPTEN_tiny__`) in ``. Starting with 4.0.24 (PR emscripten-core/emscripten#26180), uppercase became primary and lowercase was kept as deprecated aliases. bx PR #374 switched all references to the uppercase form, which is the right forward-looking direction — but it leaves users on emsdk <= 4.0.23 unable to build, because `__EMSCRIPTEN_MAJOR__` is undefined there and the preprocessor expression `(__EMSCRIPTEN_MAJOR__ * 10000 + …)` evaluates to 0. That tanks `BX_PLATFORM_EMSCRIPTEN`, which tanks `BX_PLATFORM_POSIX`, which makes `bx/src/os.cpp` skip its `` / `` includes, which causes the build to fail on `unknown type name 'timespec'`. Add a small bridge: if the uppercase macros aren't defined but the lowercase ones are, alias the uppercase forms to lowercase. The rest of bx continues to use uppercase uniformly. Newer emsdk versions are unaffected (the bridge block is skipped because uppercase is already defined). Co-authored-by: Shuang Liu <[email protected]> --- include/bx/platform.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/bx/platform.h b/include/bx/platform.h index 5e6acf5..e7cdbf7 100644 --- a/include/bx/platform.h +++ b/include/bx/platform.h @@ -204,6 +204,16 @@ # define BX_PLATFORM_OSX __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ #elif defined(__wasm__) # include + // emscripten <= 4.0.23 only defined the lowercase version macros + // (__EMSCRIPTEN_major__, _minor_, _tiny_); 4.0.24+ added uppercase as + // primary and kept lowercase as deprecated aliases. Bridge the older + // emsdk so bx (and downstream code that consumes BX_PLATFORM_EMSCRIPTEN) + // can rely on the uppercase form uniformly. +# if !defined(__EMSCRIPTEN_MAJOR__) && defined(__EMSCRIPTEN_major__) +# define __EMSCRIPTEN_MAJOR__ __EMSCRIPTEN_major__ +# define __EMSCRIPTEN_MINOR__ __EMSCRIPTEN_minor__ +# define __EMSCRIPTEN_TINY__ __EMSCRIPTEN_tiny__ +# endif # undef BX_PLATFORM_EMSCRIPTEN # define BX_PLATFORM_EMSCRIPTEN (__EMSCRIPTEN_MAJOR__ * 10000 + __EMSCRIPTEN_MINOR__ * 100 + __EMSCRIPTEN_TINY__) #elif defined(__ORBIS__)