Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow building when targeting WASI #1509

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions absl/base/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
// Windows _WIN32
// NaCL __native_client__
// AsmJS __asmjs__
// WebAssembly __wasm__
// WebAssembly (Emscripten) __EMSCRIPTEN__
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WebAssembly is an architecture, such as x86, not an operating system, which is a syscall layer so in its case, either Emscripten or WASI currently. I have changed this to clarify, as Emscripten is a WebAssembly "OS" which supports mmap while WASI does not.

I can add wasi to this list if it makes sense, but I suspect that would be a bigger decision on whether the project officially supports the OS now or not. But it would be great if we can at least add smaller fixes like this PR on a best-effort basis to allow compilation to pass to encourage the use of abseil within the server-side WebAssembly community

// Fuchsia __Fuchsia__
//
// Note that since Android defines both __ANDROID__ and __linux__, one
Expand All @@ -409,7 +409,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
#error ABSL_HAVE_MMAP cannot be directly set
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
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(__HAIKU__) || defined(__OpenBSD__) || defined(__NetBSD__) || \
defined(__QNX__) || defined(__VXWORKS__) || defined(__hexagon__)
Expand Down Expand Up @@ -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
#elif defined(__EMSCRIPTEN__)
// emscripten doesn't support signals
#elif defined(__wasi__)
// WASI doesn't support signals
#elif defined(__Fuchsia__)
// Signals don't exist on fuchsia.
#elif defined(__native_client__)
Expand Down
8 changes: 6 additions & 2 deletions absl/base/internal/thread_identity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

#if !defined(_WIN32) || defined(__MINGW32__)
#include <pthread.h>
#ifndef __wasi__
// WASI does not provide this header, either way we disable use
// of signals with it below.
#include <signal.h>
#endif
#endif

#include <atomic>
#include <cassert>
Expand Down Expand Up @@ -80,8 +84,8 @@ void SetCurrentThreadIdentity(ThreadIdentity* identity,
absl::call_once(init_thread_identity_key_once, AllocateThreadIdentityKey,
reclaimer);

#if defined(__EMSCRIPTEN__) || defined(__MINGW32__) || defined(__hexagon__)
// Emscripten and MinGW pthread implementations does not support signals.
#if defined(__wasi__) || defined(__EMSCRIPTEN__) || defined(__MINGW32__) || defined(__hexagon__)
// Emscripten, WASI and MinGW pthread implementations does not support signals.
// See https://kripken.github.io/emscripten-site/docs/porting/pthreads.html
// for more information.
pthread_setspecific(thread_identity_pthread_key,
Expand Down
2 changes: 1 addition & 1 deletion absl/debugging/failure_signal_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#include "absl/debugging/internal/examine_stack.h"
#include "absl/debugging/stacktrace.h"

#ifndef _WIN32
#if !defined(_WIN32) && !defined(__wasi__)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that Emscripten does support this codepath while wasi doesn't so I added a wasi-specific option here

#define ABSL_HAVE_SIGACTION
// Apple WatchOS and TVOS don't allow sigaltstack
// Apple macOS has sigaltstack, but using it makes backtrace() unusable.
Expand Down