Skip to content

Commit

Permalink
[Web] Disable UNIX sockets
Browse files Browse the repository at this point in the history
They are not supported anyway, emscripten has an emulation layer that
implements them over WebSocket/WebRTC, which is really surprising for
users, and also not very useful since we have proper WebSocket and
WebRTC support.

This can make the build smaller, if we also disable the UPNP module
(which will otherwise include a third party library referencing "socket"
thus forcing emscripten to include the compatibility layer)
  • Loading branch information
Faless committed Nov 8, 2024
1 parent 87318a2 commit b400de1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions drivers/unix/net_socket_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#include "core/io/net_socket.h"

#ifndef UNIX_SOCKET_UNAVAILABLE

#if defined(WINDOWS_ENABLED)
#include <winsock2.h>
#include <ws2tcpip.h>
Expand Down Expand Up @@ -105,4 +107,6 @@ class NetSocketPosix : public NetSocket {
~NetSocketPosix();
};

#endif

#endif // NET_SOCKET_POSIX_H
4 changes: 4 additions & 0 deletions drivers/unix/os_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ void OS_Unix::initialize_core() {
DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_USERDATA);
DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_FILESYSTEM);

#ifndef UNIX_SOCKET_UNAVAILABLE
NetSocketPosix::make_default();
#endif
IPUnix::make_default();
process_map = memnew((HashMap<ProcessID, ProcessInfo>));

Expand All @@ -175,7 +177,9 @@ void OS_Unix::initialize_core() {

void OS_Unix::finalize_core() {
memdelete(process_map);
#ifndef UNIX_SOCKET_UNAVAILABLE
NetSocketPosix::cleanup();
#endif
}

Vector<String> OS_Unix::get_video_adapter_driver_info() const {
Expand Down
2 changes: 1 addition & 1 deletion platform/web/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def configure(env: "SConsEnvironment"):
sys.exit(255)

env.Prepend(CPPPATH=["#platform/web"])
env.Append(CPPDEFINES=["WEB_ENABLED", "UNIX_ENABLED"])
env.Append(CPPDEFINES=["WEB_ENABLED", "UNIX_ENABLED", "UNIX_SOCKET_UNAVAILABLE"])

if env["opengl3"]:
env.AppendUnique(CPPDEFINES=["GLES3_ENABLED"])
Expand Down

0 comments on commit b400de1

Please sign in to comment.