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

Conversation

stasoid
Copy link
Contributor

@stasoid stasoid commented Dec 1, 2024

Use <AK/windows.h> instead of windows.h/winsock2.h to avoid timeval-related errors.

@ladybird-bot
Copy link
Collaborator

Hello!

One or more of the commit messages in this PR do not match the Ladybird code submission policy, please check the lint_commits CI job for more details on which commits were flagged and why.
Please do not close this PR and open another, instead modify your commit message(s) with git commit --amend and force push those changes to update this PR.

@stasoid stasoid marked this pull request as draft December 1, 2024 09:49
@stasoid stasoid force-pushed the windows.h branch 3 times, most recently from 676d4fd to cc61467 Compare December 1, 2024 10:51
@R-Goc
Copy link
Contributor

R-Goc commented Dec 1, 2024

This is not like for like. Winsock isn't the same as windows. So if we name it windows.h we should be including windows.h. winsock is only for the sockets. Maybe we can include both in AK/Windows.h.

@stasoid
Copy link
Contributor Author

stasoid commented Dec 1, 2024

winsock2.h includes windows.h, no need to include both.

@R-Goc
Copy link
Contributor

R-Goc commented Dec 1, 2024

Didn't know that. Then it's fine. Is there anything else we might want here?

@stasoid
Copy link
Contributor Author

stasoid commented Dec 1, 2024

Maybe, we will know when we need that.

@stasoid stasoid marked this pull request as ready for review December 1, 2024 11:53
@R-Goc
Copy link
Contributor

R-Goc commented Dec 4, 2024

Any reason this starts with lower case specifically?

@stasoid
Copy link
Contributor Author

stasoid commented Dec 4, 2024

Just my preference.

@R-Goc
Copy link
Contributor

R-Goc commented Dec 4, 2024

This doesn't match convention in AK, nor the normal name for it. Causes a compilation error due to non-portable-include if you write with uppercase.

@stasoid
Copy link
Contributor Author

stasoid commented Dec 4, 2024

Not matching the AK convention is deliberate. I wanted this file to be different because it is a special platform header, it doesn't define any classes/functions in AK namespace. The same goes for sockaddr-win.h.

The "normal" name for <windows.h> debatable, but I think it is more lowercase than titlecase. MSDN examples use lowercase, Visual Studio templates use lowercase. I saw lowercase version much more often in real code. Also, this header is supposed to include everything from win32 API that is not included by other headers (like sockets and time), so it doesn't directly correspond to <windows.h> and doesn't have to follow its conventions.

But again, it is more a matter of preference. If maintainers make me change it I'll change it, but for now I want to keep lowercase.

AK/windows.h Outdated
Comment on lines 9 to 14
#ifdef AK_OS_WINDOWS // needed for Swift
# define timeval dummy_timeval
# include <winsock2.h>
# undef timeval
# include <io.h>
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idea: be more restrictive with ideas like in the following?

Suggested change
#ifdef AK_OS_WINDOWS // needed for Swift
# define timeval dummy_timeval
# include <winsock2.h>
# undef timeval
# include <io.h>
#endif
#ifndef AK_OS_WINDOWS
static_assert(false, "Windows header included on non-Windows target");
#endif
// needed for Swift
#define timeval dummy_timeval
#include <winsock2.h>
#undef timeval
#include <io.h>

@stasoid stasoid mentioned this pull request Dec 7, 2024
@ADKaster
Copy link
Member

ADKaster commented Dec 9, 2024

But again, it is more a matter of preference. If maintainers make me change it I'll change it, but for now I want to keep lowercase.

Consider this a maintainer request to change the names of any headers added in your PRs to Titlecase, regardless of how platform-specific they are. :)

AK/windows.h Outdated Show resolved Hide resolved
AK/windows.h Outdated

#pragma once

#ifdef AK_OS_WINDOWS // needed for Swift
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "needed for swift" comment is confusing. Have you tried enabling swift on windows?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is related to wanting to error out on other platforms if they include this header, the path to it will need updated in the ENABLE_SWIFT branch of AK/CMakeLists.txt to be an EXCLUDED path for the Swift bridging header. See LibCore for an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added #ifdef to fix this error. LibCore (or other libs) doesn't have the word EXCLUDED in their CMakeLists files. Can you provide the exact line that should be added to exclude Windows.h?

Copy link
Contributor Author

@stasoid stasoid Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, found it: set(SWIFT_EXCLUDE_HEADERS ... in LibGfx.

Copy link
Contributor Author

@stasoid stasoid Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding set(SWIFT_EXCLUDE_HEADERS Windows.h) to AK/CMakeLists.txt didn't fix the problem (same error), so I am still using #ifdef.

@stasoid
Copy link
Contributor Author

stasoid commented Dec 9, 2024

@ADKaster I changed it to title case, but note that AK already has similar platform-specific files, kmalloc.h/.cpp, and they use lowercase. I think you are wrong on this one.

@stasoid
Copy link
Contributor Author

stasoid commented Dec 9, 2024

@awesomekling Can you comment on this ^^^ ? (Platform-specific windows.h vs Windows.h in AK)

@stasoid stasoid force-pushed the windows.h branch 2 times, most recently from 8e15027 to a36425f Compare December 9, 2024 02:44
@trflynn89
Copy link
Contributor

kmalloc.h is an ancient artifact from Serenity's kernel using AK. It is not a good argument to break naming conventions in new files.

@stasoid stasoid force-pushed the windows.h branch 3 times, most recently from 5e38c90 to 4c7b143 Compare December 9, 2024 05:03
@stasoid stasoid force-pushed the windows.h branch 4 times, most recently from 8fa05a1 to 7bb10ff Compare December 9, 2024 08:28
@awesomekling
Copy link
Member

@awesomekling Can you comment on this ^^^ ? (Platform-specific windows.h vs Windows.h in AK)

Please conform to project convention and name it Windows.h

@stasoid stasoid requested a review from ADKaster December 9, 2024 13:17
@stasoid
Copy link
Contributor Author

stasoid commented Dec 9, 2024

@ADKaster I renamed the file and added AK/Platform.h, but was unable to get rid of #ifdef.

@github-actions github-actions bot added the conflicts Pull request has merge conflicts that need resolution label Dec 18, 2024
Copy link

Your pull request has conflicts that need to be resolved before it can be reviewed and merged. Make sure to rebase your branch on top of the latest master.

Use <AK/Windows.h> instead of windows.h/winsock2.h
to avoid timeval-related errors.

Note: winsock2.h includes windows.h
@github-actions github-actions bot removed the conflicts Pull request has merge conflicts that need resolution label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants