@@ -530,33 +530,44 @@ ClangInvocationFileMapping swift::getClangInvocationFileMapping(
530
530
531
531
const llvm::Triple &triple = ctx.LangOpts .Target ;
532
532
533
+ // For modulemaps that have all the C standard library headers together in
534
+ // a single module, we end up with module cycles with the clang _Builtin_
535
+ // modules. e.g. <inttypes.h> includes <stdint.h> on these platforms. The
536
+ // clang builtin <stdint.h> include-nexts <stdint.h>. When both of those
537
+ // platform headers are in the SwiftLibc module, there's a module cycle
538
+ // SwiftLibc -> _Builtin_stdint -> SwiftLibc (i.e. inttypes.h (platform) ->
539
+ // stdint.h (builtin) -> stdint.h (platform)).
540
+ //
541
+ // Until these modulemaps can be fixed, the builtin headers need to join
542
+ // the system modules to avoid the cycle.
543
+ //
544
+ // Note that this does nothing to fix the same problem with C++ headers,
545
+ // and that this is generally a fragile solution.
546
+ //
547
+ // We start by assuming we do *not* need to do this, then enable it for
548
+ // affected modulemaps.
549
+ result.requiresBuiltinHeadersInSystemModules = false ;
550
+
533
551
SmallVector<std::pair<std::string, std::string>, 2 > libcFileMapping;
534
552
if (triple.isOSWASI ()) {
535
553
// WASI Mappings
536
554
libcFileMapping =
537
555
getLibcFileMapping (ctx, " wasi-libc.modulemap" , std::nullopt, vfs);
556
+
557
+ // WASI's module map needs fixing
558
+ result.requiresBuiltinHeadersInSystemModules = true ;
538
559
} else if (triple.isMusl ()) {
539
560
libcFileMapping =
540
561
getLibcFileMapping (ctx, " musl.modulemap" , StringRef (" SwiftMusl.h" ), vfs);
541
562
} else {
542
563
// Android/BSD/Linux Mappings
543
564
libcFileMapping = getLibcFileMapping (ctx, " glibc.modulemap" ,
544
565
StringRef (" SwiftGlibc.h" ), vfs);
566
+
567
+ // glibc.modulemap needs fixing
568
+ result.requiresBuiltinHeadersInSystemModules = true ;
545
569
}
546
570
result.redirectedFiles .append (libcFileMapping);
547
- // Both libc module maps have the C standard library headers all together in a
548
- // SwiftLibc module. That leads to module cycles with the clang _Builtin_
549
- // modules. e.g. <inttypes.h> includes <stdint.h> on these platforms. The
550
- // clang builtin <stdint.h> include-nexts <stdint.h>. When both of those
551
- // platform headers are in the SwiftLibc module, there's a module cycle
552
- // SwiftLibc -> _Builtin_stdint -> SwiftLibc (i.e. inttypes.h (platform) ->
553
- // stdint.h (builtin) -> stdint.h (platform)). Until this can be fixed in
554
- // these module maps, the clang builtin headers need to join the "system"
555
- // modules (SwiftLibc). i.e. when the clang builtin stdint.h is in the
556
- // SwiftLibc module too, the cycle goes away. Note that
557
- // -fbuiltin-headers-in-system-modules does nothing to fix the same problem
558
- // with C++ headers, and is generally fragile.
559
- result.requiresBuiltinHeadersInSystemModules = !libcFileMapping.empty ();
560
571
561
572
if (ctx.LangOpts .EnableCXXInterop )
562
573
getLibStdCxxFileMapping (result, ctx, vfs);
0 commit comments