From 00aa84f570dff7005d7bbfe1f4e9811fc0093926 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Wed, 20 Sep 2023 05:50:37 +0200 Subject: [PATCH] Fix Mingw cross-compilation. The previous pull request broke compilation with the Mingw toolchain, which does not provide . Moreover, this massive header was only used to expand a macro that generates a static volatile variable under the hood (which is not necessary here). Replace it with with a simpler and more portable code path to fix the build. Also, ensure that a broken DiskInterfaceTest, which was only disabled when using the Microsoft compiler, is also disabled for Mingw (note that the whole test code is inside a #ifdef _WIN32 .. #endif block). After this patch, a `ninja_test.exe` generated on Linux with the Mingw toolchain runs and succeeds properly on a Windows machine. --- src/disk_interface.cc | 20 +++++++++++++------- src/disk_interface_test.cc | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/disk_interface.cc b/src/disk_interface.cc index ed064e1555..0f27e9da44 100644 --- a/src/disk_interface.cc +++ b/src/disk_interface.cc @@ -23,10 +23,10 @@ #include #ifdef _WIN32 -#include -#include #include // _mkdir -#include +#include + +#include #else #include #endif @@ -162,10 +162,16 @@ RealDiskInterface::RealDiskInterface() #ifdef _WIN32 : use_cache_(false), long_paths_enabled_(false) { setlocale(LC_ALL, ""); - IFDYNAMICGETCACHEDFUNCTIONTYPEDEF(L"ntdll", BOOLEAN(WINAPI*)(), - "RtlAreLongPathsEnabled", - RtlAreLongPathsEnabled) { - long_paths_enabled_ = RtlAreLongPathsEnabled(); + + // Probe ntdll.dll for RtlAreLongPathsEnabled, and call it if it exists. + HINSTANCE ntdll_lib = ::GetModuleHandleW(L"ntdll"); + if (ntdll_lib) { + typedef BOOLEAN(WINAPI FunctionType)(); + auto* func_ptr = reinterpret_cast( + ::GetProcAddress(ntdll_lib, "RtlAreLongPathsEnabled")); + if (func_ptr) { + long_paths_enabled_ = (*func_ptr)(); + } } } #else diff --git a/src/disk_interface_test.cc b/src/disk_interface_test.cc index e8d869c871..3164a1bae4 100644 --- a/src/disk_interface_test.cc +++ b/src/disk_interface_test.cc @@ -171,7 +171,7 @@ TEST_F(DiskInterfaceTest, StatCache) { EXPECT_GT(disk_.Stat("subdir/subsubdir", &err), 1); EXPECT_EQ("", err); -#ifndef _MSC_VER // TODO: Investigate why. Also see https://github.com/ninja-build/ninja/pull/1423 +#ifndef _WIN32 // TODO: Investigate why. Also see https://github.com/ninja-build/ninja/pull/1423 EXPECT_EQ(disk_.Stat("subdir", &err), disk_.Stat("subdir/.", &err)); EXPECT_EQ("", err);