uNetworking / uWebSockets

Simple, secure & standards compliant web server for the most demanding of applications
Apache License 2.0
17.24k stars 1.75k forks source link

OSX compilation/usage issue #1149

Closed ludekvodicka closed 3 years ago

ludekvodicka commented 3 years ago

Hi there, should uWebSockets work also under OSX? I'm building multi-platform app including OSX and it seems there is an issue with thread_local in Clang compiler.

When compiling my app, in file Loop.h (https://github.com/uNetworking/uWebSockets/blob/master/src/Loop.h#L74) there is following LoopCleaner struct and thread_local usage:

 struct LoopCleaner {
        ~LoopCleaner() {
            if(loop && cleanMe) {
                loop->free();
            }
        }
        Loop *loop = nullptr;
        bool cleanMe = false;
    };

    static LoopCleaner &getLazyLoop() {
        static thread_local LoopCleaner lazyLoop;
        return lazyLoop;
    }

It seems that in OSX there can't be a complex destructor for thread_local types:

In file included from uwebsockets/include/uwebsockets/App.h:24:
In file included from uwebsockets/include/uwebsockets/HttpContext.h:23:
uwebsockets/include/uwebsockets/Loop.h:85:41: error: type of thread-local variable has non-trivial destruction
        static thread_local LoopCleaner lazyLoop;
                                        ^
uwebsockets/Loop.h:85:41: note: use 'thread_local' to allow this
ghost commented 3 years ago

We build every commit on macOS:

https://github.com/uNetworking/uWebSockets/runs/1602572214

How are you building it?

ludekvodicka commented 3 years ago

The mentioned test seems to compile only uSockets, not the project with included uWebsockets.

The issue is in uWebsockets/src/Loop.h not in uSockets/src/loop.c

ghost commented 3 years ago

It does compile everything. I added a new step that lists the compiled binaries.

ludekvodicka commented 3 years ago

Thanks. Maybe the difference is in the compiler? I'm trying it on the 10.15 Catalina OSX with clang++ shipped with the Xcode 12.1:

clang++ --version
Apple clang version 12.0.0 (clang-1200.0.32.21)
Target: x86_64-apple-darwin19.6.0
ludekvodicka commented 3 years ago

I just followed the exact steps from the GitHub Actions and this compilation works for me too. So it's probably caused by some switch in our application configuration. I will inspect it more and let you know.

glingy commented 3 years ago

One side-note, I am using a Mac with gcc 10 compiled and installed with home-brew, and everything has been compiling fine. I tried using clang, but it didn't seem up-to-date with c++20.

ghost commented 3 years ago

We do compile on macOS with default compiler (clang) without issues. You can look in the Makefile for inspiration.