[libcxx-commits] [libcxx] 7e8c80f - [libc++][C++20 modules] Tests no locale build.

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 22 11:14:33 PDT 2023


Author: Mark de Wever
Date: 2023-08-22T20:14:28+02:00
New Revision: 7e8c80fc600a3ff7a712776e7e2168f2cbf1eddb

URL: https://github.com/llvm/llvm-project/commit/7e8c80fc600a3ff7a712776e7e2168f2cbf1eddb
DIFF: https://github.com/llvm/llvm-project/commit/7e8c80fc600a3ff7a712776e7e2168f2cbf1eddb.diff

LOG: [libc++][C++20 modules] Tests no locale build.

This fixes some missing #ifndef and implements the header restrictions
in the modules script.

Depends on D158192

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D158330

Added: 
    

Modified: 
    libcxx/cmake/caches/Generic-no-localization.cmake
    libcxx/modules/std/chrono.inc
    libcxx/modules/std/complex.inc
    libcxx/modules/std/locale.inc
    libcxx/modules/std/thread.inc
    libcxx/test/libcxx/module_std.gen.py
    libcxx/utils/ci/buildkite-pipeline.yml

Removed: 
    


################################################################################
diff  --git a/libcxx/cmake/caches/Generic-no-localization.cmake b/libcxx/cmake/caches/Generic-no-localization.cmake
index 79d6b44c7139aa..54a7ec3f1f5b36 100644
--- a/libcxx/cmake/caches/Generic-no-localization.cmake
+++ b/libcxx/cmake/caches/Generic-no-localization.cmake
@@ -1 +1,2 @@
+set(LIBCXX_ENABLE_STD_MODULES ON CACHE BOOL "") # TODO MODULES Remove when enabled automatically.
 set(LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")

diff  --git a/libcxx/modules/std/chrono.inc b/libcxx/modules/std/chrono.inc
index ca89d46cf30a9d..b5e6ee7006000d 100644
--- a/libcxx/modules/std/chrono.inc
+++ b/libcxx/modules/std/chrono.inc
@@ -233,7 +233,9 @@ export namespace std {
 #endif
   } // namespace chrono
 
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
   using std::formatter;
+#endif // _LIBCPP_HAS_NO_LOCALIZATION
 
   namespace chrono {
     // using std::chrono::parse;

diff  --git a/libcxx/modules/std/complex.inc b/libcxx/modules/std/complex.inc
index 7a553242371c5f..3ccf44fa022443 100644
--- a/libcxx/modules/std/complex.inc
+++ b/libcxx/modules/std/complex.inc
@@ -19,8 +19,10 @@ export namespace std {
   using std::operator/;
 
   using std::operator==;
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
   using std::operator>>;
   using std::operator<<;
+#endif // _LIBCPP_HAS_NO_LOCALIZATION
 
   // [complex.value.ops], values
   using std::imag;

diff  --git a/libcxx/modules/std/locale.inc b/libcxx/modules/std/locale.inc
index 8e0018f6042538..c34f56530e98ce 100644
--- a/libcxx/modules/std/locale.inc
+++ b/libcxx/modules/std/locale.inc
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 export namespace std {
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
   // [locale], locale
   using std::has_facet;
   using std::locale;
@@ -71,4 +72,5 @@ export namespace std {
 
   // [depr.conversions.string]
   using std::wstring_convert;
+#endif // _LIBCPP_HAS_NO_LOCALIZATION
 } // namespace std

diff  --git a/libcxx/modules/std/thread.inc b/libcxx/modules/std/thread.inc
index aa4a7dbd202a20..89b1d232772e53 100644
--- a/libcxx/modules/std/thread.inc
+++ b/libcxx/modules/std/thread.inc
@@ -28,7 +28,9 @@ export namespace std {
   // [thread.thread.id]
   using std::operator==;
   using std::operator<=>;
+#ifndef _LIBCPP_HAS_NO_LOCALIZATION
   using std::operator<<;
+#endif // _LIBCPP_HAS_NO_LOCALIZATION
 
   using std::formatter;
 

diff  --git a/libcxx/test/libcxx/module_std.gen.py b/libcxx/test/libcxx/module_std.gen.py
index 6d146252754900..2a6b0f237afc7d 100644
--- a/libcxx/test/libcxx/module_std.gen.py
+++ b/libcxx/test/libcxx/module_std.gen.py
@@ -22,6 +22,7 @@
 
 sys.path.append(sys.argv[1])
 from libcxx.header_information import module_headers
+from libcxx.header_information import header_restrictions
 
 BLOCKLIT = (
     ""  # block Lit from interpreting a RUN/XFAIL/etc inside the generation script
@@ -131,15 +132,34 @@
 
 # Validate all module parts.
 for header in module_headers:
+    # Some headers cannot be included when a libc++ feature is disabled.
+    # In that case include the header conditionally. The header __config
+    # ensures the libc++ feature macros are available.
+    if header in header_restrictions:
+        include = (
+            f"#include <__config>{nl}"
+            + f"#if {header_restrictions[header]}{nl}"
+            + f"#  include <{header}>{nl}"
+            + f"#endif{nl}"
+        )
+    elif header == "chrono":
+        # When localization is disabled the header string is not included.
+        # When string is included chrono's operator""s is a named declaration
+        #   using std::chrono_literals::operator""s;
+        # else it is a named declaration
+        #   using std::operator""s;
+        # TODO MODULES investigate why
+        include = f"#include <string>{nl}#include <chrono>{nl}"
+    else:
+        include = f"#include <{header}>{nl}"
+
     # Generate a module partition for the header module includes. This
     # makes it possible to verify that all headers export all their
     # named declarations.
-    #
-    # TODO MODULES This needs to take the header restrictions into account.
     print(
         f"// RUN{BLOCKLIT}: echo -e \""
         f"module;{nl}"
-        f"#include <{header}>{nl}"
+        f"{include}"
         f"{nl}"
         f"// Use __libcpp_module_<HEADER> to ensure that modules {nl}"
         f"// are not named as keywords or reserved names.{nl}"
@@ -195,7 +215,7 @@
         )
 
     # Clang-tidy needs a file input
-    print(f'// RUN{BLOCKLIT}: echo "#include <{header}>" > %t.{header}.cpp')
+    print(f'// RUN{BLOCKLIT}: echo -e "' f"{include}" f'" > %t.{header}.cpp')
     print(
         f"// RUN{BLOCKLIT}: %{{clang-tidy}} %t.{header}.cpp "
         "  --checks='-*,libcpp-header-exportable-declarations' "

diff  --git a/libcxx/utils/ci/buildkite-pipeline.yml b/libcxx/utils/ci/buildkite-pipeline.yml
index 3bd64e38e87f18..cce1c5a2205532 100644
--- a/libcxx/utils/ci/buildkite-pipeline.yml
+++ b/libcxx/utils/ci/buildkite-pipeline.yml
@@ -623,8 +623,11 @@ steps:
         - "**/test-results.xml"
         - "**/*.abilist"
       env:
-          CC: "clang-${LLVM_HEAD_VERSION}"
-          CXX: "clang++-${LLVM_HEAD_VERSION}"
+          # Note: Modules require and absolute path for clang-scan-deps
+          # https://github.com/llvm/llvm-project/issues/61006
+          CC: "/usr/lib/llvm-${LLVM_HEAD_VERSION}/bin/clang"
+          CXX: "/usr/lib/llvm-${LLVM_HEAD_VERSION}/bin/clang++"
+          CMAKE: "/opt/bin/cmake"
           ENABLE_CLANG_TIDY: "On"
       agents:
         queue: "libcxx-builders"


        


More information about the libcxx-commits mailing list