Skip to content

Conversation

@orgads
Copy link
Contributor

@orgads orgads commented Mar 22, 2023

I'm not sure if the changes in nginx/config are the right way to do this, but it works for me :)

@xeioex
Copy link
Contributor

xeioex commented Mar 23, 2023

@orgads
Definitely, depending on xlst module is a bad idea.
When the module sets ngx_module_libs=".. LIBXSLT" it specifically asks nginx to discover libxlst library, not xslt module.
We may consider adding an ENV variable as a controlling option for nginx/config, but I am still looking for a way how other modules do it.

@orgads
Copy link
Contributor Author

orgads commented Apr 9, 2023

Rebased and changed to LIBXSLT.

@kuPyxa
Copy link

kuPyxa commented May 2, 2023

+1. Waiting for merge.

@xeioex
Copy link
Contributor

xeioex commented May 6, 2023

@orgads

I prepared a patch for nginx on this issue. Let's see whether it will be approved.

https://mailman.nginx.org/pipermail/nginx-devel/2023-May/IRFMVPTAGBUN3XDPQ4OTUKAK3I2FIJFS.html

@xeioex
Copy link
Contributor

xeioex commented May 11, 2023

hi @orgads,

Consider the following patch:

# HG changeset patch
# User Dmitry Volyntsev <[email protected]>
# Date 1683783413 25200
#      Wed May 10 22:36:53 2023 -0700
# Node ID 1f84f3c34bb08b3489040319aac5cd46ca172bec
# Parent  a140e71b0fbf55a3f85adfa8b0de8e282e293fac
Modules: added options to disable parts dependant on 3rd party libs.

The following environment variables are added: NJS_OPENSSL, NJS_LIBXSLT,
NJS_ZLIB.  When a variable evaluates to "NO" the part of the module
related to the corresponsing library is disabled.

For example to disable libxslt related code:
    NJS_LIBXSLT=NO ./configure  .. --add-module=/path/to/njs/module

diff --git a/nginx/config b/nginx/config
--- a/nginx/config
+++ b/nginx/config
@@ -1,13 +1,42 @@
 ngx_addon_name="ngx_js_module"
 
+NJS_OPENSSL=${NJS_OPENSSL:-YES}
+NJS_LIBXSLT=${NJS_LIBXSLT:-YES}
+NJS_ZLIB=${NJS_ZLIB:-YES}
+
 NJS_DEPS="$ngx_addon_dir/ngx_js.h \
     $ngx_addon_dir/ngx_js_fetch.h"
 NJS_SRCS="$ngx_addon_dir/ngx_js.c \
     $ngx_addon_dir/ngx_js_fetch.c \
-    $ngx_addon_dir/ngx_js_regex.c \
-    $ngx_addon_dir/../external/njs_webcrypto_module.c
-    $ngx_addon_dir/../external/njs_zlib_module.c
-    $ngx_addon_dir/../external/njs_xml_module.c"
+    $ngx_addon_dir/ngx_js_regex.c"
+
+NJS_OPENSSL_LIB=
+NJS_XSLT_LIB=
+NJS_ZLIB_LIB=
+
+if [ $NJS_OPENSSL != NO ]; then
+    NJS_OPENSSL_LIB=OPENSSL
+    have=NJS_HAVE_OPENSSL . auto/have
+    NJS_SRCS="$NJS_SRCS $ngx_addon_dir/../external/njs_webcrypto_module.c"
+
+    echo " enabled webcrypto module"
+fi
+
+if [ $NJS_LIBXSLT != NO ]; then
+    NJS_XSLT_LIB=LIBXSLT
+    have=NJS_HAVE_XML . auto/have
+    NJS_SRCS="$NJS_SRCS $ngx_addon_dir/../external/njs_xml_module.c"
+
+    echo " enabled xml module"
+fi
+
+if [ $NJS_ZLIB != NO ]; then
+    NJS_ZLIB_LIB=ZLIB
+    have=NJS_HAVE_ZLIB . auto/have
+    NJS_SRCS="$NJS_SRCS $ngx_addon_dir/../external/njs_zlib_module.c"
+
+    echo " enabled zlib module"
+fi
 
 if [ $HTTP != NO ]; then
     ngx_module_type=HTTP_AUX_FILTER
@@ -15,7 +44,8 @@ if [ $HTTP != NO ]; then
     ngx_module_incs="$ngx_addon_dir/../src $ngx_addon_dir/../build"
     ngx_module_deps="$ngx_addon_dir/../build/libnjs.a $NJS_DEPS"
     ngx_module_srcs="$ngx_addon_dir/ngx_http_js_module.c $NJS_SRCS"
-    ngx_module_libs="PCRE OPENSSL ZLIB LIBXSLT $ngx_addon_dir/../build/libnjs.a -lm"
+    ngx_module_libs="PCRE $NJS_OPENSSL_LIB $NJS_XSLT_LIB $NJS_ZLIB_LIB \
+                     $ngx_addon_dir/../build/libnjs.a -lm"
 
     . auto/module
 
@@ -30,7 +60,8 @@ if [ $STREAM != NO ]; then
     ngx_module_incs="$ngx_addon_dir/../src $ngx_addon_dir/../build"
     ngx_module_deps="$ngx_addon_dir/../build/libnjs.a $NJS_DEPS"
     ngx_module_srcs="$ngx_addon_dir/ngx_stream_js_module.c $NJS_SRCS"
-    ngx_module_libs="PCRE OPENSSL ZLIB LIBXSLT $ngx_addon_dir/../build/libnjs.a -lm"
+    ngx_module_libs="PCRE $NJS_OPENSSL_LIB $NJS_XSLT_LIB $NJS_ZLIB_LIB \
+                     $ngx_addon_dir/../build/libnjs.a -lm"
 
     . auto/module
 fi
diff --git a/nginx/ngx_js.c b/nginx/ngx_js.c
--- a/nginx/ngx_js.c
+++ b/nginx/ngx_js.c
@@ -88,9 +88,15 @@ static njs_external_t  ngx_js_ext_core[]
 
 
 njs_module_t *njs_js_addon_modules[] = {
+#ifdef NJS_HAVE_OPENSSL
     &njs_webcrypto_module,
+#endif
+#ifdef NJS_HAVE_XML
     &njs_xml_module,
+#endif
+#ifdef NJS_HAVE_ZLIB
     &njs_zlib_module,
+#endif
     NULL,
 };

@orgads
Copy link
Contributor Author

orgads commented May 11, 2023

Looks good, thanks!

@xeioex
Copy link
Contributor

xeioex commented May 11, 2023

Committed in cd1ac80.

@xeioex xeioex closed this May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants