Commit 79f3dec0 by Anuraag Agrawal Committed by Copybara-Service

PR #1509: Allow building when targeting WASI

Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1509

WASI is similar to emscripten, providing a syscall layer to WebAssembly focused on server side applications. There are some config knobs that are in place to allow building the repo for emscripten which also need to support wasi (as built with LLVM). Aside from that, there are still some features it supports less than escripten, for example related to signals, causing the build to be even more limited for it.
Merge ec9fa081609687035005dfdafd312754f31c3fbb into 861e53c8

Merging this change closes #1509

COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1509 from anuraaga:wasi-sdk-build ec9fa081609687035005dfdafd312754f31c3fbb
PiperOrigin-RevId: 557166498
Change-Id: Ic51149d8b092fd888c9a5c383275257fc8ff4232
parent 32f414f4
...@@ -395,7 +395,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || ...@@ -395,7 +395,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
// Windows _WIN32 // Windows _WIN32
// NaCL __native_client__ // NaCL __native_client__
// AsmJS __asmjs__ // AsmJS __asmjs__
// WebAssembly __wasm__ // WebAssembly (Emscripten) __EMSCRIPTEN__
// Fuchsia __Fuchsia__ // Fuchsia __Fuchsia__
// //
// Note that since Android defines both __ANDROID__ and __linux__, one // Note that since Android defines both __ANDROID__ and __linux__, one
...@@ -409,7 +409,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || ...@@ -409,7 +409,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
#error ABSL_HAVE_MMAP cannot be directly set #error ABSL_HAVE_MMAP cannot be directly set
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
defined(_AIX) || defined(__ros__) || defined(__native_client__) || \ defined(_AIX) || defined(__ros__) || defined(__native_client__) || \
defined(__asmjs__) || defined(__wasm__) || defined(__Fuchsia__) || \ defined(__asmjs__) || defined(__EMSCRIPTEN__) || defined(__Fuchsia__) || \
defined(__sun) || defined(__ASYLO__) || defined(__myriad2__) || \ defined(__sun) || defined(__ASYLO__) || defined(__myriad2__) || \
defined(__HAIKU__) || defined(__OpenBSD__) || defined(__NetBSD__) || \ defined(__HAIKU__) || defined(__OpenBSD__) || defined(__NetBSD__) || \
defined(__QNX__) || defined(__VXWORKS__) || defined(__hexagon__) defined(__QNX__) || defined(__VXWORKS__) || defined(__hexagon__)
...@@ -484,6 +484,8 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || ...@@ -484,6 +484,8 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
// https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/alarm.c // https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/alarm.c
#elif defined(__EMSCRIPTEN__) #elif defined(__EMSCRIPTEN__)
// emscripten doesn't support signals // emscripten doesn't support signals
#elif defined(__wasi__)
// WASI doesn't support signals
#elif defined(__Fuchsia__) #elif defined(__Fuchsia__)
// Signals don't exist on fuchsia. // Signals don't exist on fuchsia.
#elif defined(__native_client__) #elif defined(__native_client__)
...@@ -934,7 +936,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || ...@@ -934,7 +936,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
#error __EMSCRIPTEN_tiny__ is too big to fit in ABSL_INTERNAL_EMSCRIPTEN_VERSION #error __EMSCRIPTEN_tiny__ is too big to fit in ABSL_INTERNAL_EMSCRIPTEN_VERSION
#endif #endif
#define ABSL_INTERNAL_EMSCRIPTEN_VERSION \ #define ABSL_INTERNAL_EMSCRIPTEN_VERSION \
((__EMSCRIPTEN_major__)*1000000 + (__EMSCRIPTEN_minor__)*1000 + \ ((__EMSCRIPTEN_major__) * 1000000 + (__EMSCRIPTEN_minor__) * 1000 + \
(__EMSCRIPTEN_tiny__)) (__EMSCRIPTEN_tiny__))
#endif #endif
#endif #endif
......
...@@ -16,8 +16,12 @@ ...@@ -16,8 +16,12 @@
#if !defined(_WIN32) || defined(__MINGW32__) #if !defined(_WIN32) || defined(__MINGW32__)
#include <pthread.h> #include <pthread.h>
#ifndef __wasi__
// WASI does not provide this header, either way we disable use
// of signals with it below.
#include <signal.h> #include <signal.h>
#endif #endif
#endif
#include <atomic> #include <atomic>
#include <cassert> #include <cassert>
...@@ -80,10 +84,12 @@ void SetCurrentThreadIdentity(ThreadIdentity* identity, ...@@ -80,10 +84,12 @@ void SetCurrentThreadIdentity(ThreadIdentity* identity,
absl::call_once(init_thread_identity_key_once, AllocateThreadIdentityKey, absl::call_once(init_thread_identity_key_once, AllocateThreadIdentityKey,
reclaimer); reclaimer);
#if defined(__EMSCRIPTEN__) || defined(__MINGW32__) || defined(__hexagon__) #if defined(__wasi__) || defined(__EMSCRIPTEN__) || defined(__MINGW32__) || \
// Emscripten and MinGW pthread implementations does not support signals. defined(__hexagon__)
// See https://kripken.github.io/emscripten-site/docs/porting/pthreads.html // Emscripten, WASI and MinGW pthread implementations does not support
// for more information. // signals. See
// https://kripken.github.io/emscripten-site/docs/porting/pthreads.html for
// more information.
pthread_setspecific(thread_identity_pthread_key, pthread_setspecific(thread_identity_pthread_key,
reinterpret_cast<void*>(identity)); reinterpret_cast<void*>(identity));
#else #else
......
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
#include "absl/debugging/internal/examine_stack.h" #include "absl/debugging/internal/examine_stack.h"
#include "absl/debugging/stacktrace.h" #include "absl/debugging/stacktrace.h"
#ifndef _WIN32 #if !defined(_WIN32) && !defined(__wasi__)
#define ABSL_HAVE_SIGACTION #define ABSL_HAVE_SIGACTION
// Apple WatchOS and TVOS don't allow sigaltstack // Apple WatchOS and TVOS don't allow sigaltstack
// Apple macOS has sigaltstack, but using it makes backtrace() unusable. // Apple macOS has sigaltstack, but using it makes backtrace() unusable.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment