From 8128e661452b656c3f7969f44d1c43e2a7eaf6eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Tue, 5 Dec 2023 09:14:12 +0100 Subject: [PATCH] Add FreeBSD support --- .github/workflows/ci.yml | 15 +++++++++++++++ qjs.c | 4 +++- quickjs-libc.c | 6 +++--- quickjs.c | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e2733f..bad58e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -401,3 +401,18 @@ jobs: cmake -B build cmake --build build -j $(sysctl -n hw.ncpu) ./build/qjs -qd + + freebsd: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: build + test + uses: vmactions/freebsd-vm@v1 + with: + usesh: true + prepare: | + pkg install -y cmake + run: | + cmake -B build + cmake --build build -j $(sysctl -n hw.ncpu) + ./build/qjs -qd diff --git a/qjs.c b/qjs.c index 47e207e..0530c9e 100644 --- a/qjs.c +++ b/qjs.c @@ -38,6 +38,8 @@ #include #elif defined(__linux__) || defined(__CYGWIN__) #include +#elif defined(__FreeBSD__) +#include #endif #include "cutils.h" @@ -135,7 +137,7 @@ static inline size_t js_trace_malloc_usable_size(void *ptr) return malloc_size(ptr); #elif defined(_WIN32) return _msize(ptr); -#elif defined(__linux__) +#elif defined(__linux__) || defined(__FreeBSD__) return malloc_usable_size(ptr); #else return 0; diff --git a/quickjs-libc.c b/quickjs-libc.c index c871a16..6b3627a 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -67,13 +67,11 @@ #if defined(__APPLE__) typedef sig_t sighandler_t; -#if !defined(environ) #include #define environ (*_NSGetEnviron()) #endif -#endif /* __APPLE__ */ -#if defined(__OpenBSD__) +#if defined(__OpenBSD__) || defined(__FreeBSD__) typedef sig_t sighandler_t; extern char **environ; #endif @@ -3591,6 +3589,8 @@ void js_std_set_worker_new_context_func(JSContext *(*func)(JSRuntime *rt)) #define OS_PLATFORM "linux" #elif defined(__OpenBSD__) #define OS_PLATFORM "openbsd" +#elif defined(__FreeBSD__) +#define OS_PLATFORM "freebsd" #else #define OS_PLATFORM "unknown" #endif diff --git a/quickjs.c b/quickjs.c index 956c05e..03c10aa 100644 --- a/quickjs.c +++ b/quickjs.c @@ -1646,7 +1646,7 @@ static inline size_t js_def_malloc_usable_size(void *ptr) return malloc_size(ptr); #elif defined(_WIN32) return _msize(ptr); -#elif defined(__linux__) +#elif defined(__linux__) || defined(__FreeBSD__) return malloc_usable_size(ptr); #else return 0;