diff -Naur folly-2025.06.16.00-orig/CMake/FollyConfigChecks.cmake folly-2025.06.16.00/CMake/FollyConfigChecks.cmake
--- folly-2025.06.16.00-orig/CMake/FollyConfigChecks.cmake	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/CMake/FollyConfigChecks.cmake	2025-06-17 11:05:27.043694600 +0300
@@ -24,12 +24,6 @@
   list(APPEND FOLLY_CXX_FLAGS -Wno-psabi)
 endif()
 
-if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
-  CHECK_INCLUDE_FILE_CXX(malloc_np.h FOLLY_USE_JEMALLOC)
-else()
-  CHECK_INCLUDE_FILE_CXX(jemalloc/jemalloc.h FOLLY_USE_JEMALLOC)
-endif()
-
 if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
   # clang only rejects unknown warning flags if -Werror=unknown-warning-option
   # is also specified.
diff -Naur folly-2025.06.16.00-orig/CMake/folly-config.cmake.in folly-2025.06.16.00/CMake/folly-config.cmake.in
--- folly-2025.06.16.00-orig/CMake/folly-config.cmake.in	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/CMake/folly-config.cmake.in	2025-06-17 11:05:27.085003500 +0300
@@ -29,10 +29,21 @@
 set(FOLLY_LIBRARIES Folly::folly)
 
 # Find folly's dependencies
-find_dependency(fmt)
+find_dependency(fmt CONFIG)
+find_dependency(double-conversion CONFIG)
+find_dependency(FastFloat CONFIG)
+set(GFLAGS_USE_TARGET_NAMESPACE ON)
+find_dependency(gflags CONFIG)
+find_dependency(glog CONFIG)
+find_dependency(Libevent CONFIG)
+find_dependency(ZLIB)
+find_dependency(lz4 CONFIG)
+find_dependency(zstd CONFIG)
+find_dependency(Snappy CONFIG)
+find_dependency(sodium CONFIG)
 
 set(Boost_USE_STATIC_LIBS "@FOLLY_BOOST_LINK_STATIC@")
-find_dependency(Boost 1.51.0 MODULE
+find_dependency(Boost
   COMPONENTS
     context
     filesystem
diff -Naur folly-2025.06.16.00-orig/CMake/folly-deps.cmake folly-2025.06.16.00/CMake/folly-deps.cmake
--- folly-2025.06.16.00-orig/CMake/folly-deps.cmake	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/CMake/folly-deps.cmake	2025-06-17 11:05:27.085003500 +0300
@@ -25,7 +25,7 @@
 )
 if("${BOOST_LINK_STATIC}" STREQUAL "auto")
   # Default to linking boost statically on Windows with MSVC
-  if(MSVC)
+  if(WIN32)
     set(FOLLY_BOOST_LINK_STATIC ON)
   else()
     set(FOLLY_BOOST_LINK_STATIC OFF)
@@ -35,7 +35,7 @@
 endif()
 set(Boost_USE_STATIC_LIBS "${FOLLY_BOOST_LINK_STATIC}")
 
-find_package(Boost 1.51.0 MODULE
+find_package(Boost
   COMPONENTS
     context
     filesystem
@@ -45,35 +45,91 @@
     thread
   REQUIRED
 )
+set(Boost_LIBRARIES Boost::boost Boost::context Boost::filesystem Boost::program_options Boost::regex Boost::system Boost::thread)
 list(APPEND FOLLY_LINK_LIBRARIES ${Boost_LIBRARIES})
 list(APPEND FOLLY_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS})
 
-find_package(DoubleConversion MODULE REQUIRED)
-list(APPEND FOLLY_LINK_LIBRARIES ${DOUBLE_CONVERSION_LIBRARY})
-list(APPEND FOLLY_INCLUDE_DIRECTORIES ${DOUBLE_CONVERSION_INCLUDE_DIR})
-
-find_package(FastFloat MODULE REQUIRED)
-list(APPEND FOLLY_INCLUDE_DIRECTORIES ${FASTFLOAT_INCLUDE_DIR})
-
-find_package(Gflags MODULE)
-set(FOLLY_HAVE_LIBGFLAGS ${LIBGFLAGS_FOUND})
-if(LIBGFLAGS_FOUND)
-  list(APPEND FOLLY_LINK_LIBRARIES ${LIBGFLAGS_LIBRARY})
-  list(APPEND FOLLY_INCLUDE_DIRECTORIES ${LIBGFLAGS_INCLUDE_DIR})
-  set(FOLLY_LIBGFLAGS_LIBRARY ${LIBGFLAGS_LIBRARY})
-  set(FOLLY_LIBGFLAGS_INCLUDE ${LIBGFLAGS_INCLUDE_DIR})
-endif()
-
-find_package(Glog MODULE)
-set(FOLLY_HAVE_LIBGLOG ${GLOG_FOUND})
-list(APPEND FOLLY_LINK_LIBRARIES ${GLOG_LIBRARY})
-list(APPEND FOLLY_INCLUDE_DIRECTORIES ${GLOG_INCLUDE_DIR})
-
-find_package(LibEvent MODULE REQUIRED)
-list(APPEND FOLLY_LINK_LIBRARIES ${LIBEVENT_LIB})
-list(APPEND FOLLY_INCLUDE_DIRECTORIES ${LIBEVENT_INCLUDE_DIR})
+option(BUILD_WITH_JEMALLOC "Add support using jemalloc" OFF)
+if (BUILD_WITH_JEMALLOC)
+  if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
+    CHECK_INCLUDE_FILE_CXX(malloc_np.h FOLLY_USE_JEMALLOC)
+  else()
+    find_package(LibJemalloc MODULE)
+    set(FOLLY_USE_JEMALLOC ${LIBJEMALLOC_FOUND})
+    if(FOLLY_USE_JEMALLOC)
+      list(APPEND FOLLY_LINK_LIBRARIES ${LIBJEMALLOC_LIBRARY})
+      list(APPEND FOLLY_INCLUDE_DIRECTORIES ${LIBJEMALLOC_INCLUDE_DIR})
+    endif()
+  endif()
+endif()
+
+find_package(double-conversion CONFIG REQUIRED)
+if(double-conversion_FOUND)
+  if (TARGET double-conversion::double-conversion)
+    get_target_property(DOUBLE_CONVERSION_LIBRARY double-conversion::double-conversion IMPORTED_LOCATION)
+    if (NOT DOUBLE_CONVERSION_LIBRARY)
+      get_target_property(DOUBLE_CONVERSION_LIBRARY double-conversion::double-conversion IMPORTED_LOCATION_RELEASE)
+    endif ()
+    message(STATUS "double-conversion::double-conversion library: ${DOUBLE_CONVERSION_LIBRARY}")
+  endif ()
+  list(APPEND FOLLY_LINK_LIBRARIES double-conversion::double-conversion)
+  list(APPEND FOLLY_INCLUDE_DIRECTORIES ${DOUBLE_CONVERSION_INCLUDE_DIR})
+endif()
+
+find_package(FastFloat CONFIG REQUIRED)
+list(APPEND FOLLY_LINK_LIBRARIES FastFloat::fast_float)
+
+set(GFLAGS_USE_TARGET_NAMESPACE ON)
+find_package(gflags REQUIRED)
+set(FOLLY_HAVE_LIBGFLAGS ${gflags_FOUND})
+if(gflags_FOUND)
+  if (TARGET gflags::gflags)
+    get_target_property(LIBGFLAGS_LIBRARY gflags::gflags IMPORTED_LOCATION)
+    if (NOT LIBGFLAGS_LIBRARY)
+      get_target_property(LIBGFLAGS_LIBRARY gflags::gflags IMPORTED_LOCATION_RELEASE)
+    endif ()
+    message(STATUS "gflags::gflags library: ${LIBGFLAGS_LIBRARY}")
+  endif ()
+  list(APPEND FOLLY_LINK_LIBRARIES gflags::gflags)
+  list(APPEND FOLLY_INCLUDE_DIRECTORIES ${gflags_INCLUDE_DIR})
+endif()
+
+find_package(glog REQUIRED)
+set(FOLLY_HAVE_LIBGLOG ${glog_FOUND})
+if(glog_FOUND)
+  if (TARGET glog::glog)
+    get_target_property(GLOG_LIBRARY glog::glog IMPORTED_LOCATION)
+    if (NOT GLOG_LIBRARY)
+      get_target_property(GLOG_LIBRARY glog::glog IMPORTED_LOCATION_RELEASE)
+    endif ()
+    message(STATUS "glog::glog library: ${GLOG_LIBRARY}")
+  endif ()
+  list(APPEND FOLLY_LINK_LIBRARIES glog::glog)
+  list(APPEND FOLLY_INCLUDE_DIRECTORIES ${GLOG_INCLUDE_DIR})
+endif()
+
+set(OPENSSL_USE_STATIC_LIBS ON)
+set(LIBEVENT_STATIC_LINK ON)
+find_package(Libevent CONFIG REQUIRED)
+set(FOLLY_HAVE_LIBEVENT ${Libevent_FOUND})
+if(Libevent_FOUND)
+  if (TARGET libevent::core)
+    get_target_property(LIBEVENT_CORE_LIBRARY libevent::core IMPORTED_LOCATION)
+    if (NOT LIBEVENT_CORE_LIBRARY)
+      get_target_property(LIBEVENT_CORE_LIBRARY libevent::core IMPORTED_LOCATION_RELEASE)
+    endif ()
+    message(STATUS "libevent::core library: ${LIBEVENT_CORE_LIBRARY}")
+  endif ()
+  set(LIBEVENT_LIBS libevent::core libevent::extra)
+  if(NOT WIN32)
+    list(APPEND LIBEVENT_LIBS libevent::pthreads)
+  endif()
+  list(APPEND FOLLY_LINK_LIBRARIES ${LIBEVENT_LIBS})
+  list(APPEND FOLLY_INCLUDE_DIRECTORIES ${LIBEVENT_INCLUDE_DIR})
+endif()
 
 find_package(ZLIB MODULE)
+set(ZLIB_LIBRARIES ZLIB::ZLIB)
 set(FOLLY_HAVE_LIBZ ${ZLIB_FOUND})
 if (ZLIB_FOUND)
   list(APPEND FOLLY_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRS})
@@ -81,7 +137,8 @@
   list(APPEND CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARIES})
 endif()
 
-find_package(OpenSSL 1.1.1 MODULE REQUIRED)
+find_package(OpenSSL CONFIG REQUIRED)
+message(STATUS "OpenSSL library: ${OPENSSL_LIBRARIES}")
 list(APPEND FOLLY_LINK_LIBRARIES ${OPENSSL_LIBRARIES})
 list(APPEND FOLLY_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR})
 list(APPEND CMAKE_REQUIRED_LIBRARIES ${OPENSSL_LIBRARIES})
@@ -92,11 +149,18 @@
     list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARIES})
 endif()
 
-find_package(BZip2 MODULE)
-set(FOLLY_HAVE_LIBBZ2 ${BZIP2_FOUND})
-if (BZIP2_FOUND)
+find_package(BZip2 CONFIG)
+set(FOLLY_HAVE_LIBBZ2 ${BZip2_FOUND})
+if (BZip2_FOUND)
+  if (TARGET BZip2::BZip2)
+    get_target_property(BZIP2_LIBRARIES BZip2::BZip2 IMPORTED_LOCATION)
+    if (NOT BZIP2_LIBRARIES)
+      get_target_property(BZIP2_LIBRARIES BZip2::BZip2 IMPORTED_LOCATION_RELEASE)
+    endif ()
+    message(STATUS "BZip2::BZip2 library: ${BZIP2_LIBRARIES}")
+  endif ()
   list(APPEND FOLLY_INCLUDE_DIRECTORIES ${BZIP2_INCLUDE_DIRS})
-  list(APPEND FOLLY_LINK_LIBRARIES ${BZIP2_LIBRARIES})
+  list(APPEND FOLLY_LINK_LIBRARIES BZip2::BZip2)
 endif()
 
 find_package(LibLZMA MODULE)
@@ -106,25 +170,40 @@
   list(APPEND FOLLY_LINK_LIBRARIES ${LIBLZMA_LIBRARIES})
 endif()
 
-find_package(LZ4 MODULE)
-set(FOLLY_HAVE_LIBLZ4 ${LZ4_FOUND})
-if (LZ4_FOUND)
+find_package(lz4 CONFIG)
+set(FOLLY_HAVE_LIBLZ4 ${lz4_FOUND})
+if (lz4_FOUND)
+  if (TARGET lz4::lz4)
+    get_target_property(LZ4_LIBRARY lz4::lz4 IMPORTED_LOCATION)
+    if (NOT LZ4_LIBRARY)
+      get_target_property(LZ4_LIBRARY lz4::lz4 IMPORTED_LOCATION_RELEASE)
+    endif ()
+    message(STATUS "lz4::lz4 library: ${LZ4_LIBRARY}")
+  endif ()
   list(APPEND FOLLY_INCLUDE_DIRECTORIES ${LZ4_INCLUDE_DIR})
-  list(APPEND FOLLY_LINK_LIBRARIES ${LZ4_LIBRARY})
+  list(APPEND FOLLY_LINK_LIBRARIES lz4::lz4)
 endif()
 
-find_package(Zstd MODULE)
+find_package(ZSTD CONFIG COMPONENTS zstd::libzstd_static)
+set(ZSTD_LIBRARY zstd::libzstd_static)
 set(FOLLY_HAVE_LIBZSTD ${ZSTD_FOUND})
 if(ZSTD_FOUND)
   list(APPEND FOLLY_INCLUDE_DIRECTORIES ${ZSTD_INCLUDE_DIR})
   list(APPEND FOLLY_LINK_LIBRARIES ${ZSTD_LIBRARY})
 endif()
 
-find_package(Snappy MODULE)
-set(FOLLY_HAVE_LIBSNAPPY ${SNAPPY_FOUND})
-if (SNAPPY_FOUND)
+find_package(Snappy CONFIG)
+set(FOLLY_HAVE_LIBSNAPPY ${Snappy_FOUND})
+if(Snappy_FOUND)
+  if (TARGET Snappy::snappy)
+    get_target_property(SNAPPY_LIBRARY Snappy::snappy IMPORTED_LOCATION)
+    if (NOT SNAPPY_LIBRARY)
+      get_target_property(SNAPPY_LIBRARY Snappy::snappy IMPORTED_LOCATION_RELEASE)
+    endif ()
+    message(STATUS "Snappy::snappy library: ${SNAPPY_LIBRARY}")
+  endif ()
   list(APPEND FOLLY_INCLUDE_DIRECTORIES ${SNAPPY_INCLUDE_DIR})
-  list(APPEND FOLLY_LINK_LIBRARIES ${SNAPPY_LIBRARY})
+  list(APPEND FOLLY_LINK_LIBRARIES Snappy::snappy)
 endif()
 
 find_package(LibDwarf)
@@ -174,7 +253,12 @@
 CHECK_INCLUDE_FILE_CXX(elf.h FOLLY_HAVE_ELF)
 find_package(Backtrace)
 
-set(FOLLY_HAVE_BACKTRACE ${Backtrace_FOUND})
+CHECK_INCLUDE_FILE_CXX(execinfo.h FOLLY_HAVE_EXECINFO)
+if(FOLLY_HAVE_EXECINFO)
+  set(FOLLY_HAVE_BACKTRACE ${Backtrace_FOUND})
+else()
+  set(FOLLY_HAVE_BACKTRACE OFF)
+endif()
 set(FOLLY_HAVE_DWARF ${LIBDWARF_FOUND})
 if (NOT WIN32 AND NOT APPLE)
   set(FOLLY_USE_SYMBOLIZER ON)
@@ -315,7 +399,16 @@
     # Fallback on a normal search on the current system
     find_package(Fmt MODULE REQUIRED)
 endif()
-target_link_libraries(folly_deps INTERFACE fmt::fmt)
+if(fmt_FOUND)
+  if (TARGET fmt::fmt)
+    get_target_property(FMT_LIBRARY fmt::fmt IMPORTED_LOCATION)
+    if (NOT FMT_LIBRARY)
+      get_target_property(FMT_LIBRARY fmt::fmt IMPORTED_LOCATION_RELEASE)
+    endif ()
+    message(STATUS "fmt::fmt library: ${FMT_LIBRARY}")
+  endif ()
+  target_link_libraries(folly_deps INTERFACE fmt::fmt)
+endif()
 
 list(REMOVE_DUPLICATES FOLLY_INCLUDE_DIRECTORIES)
 target_include_directories(folly_deps INTERFACE ${FOLLY_INCLUDE_DIRECTORIES})
diff -Naur folly-2025.06.16.00-orig/CMakeLists.txt folly-2025.06.16.00/CMakeLists.txt
--- folly-2025.06.16.00-orig/CMakeLists.txt	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/CMakeLists.txt	2025-06-17 11:05:27.085003500 +0300
@@ -134,6 +134,9 @@
 
 include(folly-deps) # Find the required packages
 include(FollyConfigChecks)
+if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND MINGW)
+  set(FOLLY_HAVE_WEAK_SYMBOLS OFF)
+endif()
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/CMake/folly-config.h.cmake
   ${CMAKE_CURRENT_BINARY_DIR}/folly/folly-config.h
diff -Naur folly-2025.06.16.00-orig/build/fbcode_builder/CMake/FBBuildOptions.cmake folly-2025.06.16.00/build/fbcode_builder/CMake/FBBuildOptions.cmake
--- folly-2025.06.16.00-orig/build/fbcode_builder/CMake/FBBuildOptions.cmake	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/build/fbcode_builder/CMake/FBBuildOptions.cmake	2025-06-17 11:05:27.098901800 +0300
@@ -9,7 +9,7 @@
   # is generally discouraged.
   mark_as_advanced(USE_STATIC_DEPS_ON_UNIX)
 
-  if(UNIX AND USE_STATIC_DEPS_ON_UNIX)
+  if((UNIX OR MINGW) AND USE_STATIC_DEPS_ON_UNIX)
     SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a" PARENT_SCOPE)
   endif()
 endfunction()
diff -Naur folly-2025.06.16.00-orig/folly/CPortability.h folly-2025.06.16.00/folly/CPortability.h
--- folly-2025.06.16.00-orig/folly/CPortability.h	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/CPortability.h	2025-06-17 11:05:27.098901800 +0300
@@ -243,7 +243,7 @@
 #endif
 
 #if defined(__has_attribute)
-#if __has_attribute(weak)
+#if __has_attribute(weak) && !defined(__MINGW32__)
 #define FOLLY_ATTR_WEAK_SYMBOLS_COMPILE_TIME __attribute__((__weak__))
 #else
 #define FOLLY_ATTR_WEAK_SYMBOLS_COMPILE_TIME
diff -Naur folly-2025.06.16.00-orig/folly/FileUtil.cpp folly-2025.06.16.00/folly/FileUtil.cpp
--- folly-2025.06.16.00-orig/folly/FileUtil.cpp	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/FileUtil.cpp	2025-06-17 11:05:27.114607500 +0300
@@ -95,7 +95,7 @@
 int fdatasyncNoInt(int fd) {
 #if defined(__APPLE__)
   return int(wrapNoInt(fcntl, fd, F_FULLFSYNC));
-#elif defined(__FreeBSD__) || defined(_MSC_VER)
+#elif defined(__FreeBSD__) || defined(_WIN32)
   return int(wrapNoInt(fsync, fd));
 #else
   return int(wrapNoInt(fdatasync, fd));
diff -Naur folly-2025.06.16.00-orig/folly/Portability.h folly-2025.06.16.00/folly/Portability.h
--- folly-2025.06.16.00-orig/folly/Portability.h	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/Portability.h	2025-06-17 11:05:27.098901800 +0300
@@ -656,7 +656,7 @@
 #if defined(__NVCC__)
 // For now, NVCC matches other compilers but does not offer coroutines.
 #define FOLLY_HAS_COROUTINES 0
-#elif defined(_WIN32) && defined(__clang__) && !defined(LLVM_COROUTINES) && \
+#elif defined(_MSVC) && defined(__clang__) && !defined(LLVM_COROUTINES) && \
     !defined(LLVM_COROUTINES_CPP20)
 // LLVM and MSVC coroutines are ABI incompatible, so for the MSVC implementation
 // of <experimental/coroutine> on Windows we *don't* have coroutines.
diff -Naur folly-2025.06.16.00-orig/folly/String.cpp folly-2025.06.16.00/folly/String.cpp
--- folly-2025.06.16.00-orig/folly/String.cpp	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/String.cpp	2025-06-17 11:05:27.114607500 +0300
@@ -504,7 +504,7 @@
 
   // https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/strerror_r.3.html
   // http://www.kernel.org/doc/man-pages/online/pages/man3/strerror.3.html
-#if defined(_WIN32) && (defined(__MINGW32__) || defined(_MSC_VER))
+#if defined(_WIN32)
   // mingw64 has no strerror_r, but Windows has strerror_s, which C11 added
   // as well. So maybe we should use this across all platforms (together
   // with strerrorlen_s). Note strerror_r and _s have swapped args.
diff -Naur folly-2025.06.16.00-orig/folly/concurrency/CacheLocality.cpp folly-2025.06.16.00/folly/concurrency/CacheLocality.cpp
--- folly-2025.06.16.00-orig/folly/concurrency/CacheLocality.cpp	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/concurrency/CacheLocality.cpp	2025-06-17 11:05:27.114607500 +0300
@@ -16,7 +16,7 @@
 
 #include <folly/concurrency/CacheLocality.h>
 
-#ifndef _MSC_VER
+#ifndef _WIN32
 #define _GNU_SOURCE 1 // for RTLD_NOLOAD
 #include <dlfcn.h>
 #endif
diff -Naur folly-2025.06.16.00-orig/folly/detail/IPAddressSource.h folly-2025.06.16.00/folly/detail/IPAddressSource.h
--- folly-2025.06.16.00-orig/folly/detail/IPAddressSource.h	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/detail/IPAddressSource.h	2025-06-17 11:05:27.130676100 +0300
@@ -243,7 +243,7 @@
 }
 
 inline size_t fastIpv6ToBufferUnsafe(const in6_addr& in6Addr, char* str) {
-#ifdef _MSC_VER
+#ifdef _WIN32
   const uint16_t* bytes = reinterpret_cast<const uint16_t*>(&in6Addr.u.Word);
 #else
   const uint16_t* bytes = reinterpret_cast<const uint16_t*>(&in6Addr.s6_addr16);
diff -Naur folly-2025.06.16.00-orig/folly/external/farmhash/farmhash.cpp folly-2025.06.16.00/folly/external/farmhash/farmhash.cpp
--- folly-2025.06.16.00-orig/folly/external/farmhash/farmhash.cpp	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/external/farmhash/farmhash.cpp	2025-06-17 11:05:27.141186500 +0300
@@ -126,7 +126,7 @@
 
 #if defined(FARMHASH_UNKNOWN_ENDIAN) || !defined(bswap_64)
 
-#ifdef _MSC_VER
+#ifdef _WIN32
 
 #undef bswap_32
 #undef bswap_64
diff -Naur folly-2025.06.16.00-orig/folly/lang/Exception.cpp folly-2025.06.16.00/folly/lang/Exception.cpp
--- folly-2025.06.16.00-orig/folly/lang/Exception.cpp	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/lang/Exception.cpp	2025-06-17 11:05:27.162393900 +0300
@@ -283,7 +283,7 @@
 
 #endif // defined(__FreeBSD__)
 
-#if defined(_WIN32)
+#if defined(_MSC_VER)
 
 #if defined(__clang__)
 struct _s_ThrowInfo; // compiler intrinsic in msvc
@@ -300,7 +300,7 @@
 void* __GetExceptionInfo(_E); // builtin
 #endif
 
-#endif // defined(_WIN32)
+#endif // defined(_MSC_VER)
 
 //  implementations ---
 
@@ -517,7 +517,7 @@
 
 #endif // defined(__FreeBSD__)
 
-#if defined(_WIN32)
+#if defined(_MSC_VER)
 
 template <typename T>
 static T* win32_decode_pointer(T* ptr) {
@@ -631,7 +631,7 @@
   return nullptr;
 }
 
-#endif // defined(_WIN32)
+#endif // defined(_MSC_VER)
 
 } // namespace detail
 
diff -Naur folly-2025.06.16.00-orig/folly/logging/example/CMakeLists.txt folly-2025.06.16.00/folly/logging/example/CMakeLists.txt
--- folly-2025.06.16.00-orig/folly/logging/example/CMakeLists.txt	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/logging/example/CMakeLists.txt	2025-06-17 11:05:27.171587300 +0300
@@ -13,7 +13,7 @@
 # limitations under the License.
 
 add_executable(logging_example main.cpp)
-target_link_libraries(logging_example logging_example_lib folly)
+target_link_libraries(logging_example logging_example_lib folly ws2_32)
 
 add_library(logging_example_lib lib.cpp)
 target_link_libraries(logging_example_lib folly)
diff -Naur folly-2025.09.29.00-orig/folly/net/detail/SocketFileDescriptorMap.cpp folly-2025.09.29.00/folly/net/detail/SocketFileDescriptorMap.cpp
--- folly-2025.09.29.00-orig/folly/net/detail/SocketFileDescriptorMap.cpp	2025-09-28 07:50:07.000000000 +0300
+++ folly-2025.09.29.00/folly/net/detail/SocketFileDescriptorMap.cpp	2025-10-03 22:27:38.626197600 +0300
@@ -18,6 +18,7 @@
 
 #ifdef _WIN32
 
+#include <mutex>
 #include <shared_mutex>
 #include <unordered_map>
 
@@ -65,15 +65,12 @@
     return -1;
   }
   int c = 0;
-  __try {
+  try {
     // We expect this to fail. It still closes the file descriptor though.
     c = ::_close(fd);
     // We just have to catch the SEH exception that gets thrown when we do
     // this with a debugger attached -_-....
-  } __except (
-      GetExceptionCode() == STATUS_HANDLE_NOT_CLOSABLE
-          ? EXCEPTION_CONTINUE_EXECUTION
-          : EXCEPTION_CONTINUE_SEARCH) {
+  } catch (...) {
     // We told it to continue execution, so nothing here would
     // be run anyways.
   }
diff -Naur folly-2025.06.16.00-orig/folly/net/NetOps.h folly-2025.06.16.00/folly/net/NetOps.h
--- folly-2025.06.16.00-orig/folly/net/NetOps.h	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/net/NetOps.h	2025-06-17 11:05:27.178152800 +0300
@@ -17,6 +17,7 @@
 #pragma once
 
 #include <cstdint>
+#include <memory>
 
 #include <folly/Portability.h>
 #include <folly/net/NetworkSocket.h>
@@ -28,6 +29,12 @@
 #ifdef _WIN32
 
 #include <WS2tcpip.h> // @manual
+#ifdef __MINGW32__
+#include <mswsock.h>
+typedef WSACMSGHDR cmsghdr;
+#define CMSG_SPACE WSA_CMSG_SPACE
+typedef WSACMSGHDR CMSGHDR, *PCMSGHDR;
+#endif
 
 using nfds_t = int;
 using sa_family_t = ADDRESS_FAMILY;
diff -Naur folly-2025.06.16.00-orig/folly/portability/Dirent.cpp folly-2025.06.16.00/folly/portability/Dirent.cpp
--- folly-2025.06.16.00-orig/folly/portability/Dirent.cpp	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/Dirent.cpp	2025-06-17 11:05:27.194147700 +0300
@@ -17,6 +17,7 @@
 #include <folly/portability/Dirent.h>
 
 #ifdef _WIN32
+#include <errno.h>
 #include <stdlib.h>
 #include <string>
 
diff -Naur folly-2025.06.16.00-orig/folly/portability/Fcntl.h folly-2025.06.16.00/folly/portability/Fcntl.h
--- folly-2025.06.16.00-orig/folly/portability/Fcntl.h	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/Fcntl.h	2025-06-17 11:05:27.194147700 +0300
@@ -60,6 +60,9 @@
 
 #ifdef _WIN32
 #define FOLLY_PORT_WIN32_OPEN_BINARY _O_BINARY
+#ifdef __MINGW32__
+#include <share.h>
+#endif
 #else
 #define FOLLY_PORT_WIN32_OPEN_BINARY 0
 #endif
diff -Naur folly-2025.06.16.00-orig/folly/portability/PThread.h folly-2025.06.16.00/folly/portability/PThread.h
--- folly-2025.06.16.00-orig/folly/portability/PThread.h	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/PThread.h	2025-06-17 11:05:27.210312200 +0300
@@ -18,7 +18,7 @@
 
 #include <folly/portability/Config.h>
 
-#if !defined(_WIN32)
+#if FOLLY_HAVE_PTHREAD && !defined(_MSC_VER)
 
 #include <pthread.h>
 
diff -Naur folly-2025.06.16.00-orig/folly/portability/Sched.cpp folly-2025.06.16.00/folly/portability/Sched.cpp
--- folly-2025.06.16.00-orig/folly/portability/Sched.cpp	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/Sched.cpp	2025-06-17 11:05:27.210312200 +0300
@@ -16,7 +16,7 @@
 
 #include <folly/portability/Sched.h>
 
-#ifdef _WIN32
+#if !FOLLY_HAVE_PTHREAD && defined(_WIN32)
 #include <thread>
 
 namespace folly {
diff -Naur folly-2025.06.16.00-orig/folly/portability/Sched.h folly-2025.06.16.00/folly/portability/Sched.h
--- folly-2025.06.16.00-orig/folly/portability/Sched.h	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/Sched.h	2025-06-17 11:05:27.225991300 +0300
@@ -16,7 +16,7 @@
 
 #pragma once
 
-#ifndef _WIN32
+#if FOLLY_HAVE_PTHREAD && !defined(_MSC_VER)
 #include <sched.h>
 #else
 #define SCHED_OTHER 0
diff -Naur folly-2025.06.16.00-orig/folly/portability/Sockets.cpp folly-2025.06.16.00/folly/portability/Sockets.cpp
--- folly-2025.06.16.00-orig/folly/portability/Sockets.cpp	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/Sockets.cpp	2025-06-17 11:05:27.225991300 +0300
@@ -16,7 +16,7 @@
 
 #include <folly/portability/Sockets.h>
 
-#ifdef _MSC_VER
+#ifdef _WIN32
 
 #include <errno.h>
 #include <fcntl.h>
diff -Naur folly-2025.06.16.00-orig/folly/portability/Stdlib.cpp folly-2025.06.16.00/folly/portability/Stdlib.cpp
--- folly-2025.06.16.00-orig/folly/portability/Stdlib.cpp	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/Stdlib.cpp	2025-06-17 11:05:27.225991300 +0300
@@ -29,6 +29,8 @@
 namespace folly {
 namespace portability {
 namespace stdlib {
+
+#ifdef _MSC_VER
 char* mktemp(char* tn) {
   return _mktemp(tn);
 }
@@ -76,6 +78,7 @@
   // I sure hope the caller gave us _MAX_PATH space in the buffer....
   return _fullpath(resolved_path, path, _MAX_PATH);
 }
+#endif
 
 int setenv(const char* name, const char* value, int overwrite) {
   if (overwrite == 0 && getenv(name) != nullptr) {
@@ -165,7 +168,7 @@
     }
   }
 
-  for (auto s : data) {
+  for (const auto& s : data) {
     if (unsetenv(s.c_str()) != 0)
       return -1;
   }
diff -Naur folly-2025.06.16.00-orig/folly/portability/Stdlib.h folly-2025.06.16.00/folly/portability/Stdlib.h
--- folly-2025.06.16.00-orig/folly/portability/Stdlib.h	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/Stdlib.h	2025-06-17 11:05:27.241766600 +0300
@@ -62,9 +62,11 @@
 #endif
 
 #ifdef _WIN32
+#ifdef _MSC_VER
 char* mkdtemp(char* tn);
 int mkstemp(char* tn);
 char* realpath(const char* path, char* resolved_path);
+#endif
 int setenv(const char* name, const char* value, int overwrite);
 int unsetenv(const char* name);
 #endif
diff -Naur folly-2025.06.16.00-orig/folly/portability/String.cpp folly-2025.06.16.00/folly/portability/String.cpp
--- folly-2025.06.16.00-orig/folly/portability/String.cpp	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/String.cpp	2025-06-17 11:05:27.241766600 +0300
@@ -38,6 +38,7 @@
   memset(s, 0, n);
 }
 
+#ifdef _MSC_VER
 int strcasecmp(const char* a, const char* b) {
   return _stricmp(a, b);
 }
@@ -45,6 +46,7 @@
 int strncasecmp(const char* a, const char* b, size_t c) {
   return _strnicmp(a, b, c);
 }
+#endif
 
 char* strtok_r(char* str, char const* delim, char** ctx) {
   return strtok_s(str, delim, ctx);
diff -Naur folly-2025.06.16.00-orig/folly/portability/String.h folly-2025.06.16.00/folly/portability/String.h
--- folly-2025.06.16.00-orig/folly/portability/String.h	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/String.h	2025-06-17 11:05:27.259769900 +0300
@@ -32,8 +32,10 @@
 #ifdef _WIN32
 extern "C" {
 void bzero(void* s, size_t n);
+#ifdef _MSC_VER
 int strcasecmp(const char* a, const char* b);
 int strncasecmp(const char* a, const char* b, size_t c);
+#endif
 char* strtok_r(char* str, char const* delim, char** ctx);
 }
 #endif
diff -Naur folly-2025.06.16.00-orig/folly/portability/SysStat.h folly-2025.06.16.00/folly/portability/SysStat.h
--- folly-2025.06.16.00-orig/folly/portability/SysStat.h	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/SysStat.h	2025-06-17 11:05:27.259769900 +0300
@@ -23,6 +23,7 @@
 #ifdef _WIN32
 #include <folly/portability/SysTypes.h>
 
+#ifdef _MSC_VER
 // Windows gives weird names to these.
 #define S_IXUSR 0
 #define S_IWUSR _S_IWRITE
@@ -40,6 +41,7 @@
 
 #define S_ISDIR(mode) (((mode) & (_S_IFDIR)) == (_S_IFDIR) ? 1 : 0)
 #define S_ISREG(mode) (((mode) & (_S_IFREG)) == (_S_IFREG) ? 1 : 0)
+#endif
 
 // This isn't defined anywhere, so give a sane value.
 #define MAXSYMLINKS 255
diff -Naur folly-2025.06.16.00-orig/folly/portability/SysTime.cpp folly-2025.06.16.00/folly/portability/SysTime.cpp
--- folly-2025.06.16.00-orig/folly/portability/SysTime.cpp	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/SysTime.cpp	2025-06-17 11:05:27.271786500 +0300
@@ -21,6 +21,8 @@
 #include <cstdint>
 
 extern "C" {
+
+#ifdef _MSC_VER
 int gettimeofday(timeval* tv, folly_port_struct_timezone*) {
   constexpr auto posixWinFtOffset = 116444736000000000ULL;
 
@@ -39,6 +41,7 @@
 
   return 0;
 }
+#endif
 
 void timeradd(timeval* a, timeval* b, timeval* res) {
   res->tv_sec = a->tv_sec + b->tv_sec;
diff -Naur folly-2025.06.16.00-orig/folly/portability/SysTime.h folly-2025.06.16.00/folly/portability/SysTime.h
--- folly-2025.06.16.00-orig/folly/portability/SysTime.h	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/SysTime.h	2025-06-17 11:05:27.273556100 +0300
@@ -42,7 +42,9 @@
 // a global field that contains information on the current timezone.
 // As such "timezone" is not a good name to use inside of C/C++ code on
 // Windows.  Instead users should use folly_port_struct_timezone instead.
+#ifdef _MSC_VER
 int gettimeofday(timeval* tv, folly_port_struct_timezone*);
+#endif
 void timeradd(timeval* a, timeval* b, timeval* res);
 void timersub(timeval* a, timeval* b, timeval* res);
 }
diff -Naur folly-2025.06.16.00-orig/folly/portability/SysTypes.h folly-2025.06.16.00/folly/portability/SysTypes.h
--- folly-2025.06.16.00-orig/folly/portability/SysTypes.h	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/SysTypes.h	2025-06-17 11:05:27.283343200 +0300
@@ -24,7 +24,9 @@
 // This is a massive pain to have be an `int` due to the pthread implementation
 // we support, but it's far more compatible with the rest of the windows world
 // as an `int` than it would be as a `void*`
+#ifdef _MSC_VER
 using pid_t = int;
+#endif
 
 using uid_t = int;
 using gid_t = int;
@@ -38,7 +40,10 @@
 #define HAVE_MODE_T 1
 // The Windows headers don't define this anywhere, nor do any of the libs
 // that Folly depends on, so define it here.
+#ifndef _MODE_T_
 using mode_t = unsigned int;
 #endif
 
 #endif
+
+#endif
diff -Naur folly-2025.06.16.00-orig/folly/portability/Time.cpp folly-2025.06.16.00/folly/portability/Time.cpp
--- folly-2025.06.16.00-orig/folly/portability/Time.cpp	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/Time.cpp	2025-06-17 11:05:27.289196400 +0300
@@ -169,6 +169,7 @@
   return result;
 }
 
+#if !FOLLY_HAVE_PTHREAD
 extern "C" int clock_getres(clockid_t clock_id, struct timespec* res) {
   if (!res) {
     errno = EFAULT;
@@ -275,6 +276,7 @@
       return -1;
   }
 }
+#endif
 #else
 #error No clock_gettime(3) compatibility wrapper available for this platform.
 #endif
@@ -287,6 +289,8 @@
 #include <folly/portability/Windows.h>
 
 extern "C" {
+
+#ifdef _MSC_VER
 char* asctime_r(const tm* tm, char* buf) {
   char tmpBuf[64];
   if (asctime_s(tmpBuf, tm)) {
@@ -312,13 +316,6 @@
   return nullptr;
 }
 
-tm* localtime_r(const time_t* t, tm* o) {
-  if (!localtime_s(o, t)) {
-    return o;
-  }
-  return nullptr;
-}
-
 int nanosleep(const struct timespec* request, struct timespec* remain) {
   Sleep((DWORD)((request->tv_sec * 1000) + (request->tv_nsec / 1000000)));
   if (remain != nullptr) {
@@ -327,6 +324,14 @@
   }
   return 0;
 }
+#endif
+
+tm* localtime_r(const time_t* t, tm* o) {
+  if (!localtime_s(o, t)) {
+    return o;
+  }
+  return nullptr;
+}
 
 char* strptime(
     const char* __restrict s,
diff -Naur folly-2025.06.16.00-orig/folly/portability/Time.h folly-2025.06.16.00/folly/portability/Time.h
--- folly-2025.06.16.00-orig/folly/portability/Time.h	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/Time.h	2025-06-17 11:05:27.289196400 +0300
@@ -50,20 +50,24 @@
 #define CLOCK_PROCESS_CPUTIME_ID 2
 #define CLOCK_THREAD_CPUTIME_ID 3
 
+#if !FOLLY_HAVE_PTHREAD
 typedef uint8_t clockid_t;
 extern "C" int clock_gettime(clockid_t clk_id, struct timespec* ts);
 extern "C" int clock_getres(clockid_t clk_id, struct timespec* ts);
 #endif
+#endif
 
 #ifdef _WIN32
 #define TM_YEAR_BASE (1900)
 
 extern "C" {
+#ifdef _MSC_VER
 char* asctime_r(const tm* tm, char* buf);
 char* ctime_r(const time_t* t, char* buf);
 tm* gmtime_r(const time_t* t, tm* res);
-tm* localtime_r(const time_t* t, tm* o);
 int nanosleep(const struct timespec* request, struct timespec* remain);
+#endif
+tm* localtime_r(const time_t* t, tm* o);
 char* strptime(
     const char* __restrict buf,
     const char* __restrict fmt,
diff -Naur folly-2025.06.16.00-orig/folly/portability/Unistd.cpp folly-2025.06.16.00/folly/portability/Unistd.cpp
--- folly-2025.06.16.00-orig/folly/portability/Unistd.cpp	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/Unistd.cpp	2025-06-17 11:05:27.299093100 +0300
@@ -255,9 +255,11 @@
   return _locking(fd, cmd, len);
 }
 
+#ifdef _MSC_VER
 off64_t lseek64(int fh, off64_t off, int orig) {
   return _lseeki64(fh, static_cast<int64_t>(off), orig);
 }
+#endif
 
 ssize_t pread(int fd, void* buf, size_t count, off_t offset) {
   const bool is64Bit = false;
diff -Naur folly-2025.06.16.00-orig/folly/portability/Unistd.h folly-2025.06.16.00/folly/portability/Unistd.h
--- folly-2025.06.16.00-orig/folly/portability/Unistd.h	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/portability/Unistd.h	2025-06-17 11:05:27.305083500 +0300
@@ -59,7 +59,7 @@
 // Windows is weird and doesn't actually defined these
 // for the parameters to access, so we have to do it ourselves -_-...
 #define F_OK 0
-#define X_OK F_OK
+#define X_OK 1
 #define W_OK 2
 #define R_OK 4
 #define RW_OK 6
@@ -78,7 +78,9 @@
 pid_t getppid();
 int getuid();
 int lockf(int fd, int cmd, off_t len);
+#ifdef _MSC_VER
 off64_t lseek64(int fh, off64_t off, int orig);
+#endif
 ssize_t pread(int fd, void* buf, size_t count, off_t offset);
 ssize_t pread64(int fd, void* buf, size_t count, off64_t offset);
 ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset);
diff -Naur folly-2025.06.16.00-orig/folly/system/ThreadId.cpp folly-2025.06.16.00/folly/system/ThreadId.cpp
--- folly-2025.06.16.00-orig/folly/system/ThreadId.cpp	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/system/ThreadId.cpp	2025-06-17 11:05:27.305083500 +0300
@@ -29,7 +29,7 @@
 uint64_t getCurrentThreadID() {
 #if defined(__APPLE__)
   return uint64_t(pthread_mach_thread_np(pthread_self()));
-#elif defined(_WIN32)
+#elif defined(_WIN32) && !defined(FOLLY_HAVE_PTHREAD)
   return uint64_t(GetCurrentThreadId());
 #else
   return uint64_t(pthread_self());
diff -Naur folly-2025.06.16.00-orig/folly/system/ThreadName.cpp folly-2025.06.16.00/folly/system/ThreadName.cpp
--- folly-2025.06.16.00-orig/folly/system/ThreadName.cpp	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/system/ThreadName.cpp	2025-06-17 11:05:27.321075500 +0300
@@ -48,6 +48,8 @@
 // pthread_setname_np was introduced in Android NDK version 9
 #elif defined(__ANDROID__) && __ANDROID_API__ >= 9
 #define FOLLY_HAS_PTHREAD_SETNAME_NP_THREAD_NAME 1
+#elif FOLLY_HAVE_PTHREAD && defined(__MINGW32__)
+#define FOLLY_HAS_PTHREAD_SETNAME_NP_THREAD_NAME 1
 #else
 #define FOLLY_HAS_PTHREAD_SETNAME_NP_THREAD_NAME 0
 #endif
@@ -58,24 +60,51 @@
 #define FOLLY_HAS_PTHREAD_SETNAME_NP_NAME 0
 #endif // defined(__APPLE__)
 
+namespace ns {
+
+struct dummy {};
+using thread_id_access = std::basic_ostream<dummy>;
+
+} // namespace ns
+
+namespace std {
+template <>
+class basic_ostream<ns::dummy> {
+ public:
+  using id_type = std::thread::native_handle_type;
+  id_type id = 0;
+};
+
+template <>
+ns::thread_id_access& operator<<(ns::thread_id_access& os, std::thread::id id) {
+#if defined(_LIBCPP_VERSION)
+  os.id = reinterpret_cast<std::thread::native_handle_type>(id.__id_);
+#elif defined(_GLIBCXX_RELEASE)
+  os.id = reinterpret_cast<std::thread::native_handle_type>(id._M_thread);
+#elif defined(_MSC_VER)
+  os.id = (std::thread::native_handle_type)(id._Id);
+#else
+#error Search your implementation
+#endif
+  return os;
+}
+
+} // namespace std
+
 namespace folly {
 
 namespace {
 
-#if FOLLY_HAVE_PTHREAD && !defined(_WIN32)
+inline auto GetThreadId(std::thread::id id) {
+  ns::thread_id_access t;
+  t << id;
+  return t.id;
+}
+
+#ifdef FOLLY_HAVE_PTHREAD
 pthread_t stdTidToPthreadId(std::thread::id tid) {
-  static_assert(
-      std::is_same<pthread_t, std::thread::native_handle_type>::value,
-      "This assumes that the native handle type is pthread_t");
-  static_assert(
-      sizeof(std::thread::native_handle_type) == sizeof(std::thread::id),
-      "This assumes std::thread::id is a thin wrapper around "
-      "std::thread::native_handle_type, but that doesn't appear to be true.");
-  // In most implementations, std::thread::id is a thin wrapper around
-  // std::thread::native_handle_type, which means we can do unsafe things to
-  // extract it.
-  pthread_t id;
-  std::memcpy(&id, &tid, sizeof(id));
+  auto h = GetThreadId(tid);
+  pthread_t id = reinterpret_cast<pthread_t>(h);
   return id;
 }
 #endif
@@ -235,6 +264,7 @@
 
   TNIUnion tniUnion = {0x1000, trimmed, id, 0};
 
+#ifdef _MSC_VER
   // SEH requires no use of C++ object destruction semantics in this stack
   // frame.
   __try {
@@ -245,20 +275,13 @@
           : EXCEPTION_EXECUTE_HANDLER) {
     // Swallow the exception when a debugger isn't attached.
   }
+#endif
   return true;
 }
 
 bool setThreadNameWindows(std::thread::id tid, StringPiece name) {
-  static_assert(
-      sizeof(DWORD) == sizeof(std::thread::id),
-      "This assumes std::thread::id is a thin wrapper around "
-      "the Win32 thread id, but that doesn't appear to be true.");
-
-  // std::thread::id is a thin wrapper around the Windows thread ID,
-  // so just extract it.
-  DWORD id;
-  std::memcpy(&id, &tid, sizeof(id));
-
+  auto h = GetThreadId(tid);
+  DWORD id = static_cast<DWORD>(reinterpret_cast<std::uintptr_t>(h));
   // First, try the Windows 10 1607 SetThreadDescription call.
   if (setThreadNameWindowsViaDescription(id, name)) {
     return true;
@@ -273,7 +296,7 @@
 } // namespace
 
 bool setThreadName(std::thread::id tid, StringPiece name) {
-#ifdef _WIN32
+#if !FOLLY_HAVE_PTHREAD && defined(_WIN32)
   return setThreadNameWindows(tid, name);
 #else
   return setThreadName(stdTidToPthreadId(tid), name);
@@ -281,7 +304,7 @@
 }
 
 bool setThreadName(pthread_t pid, StringPiece name) {
-#ifdef _WIN32
+#if !FOLLY_HAVE_PTHREAD && defined(_WIN32)
   static_assert(
       sizeof(unsigned int) == sizeof(std::thread::id),
       "This assumes std::thread::id is a thin wrapper around "
diff -Naur folly-2025.06.16.00-orig/folly/testing/TestUtil.cpp folly-2025.06.16.00/folly/testing/TestUtil.cpp
--- folly-2025.06.16.00-orig/folly/testing/TestUtil.cpp	2025-06-16 00:19:41.000000000 +0300
+++ folly-2025.06.16.00/folly/testing/TestUtil.cpp	2025-06-17 11:05:27.321075500 +0300
@@ -146,7 +146,7 @@
 namespace detail {
 
 SavedState disableInvalidParameters() {
-#ifdef _WIN32
+#ifdef _MSC_VER
   SavedState ret;
   ret.previousThreadLocalHandler = _set_thread_local_invalid_parameter_handler(
       [](const wchar_t*,
@@ -161,7 +161,7 @@
 #endif
 }
 
-#ifdef _WIN32
+#ifdef _MSC_VER
 void enableInvalidParameters(SavedState state) {
   _set_thread_local_invalid_parameter_handler(
       (_invalid_parameter_handler)state.previousThreadLocalHandler);
