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/ 
/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/  -stdlib=libc++ -mmacosx-version-min=10.9 -isysroot /Applications/ -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/ -MF lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.osx.dir/ -o lib/sanitizer_common/CMakeFiles/RTSanitizerCommonNoTermination.osx.dir/ -c /Users/admin/swift-source/llvm/projects/compiler-rt/lib/sanitizer_common/
/Users/admin/swift-source/llvm/projects/compiler-rt/lib/sanitizer_common/ 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/ note: forward declaration of '__sanitizer::stat64'
  unsigned struct_stat64_sz = sizeof(struct stat64);
/Users/admin/swift-source/llvm/projects/compiler-rt/lib/sanitizer_common/ 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/ 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 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.


1 Like


Terms of Service

Privacy Policy

Cookie Policy