Swift 5.3 - stdint not found when building parts of llvm?

Hi,

I'm building on macOS Monterey 12.2.1 (21D62) with Xcode 13.2.1 (13C100). I follow a slightly odd build process. After getting all the relevant repos with utils/update-checkout., I use the build script utils/build-script basically as a frontend to CMake -G Ninja without actually running the build: utils/build-script -R -S. then go into the subdirectories one by one and do the actual build with ninja.

The reason for this odd looking approach is I want to build all of cmark and llvm but only the compiler, not the standard library or runtime in swift-macosx-x86_64 (I'm making a customised cross compiler.)

The issue is in llvm, I'm getting errors like...

Carls-MacBook-Pro:llvm-macosx-x86_64 carlpeto$ ninja -v
[0/4] cd /Users/carlpeto/compilers/avr-swift/build/Ninja-ReleaseAssert/llvm-macosx-x86_64/tools/clang/runtime/compiler-rt-bins && /Applications/CMake.app/Contents/bin/cmake --build . && /Applications/CMake.app/Contents/bin/cmake -E touch /Users/carlpeto/compilers/avr-swift/build/Ninja-ReleaseAssert/llvm-macosx-x86_64/tools/clang/runtime/compiler-rt-stamps//compiler-rt-build
[1/1132] Building CXX object lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibcNoHooks.osx.dir/sanitizer_posix_libcdep.cpp.o
FAILED: lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibcNoHooks.osx.dir/sanitizer_posix_libcdep.cpp.o
/Users/carlpeto/compilers/avr-swift/build/Ninja-ReleaseAssert/llvm-macosx-x86_64/./bin/clang++ -DHAVE_RPC_XDR_H=0 -I/Users/carlpeto/compilers/avr-swift/llvm-project/llvm/projects/compiler-rt/lib/sanitizer_common/.. -Wall -std=c++14 -Wno-unused-parameter -O3 -DNDEBUG -arch arm64 -arch x86_64 -arch x86_64h -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk  -stdlib=libc++ -mmacosx-version-min=10.9 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -fPIC -fno-builtin -fno-exceptions -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -fno-rtti -Wframe-larger-than=570 -Wglobal-constructors -DSANITIZER_SUPPORTS_WEAK_HOOKS=0 -MD -MT lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibcNoHooks.osx.dir/sanitizer_posix_libcdep.cpp.o -MF lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibcNoHooks.osx.dir/sanitizer_posix_libcdep.cpp.o.d -o lib/sanitizer_common/CMakeFiles/RTSanitizerCommonLibcNoHooks.osx.dir/sanitizer_posix_libcdep.cpp.o -c /Users/carlpeto/compilers/avr-swift/llvm-project/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
In file included from /Users/carlpeto/compilers/avr-swift/llvm-project/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp:31:
/Users/carlpeto/compilers/avr-swift/build/Ninja-ReleaseAssert/llvm-macosx-x86_64/./bin/../include/c++/v1/stdlib.h:142:34: error: unknown type name 'ldiv_t'
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
                                 ^
/Users/carlpeto/compilers/avr-swift/build/Ninja-ReleaseAssert/llvm-macosx-x86_64/./bin/../include/c++/v1/stdlib.h:143:12: error: no member named 'ldiv' in the global namespace
  return ::ldiv(__x, __y);
         ~~^
/Users/carlpeto/compilers/avr-swift/build/Ninja-ReleaseAssert/llvm-macosx-x86_64/./bin/../include/c++/v1/stdlib.h:146:34: error: unknown type name 'lldiv_t'
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
                                 ^
/Users/carlpeto/compilers/avr-swift/build/Ninja-ReleaseAssert/llvm-macosx-x86_64/./bin/../include/c++/v1/stdlib.h:148:12: error: no member named 'lldiv' in the global namespace
  return ::lldiv(__x, __y);
         ~~^
In file included from /Users/carlpeto/compilers/avr-swift/llvm-project/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/resource.h:202:2: error: unknown type name 'uint8_t'
        uint8_t  ri_uuid[16];

It seems to have already built clang and the llvm static libs, llc, etc. already, so actually this doesn't stop me. It looks like it's parts of compiler-rt that aren't building.

But I don't really understand how clang can't find stdint.h in these circumstances?

I think this is a new issue since I upgraded from Catalina and Xcode 12.

Can anyone shed any light to help me please? This cmake wizardry is beyond my skill!

All help gratefully received.