-
Notifications
You must be signed in to change notification settings - Fork 132
[fix][Windows][clang-cl build] add missing STL includes #299
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
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Dec 13, 2025
|
@zhiningli has imported this pull request. If you are a Meta employee, you can view this in D89547335. |
Adds missing headers required for Windows builds: - <string> for std::to_string - <numeric> for std::accumulate, std::iota - <stdexcept> for std::runtime_error - <array> for std::array - <optional> for std::optional - <chrono> for std::chrono::high_resolution_clock - MSVC detection for IEEE 754 in portability.h Fixes facebook#95
c05e237 to
ac7d30e
Compare
meta-codesync bot
pushed a commit
that referenced
this pull request
Dec 20, 2025
… enum test (#302) Summary: Enables the error message type printing feature (ZL_ENABLE_RET_IF_ARG_PRINTING) on clang-cl and fixes a cross-platform test incompatibility. ### Issue 1: Type printing disabled on clang-cl **File:** include/openzl/detail/zl_errors_detail.h (line 570) The preprocessor check for enabling verbose error messages only checked for \__GNUC_\_. However, clang-cl defines \__clang__ instead, causing the feature to remain disabled on Windows/Clang builds. **Before:** ` if defined(\__GNUC_\_) && !defined(\__cplusplus) ` **After:** ` if (defined(\__GNUC_\_) || defined(\__clang_\_)) && !defined(\__cplusplus) ` ### Issue 2: Enum type differs between platforms **File:** tests/unittest/common/test_errors_in_c.c (line 223) C enums have different underlying types depending on the platform ABI: - **Linux/GCC:** unsigned int - **Windows/MSVC ABI:** int - **ARM64**: May use either depending on ABI The test previously expected a strict string match that failed on Windows. **Before:** `EXPECT_ERROR_MESSAGE_CONTAINS(e_1, e_2, "(unsigned int)"); ` **After:** ``` // Explicitly check for both possibilities using exact string matching const char* _found_int = strstr(_str, "(int)"); const char* _found_uint = strstr(_str, "(unsigned int)"); if (!_found_int && !_found_uint) { ZL_RET_R_ERR(GENERIC, "Message '(int)' or '(unsigned int)' not found..."); } ``` ## Type of Change - \[x\] Bug fix (non-breaking change which fixes an issue) Pull Request resolved: #302 Test Plan: **Test affected:** ErrorsTest.BinaryTestArgTypesDeducedInC (Test #306) Built and ran the full test suite on Windows. ``` cmake --build build --config Release cd build && ctest -C Release --timeout 60 ``` **Result:** **1209/1209 tests passing (100%)** ✅ <img width="891" height="359" alt="image" src="https://github.com/user-attachments/assets/e13fc529-c1fa-4676-879d-26d71786b182" /> After windows compatibility fix #97, #299, #301 Specifically verified the affected test: ctest -C Release -R "ErrorsTest.BinaryTestArgTypesDeducedInC" --output-on-failure **Output:** \# Result: 1/1 Test #306: ErrorsTest.BinaryTestArgTypesDeducedInC ... Passed ### Test Configuration | **Component** | **Detail** | | **Compiler** | clang-cl (ClangCL toolset) | | **Generator** | Visual Studio with ClangCL toolset (-T ClangCL) | | **Build type** | Release | | **Platform** | Windows 11 x64 | Reviewed By: Cyan4973 Differential Revision: D89547438 Pulled By: zhiningli fbshipit-source-id: 4e4b089a3265ff66669572d72cb7ff4555f1e5cb
|
@zhiningli merged this pull request in a9bfe98. |
zhiningli
added a commit
to zhiningli/openzl
that referenced
this pull request
Dec 20, 2025
…facebook#301) Summary: MSVC's `std::uniform_int_distribution<T>` requires `T` to be `short` or larger per C++ standard N4950 [rand.req.genl]/1.5. GCC/Clang are more permissive and allow `uint8_t`/`int8_t`. This adds `compat_uniform_distribution.h` with cross-platform wrappers: - `compat_uniform_int_distribution<T>` - `compat_binomial_distribution<T>` - `compat_geometric_distribution<T>` On MSVC, small types (`uint8_t`, `int8_t`) are promoted to `short`/`unsigned short` internally, then cast back. On GCC/Clang, the wrappers are simple type aliases to `std::` types. **No performance impact** - the promotion is a single cast at generation time, identical to what `std::uniform_int_distribution<short>` would produce. Fixes facebook#300 **Note:** Together with facebook#299 (missing STL includes), this brings Windows test pass rate to **1208/1209 (99.9%)**. The remaining failure (`ErrorsTest.BinaryTestArgTypesDeducedInC`) is a platform-specific error message formatting difference and will be addressed in a future diff. ## Type of Change - [x] Bug fix (non-breaking change which fixes an issue) Test Plan: Built and ran full test suite on Windows: ershell cmake -S . -B build -G "Visual Studio 14 2015" -T ClangCL cmake --build build --config Release cd build && ctest -C Release --output-on-failure --timeout 60**Result:** 1208/1209 tests passing (99.9%) - 1 platform-specific error message formatting test (known MSVC difference, future fix) <img width="839" height="201" alt="image" src="https://github.com/user-attachments/assets/7aa15bc9-dac7-4f63-95a8-a9ec69b2dae8" /> ### Test Configuration - **Compiler:** clang-cl (ClangCL toolset) - **Generator:** Visual Studio 14 2015 with ClangCL toolset (`-T ClangCL`) - **Build type:** Release - **Platform:** Windows 11 x64 Reviewed By: Cyan4973 Differential Revision: D89547407 Pulled By: zhiningli
meta-codesync bot
pushed a commit
that referenced
this pull request
Dec 20, 2025
…#301) Summary: MSVC's `std::uniform_int_distribution<T>` requires `T` to be `short` or larger per C++ standard N4950 [rand.req.genl]/1.5. GCC/Clang are more permissive and allow `uint8_t`/`int8_t`. This adds `compat_uniform_distribution.h` with cross-platform wrappers: - `compat_uniform_int_distribution<T>` - `compat_binomial_distribution<T>` - `compat_geometric_distribution<T>` On MSVC, small types (`uint8_t`, `int8_t`) are promoted to `short`/`unsigned short` internally, then cast back. On GCC/Clang, the wrappers are simple type aliases to `std::` types. **No performance impact** - the promotion is a single cast at generation time, identical to what `std::uniform_int_distribution<short>` would produce. Fixes #300 **Note:** Together with #299 (missing STL includes), this brings Windows test pass rate to **1208/1209 (99.9%)**. The remaining failure (`ErrorsTest.BinaryTestArgTypesDeducedInC`) is a platform-specific error message formatting difference and will be addressed in a future diff. ## Type of Change - [x] Bug fix (non-breaking change which fixes an issue) Pull Request resolved: #301 Test Plan: Built and ran full test suite on Windows: ershell cmake -S . -B build -G "Visual Studio 14 2015" -T ClangCL cmake --build build --config Release cd build && ctest -C Release --output-on-failure --timeout 60**Result:** 1208/1209 tests passing (99.9%) - 1 platform-specific error message formatting test (known MSVC difference, future fix) <img width="839" height="201" alt="image" src="https://github.com/user-attachments/assets/7aa15bc9-dac7-4f63-95a8-a9ec69b2dae8" /> ### Test Configuration - **Compiler:** clang-cl (ClangCL toolset) - **Generator:** Visual Studio 14 2015 with ClangCL toolset (`-T ClangCL`) - **Build type:** Release - **Platform:** Windows 11 x64 Reviewed By: Cyan4973 Differential Revision: D89547407 Pulled By: zhiningli fbshipit-source-id: 18a0b3ae02a2006d5d54b4f221db543dbba94f87
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds missing STL headers required for Windows/clang-cl builds:
<string>forstd::to_stringinLogger.h<numeric>forstd::accumulate,std::iotain test and training files<stdexcept>forstd::runtime_errorinInputSet*.cpp<array>forstd::arrayintest_functionGraphs.cpp<optional>forstd::optionalinInputSetBuilder.h<chrono>forstd::chrono::high_resolution_clockin trainer files_MSC_VER) for IEEE 754 floating-point support inportability.hThese headers are implicitly included via transitive dependencies on GCC/Clang but MSVC requires explicit includes. No runtime or performance impact - purely compile-time fixes.
Fixes #95
Note: I have also validated that #97 (std::future move-only fix) works correctly on my Windows setup.
Type of Change
Test Plan
Built the project
cmake -S . -B build -G "Visual Studio 14 2015" -T ClangCL
cmake --build build --config Release
build is now successful
The only error is for libzstd_shared.vcxproj (the shared/DLL version of zstd):
fatal error RC1012: mismatched parenthesis : missing 'This is a resource compiler issue with Clang headers when building the shared library. But this is non-blocking
After build successful, subsequent fix is about passing test, correcting
std::futureusing PR from #97 and std::uniform distribution #301Test Configuration
-T ClangCL)