Build failure locally

I'm trying to do a clean build for the compiler but it's failing.

The first failure is related to building the early-swift-driver. I'm trying to build with the following command.

utils/build-script --skip-build-benchmarks \
  --skip-ios --skip-watchos --skip-tvos --swift-darwin-supported-archs "$(uname -m)" \
  --sccache --release-debuginfo --swift-disable-dead-stripping --test

But I'm getting the following error.

Building Swift Driver dependency: llbuild
CMake Error at /usr/local/Cellar/cmake/3.22.2/share/cmake/Modules/CMakeTestCXXCompiler.cmake:62 (message):
  The C++ compiler

    "/usr/local/opt/llvm/bin/clang++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /Users/hassaneldesouky/Data/OpenSource/swift-project/build/Ninja-RelWithDebInfoAssert/earlyswiftdriver-macosx-x86_64/release/dependencies/llbuild/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/local/bin/ninja cmTC_bdbd6 && [1/2][ 50%][0.069s] Building CXX object CMakeFiles/cmTC_bdbd6.dir/testCXXCompiler.cxx.o
    [2/2][100%][0.145s] Linking CXX executable cmTC_bdbd6
    FAILED: cmTC_bdbd6
    : && /usr/local/opt/llvm/bin/clang++ -target x86_64-apple-macosx10.15  -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -mmacosx-version-min=10.15 -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/cmTC_bdbd6.dir/testCXXCompiler.cxx.o -o cmTC_bdbd6   && :
    ld: library not found for -lc++
    clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:15 (project)


Traceback (most recent call last):
  File "/Users/hassaneldesouky/Data/OpenSource/swift-project/swift-driver/Utilities/build-script-helper.py", line 703, in <module>
    main()
  File "/Users/hassaneldesouky/Data/OpenSource/swift-project/swift-driver/Utilities/build-script-helper.py", line 700, in main
    handle_invocation(args)
  File "/Users/hassaneldesouky/Data/OpenSource/swift-project/swift-driver/Utilities/build-script-helper.py", line 194, in handle_invocation
    build_using_cmake(args, toolchain_bin, args.build_path, targets)
  File "/Users/hassaneldesouky/Data/OpenSource/swift-project/swift-driver/Utilities/build-script-helper.py", line 448, in build_using_cmake
    build_llbuild_using_cmake(args, target, swiftc_exec, dependencies_dir,
  File "/Users/hassaneldesouky/Data/OpenSource/swift-project/swift-driver/Utilities/build-script-helper.py", line 492, in build_llbuild_using_cmake
    cmake_build(args, swiftc_exec, llbuild_cmake_flags, llbuild_swift_flags,
  File "/Users/hassaneldesouky/Data/OpenSource/swift-project/swift-driver/Utilities/build-script-helper.py", line 581, in cmake_build
    subprocess.check_output(cmd, cwd=build_dir)
  File "/Users/hassaneldesouky/opt/anaconda3/lib/python3.8/subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/Users/hassaneldesouky/opt/anaconda3/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/usr/local/bin/cmake', '-G', 'Ninja', '-DCMAKE_MAKE_PROGRAM=/usr/local/bin/ninja', '-DCMAKE_BUILD_TYPE:=Release', '-DCMAKE_Swift_FLAGS=-module-cache-path "/Users/hassaneldesouky/Data/OpenSource/swift-project/build/Ninja-RelWithDebInfoAssert/earlyswiftdriver-macosx-x86_64/module-cache" -target x86_64-apple-macosx10.15 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk', '-DCMAKE_Swift_COMPILER:=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc', '-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15', '-DCMAKE_C_COMPILER:=clang', '-DCMAKE_CXX_COMPILER:=clang++', '-DCMAKE_CXX_FLAGS=-target x86_64-apple-macosx10.15', '-DLLBUILD_SUPPORT_BINDINGS:=Swift', '-DCMAKE_OSX_ARCHITECTURES=x86_64', '-DSQLite3_INCLUDE_DIR=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include', '-DSQLite3_LIBRARY=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/libsqlite3.tbd', '/Users/hassaneldesouky/Data/OpenSource/swift-project/llbuild']' returned non-zero exit status 1.
ERROR: command terminated with a non-zero exit status 1, aborting

I tried to build without using the early-swift-driver so I tried to build with the same command but added --skip-early-swift-driver at the end. I got another error:

Building the standard library for: swift-test-stdlib-macosx-x86_64
Running Swift tests for: check-swift-macosx-x86_64
symlinking the system headers (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../../usr/include/c++) into the local clang build directory (/Users/hassaneldesouky/Data/OpenSource/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-x86_64/include).
+ ln -s -f /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../../usr/include/c++ /Users/hassaneldesouky/Data/OpenSource/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-x86_64/include
+ /usr/local/bin/cmake --build /Users/hassaneldesouky/Data/OpenSource/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-x86_64 -- -j16 all
[0/3][  0%][0.000s] Performing build step for 'compiler-rt'
[1/407][  0%][1.026s] cd /Users/hassaneldesouky/Data/OpenSource/swift-project/build/Ninja-Rel...ng/runtime/compiler-rt-bins/lib/builtins/outline_atomic_helpers.dir/outline_atomic_ldset8_4.S
[1/3][ 33%][1.137s] No install step for 'compiler-rt'
[3/3][100%][1.202s] Completed 'compiler-rt'
copying compiler-rt embedded builtins from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/13.0.0/lib/darwin into the local clang build directory /Users/hassaneldesouky/Data/OpenSource/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-x86_64/bin/../lib/clang/13.0.0/lib/darwin.
+ lipo -remove i386 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/13.0.0/lib/darwin/libclang_rt.tvossim.a -output /Users/hassaneldesouky/Data/OpenSource/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-x86_64/bin/../lib/clang/13.0.0/lib/darwin/libclang_rt.tvossim.a
llvm-lipo: error: unknown argument '-remove'
ERROR: command terminated with a non-zero exit status 1, aborting

I'm not sure what's the problem. Does anyone know how to solve these issues?

This seems like you have llvm binaries installed in your machine which is llvm clang and cmake is selecting it to compile thing instead of apple clang which ships with Xcode. For example when you run a command ./swift/utils/build-script --release --skip-build-benchmarks --swift-darwin-supported-archs "$(uname -m)" --sccache --skip-ios --skip-tvos --skip-watchos it should appear in the logs:

-- CMake (/opt/homebrew/Cellar/cmake/3.22.2/bin/cmake) Version: 3.22.2
-- CMake Make Program (/opt/homebrew/bin/ninja) Version: 1.10.2
-- C Compiler (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang) Version: 13.0.0.13000029
-- C++ Compiler (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++) Version: 13.0.0.13000029

What does appear in your logs?
I'm not really sure this is the issue, but I'd give a try either specify the Xcode clang compiler... but not sure how to change it in the build script (you could take a look in those cmake variables CXX — CMake 3.28.0-rc5 Documentation), other option you could uninstall llvm binaries and try it, but that don't seem the correct one...

Hope that helps in some way =]

2 Likes

Haha. :smile: You're correct! I completely forgot about that! Thank you!