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: |
cd $GITHUB_WORKSPACE
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)
endif()
list(APPEND qjs_defines _GNU_SOURCE)
list(APPEND qjs_libs qjs)
if(NOT WIN32)
list(APPEND qjs_libs dl)
endif()
list(APPEND qjs_libs qjs ${CMAKE_DL_LIBS})
if(NOT MSVC)
list(APPEND qjs_libs m pthread)
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);
#elif defined(_WIN32)
return _msize(ptr);
#elif defined(EMSCRIPTEN)
return 0;
#elif defined(__linux__)
return malloc_usable_size(ptr);
#else
/* change this to `return 0;` if compilation fails */
return malloc_usable_size(ptr);
return 0;
#endif
}
@ -257,13 +254,10 @@ static const JSMallocFunctions trace_mf = {
malloc_size,
#elif defined(_WIN32)
(size_t (*)(const void *))_msize,
#elif defined(EMSCRIPTEN)
NULL,
#elif defined(__linux__) || defined(__CYGWIN__)
(size_t (*)(const void *))malloc_usable_size,
#else
/* change this to `NULL,` if compilation fails */
malloc_usable_size,
NULL,
#endif
};

View file

@ -73,12 +73,15 @@ typedef sig_t sighandler_t;
#endif
#endif /* __APPLE__ */
#if defined(__OpenBSD__)
typedef sig_t sighandler_t;
extern char **environ;
#endif
#if !defined(_WIN32)
/* enable the os.Worker API. IT relies on POSIX threads */
#define USE_WORKER
#endif
#endif /* _WIN32 */
#ifdef USE_WORKER
#include <pthread.h>
@ -3584,8 +3587,12 @@ void js_std_set_worker_new_context_func(JSContext *(*func)(JSRuntime *rt))
#define OS_PLATFORM "js"
#elif defined(__CYGWIN__)
#define OS_PLATFORM "cygwin"
#else
#elif defined(__linux__)
#define OS_PLATFORM "linux"
#elif defined(__OpenBSD__)
#define OS_PLATFORM "openbsd"
#else
#define OS_PLATFORM "unknown"
#endif
#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);
#elif defined(_WIN32)
return _msize(ptr);
#elif defined(EMSCRIPTEN)
return 0;
#elif defined(__linux__)
return malloc_usable_size(ptr);
#else
/* change this to `return 0;` if compilation fails */
return malloc_usable_size(ptr);
return 0;
#endif
}
@ -1720,13 +1717,10 @@ static const JSMallocFunctions def_malloc_funcs = {
malloc_size,
#elif defined(_WIN32)
(size_t (*)(const void *))_msize,
#elif defined(EMSCRIPTEN)
NULL,
#elif defined(__linux__) || defined (__CYGWIN__)
(size_t (*)(const void *))malloc_usable_size,
#else
/* change this to `NULL,` if compilation fails */
malloc_usable_size,
NULL,
#endif
};