Cmake build failures with utils/build-script and ninja

cmake version 3.25.1
mac OS 12.6.1 on an M1

Hi all. I'm brand new to the Swift compiler and am running into some issues with building. I have successfully built a few times, and have compiled a helloworld.swift with the built compiler. But I am running into some issues with cmake that is preventing me from building both through the build-script and through ninja.

Using the build-script, a number of CMake errors like this appear near what seems like the end of the build process. I've provided the first error below, with some succesful output above it, to give it context in the build process.

-- Swift Benchmark Suite:
--   SWIFT_BENCHMARK_BUILT_STANDALONE = FALSE
--   SWIFT_BENCHMARK_USE_OS_LIBRARIES = OFF
--   SWIFT_EXEC         = /Users/mwylder/Developer/swift-project/build/Xcode-DebugAssert/swift-macosx-arm64/Debug/bin/swiftc
--   SWIFT_LIBRARY_PATH = /Users/mwylder/Developer/swift-project/build/Xcode-DebugAssert/swift-macosx-arm64/Debug/lib/swift
--   SWIFT_RPATH_BASE   = @executable_path/../lib/swift
--   CLANG_EXEC         = /Applications/Xcode-14.1.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
--   SWIFT_BENCHMARK_EXTRA_FLAGS =
--   SWIFT_OPTIMIZATION_LEVELS = Onone;O;Osize
--   ONLY_PLATFORMS = macosx;iphoneos;appletvos;watchos;linux
--   PAGE_ALIGNMENT_OPTION = -Xllvm;-align-module-to-page-size
--   found platforms: macosx;iphoneos;appletvos;watchos
--   found sdks:
--     /Applications/Xcode-14.1.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk
--     /Applications/Xcode-14.1.0.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.1.sdk
--     /Applications/Xcode-14.1.0.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS16.1.sdk
--     /Applications/Xcode-14.1.0.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS9.1.sdk
CMake Warning at docs/CMakeLists.txt:23 (message):
  Unable to find sphinx-build program.  Not building docs


-- Configuring done
-- Generating done
CMake Error in lib/ASTGen/CMakeLists.txt:
  Imported target "SwiftSyntax::SwiftBasicFormat" includes non-existent path

    "/Users/mwylder/Developer/swift-project/build/Xcode-DebugAssert/earlyswiftsyntax-macosx-arm64/lib/swift/host"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.

Ninja also errors out - it seems to want to use a different version of cmake than the one currently installed.

ninja: Entering directory `../build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64'
[0/1] Re-running CMake...
/bin/sh: /opt/homebrew/Cellar/cmake/3.23.2/bin/cmake: No such file or directory
FAILED: build.ninja
/opt/homebrew/Cellar/cmake/3.23.2/bin/cmake --regenerate-during-build -S/Users/mwylder/Developer/swift-project/swift -B/Users/mwylder/Developer/swift-project/build/Ninja-RelWithDebInfoAssert/swift-macosx-arm64
ninja: error: rebuilding 'build.ninja': subcommand failed

Some of this seems to be related to my environment setup. I upgraded cmake after encountering this issue. I may also not understand when to use the build-script vs ninja -- the error message for build-script mentions that an "uninstall procedure" may not have completed successfully.

Thanks in advance. Hope to start contributing to the language soon :slight_smile:

Fixed the build-script issue by adding --bootstrapping=off because it is on an M1 Mac, but still have issues with ninja.

Have you try a build with --clean after upgrading cmake?
I know @anthonylatsis was investigating an issue regarding ninja/cmake failures in some environment. But not sure is the same thing...

Hi! I was experiencing the same error with --clean, but I was able to fix the issue with --bootstrapping=off, but am still experiencing the ninja error.

Ok, there is any other error bellow that No such file or directory? Sometimes there is an earlier failure that end up causing those sort of error where cmake expects a file produced by an early stage that failed. So can you try spot any other suspect output in the logs? Kinda looking for the root =]

So you have done a successful clean build and you are still seeing this Ninja error in the newly generated build directory? Could you share your build-script and Ninja invocations?

You use build-script to build the entire toolchain after a checkout, and ninja to build compiler targets (most commonly swift-frontend) incrementally after modifications.

Thanks for walking through this everyone. I seem to have worked through it. I was losing track of which flags I was using and what results they were giving me. It's easy to lose track :face_with_spiral_eyes:

Seems like the problem had to do with invoking utils/build-script with the flags --xcode and --clean together. Some takeaways:

  • --bootstrapping=off was needed for my M1 Mac
  • --clean was needed to clean out any reference to older versions of cmake.
  • Invoking both --xcode and --clean was causing the error in the first code snippet in the OP.
  • --xcode without --clean worked after a successful --clean invokation
  • ninja -C ../build/Ninja-RelWithDebInfoAssert/swift-macosx-$(uname -m) swift-frontend worked after a successful invokation with --clean
1 Like