diff --git a/CMakeLists.txt b/CMakeLists.txt index 504a6608..2fe691ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,6 +158,9 @@ if(WIN32) endif() list(APPEND qjs_libs qjs ${CMAKE_DL_LIBS}) find_package(Threads) +if(MINGW AND CMAKE_USE_PTHREADS_INIT) + list(APPEND qjs_defines USE_WINPTHREAD) +endif() if(NOT CMAKE_SYSTEM_NAME STREQUAL "WASI") list(APPEND qjs_libs ${CMAKE_THREAD_LIBS_INIT}) endif() @@ -235,7 +238,7 @@ endif() # # run-test262 uses pthreads. -if(NOT WIN32 AND NOT EMSCRIPTEN) +if((NOT WIN32 AND NOT EMSCRIPTEN) OR (MINGW AND CMAKE_USE_PTHREADS_INIT)) add_executable(run-test262 quickjs-libc.c run-test262.c diff --git a/quickjs-libc.c b/quickjs-libc.c index a594d742..04f1355d 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -58,6 +58,9 @@ #define rmdir _rmdir #define getcwd _getcwd #define chdir _chdir +#ifdef USE_WINPTHREAD +#define pipe(fds) _pipe(fds,1024, _O_BINARY) +#endif #else #include #if !defined(__wasi__) @@ -80,7 +83,7 @@ extern char **environ; #endif /* _WIN32 */ -#if !defined(_WIN32) && !defined(__wasi__) +#if (!defined(_WIN32) || defined(USE_WINPTHREAD)) && !defined(__wasi__) /* enable the os.Worker API. IT relies on POSIX threads */ #define USE_WORKER #endif