Add OpenBSD support

This commit is contained in:
Saúl Ibarra Corretgé 2023-12-04 23:18:41 +01:00
parent 56738d8b4b
commit 478bcf74f2
5 changed files with 30 additions and 23 deletions

View file

@ -386,3 +386,18 @@ jobs:
run: | run: |
cd $GITHUB_WORKSPACE cd $GITHUB_WORKSPACE
make --debug test make --debug test
openbsd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: build + test
uses: vmactions/openbsd-vm@v1
with:
usesh: true
prepare: |
pkg_add cmake
run: |
cmake -B build
cmake --build build -j $(sysctl -n hw.ncpu)
./build/qjs -qd

View file

@ -145,10 +145,7 @@ if(BUILD_QJS_LIBC)
list(APPEND qjs_sources quickjs-libc.c) list(APPEND qjs_sources quickjs-libc.c)
endif() endif()
list(APPEND qjs_defines _GNU_SOURCE) list(APPEND qjs_defines _GNU_SOURCE)
list(APPEND qjs_libs qjs) list(APPEND qjs_libs qjs ${CMAKE_DL_LIBS})
if(NOT WIN32)
list(APPEND qjs_libs dl)
endif()
if(NOT MSVC) if(NOT MSVC)
list(APPEND qjs_libs m pthread) list(APPEND qjs_libs m pthread)
endif() endif()

10
qjs.c
View file

@ -135,13 +135,10 @@ static inline size_t js_trace_malloc_usable_size(void *ptr)
return malloc_size(ptr); return malloc_size(ptr);
#elif defined(_WIN32) #elif defined(_WIN32)
return _msize(ptr); return _msize(ptr);
#elif defined(EMSCRIPTEN)
return 0;
#elif defined(__linux__) #elif defined(__linux__)
return malloc_usable_size(ptr); return malloc_usable_size(ptr);
#else #else
/* change this to `return 0;` if compilation fails */ return 0;
return malloc_usable_size(ptr);
#endif #endif
} }
@ -257,13 +254,10 @@ static const JSMallocFunctions trace_mf = {
malloc_size, malloc_size,
#elif defined(_WIN32) #elif defined(_WIN32)
(size_t (*)(const void *))_msize, (size_t (*)(const void *))_msize,
#elif defined(EMSCRIPTEN)
NULL,
#elif defined(__linux__) || defined(__CYGWIN__) #elif defined(__linux__) || defined(__CYGWIN__)
(size_t (*)(const void *))malloc_usable_size, (size_t (*)(const void *))malloc_usable_size,
#else #else
/* change this to `NULL,` if compilation fails */ NULL,
malloc_usable_size,
#endif #endif
}; };

View file

@ -73,12 +73,15 @@ typedef sig_t sighandler_t;
#endif #endif
#endif /* __APPLE__ */ #endif /* __APPLE__ */
#if defined(__OpenBSD__)
typedef sig_t sighandler_t;
extern char **environ;
#endif #endif
#if !defined(_WIN32)
/* enable the os.Worker API. IT relies on POSIX threads */ /* enable the os.Worker API. IT relies on POSIX threads */
#define USE_WORKER #define USE_WORKER
#endif
#endif /* _WIN32 */
#ifdef USE_WORKER #ifdef USE_WORKER
#include <pthread.h> #include <pthread.h>
@ -3584,8 +3587,12 @@ void js_std_set_worker_new_context_func(JSContext *(*func)(JSRuntime *rt))
#define OS_PLATFORM "js" #define OS_PLATFORM "js"
#elif defined(__CYGWIN__) #elif defined(__CYGWIN__)
#define OS_PLATFORM "cygwin" #define OS_PLATFORM "cygwin"
#else #elif defined(__linux__)
#define OS_PLATFORM "linux" #define OS_PLATFORM "linux"
#elif defined(__OpenBSD__)
#define OS_PLATFORM "openbsd"
#else
#define OS_PLATFORM "unknown"
#endif #endif
#define OS_FLAG(x) JS_PROP_INT32_DEF(#x, x, JS_PROP_CONFIGURABLE ) #define OS_FLAG(x) JS_PROP_INT32_DEF(#x, x, JS_PROP_CONFIGURABLE )

View file

@ -1646,13 +1646,10 @@ static inline size_t js_def_malloc_usable_size(void *ptr)
return malloc_size(ptr); return malloc_size(ptr);
#elif defined(_WIN32) #elif defined(_WIN32)
return _msize(ptr); return _msize(ptr);
#elif defined(EMSCRIPTEN)
return 0;
#elif defined(__linux__) #elif defined(__linux__)
return malloc_usable_size(ptr); return malloc_usable_size(ptr);
#else #else
/* change this to `return 0;` if compilation fails */ return 0;
return malloc_usable_size(ptr);
#endif #endif
} }
@ -1720,13 +1717,10 @@ static const JSMallocFunctions def_malloc_funcs = {
malloc_size, malloc_size,
#elif defined(_WIN32) #elif defined(_WIN32)
(size_t (*)(const void *))_msize, (size_t (*)(const void *))_msize,
#elif defined(EMSCRIPTEN)
NULL,
#elif defined(__linux__) || defined (__CYGWIN__) #elif defined(__linux__) || defined (__CYGWIN__)
(size_t (*)(const void *))malloc_usable_size, (size_t (*)(const void *))malloc_usable_size,
#else #else
/* change this to `NULL,` if compilation fails */ NULL,
malloc_usable_size,
#endif #endif
}; };