Problems with building the Swift compiler

Hey. Since yesterday I'm trying to build the Swift compiler but I'm always getting the exact same error:

FAILED: lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.osx.dir/sanitizer_platform_limits_posix.cc.o 
/Users/admin/swift-source/build/Ninja-ReleaseAssert/llvm-macosx-x86_64/./bin/clang++ -DHAVE_RPC_XDR_H=0 -I/Users/admin/swift-source/llvm/projects/compiler-rt/lib/sanitizer_common/.. -Wall -std=c++11 -Wno-unused-parameter -O3 -DNDEBUG -arch arm64 -arch x86_64 -arch x86_64h -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk  -stdlib=libc++ -mmacosx-version-min=10.9 -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.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 -MD -MT lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.osx.dir/sanitizer_platform_limits_posix.cc.o -MF lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.osx.dir/sanitizer_platform_limits_posix.cc.o.d -o lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.osx.dir/sanitizer_platform_limits_posix.cc.o -c /Users/admin/swift-source/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
/Users/admin/swift-source/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc:169:31: error: invalid application of 'sizeof' to an incomplete type 'struct stat64'
  unsigned struct_stat64_sz = sizeof(struct stat64);
                              ^     ~~~~~~~~~~~~~~~
/Users/admin/swift-source/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc:169:45: note: forward declaration of '__sanitizer::stat64'
  unsigned struct_stat64_sz = sizeof(struct stat64);
                                            ^
/Users/admin/swift-source/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc:195:33: error: invalid application of 'sizeof' to an incomplete type 'struct statfs64'
  unsigned struct_statfs64_sz = sizeof(struct statfs64);
                                ^     ~~~~~~~~~~~~~~~~~
/Users/admin/swift-source/llvm/projects/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc:195:47: note: forward declaration of '__sanitizer::statfs64'
  unsigned struct_statfs64_sz = sizeof(struct statfs64);
                                              ^
2 errors generated.
...
ninja: build stopped: subcommand failed.
FAILED: tools/clang/runtime/compiler-rt-stamps/compiler-rt-build 
cd /Users/admin/swift-source/build/Ninja-ReleaseAssert/llvm-macosx-x86_64/tools/clang/runtime/compiler-rt-bins && /usr/local/Cellar/cmake/3.18.2/bin/cmake --build . && /usr/local/Cellar/cmake/3.18.2/bin/cmake -E touch /Users/admin/swift-source/build/Ninja-ReleaseAssert/llvm-macosx-x86_64/tools/clang/runtime/compiler-rt-stamps//compiler-rt-build
ninja: build stopped: subcommand failed.
utils/build-script: fatal error: command terminated with a non-zero exit status 1, aborting

I've tried everything, I could possibly try. I installed different versions of the Xcode 12 Beta (3,4 and 5), and also tried different macOS versions (10.15.5, 10.15.6, 11.0 Beta (20A5354i)). Still I got the same error every time.

I used the following command, to build:

utils/build-script --clean --release --swift-darwin-supported-archs 'x86_64'

The build process always lasts ~25 minutes until this error occurs.


I hope, that with the given information someone can help me.

Not sure why this is happening but one possibility is that there is something wrong with CommandLineTools on your system and a header from there is getting included. Do you have CommandLineTools installed? If so, could you temporarily move it to a different directory?

You could also try adding a #include <sys/stat.h> to that file, to see if that helps as a workaround.

Lastly, since you are rebuilding things, you likely want to set up sccache to speed up iteration time.

As I said, I reinstalled Xcode multiple times and also removed the CommandLineTools every time. So that should be safe, I hope.
I'd rather not mess with files in llvm...

Thanks for the tip with sccache.

I got it working.
Apparently util/update-checkout messes up, when the Swift repository is cloned from a fork :man_shrugging:

So I spent literally two days building Swift in all possible constellations, but I just cloned it wrong.

That's really unfortunate. :frowning_face: I remember hitting bizarre failures earlier at some point where I had origin pointing at my fork instead of apple/swift. cc @mishal_shah: how do you think we can address this? Have some additional checks in the update-checkout script?

1 Like

Can you file a bug on bugs.swift.org? One workaround I can think of is using --skip-repository swift to avoid from causing an issue with fork repo. However, I am trying to understand what is causing the issue.

Filed [SR-13476] Strange LLVM failure when building using fork of Swift · Issue #55918 · apple/swift · GitHub.

1 Like

Thanks!

I also encounter this problem too.

More info, hope it help you.

macOS Catalina 10.15.7

xcode Version 12.2 beta 3 (12B5035g)

build for swift-5.2.4-release not swift-5.3-release

  • repo version hash code:
   def self.swift
      return "0bab712aea8f0eb74f3acc303d96857f697a98d8"

   def self.llvm
      return "c2133f2b08047708b17230b598cb789062143650"
  • error log:
ninja: Entering directory `/Users/xxxxx/dev_kit/sdk/swift_source/swift-everywhere-toolchain/ToolChain/Build/darwin-host/llvm-project'
[0/3] Performing build step for 'compiler-rt'
[4/4807] Building CXX object lib/sanitizer_common/CMakeFi...ommonNoHooks.osx.dir/sanitizer_platform_limits_posix.cc.o
FAILED: lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoHooks.osx.dir/sanitizer_platform_limits_posix.cc.o
/Users/xxxxx/dev_kit/sdk/swift_source/swift-everywhere-toolchain/ToolChain/Build/darwin-host/llvm-project/./bin/clang++  -DHAVE_RPC_XDR_H=0 -I/Users/xxxxx/dev_kit/sdk/swift_source/swift-everywhere-toolchain/ToolChain/Sources/llvm-project/compiler-rt/lib/sanitizer_common/.. -Wall -std=c++11 -Wno-unused-parameter -O3 -DNDEBUG -arch arm64 -arch x86_64 -arch x86_64h -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk    -stdlib=libc++ -mmacosx-version-min=10.9 -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.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/RTSanitizerCommonNoHooks.osx.dir/sanitizer_platform_limits_posix.cc.o -MF lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoHooks.osx.dir/sanitizer_platform_limits_posix.cc.o.d -o lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoHooks.osx.dir/sanitizer_platform_limits_posix.cc.o -c /Users/xxxxx/dev_kit/sdk/swift_source/swift-everywhere-toolchain/ToolChain/Sources/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
/Users/xxxxx/dev_kit/sdk/swift_source/swift-everywhere-toolchain/ToolChain/Sources/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc:169:31: error: invalid application of 'sizeof' to an incomplete type 'struct stat64'
  unsigned struct_stat64_sz = sizeof(struct stat64);
                              ^     ~~~~~~~~~~~~~~~
/Users/xxxxx/dev_kit/sdk/swift_source/swift-everywhere-toolchain/ToolChain/Sources/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc:169:45: note: forward declaration of '__sanitizer::stat64'
  unsigned struct_stat64_sz = sizeof(struct stat64);
                                            ^
/Users/xxxxx/dev_kit/sdk/swift_source/swift-everywhere-toolchain/ToolChain/Sources/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc:195:33: error: invalid application of 'sizeof' to an incomplete type 'struct statfs64'
  unsigned struct_statfs64_sz = sizeof(struct statfs64);
                                ^     ~~~~~~~~~~~~~~~~~
/Users/xxxxx/dev_kit/sdk/swift_source/swift-everywhere-toolchain/ToolChain/Sources/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cc:195:47: note: forward declaration of '__sanitizer::statfs64'
  unsigned struct_statfs64_sz = sizeof(struct statfs64);
                                              ^
2 errors generated.
[13/4807] Building CXX object lib/sanitizer_common/CMakeF...CommonLibcNoHooks.iossim.dir/sanitizer_posix_libcdep.cc.o
ninja: build stopped: subcommand failed.
FAILED: tools/clang/runtime/compiler-rt-stamps/compiler-rt-build

(Replied on the bug report, let's follow up there.)

Also replied on the bug report at the same time :sunglasses: