[Stuck Newbie Needs Help] Can't run bin/swiftc

I tried to play around with the code in Version.cpp to see if the changes I was making to the codebase were actually working on the build (by running swift --version). I found that the binaries built by Xcode are in the


directory (why not right in build/Ninja-.../swift-macosx-arm64/bin? I followed these instructions)

Anyway, if I try to interpret a file, running

path/to/my/bin/swiftc /path/to/file.swift

, I get

error: unable to load standard library for target 'arm64-apple-macosx12.0'

Some people on the internet say that just restarting Xcode worked for them for similar issues. Didn't work for me.

I also tried using bin/swift-frontend -interpret.

Built with this command, not getting that error anymore :+1:

A small piece of the compiler has recently been implemented in Swift. Hence to build swift-frontend with Swift sources, we must now first build a version of swift-frontend that excludes them (or use a compiler from a pre-installed Swift toolchain). bootstrapping0/bin is where the latter so-called level-0 swift-frontend winds up. This error pops out because there is no Standard Library module built for the level-0 compiler. You are still welcome to grab the host system Standard Library with xcrun -sdk macosx .../bootstrapping0/bin/swift-frontend or .../bootstrapping0/bin/swift-frontend -sdk $(xcrun --show-sdk-path).

Is there no swift-frontend binary in build/Ninja-.../swift-macosx-arm64/bin?

1 Like

When I used Xcode, I did have a build/Ninja-.../swift-macosx-arm64/bin but it did not update with my code changes when I rebuilt the project with cmd + b, only build/Ninja-.../swift-macosx-arm64/bootstrapping0/bin used to reflect my code changes.

I gave up on using Xcode now, I'll just use a naked text editor like Vim or Vscode and see warnings and errors when compiling in the terminal.

I'm using the following commands and everything is finally working fine!

# Clean first build
utils/build-script --release --debug-swift --clean

# Incremental build
ninja -C ../build/Ninja-ReleaseAssert+swift-DebugAssert/swift-macosx-arm64 && ../build/Ninja-ReleaseAssert+swift-DebugAssert/swift-macosx-arm64/bin/swiftc --version

# Compile and run main.swift file
../build/Ninja-ReleaseAssert+swift-DebugAssert/swift-macosx-arm64/bin/swiftc -sdk $(xcrun --show-sdk-path) && ./main

Thank you much for your help, those are exactly the pointers I needed.

You can work around this issue by passing the --bootstrapping=off option to build-script.

1 Like