[llvm-branch-commits] [libcxx] [libc++][modules] Adds module testing. (PR #76246)

Louis Dionne via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 16 08:53:17 PST 2024


================
@@ -132,13 +154,62 @@ def parseScript(test, preamble):
     script += scriptInTest
 
     # Add compile flags specified with ADDITIONAL_COMPILE_FLAGS.
+    # Modules need to be build with the same compilation flags as the
+    # test. So add these flags before adding the modules.
     substitutions = [
         (s, x + " " + " ".join(additionalCompileFlags))
         if s == "%{compile_flags}"
         else (s, x)
         for (s, x) in substitutions
     ]
 
+    if modules:
+        _validateModuleDependencies(modules)
+
+        # This flag is needed for both modules.
+        #moduleCompileFlags.append("-fprebuilt-module-path=%T")
+
+        # The moduleCompileFlags are added to the %{compile_flags}, but
+        # the modules need should be built without these flags. So
+        # expand the compile_flags and add the expanded value to the
+        # build script.
+        compileFlags = _getSubstitution("%{compile_flags}", test.config)
+
+        # Building the modules needs to happen before the other script
+        # commands are executed. Therefore the commands are added to the
+        # front of the list.
+        if "std.compat" in modules:
+            script.insert(
+                0,
+                "%dbg(MODULE std.compat) %{cxx} %{flags} "
+                f"{compileFlags} "
+                "-Wno-reserved-module-identifier -Wno-reserved-user-defined-literal "
+                "--precompile -o %T/std.compat.pcm -c %{module}/std.compat.cppm",
+            )
+            moduleCompileFlags.append("-fmodule-file=std.compat=%T/std.compat.pcm %T/std.compat.pcm")
+
+        # Make sure the std module is added before std.compat. Libc++'s
+        # std.compat module will depend on its std module.  It is not
+        # known whether the compiler expects the modules in the order of
+        # their dependencies. However it's trivial to provide them in
+        # that order.
+        script.insert(
+            0,
+            "%dbg(MODULE std) %{cxx} %{flags} "
+            f"{compileFlags} "
+            "-Wno-reserved-module-identifier -Wno-reserved-user-defined-literal "
+            "--precompile -o %T/std.pcm -c %{module}/std.cppm",
+        )
+        moduleCompileFlags.append("-fmodule-file=std=%T/std.pcm %T/std.pcm")
----------------
ldionne wrote:

```suggestion
        moduleCompileFlags.extend(["-fmodule-file=std=%T/std.pcm", "%T/std.pcm"])
```

https://github.com/llvm/llvm-project/pull/76246


More information about the llvm-branch-commits mailing list