Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Commit 663fe94

Browse files
committed
added emscripten support
1 parent a34226c commit 663fe94

File tree

10 files changed

+93
-21
lines changed

10 files changed

+93
-21
lines changed

.github/workflows/emscripten.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Emscripten
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build-linux:
7+
defaults:
8+
run:
9+
shell: bash
10+
name: Emscripten-C++${{matrix.std}}-${{matrix.build_type}}-${{matrix.lib}}-${{matrix.extra}}
11+
runs-on: ubuntu-latest
12+
container: emscripten/emsdk
13+
strategy:
14+
fail-fast: true
15+
matrix:
16+
build_type: [Release, Debug]
17+
extra: [no-custom-prefix, custom-prefix]
18+
lib: [static]
19+
std: [98, 11, 14, 17, 20]
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
24+
- name: Setup Dependencies
25+
run: |
26+
apt-get update
27+
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y \
28+
cmake \
29+
ninja-build
30+
31+
- name: Setup C++98 Environment
32+
if: matrix.std == '98'
33+
run: |
34+
echo 'CXXFLAGS=-Wno-error=variadic-macros -Wno-error=long-long ${{env.CXXFLAGS}}' >> $GITHUB_ENV
35+
36+
- name: Configure
37+
env:
38+
CXXFLAGS: -Wall -Wextra -Wsign-conversion -Wtautological-compare -Wformat-nonliteral -Wundef -Werror -Wno-error=wasm-exception-spec ${{env.CXXFLAGS}}
39+
run: |
40+
cmake -S . -B build_${{matrix.build_type}} \
41+
-DBUILD_SHARED_LIBS=${{matrix.lib == 'shared'}} \
42+
-DCMAKE_AR=$(which emar) \
43+
-DCMAKE_C_COMPILER=$(which emcc) \
44+
-DCMAKE_CXX_COMPILER=$(which em++) \
45+
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
46+
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
47+
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
48+
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
49+
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY \
50+
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
51+
-DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install \
52+
-DCMAKE_RANLIB=$(which emranlib) \
53+
-DWITH_CUSTOM_PREFIX=${{matrix.extra == 'custom-prefix'}} \
54+
-G Ninja \
55+
-Werror
56+
57+
- name: Build
58+
run: |
59+
cmake --build build_${{matrix.build_type}} \
60+
--config ${{matrix.build_type}}

CMakeLists.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ find_package (Unwind)
9393
if (Unwind_FOUND)
9494
set (HAVE_LIB_UNWIND 1)
9595
else (Unwind_FOUND)
96-
check_include_file_cxx (unwind.h HAVE_UNWIND_H)
9796
# Check whether linking actually succeeds. ARM toolchains of LLVM unwind
9897
# implementation do not necessarily provide the _Unwind_Backtrace function
9998
# which causes the previous check to succeed but the linking to fail.
10099
check_cxx_symbol_exists (_Unwind_Backtrace unwind.h HAVE__UNWIND_BACKTRACE)
100+
check_cxx_symbol_exists (_Unwind_GetIP unwind.h HAVE__UNWIND_GETIP)
101101
endif (Unwind_FOUND)
102102

103103
check_include_file_cxx (dlfcn.h HAVE_DLFCN_H)
@@ -197,9 +197,10 @@ int main(void)
197197
}
198198
" HAVE___SYNC_VAL_COMPARE_AND_SWAP)
199199

200-
cmake_push_check_state (RESET)
201-
set (CMAKE_REQUIRED_LIBRARIES Threads::Threads)
202-
check_cxx_source_compiles ("
200+
if (Threads_FOUND)
201+
cmake_push_check_state (RESET)
202+
set (CMAKE_REQUIRED_LIBRARIES Threads::Threads)
203+
check_cxx_source_compiles ("
203204
#define _XOPEN_SOURCE 500
204205
#include <pthread.h>
205206
int main(void)
@@ -209,8 +210,9 @@ int main(void)
209210
pthread_rwlock_rdlock(&l);
210211
return 0;
211212
}
212-
" HAVE_RWLOCK)
213-
cmake_pop_check_state ()
213+
" HAVE_RWLOCK)
214+
cmake_pop_check_state ()
215+
endif (Threads_FOUND)
214216

215217
check_cxx_source_compiles ("
216218
__declspec(selectany) int a;

src/config.h.cmake.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@
118118
/* Define to 1 if you have the <unistd.h> header file. */
119119
#cmakedefine HAVE_UNISTD_H ${HAVE_UNISTD_H}
120120

121-
/* Define if you have the <unwind.h> header file. */
122-
#cmakedefine HAVE_UNWIND_H
123-
124121
/* Define if you linking to _Unwind_Backtrace is possible. */
125122
#cmakedefine HAVE__UNWIND_BACKTRACE
126123

124+
/* Define if you linking to _Unwind_GetIP is possible. */
125+
#cmakedefine HAVE__UNWIND_GETIP
126+
127127
/* define if the compiler supports using expression for operator */
128128
#cmakedefine HAVE_USING_OPERATOR
129129

src/glog/logging.h.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797

9898
@ac_google_start_namespace@
9999

100-
#if @ac_cv_have_uint16_t@ // the C99 format
100+
#if @ac_cv_have_stdint_h@ // the C99 format
101101
typedef int32_t int32;
102102
typedef uint32_t uint32;
103103
typedef int64_t int64;
@@ -1822,8 +1822,8 @@ GLOG_EXPORT void SetEmailLogging(LogSeverity min_severity,
18221822

18231823
// A simple function that sends email. dest is a commma-separated
18241824
// list of addressess. Thread-safe.
1825-
GLOG_EXPORT bool SendEmail(const char *dest,
1826-
const char *subject, const char *body);
1825+
GLOG_EXPORT bool SendEmail(const char* dest, const char* subject,
1826+
const char* body);
18271827

18281828
GLOG_EXPORT const std::vector<std::string>& GetLoggingDirectories();
18291829

src/glog/platform.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
#define GLOG_OS_NETBSD
5151
#elif defined(__OpenBSD__)
5252
#define GLOG_OS_OPENBSD
53+
#elif defined(__EMSCRIPTEN__)
54+
#define GLOG_OS_EMSCRIPTEN
5355
#else
5456
// TODO(hamaji): Add other platforms.
5557
#error Platform not supported by glog. Please consider to contribute platform information by submitting a pull request on Github.

src/logging.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,7 @@ void SetExitOnDFatal(bool value) {
21882188
} // namespace internal
21892189
} // namespace base
21902190

2191+
#ifndef GLOG_OS_EMSCRIPTEN
21912192
// Shell-escaping as we need to shell out ot /bin/mail.
21922193
static const char kDontNeedShellEscapeChars[] =
21932194
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@@ -2222,14 +2223,14 @@ static string ShellEscape(const string& src) {
22222223
}
22232224
return result;
22242225
}
2225-
2226+
#endif
22262227

22272228
// use_logging controls whether the logging functions LOG/VLOG are used
22282229
// to log errors. It should be set to false when the caller holds the
22292230
// log_mutex.
22302231
static bool SendEmailInternal(const char*dest, const char *subject,
22312232
const char*body, bool use_logging) {
2232-
#ifndef __EMSCRIPTEN__
2233+
#ifndef GLOG_OS_EMSCRIPTEN
22332234
if (dest && *dest) {
22342235
if ( use_logging ) {
22352236
VLOG(1) << "Trying to send TITLE:" << subject
@@ -2275,6 +2276,12 @@ static bool SendEmailInternal(const char*dest, const char *subject,
22752276
}
22762277
}
22772278
}
2279+
#else
2280+
(void)dest;
2281+
(void)subject;
2282+
(void)body;
2283+
(void)use_logging;
2284+
LOG(WARNING) << "Email support not available; not sending message";
22782285
#endif
22792286
return false;
22802287
}

src/raw_logging.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@
5959
# include <unistd.h>
6060
#endif
6161

62-
#if (defined(HAVE_SYSCALL_H) || defined(HAVE_SYS_SYSCALL_H)) && (!(defined(GLOG_OS_MACOSX)))
63-
# define safe_write(fd, s, len) syscall(SYS_write, fd, s, len)
62+
#if (defined(HAVE_SYSCALL_H) || defined(HAVE_SYS_SYSCALL_H)) && \
63+
(!(defined(GLOG_OS_MACOSX))) && !defined(GLOG_OS_EMSCRIPTEN)
64+
#define safe_write(fd, s, len) syscall(SYS_write, fd, s, len)
6465
#else
65-
// Not so safe, but what can you do?
66-
# define safe_write(fd, s, len) write(fd, s, len)
66+
// Not so safe, but what can you do?
67+
#define safe_write(fd, s, len) write(fd, s, len)
6768
#endif
6869

6970
_START_GOOGLE_NAMESPACE_

src/stacktrace_unwind-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static _Unwind_Reason_Code GetOneFrame(struct _Unwind_Context *uc, void *opq) {
7373
if (targ->skip_count > 0) {
7474
targ->skip_count--;
7575
} else {
76-
targ->result[targ->count++] = (void *) _Unwind_GetIP(uc);
76+
targ->result[targ->count++] = reinterpret_cast<void *>(_Unwind_GetIP(uc));
7777
}
7878

7979
if (targ->count == targ->max_depth) {

src/symbolize.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ static ATTRIBUTE_NOINLINE bool SymbolizeAndDemangle(void *pc, char *out,
834834

835835
_END_GOOGLE_NAMESPACE_
836836

837-
#elif defined(GLOG_OS_MACOSX) && defined(HAVE_DLADDR)
837+
#elif (defined(GLOG_OS_MACOSX) || defined(GLOG_OS_EMSCRIPTEN)) && defined(HAVE_DLADDR)
838838

839839
#include <dlfcn.h>
840840
#include <cstring>

src/utilities.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888

8989
#if defined(HAVE_LIB_UNWIND)
9090
# define STACKTRACE_H "stacktrace_libunwind-inl.h"
91-
#elif defined(HAVE__UNWIND_BACKTRACE)
91+
#elif defined(HAVE__UNWIND_BACKTRACE) && defined(HAVE__UNWIND_GETIP)
9292
# define STACKTRACE_H "stacktrace_unwind-inl.h"
9393
#elif !defined(NO_FRAME_POINTER)
9494
# if defined(__i386__) && __GNUC__ >= 2

0 commit comments

Comments
 (0)