Swift build - XCTest sometimes missing

Dear All,

I am using two Macs for development, both have the latest macOS (15.1 (24B83)) and XCode (16.1 (16B40)) versions.

On the laptop, this works:

git clone https://github.com/jakeheis/Ice
cd Ice
swift build -c release

...and I get the executable in .build/release/ice

On the desktop, the build fails with the following error:

/.../Snow/.build/checkouts/Icebox/Sources/Icebox/Icebox.swift:11:8: error: no such module 'XCTest'
  9 | import Foundation
 10 | import PathKit
 11 | import XCTest
    |        `- error: no such module 'XCTest'
 12 | 
 13 | public protocol IceboxConfig {

I have removed and reinstalled XCode and the command line tools on the desktop, but still get the same error.

As the installation process for both machines was the same, I am rather perplexed what might be causing the issue.

I am new to server side swift, coming from java/quarkus, rust, python etc. and all those have their idiosyncrasies, but usually those are consistent across machines.

As I literally have only two swift projects, Ice (for re-build watching) and my own, on both machines, I would much appreciate any guidance as to how to resolve this issue.

Cheers,
Thomas

I'm surprised this works on both machines to be honest. You shouldn't be able to import XCTest in a non-test binary because it's not there for an executable build, as you found. What are you using it for?

Ice is a tool I was using to auto-rebuild my own project when the source is updated (ice run -w).

I have not touched the source of Ice at all.

It does build on the laptop without any changes or issues (as per its github page GitHub - jakeheis/Ice: ❄️ A developer friendly package manager for Swift; 100% compatible with Swift Package Manager) and the compiled executable runs on both machines.

Honestly surprised that works, but I can build it locally too.

So, the next question is what is different to your setup. Do you have Homebrew installed? That sometimes messes up the Swift toolchain. You can try fixing it with sudo xcode-select -s /Applications/Xcode.app (or wherever Xcode is installed) to make sure it's using a proper toolchain

Brilliant! That was it.

Thank you very much for your help, I have been looking for a solution for quite a few hours.

Out of curiosity...

Doing sudo xcode-select -s /Library/Developer/CommandLineTools, as the command line tools were also installed (on both machines, by the way), causes the build to fail again with the XCTest error.

So I gather that the Xcode command line tools are actually missing some Xcode parts?

Homebrew is also installed on both machines -- would it set the toolchain to CommandLineTools instead of Xcode.app under certain (not entirely evident) circumstances?

Apologies for the many questions, I am evaluating swift as a long-term option and having a stable dev/build environment is rather important.

(Testing vapor, by the way, and I have been extending Ice to watch Resources and run tailwind before each build.)

Cool!

The Command line tools contain things like Git, Python and other things. It does not contain the full SDKs to build Swift programs on macOS. The fact that Homebrew requires it and then overrides the default toolchain path is frustrating to say the least. IIRC if you install Xcode and then Homebrew it overwrites it. We've been fighting this issue for years in Vapor.

It looks like there is vapor on MacPorts, but it's a rather different software...

So will be staying with HomeBrew, and added sudo xcode-select -s /Applications/Xcode.app to my machine deployment "script".

Thanks again for your help! And for your work on Vapor..!