From f37c6bbb373f2c1a05d6d4dfc2def54b5795289b Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Tue, 18 Nov 2025 17:12:48 -0800 Subject: [PATCH 1/5] Modules: removed extra not needed QuickJS checks. --- nginx/config | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/nginx/config b/nginx/config index 3386dac08..9d16ddd47 100644 --- a/nginx/config +++ b/nginx/config @@ -87,21 +87,6 @@ if [ $NJS_QUICKJS != NO ]; then exit 1; fi - ngx_feature="QuickJS JS_NewTypedArray()" - ngx_feature_name=NJS_HAVE_QUICKJS_NEW_TYPED_ARRAY - ngx_feature_test="JSValue argv; - (void) JS_NewTypedArray(NULL, 1, &argv, - JS_TYPED_ARRAY_UINT8); - return 0;" - - . auto/feature - - ngx_feature="QuickJS JS_IsSameValue()" - ngx_feature_name=NJS_HAVE_QUICKJS_IS_SAME_VALUE - ngx_feature_test="(void) JS_IsSameValue(NULL, JS_UNDEFINED, JS_UNDEFINED);" - - . auto/feature - NJS_HAVE_QUICKJS=YES NJS_QUICKJS_LIB="$ngx_feature_libs" NJS_QUICKJS_INC=`echo "$ngx_feature_path" | sed -e "s|^$NJS_QUICKJS_DEFAULT_INCS||"` From 88272af045335ec281322e638027032aad80534f Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Tue, 18 Nov 2025 16:10:52 -0800 Subject: [PATCH 2/5] QuickJS: fixed compatibility issue with QuickJS-NG 0.11.0. --- .github/workflows/check-pr.yml | 2 +- auto/quickjs | 18 ++++++++++++++++++ external/njs_shell.c | 2 +- external/qjs_fs_module.c | 6 +++--- src/qjs.h | 6 ++++++ 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-pr.yml b/.github/workflows/check-pr.yml index d5e0edd27..b64adbacb 100644 --- a/.github/workflows/check-pr.yml +++ b/.github/workflows/check-pr.yml @@ -55,7 +55,7 @@ jobs: run: | git clone https://github.com/quickjs-ng/quickjs quickjs-ng cd quickjs-ng - git checkout v0.9.0 + git checkout v0.11.0 CFLAGS="$CC_OPT -fPIC" LDFLAGS=$LD_OPT cmake -B build cmake --build build --target qjs -j $(nproc) diff --git a/auto/quickjs b/auto/quickjs index 8d6b544f9..00fcbc0b8 100644 --- a/auto/quickjs +++ b/auto/quickjs @@ -136,6 +136,24 @@ if [ $NJS_TRY_QUICKJS = YES ]; then . auto/feature + njs_feature="QuickJS JS_IsError()" + njs_feature_name=NJS_HAVE_QUICKJS_IS_ERROR_SINGLE_ARG + njs_feature_test="#include + + int main() { + JSRuntime *rt; + JSContext *ctx; + + rt = JS_NewRuntime(); + ctx = JS_NewContext(rt); + (void) JS_IsError(JS_UNDEFINED); + JS_FreeContext(ctx); + JS_FreeRuntime(rt); + return 0; + }" + + . auto/feature + njs_feature="QuickJS JS_AddIntrinsicBigInt()" njs_feature_name=NJS_HAVE_QUICKJS_ADD_INTRINSIC_BIG_INT njs_feature_test="#include diff --git a/external/njs_shell.c b/external/njs_shell.c index d4132d28f..d72a3d987 100644 --- a/external/njs_shell.c +++ b/external/njs_shell.c @@ -1960,7 +1960,7 @@ njs_qjs_dump_error2(JSContext *ctx, JSValueConst exception) _Bool is_error; JSValue val; - is_error = JS_IsError(ctx, exception); + is_error = qjs_is_error(ctx, exception); njs_qjs_dump_obj(ctx, stderr, exception, "Thrown:\n", ""); diff --git a/external/qjs_fs_module.c b/external/qjs_fs_module.c index 48ae9833c..4fcce40f8 100644 --- a/external/qjs_fs_module.c +++ b/external/qjs_fs_module.c @@ -2696,7 +2696,7 @@ qjs_fs_result(JSContext *cx, JSValue result, int calltype, JSValue callback) switch (calltype) { case QJS_FS_DIRECT: - if (JS_IsError(cx, result)) { + if (qjs_is_error(cx, result)) { JS_Throw(cx, result); return JS_EXCEPTION; } @@ -2704,7 +2704,7 @@ qjs_fs_result(JSContext *cx, JSValue result, int calltype, JSValue callback) return result; case QJS_FS_PROMISE: - if (JS_IsError(cx, result)) { + if (qjs_is_error(cx, result)) { JS_Throw(cx, result); return qjs_promise_result(cx, JS_EXCEPTION); } @@ -2712,7 +2712,7 @@ qjs_fs_result(JSContext *cx, JSValue result, int calltype, JSValue callback) return qjs_promise_result(cx, result); case QJS_FS_CALLBACK: - if (JS_IsError(cx, result)) { + if (qjs_is_error(cx, result)) { arguments[0] = result; arguments[1] = JS_UNDEFINED; diff --git a/src/qjs.h b/src/qjs.h index df5bfd11c..240e150ba 100644 --- a/src/qjs.h +++ b/src/qjs.h @@ -150,6 +150,12 @@ static inline JS_BOOL JS_IsNullOrUndefined(JSValueConst v) #define qjs_is_array(cx, a) JS_IsArray(cx, a) #endif +#ifdef NJS_HAVE_QUICKJS_IS_ERROR_SINGLE_ARG +#define qjs_is_error(cx, a) JS_IsError(a) +#else +#define qjs_is_error(cx, a) JS_IsError(cx, a) +#endif + extern qjs_module_t *qjs_modules[]; #endif /* _QJS_H_INCLUDED_ */ From 4a5ed865c30de23ed921b36855029b8a8729fbca Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Tue, 18 Nov 2025 17:46:41 -0800 Subject: [PATCH 3/5] Added pkg-config discovery for QuickJS-NG. --- auto/quickjs | 15 +++++++++++++++ nginx/config | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/auto/quickjs b/auto/quickjs index 00fcbc0b8..f14617d5f 100644 --- a/auto/quickjs +++ b/auto/quickjs @@ -49,6 +49,21 @@ if [ $NJS_TRY_QUICKJS = YES ]; then . auto/feature fi + if [ $njs_found = no ]; then + if command -v pkg-config >/dev/null 2>&1 && pkg-config --exists quickjs-ng; then + + # pkg-config + + njs_feature="QuickJS-NG library via pkg-config" + + njs_feature_incs="$NJS_QUICKJS_DEFAULT_INCS" + njs_feature_incs="$njs_feature_incs $(pkg-config quickjs-ng --cflags-only-I | sed -e 's/-I//g')" + njs_feature_libs=$(pkg-config quickjs-ng --libs) + + . auto/feature + fi + fi + if [ $njs_found = no ]; then njs_feature="QuickJS-NG library -lqjs" njs_feature_incs="$NJS_QUICKJS_DEFAULT_INCS" diff --git a/nginx/config b/nginx/config index 9d16ddd47..5e2d9277f 100644 --- a/nginx/config +++ b/nginx/config @@ -63,6 +63,21 @@ if [ $NJS_QUICKJS != NO ]; then . auto/feature fi + if [ $ngx_found = no ]; then + if command -v pkg-config >/dev/null 2>&1 && pkg-config --exists quickjs-ng; then + + # pkg-config + + ngx_feature="QuickJS-NG library via pkg-config" + + ngx_feature_path="$NJS_QUICKJS_DEFAULT_INCS" + ngx_feature_path="$ngx_feature_path $(pkg-config quickjs-ng --cflags-only-I | sed -e 's/-I//g')" + ngx_feature_libs=$(pkg-config quickjs-ng --libs) + + . auto/feature + fi + fi + if [ $ngx_found = no ]; then ngx_feature="QuickJS-NG library -lqjs" ngx_feature_path="$NJS_QUICKJS_DEFAULT_INCS" From 1abc7a57a37e0ca6f611d2c27e5ab653de597511 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Tue, 18 Nov 2025 17:54:45 -0800 Subject: [PATCH 4/5] CI: using meson and pkg-config for QuickJS-NG. --- .github/workflows/check-pr.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/check-pr.yml b/.github/workflows/check-pr.yml index b64adbacb..03b0c3dbf 100644 --- a/.github/workflows/check-pr.yml +++ b/.github/workflows/check-pr.yml @@ -29,7 +29,7 @@ jobs: sudo apt-get install \ libssl-dev zlib1g-dev libpcre2-dev libxslt1-dev libgeoip-dev \ libgd-dev libxml2-dev libedit-dev libperl-dev libtest-harness-perl \ - libgd-perl libgeoip-dev expect + libgd-perl libgeoip-dev expect meson ninja-build - name: Install x86 build dependencies run: | @@ -56,8 +56,10 @@ jobs: git clone https://github.com/quickjs-ng/quickjs quickjs-ng cd quickjs-ng git checkout v0.11.0 - CFLAGS="$CC_OPT -fPIC" LDFLAGS=$LD_OPT cmake -B build - cmake --build build --target qjs -j $(nproc) + CFLAGS="$CC_OPT -fPIC" LDFLAGS=$LD_OPT meson setup build --prefix=$HOME/.local --libdir=lib + meson compile -C build + meson install -C build + echo "PKG_CONFIG_PATH=$HOME/.local/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV - name: Configure and make njs run: | @@ -103,8 +105,8 @@ jobs: run: | ./configure \ --with-quickjs \ - --cc-opt="$CC_OPT -Iquickjs-ng" \ - --ld-opt="$LD_OPT -Lquickjs-ng/build" \ + --cc-opt="$CC_OPT" \ + --ld-opt="$LD_OPT" \ || cat build/autoconf.err $MAKE_UTILITY -j$(nproc) @@ -214,7 +216,7 @@ jobs: - name: Configure and build nginx and njs modules with quickjs-ng, asan, static modules run: | cd nginx-source - $NGINX_CONFIGURE_CMD --with-cc-opt="$CC_OPT -I${{ github.workspace }}/quickjs-ng -fsanitize=address -DNJS_DEBUG_MEMORY -DNGX_DEBUG_PALLOC -DNGX_DEBUG_MALLOC" --with-ld-opt="$LD_OPT -L${{ github.workspace }}/quickjs-ng/build -fsanitize=address" --add-module=../nginx || cat objs/autoconf.err + $NGINX_CONFIGURE_CMD --with-cc-opt="$CC_OPT -fsanitize=address -DNJS_DEBUG_MEMORY -DNGX_DEBUG_PALLOC -DNGX_DEBUG_MALLOC" --with-ld-opt="$LD_OPT -fsanitize=address" --add-module=../nginx || cat objs/autoconf.err $MAKE_UTILITY -j$(nproc) - name: Test njs modules, quickjs-ng, static modules @@ -242,7 +244,7 @@ jobs: - name: Configure and build nginx and njs modules with quickjs-ng, asan, dynamic modules run: | cd nginx-source - $NGINX_CONFIGURE_CMD --with-debug --with-cc-opt="$CC_OPT -I${{ github.workspace }}/quickjs-ng -fsanitize=address -DNJS_DEBUG_MEMORY -DNGX_DEBUG_PALLOC -DNGX_DEBUG_MALLOC" --with-ld-opt="$LD_OPT -L${{ github.workspace }}/quickjs-ng/build -fsanitize=address" --add-dynamic-module=../nginx || cat objs/autoconf.err + $NGINX_CONFIGURE_CMD --with-debug --with-cc-opt="$CC_OPT -fsanitize=address -DNJS_DEBUG_MEMORY -DNGX_DEBUG_PALLOC -DNGX_DEBUG_MALLOC" --with-ld-opt="$LD_OPT -fsanitize=address" --add-dynamic-module=../nginx || cat objs/autoconf.err $MAKE_UTILITY -j$(nproc) modules $MAKE_UTILITY -j$(nproc) From 9f92555a0a69ea89b7ae5a47655bf89897f838be Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Tue, 18 Nov 2025 17:57:37 -0800 Subject: [PATCH 5/5] CI: cancel stale workflows. --- .github/workflows/check-pr.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/check-pr.yml b/.github/workflows/check-pr.yml index 03b0c3dbf..d71addbd0 100644 --- a/.github/workflows/check-pr.yml +++ b/.github/workflows/check-pr.yml @@ -3,6 +3,10 @@ name: check-pr on: pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + jobs: build: runs-on: [ ubuntu-24.04 ]