[libcxx-commits] [PATCH] D99178: [libcxx] Disable c++experimental by default in DLL builds

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 1 14:20:57 PDT 2021


mstorsjo updated this revision to Diff 334827.
mstorsjo added a comment.

Explicitly error out on the cmake level if trying to enable the unsupported combination.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99178/new/

https://reviews.llvm.org/D99178

Files:
  libcxx/CMakeLists.txt
  libcxx/docs/BuildingLibcxx.rst
  libcxx/test/libcxx/experimental/lit.local.cfg
  libcxx/test/std/experimental/lit.local.cfg


Index: libcxx/test/std/experimental/lit.local.cfg
===================================================================
--- libcxx/test/std/experimental/lit.local.cfg
+++ libcxx/test/std/experimental/lit.local.cfg
@@ -1,3 +1,7 @@
 # Disable all of the experimental tests if the correct feature is not available.
 if 'c++experimental' not in config.available_features:
   config.unsupported = True
+# If built as a DLL on Windows, headers indicate DLL linkage, which breaks
+# linking against the static-only libc++experimental.
+if config.enable_shared and 'windows' in config.available_features:
+  config.unsupported = True
Index: libcxx/test/libcxx/experimental/lit.local.cfg
===================================================================
--- libcxx/test/libcxx/experimental/lit.local.cfg
+++ libcxx/test/libcxx/experimental/lit.local.cfg
@@ -1,3 +1,7 @@
 # Disable all of the experimental tests if the correct feature is not available.
 if 'c++experimental' not in config.available_features:
   config.unsupported = True
+# If built as a DLL on Windows, headers indicate DLL linkage, which breaks
+# linking against the static-only libc++experimental.
+if config.enable_shared and 'windows' in config.available_features:
+  config.unsupported = True
Index: libcxx/docs/BuildingLibcxx.rst
===================================================================
--- libcxx/docs/BuildingLibcxx.rst
+++ libcxx/docs/BuildingLibcxx.rst
@@ -90,7 +90,6 @@
           -T "ClangCL"                            ^
           -DLIBCXX_ENABLE_SHARED=YES              ^
           -DLIBCXX_ENABLE_STATIC=NO               ^
-          -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=NO ^
           \path\to\libcxx
   > cmake --build .
 
@@ -120,7 +119,6 @@
           -DCMAKE_BUILD_TYPE=Release                                                  ^
           -DCMAKE_C_COMPILER=clang-cl                                                 ^
           -DCMAKE_CXX_COMPILER=clang-cl                                               ^
-          -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=NO                                     ^
           path/to/libcxx
   > ninja cxx
   > ninja check-cxx
Index: libcxx/CMakeLists.txt
===================================================================
--- libcxx/CMakeLists.txt
+++ libcxx/CMakeLists.txt
@@ -91,7 +91,13 @@
 option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." OFF)
 option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
 option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON)
-option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "Build libc++experimental.a" ON)
+set(ENABLE_EXPERIMENTAL_DEFAULT ON)
+if (WIN32 AND LIBCXX_ENABLE_SHARED)
+  # When libc++ is built as a DLL, all headers indicate DLL linkage, while
+  # libc++experimental always is linked statically.
+  set(ENABLE_EXPERIMENTAL_DEFAULT OFF)
+endif()
+option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "Build libc++experimental.a" ${ENABLE_EXPERIMENTAL_DEFAULT})
 set(ENABLE_FILESYSTEM_DEFAULT ON)
 if (WIN32 AND NOT MINGW)
   # Filesystem is buildable for windows, but it requires __int128 helper
@@ -402,6 +408,14 @@
   message(FATAL_ERROR "Only one of LIBCXX_ABI_FORCE_ITANIUM and LIBCXX_ABI_FORCE_MICROSOFT can be specified.")
 endif ()
 
+if (WIN32 AND LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
+  message(FATAL_ERROR "LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY can't be enabled"
+                      " when LIBCXX_ENABLE_SHARED also is enabled for Windows,"
+                      " as the c++experimental library only is built as a"
+                      " static library, while the headers signal dllimport"
+                      " linkage.")
+endif()
+
 #===============================================================================
 # Configure System
 #===============================================================================


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99178.334827.patch
Type: text/x-patch
Size: 3872 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210401/c547b17d/attachment-0001.bin>


More information about the libcxx-commits mailing list