Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AK: Simplify usage of windows.h and winsock2.h #2674

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
AK: Simplify usage of windows.h and winsock2.h
Use <AK/Windows.h> instead of windows.h/winsock2.h
to avoid timeval-related errors.

Note: winsock2.h includes windows.h
  • Loading branch information
stasoid committed Dec 18, 2024
commit 1b033355f62a853fe303da6a99d68fd722564392
4 changes: 1 addition & 3 deletions AK/Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#include <AK/Time.h>

#ifdef AK_OS_WINDOWS
# define timeval dummy_timeval
# include <windows.h>
# undef timeval
# include <AK/Windows.h>
#endif

namespace AK {
Expand Down
20 changes: 20 additions & 0 deletions AK/Windows.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2024, stasoid <stasoid@yahoo.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

// This header should be included only in cpp files.
// It should be included after all other files and should be separated from them by a non-#include line to prevent clang-format from changing header order.

#pragma once

#include <AK/Platform.h>

#ifdef AK_OS_WINDOWS // needed for Swift
# define timeval dummy_timeval
# include <winsock2.h>
# undef timeval
# pragma comment(lib, "ws2_32.lib")
# include <io.h>
#endif
4 changes: 0 additions & 4 deletions Libraries/LibCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,3 @@ endif()
if (ANDROID)
target_link_libraries(LibCore PRIVATE log)
endif()

if (WIN32)
target_link_libraries(LibCore PRIVATE ws2_32.lib)
endif()
4 changes: 2 additions & 2 deletions Libraries/LibCore/EventLoopImplementationWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <LibCore/EventLoopImplementationWindows.h>
#include <LibCore/Notifier.h>
#include <LibCore/ThreadEventQueue.h>
#include <WinSock2.h>
#include <io.h>

#include <AK/Windows.h>

struct Handle {
HANDLE handle = NULL;
Expand Down
Loading