Skip to content

Commit

Permalink
[Support] Canonicalise ws2_32 casing, fix MinGW cross compilation
Browse files Browse the repository at this point in the history
This originally used the spelling Ws2_32 when added in
a5ffabc, but was changed to WS2_32
in 042a2e8 with the intent to
use the canonical spelling from WinSDK, in order to aid cross
compilation from case sensitive file systems with WinSDK.

However, the WinSDK itself is self-inconsistent with respect
to file name cases. Headers refer to each other with many different
casings, so the original, out of the box casing doesn't work
on case sensitive file systems. Import libraries like these
use a variety of casings (some use all lowercase, some use
CamelCase, some all uppercase, and the suffix is either .lib,
.Lib or .LIB).

In order to use the WinSDK on a case sensitive file system, these
case issues has to be worked around somehow. Either by lowercasing
all files (and the #includes within them, and potentially keeping
symlinks with their original casing), or by setting up a Clang
case insensitive VFS overlay. LLVM's llvm/cmake/platforms/WinMsvc.cmake
sets up such a VFS overlay. For the linker, it creates a directory
with lowercase symlinks.

Therefore, the canonical way of handling these casing issues on
case sensitive file systems is to consistently use lowercase. That
is also what MinGW toolchains use.

As an example, the same list of system_libs refers to advapi32,
even if the actual file on disk in WinSDK is AdvAPI32.Lib.

Likewise, other in-tree build systems that picked up this change
for ws2_32 made it all lowercase, in
b07aaf8 and
d22dad9. This also matches other
existing references to ws2_32 in e.g.
lldb/source/Plugins/Process/Windows/Common/CMakeLists.txt and
lldb/source/Utility/CMakeLists.txt.
  • Loading branch information
mstorsjo committed Dec 14, 2023
1 parent b7fc782 commit 554e4df
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ endif()
if( MSVC OR MINGW )
# libuuid required for FOLDERID_Profile usage in lib/Support/Windows/Path.inc.
# advapi32 required for CryptAcquireContextW in lib/Support/Windows/Path.inc.
set(system_libs ${system_libs} psapi shell32 ole32 uuid advapi32 WS2_32)
set(system_libs ${system_libs} psapi shell32 ole32 uuid advapi32 ws2_32)
elseif( CMAKE_HOST_UNIX )
if( HAVE_LIBRT )
set(system_libs ${system_libs} rt)
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-config/system-libs.windows.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ RUN: llvm-config --link-static --system-libs Support 2>&1 | FileCheck %s
REQUIRES: static-libs
REQUIRES: host={{.*-windows-msvc}}
CHECK-NOT: -l
CHECK: psapi.lib shell32.lib ole32.lib uuid.lib advapi32.lib WS2_32.lib
CHECK: psapi.lib shell32.lib ole32.lib uuid.lib advapi32.lib ws2_32.lib
CHECK-NOT: error
CHECK-NOT: warning

0 comments on commit 554e4df

Please sign in to comment.