Skip to content

Improved Compatibility with 🍏 LLVM and 🪟 MSVC

Choose a tag to compare

@ashvardanian ashvardanian released this 16 Sep 21:57

Use the C++ Standard Library... they say!

Not an easy call when your code runs on more platforms than most standard libraries do. And now, thanks to sharp-eyed users and contributors, we’ve got two more reasons to be cautious: one in Apple Clang’s libc++, the other in MSVC.

@yrashk spotted a libc++ quirk shipped with Apple Clang: until version 19, its std::allocation_result is non‑conforming and only takes one template parameter instead of the two the standard requires. Yes, really. Here’s the shim Fork Union now carries to paper over that inconsistency:

#if defined(__cpp_lib_allocate_at_least)
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 190000
    operator std::allocation_result<pointer_type>() const noexcept {
        return std::allocation_result<pointer_type> {ptr, static_cast<std::size_t>(count)};
    }
#else
    operator std::allocation_result<pointer_type, size_type>() const noexcept {
        return std::allocation_result<pointer_type, size_type>(ptr, count);
    }
#endif
#endif 

@atufankjian noticed a compilation issue on MSVC, originating in its std::variant implementation, that couldn't deal with objects aligned to 128-byte boundary optimal for most new x86 server platforms and Arm chips! So we've had to implement a custom union class for our lib.cpp to pass compilation on Windows 🤦‍♂️

Patch

  • Make: Cross-compile separately (4898bde)
  • Fix: Alignment violation warnings (3e5ef5c)
  • Fix: Casting ull to size on 32-bit machines (5f7c569)
  • Make: Avoid x86-only -fcf-protection=full (f914e4b)
  • Fix: "duplicate explicit instantiation" for std::size_t (76105d6)
  • Make: Cross-compile big-endian & 32-bit (f11ef09)
  • Make: Incorrect MSVC command (c67ff98)
  • Docs: Add badges (a0a6c17)
  • Make: Broaden CI coverage (6d6db9d)
  • Make: Cover more MSVC targets in CI (f48b846)
  • Fix: std::variant for alignas(128) in MSVC (d0c1f8a)
  • Make: Test many LLVM & AppleClang versions (0dfb931)
  • Fix: 1 template argument before Clang 19 (3dc4f3c)
  • Make: Include C++23 tests (f9b4899)
  • Fix: AppleClang16 issues (#27) (dd04bc9)
  • Make: Check for -fcf-protection (92cf3e6)
  • Make: Always link to pthread on Linux (87101e0)