Skip to content

Commit 9fcbc7c

Browse files
authored
[minor enhance] Add macros to identify the Emscripten compiler
1 parent fa71665 commit 9fcbc7c

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/base/compiler/version.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,17 @@
136136
# define UNITEX_COMPILER_CLANG (__clang_major__ * 10000000 \
137137
+ __clang_minor__ * 100000 \
138138
+ __clang_patchlevel__ * 1)
139+
// Emscripten uses Clang/LLVM as its underlying codegen compiler
140+
#if defined(__EMSCRIPTEN__)
141+
// UNITEX_COMPILER_IS_CLANG_EMSCRIPTEN
142+
# define UNITEX_COMPILER_IS_CLANG_EMSCRIPTEN 1
143+
# define UNITEX_COMPILER_CLANG_EMSCRIPTEN\
144+
(__EMSCRIPTEN_major__ * 10000000 \
145+
+ __EMSCRIPTEN_minor__ * 100000 \
146+
+ __EMSCRIPTEN_tiny__ * 1)
139147
// Take notice that Apple's Clang distribution bundled with XCode may rewrite
140148
// __clang_major__ and __clang_minor__ open source Clang distribution' values
141-
#if defined(__apple_build_version__)
149+
#elif defined(__apple_build_version__)
142150
// UNITEX_COMPILER_IS_CLANG_APPLE
143151
# define UNITEX_COMPILER_IS_CLANG_APPLE 1
144152
// __APPLE_CC__ // distinguish compilers based on the same version of GCC
@@ -568,6 +576,10 @@ const struct /* compiler_name_version_table_t */ {
568576
// MINGW
569577
# define UNITEX_COMPILER_NAME "mingw"
570578
# define UNITEX_COMPILER_VERSION UNITEX_COMPILER_MINGW
579+
#elif UNITEX_COMPILER_IS(CLANG_EMSCRIPTEN)
580+
// CLANG_EMSCRIPTEN
581+
# define UNITEX_COMPILER_NAME "clang.emscripten"
582+
# define UNITEX_COMPILER_VERSION UNITEX_COMPILER_CLANG_EMSCRIPTEN
571583
#elif UNITEX_COMPILER_IS(CLANG_APPLE)
572584
// CLANG_APPLE
573585
# define UNITEX_COMPILER_NAME "clang.apple"

src/base/os/version.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@
204204
# if defined(__pnacl__)
205205
# define UNITEX_OS_UNIX_NACL_PORTABLE 1
206206
# endif // !defined(__native_client_nonsfi__)
207+
// Emscripten behaves like a variant of Unix, so the preprocessor defines unix,
208+
// _unix and __unix__ are always present when compiling code with Emscripten
209+
// Note that Native Client sandbox technologies were deprecated on Q4 2019 in
210+
// favor of WebAssembly. WebAssembly (abbreviated Wasm) is a binary instruction
211+
// format for a stack-based virtual machine
212+
# elif defined(__EMSCRIPTEN__)
213+
# include <emscripten/version.h> // __EMSCRIPTEN_major__
214+
// WebAssembly runtime environments (RE)
215+
# define UNITEX_OS_UNIX_WEBASSEMBLY_RE 1
207216
// Android
208217
// - UNITEX_OS_UNIX_IS(ANDROID)
209218
# elif defined(__ANDROID__)
@@ -659,6 +668,8 @@
659668
# define UNITEX_OS_NAME "unix.apple.osx"
660669
# elif UNITEX_OS_UNIX_IS(DRAGONFLY)
661670
# define UNITEX_OS_NAME "unix.dragonfly"
671+
# elif UNITEX_OS_UNIX_IS(WEBASSEMBLY_RE)
672+
# define UNITEX_OS_NAME "unix.webassembly_re"
662673
# elif UNITEX_OS_UNIX_IS(FREEBSD)
663674
# define UNITEX_OS_NAME "unix.freebsd"
664675
# elif UNITEX_OS_UNIX_IS(GNU_HURD)

src/base/vendor/whereami/whereami.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
160160
return length;
161161
}
162162

163-
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__sun) || defined(WAI_USE_PROC_SELF_EXE)
163+
#elif defined(__linux__) || defined(__CYGWIN__) || defined(__sun) || defined(WAI_USE_PROC_SELF_EXE) || defined(__unix__)
164164

165165
#include <stdio.h>
166166
#include <stdlib.h>

0 commit comments

Comments
 (0)