Skip to content

Commit b1e8e26

Browse files
committed
feature: added dynamic module support.
bugfix: FFI availability feature test was broken on Windows. bugfix: we now avoided passing -DLUA_DEFAULT_PATH=... and -DLUA_DEFAULT_CPATH=... options via CFLAGS. This is know to cause problems in some cases. openresty/openresty#587. bugfix: some LuaJIT related feature tests may cause unwanted C compiler errors due to `#endif;`.
1 parent 29dec04 commit b1e8e26

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ html_out/
5656
ebooks.sh
5757
*.pdf
5858
*.patch
59+
src/ngx_stream_lua_autoconf.h

config

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,17 @@ else
153153
fi
154154
fi
155155

156+
ngx_module_incs=
157+
ngx_module_libs=
158+
156159
if [ $ngx_found = yes ]; then
157160
# this is a hack to persuade nginx's build system to favor
158161
# the paths set by our user environment
159162
CFLAGS="$ngx_lua_opt_I $CFLAGS"
160163
NGX_LD_OPT="$ngx_lua_opt_L $NGX_LD_OPT"
161164

162-
CORE_INCS="$CORE_INCS $ngx_feature_path"
163-
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
165+
ngx_module_incs="$ngx_module_incs $ngx_feature_path"
166+
ngx_module_libs="$ngx_module_libs $ngx_feature_libs"
164167
else
165168
cat << END
166169
$0: error: ngx_stream_lua_module requires the LuaJIT library.
@@ -175,7 +178,8 @@ ngx_feature_run=no
175178
ngx_feature_incs="#include <luajit.h>"
176179
ngx_feature_test="#if !defined(LUAJIT_VERSION_NUM) || LUAJIT_VERSION_NUM < 20000
177180
# error unsupported LuaJIT version
178-
#endif"
181+
#endif
182+
"
179183

180184
. auto/feature
181185

@@ -193,7 +197,8 @@ ngx_feature_run=no
193197
ngx_feature_incs="#include <lua.h>"
194198
ngx_feature_test="#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM != 501
195199
# error unsupported Lua language version
196-
#endif"
200+
#endif
201+
"
197202

198203
. auto/feature
199204

@@ -207,14 +212,17 @@ fi
207212
# ----------------------------------------
208213

209214
ngx_feature="LuaJIT has FFI"
210-
ngx_feature_libs="$LUAJIT_LIB/libluajit-5.1.a $luajit_ld_opt"
211-
ngx_feature_run=yes
215+
CC_TEST_FLAGS="$ngx_lua_opt_I $CFLAGS"
216+
ngx_feature_libs="$ngx_module_libs"
217+
ngx_feature_run=no
212218
ngx_feature_incs="#include <lualib.h>
213219
#include <lauxlib.h>
214-
#include <assert.h>"
220+
#include <assert.h>
221+
"
215222
ngx_feature_test="lua_State *L = luaL_newstate();
216223
assert(L != NULL);
217-
luaopen_ffi(L);"
224+
luaopen_ffi(L);
225+
"
218226

219227
. auto/feature
220228

@@ -228,7 +236,7 @@ fi
228236
# ----------------------------------------
229237

230238
ngx_addon_name=ngx_stream_lua_module
231-
NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
239+
STREAM_LUA_SRCS=" \
232240
$ngx_addon_dir/src/ngx_stream_lua_api.c \
233241
$ngx_addon_dir/src/ngx_stream_lua_request.c \
234242
$ngx_addon_dir/src/ngx_stream_lua_module.c \
@@ -274,8 +282,9 @@ NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
274282
$ngx_addon_dir/src/ngx_stream_lua_input_filters.c \
275283
"
276284

277-
NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
285+
STREAM_LUA_DEPS=" \
278286
$ngx_addon_dir/src/ddebug.h \
287+
$ngx_addon_dir/src/ngx_stream_lua_autoconf.h \
279288
$ngx_addon_dir/src/api/ngx_stream_lua_api.h \
280289
$ngx_addon_dir/src/ngx_stream_lua_request.h \
281290
$ngx_addon_dir/src/ngx_stream_lua_common.h \
@@ -316,8 +325,6 @@ NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
316325
$ngx_addon_dir/src/ngx_stream_lua_input_filters.h \
317326
"
318327

319-
STREAM_MODULES="$STREAM_MODULES $ngx_addon_name"
320-
321328
# ----------------------------------------
322329

323330
ngx_feature="export symbols by default (-E)"
@@ -379,6 +386,24 @@ ngx_feature_test='struct sigaction act;
379386

380387
# ----------------------------------------
381388

389+
if [ -n "$ngx_module_link" ]; then
390+
ngx_module_type=STREAM
391+
ngx_module_name=$ngx_addon_name
392+
ngx_module_deps="$STREAM_LUA_DEPS"
393+
ngx_module_srcs="$STREAM_LUA_SRCS"
394+
395+
. auto/module
396+
else
397+
STREAM_MODULES="$STREAM_MODULES $ngx_addon_name"
398+
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $STREAM_LUA_SRCS"
399+
NGX_ADDON_DEPS="$NGX_ADDON_DEPS $STREAM_LUA_DEPS"
400+
401+
CORE_INCS="$CORE_INCS $ngx_module_incs"
402+
CORE_LIBS="$CORE_LIBS $ngx_module_libs"
403+
fi
404+
405+
# ----------------------------------------
406+
382407
if [ $USE_PCRE = YES -o $PCRE != NONE ] && [ $PCRE != NO -a $PCRE != YES ]; then
383408
# force pcre_version symbol to be required when PCRE is statically linked
384409
case "$NGX_PLATFORM" in
@@ -426,5 +451,4 @@ USE_SHA1=YES
426451

427452
CORE_INCS="$CORE_INCS $ngx_addon_dir/src/api"
428453

429-
#CFLAGS=$"$CFLAGS -DLUA_DEFAULT_PATH='\"/usr/local/openresty/lualib/?.lua\"'"
430-
#CFLAGS=$"$CFLAGS -DLUA_DEFAULT_CPATH='\"/usr/local/openresty/lualib/?.so\"'"
454+
echo "/* DO NOT EDIT! This file was automatically generated by config */" > "$ngx_addon_dir/src/ngx_stream_lua_autoconf.h"

src/ngx_stream_lua_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#define _NGX_STREAM_LUA_COMMON_H_INCLUDED_
1818

1919

20+
#include "ngx_stream_lua_autoconf.h"
21+
2022
#include <nginx.h>
2123
#include <ngx_core.h>
2224
#include <ngx_stream.h>

0 commit comments

Comments
 (0)