emscripten compatibility fixes

This commit is contained in:
Andrei Alexeyev 2019-12-18 15:33:36 +02:00
parent 030fae87f5
commit 6834796262
No known key found for this signature in database
GPG key ID: 363707CD4C7FE8A4
7 changed files with 54 additions and 22 deletions

View file

@ -35,6 +35,25 @@ cc = meson.get_compiler('c')
python3 = import('python3').find_python()
macos_app_bundle = get_option('macos_bundle') and host_machine.system() == 'darwin'
if cc.get_id() == 'emscripten'
# emscripten LTO is really tricky
# this logic should really be in Meson
if get_option('b_lto')
emscripten_global_link_args = [
'-s', 'WASM_OBJECT_FILES=0',
'--llvm-lto', '1',
'-flto',
]
else
emscripten_global_link_args = []
endif
add_global_arguments(emscripten_global_link_args, language : 'c', native : false)
add_global_arguments(emscripten_global_link_args, language : 'cpp', native : false)
add_global_link_arguments(emscripten_global_link_args, language : 'c', native : false)
add_global_link_arguments(emscripten_global_link_args, language : 'cpp', native : false)
endif
subdir('scripts')
config = configuration_data()
@ -204,7 +223,16 @@ config.set('TAISEI_BUILDCONF_HAVE_TIMESPEC', have_timespec)
config.set('TAISEI_BUILDCONF_HAVE_INT128', cc.sizeof('__int128') == 16)
config.set('TAISEI_BUILDCONF_HAVE_LONG_DOUBLE', cc.sizeof('long double') > 8)
config.set('TAISEI_BUILDCONF_HAVE_POSIX', have_posix)
config.set('TAISEI_BUILDCONF_MALLOC_ALIGNMENT', cc.alignment('max_align_t', prefix : '#include <stddef.h>\n'))
if host_machine.system() == 'emscripten'
# Emscripten bug: https://github.com/emscripten-core/emscripten/issues/10072
config.set('TAISEI_BUILDCONF_MALLOC_ALIGNMENT', 8)
config.set('TAISEI_BUILDCONF_HAVE_MAX_ALIGN_T', false)
else
malloc_alignment = cc.alignment('max_align_t', prefix : '#include <stddef.h>\n')
config.set('TAISEI_BUILDCONF_MALLOC_ALIGNMENT', malloc_alignment)
config.set('TAISEI_BUILDCONF_HAVE_MAX_ALIGN_T', malloc_alignment > 0)
endif
prefer_relpath_systems = [
'windows',

View file

@ -116,7 +116,8 @@ ListContainer* list_wrap_container(void *data) attr_returns_allocated;
"struct must implement ListInterface (use the LIST_INTERFACE macro)"); \
static_assert(__builtin_offsetof(__typeof__(**(expr)), list_interface) == 0, \
"list_interface must be the first member in struct"); \
CASTPTR_ASSUME_ALIGNED((expr), List*); \
(void)ASSUME_ALIGNED(*(expr), alignof(List)); \
(List**)(expr); \
}))
#define LIST_ANCHOR_CAST(expr) (__extension__ ({ \

View file

@ -190,7 +190,7 @@ if host_machine.system() == 'emscripten'
'-s', 'ALLOW_MEMORY_GROWTH=1',
'-s', 'ENVIRONMENT=web',
'-s', 'EXIT_RUNTIME=0',
'-s', 'EXPORTED_RUNTIME_METHODS=["ccall"]',
'-s', 'EXTRA_EXPORTED_RUNTIME_METHODS=["ccall"]',
'-s', 'EXPORT_NAME=Taisei',
'-s', 'FILESYSTEM=1',
'-s', 'FORCE_FILESYSTEM=1',
@ -229,14 +229,6 @@ if host_machine.system() == 'emscripten'
]
endif
if get_option('b_lto')
em_link_args += [
# See https://github.com/emscripten-core/emscripten/issues/8574
'-s', 'WASM_OBJECT_FILES=0',
'--llvm-lto', '1',
]
endif
foreach suffix : em_link_output_suffixes
em_link_outputs += ['@0@.@1@'.format(taisei_basename, suffix)]
endforeach
@ -257,12 +249,17 @@ if host_machine.system() == 'emscripten'
command : [
cc.cmd_array(),
taisei.full_path(),
emscripten_global_link_args,
em_bundle_link_args,
'--pre-js', em_preamble,
'--shell-file', em_shell,
get_option('c_args'),
get_option('c_link_args'),
em_link_args,
# Emscripten bug https://github.com/emscripten-core/emscripten/issues/10066
'-s', 'WASM_OBJECT_FILES=1',
'-o', '@OUTPUT0@',
],
build_by_default : true,
@ -271,6 +268,8 @@ if host_machine.system() == 'emscripten'
install : true,
install_dir : bindir,
)
bindist_deps += taisei_html
elif host_machine.system() == 'nx'
taisei_elf_name = '@0@.elf'.format(taisei_basename)
taisei_elf = executable(taisei_elf_name, taisei_src, version_deps,

View file

@ -275,13 +275,13 @@ uint taskmgr_remaining(TaskManager *mgr) {
return SDL_AtomicGet(&mgr->numtasks);
}
static void taskmgr_finalize_and_wait(TaskManager *mgr, bool abort) {
static void taskmgr_finalize_and_wait(TaskManager *mgr, bool do_abort) {
log_debug(
"%08lx [%p] waiting for %u tasks (abort = %i)",
SDL_ThreadID(),
(void*)mgr,
taskmgr_remaining(mgr),
abort
do_abort
);
assert(mgr->running);
@ -289,7 +289,7 @@ static void taskmgr_finalize_and_wait(TaskManager *mgr, bool abort) {
SDL_LockMutex(mgr->mutex);
mgr->running = false;
mgr->aborted = abort;
mgr->aborted = do_abort;
SDL_CondBroadcast(mgr->cond);
SDL_UnlockMutex(mgr->mutex);

View file

@ -18,6 +18,6 @@ void _ts_assert_fail(const char *cond, const char *func, const char *file, int l
if(use_log) {
_taisei_log(LOG_FAKEFATAL, func, file, line, "%s:%i: assertion `%s` failed", file, line, cond);
} else {
tsfprintf(stderr, "%s:%i: %s(): assertion `%s` failed", file, line, func, cond);
tsfprintf(stderr, "%s:%i: %s(): assertion `%s` failed\n", file, line, func, cond);
}
}

View file

@ -18,7 +18,7 @@ void _ts_assert_fail(const char *cond, const char *func, const char *file, int l
#define static_assert _Static_assert
#if defined(NDEBUG)
#if defined(NDEBUG) || defined(__EMSCRIPTEN__)
#define TRAP() abort()
#elif defined(__clang__)
#define TRAP() __builtin_debugtrap()

View file

@ -183,12 +183,16 @@ typedef cmplx64 cmplx;
#define M_PI_4 0.78539816339744830962
#define M_E 2.7182818284590452354
// FIXME this is likely incorrect!
#if TAISEI_BUILDCONF_MALLOC_ALIGNMENT < 0
#warning max_align_t not supported
#undef TAISEI_BUILDCONF_MALLOC_ALIGNMENT
#define TAISEI_BUILDCONF_MALLOC_ALIGNMENT 8
typedef struct { alignas(TAISEI_BUILDCONF_MALLOC_ALIGNMENT) float64x a; } max_align_t;
#ifndef TAISEI_BUILDCONF_HAVE_MAX_ALIGN_T
#if TAISEI_BUILDCONF_MALLOC_ALIGNMENT <= 0
#warning malloc alignment is unknown, assuming 8
#undef TAISEI_BUILDCONF_MALLOC_ALIGNMENT
#define TAISEI_BUILDCONF_MALLOC_ALIGNMENT 8
#endif
#undef max_align_t
#define max_align_t _fake_max_align_t
typedef struct { alignas(TAISEI_BUILDCONF_MALLOC_ALIGNMENT) char a; } max_align_t;
#endif
// In case the C11 CMPLX macro is not present, try our best to provide a substitute