diff --git a/.github/workflows/check-pr.yml b/.github/workflows/check-pr.yml index d5e0edd27..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 ] @@ -29,7 +33,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: | @@ -55,9 +59,11 @@ jobs: run: | git clone https://github.com/quickjs-ng/quickjs quickjs-ng cd quickjs-ng - git checkout v0.9.0 - CFLAGS="$CC_OPT -fPIC" LDFLAGS=$LD_OPT cmake -B build - cmake --build build --target qjs -j $(nproc) + git checkout v0.11.0 + 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 +109,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 +220,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 +248,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) diff --git a/auto/quickjs b/auto/quickjs index 8d6b544f9..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" @@ -136,6 +151,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/nginx/config b/nginx/config index 3386dac08..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" @@ -87,21 +102,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||"` 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_ */