From 56738d8b4b039eb227a4c2e9292f8ef60b11fc52 Mon Sep 17 00:00:00 2001 From: Felipe Gasper Date: Sun, 3 Dec 2023 12:15:07 -0500 Subject: [PATCH] Add Cygwin compatibility --- .github/workflows/ci.yml | 36 ++++++++++++++++++++++++++++++++++++ qjs.c | 4 ++-- quickjs-libc.c | 2 ++ quickjs.c | 4 ++-- run-test262.c | 4 ++-- tests/test_builtin.js | 4 ++-- 6 files changed, 46 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8bfb7e0..89ee5f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -350,3 +350,39 @@ jobs: emmake make -C build qjs_wasm -j$(getconf _NPROCESSORS_ONLN) - name: result run: ls -lh build + + cygwin: + runs-on: windows-latest + defaults: + run: + shell: C:\cygwin\bin\bash.exe --login --norc -eo pipefail -o igncr '{0}' + steps: + - name: Set up Cygwin + uses: cygwin/cygwin-install-action@master + with: + packages: make cmake gcc-g++ bash + + - uses: actions/checkout@v3 + + - name: build + + # Plain `make` fails here with this error: + # No rule to make target '/cygdrive/d/a/quickjs-ng/quickjs-ng/cutils.c', + # needed by 'CMakeFiles/qjs.dir/cutils.c.o'. Stop. + # + # For some reason, making the build directory then `make`ing in there + # fixes it. + run: | + cd $GITHUB_WORKSPACE + make build/CMakeCache.txt + make --directory build + + - name: stats + run: | + cd $GITHUB_WORKSPACE + make --debug stats + + - name: test + run: | + cd $GITHUB_WORKSPACE + make --debug test diff --git a/qjs.c b/qjs.c index 53d136d..4bedc8b 100644 --- a/qjs.c +++ b/qjs.c @@ -36,7 +36,7 @@ #include #if defined(__APPLE__) #include -#elif defined(__linux__) +#elif defined(__linux__) || defined(__CYGWIN__) #include #endif @@ -259,7 +259,7 @@ static const JSMallocFunctions trace_mf = { (size_t (*)(const void *))_msize, #elif defined(EMSCRIPTEN) NULL, -#elif defined(__linux__) +#elif defined(__linux__) || defined(__CYGWIN__) (size_t (*)(const void *))malloc_usable_size, #else /* change this to `NULL,` if compilation fails */ diff --git a/quickjs-libc.c b/quickjs-libc.c index aaca43e..08eb00d 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -3582,6 +3582,8 @@ void js_std_set_worker_new_context_func(JSContext *(*func)(JSRuntime *rt)) #define OS_PLATFORM "darwin" #elif defined(EMSCRIPTEN) #define OS_PLATFORM "js" +#elif defined(__CYGWIN__) +#define OS_PLATFORM "cygwin" #else #define OS_PLATFORM "linux" #endif diff --git a/quickjs.c b/quickjs.c index bcb624e..de9ad3e 100644 --- a/quickjs.c +++ b/quickjs.c @@ -38,7 +38,7 @@ #include #if defined(__APPLE__) #include -#elif defined(__linux__) +#elif defined(__linux__) || defined(__CYGWIN__) #include #elif defined(__FreeBSD__) #include @@ -1722,7 +1722,7 @@ static const JSMallocFunctions def_malloc_funcs = { (size_t (*)(const void *))_msize, #elif defined(EMSCRIPTEN) NULL, -#elif defined(__linux__) +#elif defined(__linux__) || defined (__CYGWIN__) (size_t (*)(const void *))malloc_usable_size, #else /* change this to `NULL,` if compilation fails */ diff --git a/run-test262.c b/run-test262.c index 6944dc0..be56001 100644 --- a/run-test262.c +++ b/run-test262.c @@ -1668,7 +1668,7 @@ int run_test(const char *filename, int index) /* XXX: should extract the phase */ char *q = find_tag(p, "type:", &state); if (q) { - while (isspace(*q)) + while (isspace((unsigned char)*q)) q++; error_type = strdup_len(q, strcspn(q, " \n")); } @@ -2089,7 +2089,7 @@ int main(int argc, char **argv) update_exclude_dirs(); if (is_dir_list) { - if (optind < argc && !isdigit(argv[optind][0])) { + if (optind < argc && !isdigit((unsigned char)argv[optind][0])) { filename = argv[optind++]; namelist_load(&test_list, filename); } diff --git a/tests/test_builtin.js b/tests/test_builtin.js index 6ddea8e..25c6e47 100644 --- a/tests/test_builtin.js +++ b/tests/test_builtin.js @@ -345,8 +345,8 @@ function test_number() assert(Number.isNaN(Number("-"))); assert(Number.isNaN(Number("\x00a"))); - // TODO: Fix rounding errors on Windows. - if (os.platform === 'win32') { + // TODO: Fix rounding errors on Windows/Cygwin. + if (['win32', 'cygwin'].includes(os.platform)) { return; }