Skip to content

Commit b5071bc

Browse files
authored
Add host std lib version detection (#6678)
1 parent f175368 commit b5071bc

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

libcudacxx/include/cuda/std/__cccl/host_std_lib.h

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
# pragma system_header
2424
#endif // no system header
2525

26-
#define _CCCL_HOST_STD_LIB_LIBSTDCXX() 0
27-
#define _CCCL_HOST_STD_LIB_LIBCXX() 0
28-
#define _CCCL_HOST_STD_LIB_STL() 0
26+
#define _CCCL_HOST_STD_LIB_LIBSTDCXX() _CCCL_VERSION_INVALID()
27+
#define _CCCL_HOST_STD_LIB_LIBCXX() _CCCL_VERSION_INVALID()
28+
#define _CCCL_HOST_STD_LIB_STL() _CCCL_VERSION_INVALID()
2929

3030
// include a minimal header
3131
#if _CCCL_HAS_INCLUDE(<version>)
@@ -34,19 +34,26 @@
3434
# include <ciso646>
3535
#endif // ^^^ _CCCL_HAS_INCLUDE(<ciso646>) ^^^
3636

37+
#define _CCCL_HOST_STD_LIB_MAKE_VERSION(_MAJOR, _MINOR) ((_MAJOR) * 100 + (_MINOR))
38+
#define _CCCL_HOST_STD_LIB(...) _CCCL_VERSION_COMPARE(_CCCL_HOST_STD_LIB_, _CCCL_HOST_STD_LIB_##__VA_ARGS__)
39+
3740
#if defined(_MSVC_STL_VERSION)
3841
# undef _CCCL_HOST_STD_LIB_STL
39-
# define _CCCL_HOST_STD_LIB_STL() 1
42+
# define _CCCL_HOST_STD_LIB_STL() (_MSVC_STL_VERSION, 0)
4043
#elif defined(__GLIBCXX__)
4144
# undef _CCCL_HOST_STD_LIB_LIBSTDCXX
42-
# define _CCCL_HOST_STD_LIB_LIBSTDCXX() 1
45+
# define _CCCL_HOST_STD_LIB_LIBSTDCXX() (_GLIBCXX_RELEASE, 0)
4346
#elif defined(_LIBCPP_VERSION)
4447
# undef _CCCL_HOST_STD_LIB_LIBCXX
45-
# define _CCCL_HOST_STD_LIB_LIBCXX() 1
48+
// since llvm-16, the version scheme has been changed from MMppp to MMmmpp
49+
# if _LIBCPP_VERSION / 10000 < 2
50+
# define _CCCL_HOST_STD_LIB_LIBCXX() (_LIBCPP_VERSION / 1000, 0)
51+
# else
52+
# define _CCCL_HOST_STD_LIB_LIBCXX() (_LIBCPP_VERSION / 10000, (_LIBCPP_VERSION / 100) % 100)
53+
# endif
4654
#endif // ^^^ _LIBCPP_VERSION ^^^
4755

48-
#define _CCCL_HOST_STD_LIB(_X) _CCCL_HOST_STD_LIB_##_X()
4956
#define _CCCL_HAS_HOST_STD_LIB() \
50-
(_CCCL_HOST_STD_LIB_LIBSTDCXX() || _CCCL_HOST_STD_LIB_LIBCXX() || _CCCL_HOST_STD_LIB_STL())
57+
(_CCCL_HOST_STD_LIB(LIBSTDCXX) || _CCCL_HOST_STD_LIB(LIBCXX) || _CCCL_HOST_STD_LIB(STL))
5158

5259
#endif // __CCCL_HOST_STD_LIB_H

0 commit comments

Comments
 (0)