build: Add NOMINMAX definition for MSVC compatibility#478
build: Add NOMINMAX definition for MSVC compatibility#478siposcsaba89 wants to merge 1 commit intostotko:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #478 +/- ##
=======================================
Coverage 96.64% 96.64%
=======================================
Files 33 33
Lines 2622 2622
=======================================
Hits 2534 2534
Misses 88 88 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks! I'm a bit hesitant to merge this fix since I don't believe that the proposed preprocessor definition should belong to stdgpu. In fact, the culprit is the |
Sorry, thad I did not give you more detailed description. I am trying to port our project to compile with cuda 13, and I belive that thrust and cuda in version 13 includes windows.h or some header from windows that defines min, max, which breaks our build. I understand, that you are hesitant, and I tought about that too, that it could break other cases, could give warning from already defined macros, etc., but if I do not set it, it won't compile. Maybe a pragma pop, push solution would be better, that's how nvidia does it, so I think you are right not to merge it, let me see if I can provide a better solution. |
|
I just made a #pragma push_macro/#pragma pop_macro variation, needed to add to two files. I am not sure, that it is better or not, it solves the problem locally insted of global define, but maybe it would be better to put these in a header file. I am not sure. But for now I think it is the best I can come up with. |
stotko
left a comment
There was a problem hiding this comment.
Thanks for coming up with a local version. Limiting the scope to only the necessary areas is the right direction 👍 Since this is a Windows-only issue, I suggest to further limit the scope to that particular platform even though it should have no effect on other platforms.
src/stdgpu/algorithm.h
Outdated
| #pragma push_macro("min") | ||
| #pragma push_macro("max") | ||
| #undef min | ||
| #undef max |
There was a problem hiding this comment.
| #pragma push_macro("min") | |
| #pragma push_macro("max") | |
| #undef min | |
| #undef max | |
| #if defined(_WIN32) | |
| #pragma push_macro("min") | |
| #pragma push_macro("max") | |
| #undef min | |
| #undef max | |
| #endif |
src/stdgpu/algorithm.h
Outdated
| #pragma pop_macro("min") | ||
| #pragma pop_macro("max") |
There was a problem hiding this comment.
| #pragma pop_macro("min") | |
| #pragma pop_macro("max") | |
| #if defined(_WIN32) | |
| #pragma pop_macro("min") | |
| #pragma pop_macro("max") | |
| #endif |
src/stdgpu/limits.h
Outdated
| #pragma push_macro("min") | ||
| #pragma push_macro("max") | ||
| #undef min | ||
| #undef max |
src/stdgpu/limits.h
Outdated
| #pragma pop_macro("min") | ||
| #pragma pop_macro("max") |
With test to compile I also needed to add it to several files, so decided to create a header push/pop pair, but it counts where the user includes them, but clang-format keep fighting the order. I am not sure what is the best solution here. What do you think about a private NOMINMAX definition to be able to compile stdgpu (for example vcpkg, as we do it), then everyone should handle NOMINMAX in their own project? (Maybe it would be cleaner than putting push/pop everywhere) |
minandmaxmacros defined in Windows headers.