Skip to content

Commit

Permalink
Add OpenBSD support
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Dec 5, 2023
1 parent 56738d8 commit 478bcf7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 2 additions & 8 deletions qjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
};

Expand Down
13 changes: 10 additions & 3 deletions quickjs-libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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 )
Expand Down
10 changes: 2 additions & 8 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
};

Expand Down

0 comments on commit 478bcf7

Please sign in to comment.