From 0b36c4d0b2ebaa1f29717bcee06c575227865385 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Fri, 27 Dec 2024 11:46:54 +0800 Subject: [PATCH 1/2] Fix compilation of quickjs-libc under emscripten --- .github/workflows/ci.yml | 2 +- quickjs-libc.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a99cf3c27..2b5006ab3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -398,7 +398,7 @@ jobs: run: emcc -v - name: build run: | - emcmake cmake -B build + emcmake cmake -B build -DBUILD_QJS_LIBC=ON emmake make -C build qjs_wasm -j$(getconf _NPROCESSORS_ONLN) - name: result run: ls -lh build diff --git a/quickjs-libc.c b/quickjs-libc.c index 6dbe501e6..d18cd64ee 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -3035,15 +3035,19 @@ static int my_execvpe(const char *filename, char **argv, char **envp) return -1; } -static js_once_t js_os_exec_once = JS_ONCE_INIT; - static void (*js_os_exec_closefrom)(int); +#ifndef EMSCRIPTEN + +static js_once_t js_os_exec_once = JS_ONCE_INIT; + static void js_os_exec_once_init(void) { js_os_exec_closefrom = dlsym(RTLD_DEFAULT, "closefrom"); } +#endif + /* exec(args[, options]) -> exitcode */ static JSValue js_os_exec(JSContext *ctx, JSValue this_val, int argc, JSValue *argv) @@ -3163,9 +3167,11 @@ static JSValue js_os_exec(JSContext *ctx, JSValue this_val, } } +#ifndef EMSCRIPTEN // should happen pre-fork because it calls dlsym() // and that's not an async-signal-safe function js_once(&js_os_exec_once, js_os_exec_once_init); +#endif pid = fork(); if (pid < 0) { From 336eb2df19ae403818819c4359ed389de13c4494 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Fri, 27 Dec 2024 17:32:32 +0800 Subject: [PATCH 2/2] Match WASM guard to cutils --- quickjs-libc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quickjs-libc.c b/quickjs-libc.c index d18cd64ee..a7b334fbb 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -3037,7 +3037,7 @@ static int my_execvpe(const char *filename, char **argv, char **envp) static void (*js_os_exec_closefrom)(int); -#ifndef EMSCRIPTEN +#if !defined(EMSCRIPTEN) && !defined(__wasi__) static js_once_t js_os_exec_once = JS_ONCE_INIT; @@ -3167,7 +3167,7 @@ static JSValue js_os_exec(JSContext *ctx, JSValue this_val, } } -#ifndef EMSCRIPTEN +#if !defined(EMSCRIPTEN) && !defined(__wasi__) // should happen pre-fork because it calls dlsym() // and that's not an async-signal-safe function js_once(&js_os_exec_once, js_os_exec_once_init);