wandenberg / nginx-push-stream-module

A pure stream http push technology for your Nginx setup. Comet made easy and really scalable.
Other
2.21k stars 295 forks source link

Compilation fails on Mac OS/Clang 14.X.X #304

Closed dobrite closed 1 year ago

dobrite commented 1 year ago

We are on Mac M2's attempting to compile nginx-push-stream-module into nginx (among other plugins). Compilation fails on a warning-turned-error. My guess is that recent Clang versions set to Werror turned on Wunused-but-set-variable. This is the line that is failing, and the flags set:

                -o objs/addon/src/ngx_http_push_stream_module.o \
        /tmp/nginx-push-stream-module/src/ngx_http_push_stream_module.c
   cc -c -I/opt/homebrew/Cellar/luajit-openresty/2.1-20230119/include/luajit-2.1  -pipe  -O -Wall -Wextra -Wpointer-arith -Wconditional-uninitialized -Wno-unused-parameter -Wno-deprecated-declarations -Werror -g -I/usr/local/include -I/opt/homebrew/Cellar/pcre/8.45/include -I/opt/homebrew/Cellar/openssl@1.1/1.1.1t/include -I/opt/homebrew/Cellar/luajit-openresty/2.1-20230119/include/luajit-2.1 -DNDK_SET_VAR -I src/core -I src/event -I src/event/modules -I src/os/unix -I /tmp/ngx_devel_kit-0.3.1/objs -I objs/addon/ndk -I /tmp/lua-nginx-module-0.10.13/src/api -I /tmp/nginx-push-stream-module/src -I /tmp/nginx-push-stream-module/include -I objs \
        -o objs/ngx_modules.o \
        objs/ngx_modules.c
   sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
        -e "s|%%PID_PATH%%|/usr/local/var/run/nginx.pid|" \
        -e "s|%%CONF_PATH%%|/usr/local/etc/nginx/nginx.conf|" \
        -e "s|%%ERROR_LOG_PATH%%|/usr/local/var/log/nginx/error.log|" \
        < man/nginx.8 > objs/nginx.8
   In file included from /tmp/nginx-push-stream-module/src/ngx_http_push_stream_module.c:29:
   /tmp/nginx-push-stream-module/src/ngx_http_push_stream_module_utils.c:2382:13: error: variable 'len' set but not used [-Werror,-Wunused-but-set-variable]
       size_t  len;
               ^
   1 error generated.
   make[1]: *** [objs/addon/src/ngx_http_push_stream_module.o] Error 1
   make[1]: *** Waiting for unfinished jobs....
   make: *** [build] Error 2

Clang version

~ cc --version
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

What did not work was:

ngx_flag_t
ngx_http_push_stream_is_utf8(u_char *p, size_t n)
{
    u_char  c, *last;

    last = p + n;

    for (size_t len = 0; p < last; len++) {

        c = *p;

    /* more...*/

What did work, but might not be the best approach (admittedly I do not know much C).

ngx_flag_t
ngx_http_push_stream_is_utf8(u_char *p, size_t n)
{
    u_char  c, *last;
    size_t  len __attribute__((unused));

    last = p + n;

    for (len = 0; p < last; len++) {

        c = *p;

    /* more...*/

In any case, we added -Wno-unused-but-set-variable to our compilation flags and were able to get past the error. Just reporting this issue so 1) others can see the issue and solution, and 2) that a fix can get upstreamed.

Appreciate all the work over the years!

sunnychun commented 1 year ago

您的信已收到,我将尽快给您答复

wandenberg commented 1 year ago

Thanks for the report. Fixed on the master branch.