www-nginx/njs: new package, add 0.9.4

njs[1] is a "subset of JavaScript language to use in NGINX".

The primary dependency is dev-libs/quickjs-ng. The package consists of
roughly two parts: libnjs (including libqjs), and the actual njs_module.
libnjs is configured and built first in order to use the correct ar and
explicitly control other options (e.g. dependencies like OpenSSL, zlib
etc).

[1]: https://github.com/nginx/njs

Closes: https://bugs.gentoo.org/959735
Signed-off-by: Zurab Kvachadze <zurabid2016@gmail.com>
Part-of: https://github.com/gentoo/gentoo/pull/44669
Closes: https://github.com/gentoo/gentoo/pull/44669
Signed-off-by: Sam James <sam@gentoo.org>
This commit is contained in:
Zurab Kvachadze
2025-11-19 03:48:49 +01:00
committed by Sam James
parent 71ff86d1b6
commit 84802aaafa
5 changed files with 314 additions and 0 deletions

1
www-nginx/njs/Manifest Normal file
View File

@@ -0,0 +1 @@
DIST njs-0.9.4.tar.gz 939082 BLAKE2B f0035edaf72fd5ef1768b3dbd13492105a1885d89c3d2ec97814d3b8e2606a4444eccff4500c7f55a5a92aa4eca1bfa96f1f541d04a971dc60d787c5f76ee8fc SHA512 50b72b9e38dc54b0d013baeff4b00f1857f5b218333d1f090188fbb3bcafcd580edf6807b498002d418bd70490d3c7c16fa5133417aca9faa6f45bf1562020ae

View File

@@ -0,0 +1,85 @@
The initial suggestion and discussion: https://github.com/nginx/njs/pull/990
The subsequent (authored by a maintainer?) PR: https://github.com/nginx/njs/pull/993
diff --git a/auto/cc b/auto/cc
index 8a615ec4..d4b28489 100644
--- a/auto/cc
+++ b/auto/cc
@@ -64,7 +64,6 @@ case $NJS_CC_NAME in
gcc)
njs_define=NJS_GCC . auto/define
- NJS_CFLAGS="$NJS_CFLAGS -pipe"
NJS_CFLAGS="$NJS_CFLAGS -fPIC"
# Do not export symbols except explicitly marked with NJS_EXPORT.
@@ -72,9 +71,6 @@ case $NJS_CC_NAME in
# c99/gnu99 conflict with Solaris XOPEN.
#NJS_CFLAGS="$NJS_CFLAGS -std=gnu99"
-
- NJS_CFLAGS="$NJS_CFLAGS -O"
- #NJS_CFLAGS="$NJS_CFLAGS -O0"
NJS_CFLAGS="$NJS_CFLAGS -W -Wall -Wextra"
#NJS_CFLAGS="$NJS_CFLAGS -Wunused-result"
@@ -94,12 +90,6 @@ case $NJS_CC_NAME in
NJS_CFLAGS="$NJS_CFLAGS -Wmissing-prototypes"
- # Stop on warning.
- NJS_CFLAGS="$NJS_CFLAGS -Werror"
-
- # Debug.
- NJS_CFLAGS="$NJS_CFLAGS -g"
-
if [ "$NJS_ADDRESS_SANITIZER" = "YES" ]; then
NJS_CFLAGS="$NJS_CFLAGS -fsanitize=address"
NJS_CFLAGS="$NJS_CFLAGS -fno-omit-frame-pointer"
@@ -109,14 +99,11 @@ case $NJS_CC_NAME in
clang)
njs_define=NJS_CLANG . auto/define
- NJS_CFLAGS="$NJS_CFLAGS -pipe"
NJS_CFLAGS="$NJS_CFLAGS -fPIC"
# Do not export symbols except explicitly marked with NJS_EXPORT.
NJS_CFLAGS="$NJS_CFLAGS -fvisibility=hidden"
- NJS_CFLAGS="$NJS_CFLAGS -O"
- #NJS_CFLAGS="$NJS_CFLAGS -O0"
NJS_CFLAGS="$NJS_CFLAGS -W -Wall -Wextra"
#NJS_CFLAGS="$NJS_CFLAGS -Wunused-result"
@@ -130,17 +117,6 @@ case $NJS_CC_NAME in
NJS_CFLAGS="$NJS_CFLAGS -Wmissing-prototypes"
- # Stop on warning.
- NJS_CFLAGS="$NJS_CFLAGS -Werror"
-
- # Debug.
-
- if [ "$NJS_SYSTEM_PLATFORM" != "powerpc" ]; then
- # "-g" flag causes the "unknown pseudo-op: `.cfi_sections'"
- # error on PowerPC Clang.
- NJS_CFLAGS="$NJS_CFLAGS -g"
- fi
-
if [ "$NJS_ADDRESS_SANITIZER" = "YES" ]; then
NJS_CFLAGS="$NJS_CFLAGS -fsanitize=address"
NJS_CFLAGS="$NJS_CFLAGS -fno-omit-frame-pointer"
diff --git a/auto/options b/auto/options
index 0a4dc6c7..c3399062 100644
--- a/auto/options
+++ b/auto/options
@@ -3,8 +3,8 @@
# Copyright (C) NGINX, Inc.
-NJS_CC_OPT=${NJS_CC_OPT:--O}
-NJS_LD_OPT=${NJS_CC_OPT:--O}
+NJS_CC_OPT=
+NJS_LD_OPT=
NJS_DEBUG=NO
NJS_DEBUG_MEMORY=NO

View File

@@ -0,0 +1,88 @@
Original proposal: https://github.com/nginx/njs/pull/988
Enhanced version merged upstream in: https://github.com/nginx/njs/pull/989
diff --git a/src/quickjs_compat.h b/src/quickjs_compat.h
index 3b7a618c7..7753086d3 100644
--- a/src/quickjs_compat.h
+++ b/src/quickjs_compat.h
@@ -22,3 +22,7 @@
#ifndef JS_BOOL
#define JS_BOOL bool
#endif
+
+#ifdef QUICKJS_NG
+ #define JS_IsError(cx, val) JS_IsError(val)
+#endif
diff --git a/auto/quickjs b/auto/quickjs
index 8d6b544f9..c574c83f3 100644
--- a/auto/quickjs
+++ b/auto/quickjs
@@ -7,6 +7,10 @@ NJS_QUICKJS_LIB=
NJS_HAVE_QUICKJS=NO
NJS_QUICKJS_DEFAULT_INCS="src $NJS_BUILD_DIR"
+# Alternative pkg-config binary can be supplied by setting the PKG_CONFIG
+# environment variable.
+: "${PKG_CONFIG:=pkg-config}"
+
if [ $NJS_TRY_QUICKJS = YES ]; then
njs_found=no
@@ -57,6 +61,20 @@ if [ $NJS_TRY_QUICKJS = YES ]; then
. auto/feature
fi
+ if [ $njs_found = no ]; then
+ njs_feature="QuickJS-NG library via pkg-config"
+
+ flags="$("${PKG_CONFIG}" --cflags-only-I quickjs-ng)"
+ # Trim the -I prefix from includes.
+ pkg_config_includes="$(printf "%s\n" "$flags" | sed 's|-I||g')"
+ pkg_config_libs="$("${PKG_CONFIG}" --libs quickjs-ng)"
+
+ njs_feature_incs="$NJS_QUICKJS_DEFAULT_INCS ${pkg_config_includes}"
+ njs_feature_libs="-lm -ldl -lpthread ${pkg_config_libs}"
+
+ . auto/feature
+ fi
+
if [ $njs_found = yes ]; then
diff --git a/nginx/config b/nginx/config
index 3386dac08..0a74cd969 100644
--- a/nginx/config
+++ b/nginx/config
@@ -26,6 +26,10 @@ NJS_QUICKJS_INC=
NJS_QUICKJS_DEFAULT_INCS="$ngx_addon_dir/../src $ngx_addon_dir/../build"
NJS_HAVE_QUICKJS=
+# Alternative pkg-config binary can be supplied by setting the PKG_CONFIG
+# environment variable.
+: "${PKG_CONFIG:=pkg-config}"
+
if [ $NJS_QUICKJS != NO ]; then
ngx_feature="QuickJS library -lquickjs.lto"
@@ -71,6 +75,21 @@ if [ $NJS_QUICKJS != NO ]; then
. auto/feature
fi
+ if [ $ngx_found = no ]; then
+ ngx_feature="QuickJS-NG library via pkg-config"
+
+ flags="$("${PKG_CONFIG}" --cflags-only-I quickjs-ng)"
+ # Trim the -I prefix from includes.
+ pkg_config_includes="$(printf "%s\n" "$flags" | sed 's|-I||g')"
+ pkg_config_libs="$("${PKG_CONFIG}" --libs quickjs-ng)"
+
+ ngx_feature_path="$NJS_QUICKJS_DEFAULT_INCS ${pkg_config_includes}"
+ ngx_feature_libs="-lm -ldl -lpthread ${pkg_config_libs}"
+
+ . auto/feature
+ fi
+
+
if [ $ngx_found = yes ]; then
ngx_feature="QuickJS JS_GetClassID()"

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "https://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
<maintainer type="person" proxied="yes">
<email>zurabid2016@gmail.com</email>
<name>Zurab Kvachadze</name>
</maintainer>
<maintainer type="project" proxied="proxy">
<email>proxy-maint@gentoo.org</email>
<name>Proxy Maintainers</name>
</maintainer>
<use>
<flag name="tools">Build the command-line utility njs</flag>
</use>
<longdescription>
NGINX JavaScript, also known as NJS, is a dynamic module for NGINX that enables the
extension of built-in functionality using familiar JavaScript syntax. The NJS language is a
subset of JavaScript, compliant with ES5 (ECMAScript 5.1 Strict Variant) with some ES6
(ECMAScript 6) and newer extensions.
</longdescription>
<upstream>
<bugs-to>https://github.com/nginx/njs/issues</bugs-to>
<remote-id type="github">nginx/njs</remote-id>
</upstream>
</pkgmetadata>

View File

@@ -0,0 +1,115 @@
# Copyright 1999-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
NGINX_MOD_CONFIG_DIR="nginx"
inherit edo nginx-module toolchain-funcs
DESCRIPTION="A subset of JavaScript language to use in NGINX"
HOMEPAGE="https://github.com/nginx/njs https://nginx.org/en/docs/njs/"
SRC_URI="
https://github.com/nginx/njs/archive/refs/tags/${PV}.tar.gz -> ${P}.tar.gz
"
LICENSE="BSD-2"
SLOT="0"
KEYWORDS="~amd64"
IUSE="tools +ssl +xml +zlib"
RDEPEND="
dev-libs/quickjs-ng:=
tools? (
dev-libs/libpcre2:=
sys-libs/readline:=
)
ssl? ( dev-libs/openssl:= )
xml? (
dev-libs/libxml2:=
dev-libs/libxslt:=
)
zlib? ( virtual/zlib:= )
"
DEPEND="${RDEPEND}"
BDEPEND="virtual/pkgconfig"
PATCHES=(
# Note: drop on the next upgrade, has been merged upstream as PR 989.
"${FILESDIR}/${PN}-0.9.4-support-quickjs-ng.patch"
"${FILESDIR}/${PN}-0.9.4-do-not-add-opt-debug-cflags.patch"
)
src_configure() {
## The core part, i.e. libnjs and libqjs.
local myargs=(
--build-dir=build
--cc="$(tc-getCC)"
--ld-opt="${LDFLAGS}"
--ar="$(tc-getAR)"
)
local nocliargs=(
--no-openssl
--no-libxml2
--no-zlib
)
if use tools; then
use !ssl && myargs+=( '--no-openssl' )
use !xml && myargs+=( '--no-libxml2' )
use !zlib && myargs+=( '--no-zlib' )
else
myargs+=( "${nocliargs[@]}" )
fi
pushd "${NGINX_MOD_S}" >/dev/null || die "pushd failed"
edo ./configure "${myargs[@]}"
popd >/dev/null || die "popd failed"
## The NGINX module part.
# Build the stream module unconditionally.
sed -i "s/\\\$STREAM/YES/" "${NGINX_MOD_S}/${NGINX_MOD_CONFIG_DIR}/config" ||
die "sed failed"
# Export PKG_CONFIG for pkg-config-based QuickJS-NG detection.
tc-export PKG_CONFIG
if use ssl; then
# Because NGINX build system refuses to link OPENSSL and ZLIB normally
# like other libraries.
ngx_mod_link_lib openssl
else
local -x NJS_OPENSSL=NO
fi
if use zlib; then
# Ditto.
ngx_mod_link_lib zlib
else
local -x NJS_ZLIB=NO
fi
use !xml && local -x NJS_LIBXSLT=NO
nginx-module_src_configure
}
src_compile() {
# Build the core first.
if use tools; then
emake -C "${NGINX_MOD_S}"
else
emake -C "${NGINX_MOD_S}" libnjs libqjs
fi
nginx-module_src_compile
}
src_install() {
use tools && dobin "${NGINX_MOD_S}"/build/njs
nginx-module_src_install
}