Building PackageManager fails

Whenever I try building SwiftPM as part of a build of Swift on Linux it fails with this error:

/swift_source/swiftpm/TSC/Sources/TSCTestSupport/AssertMatch.swift:11:8: error: no such module 'XCTest'

I did specify --xctest=1 in my build-script arguments.

Any help appreciated!

Could you provide your full build-script invocation?

That particular run was with this command below. I also tried it with --xctest=1, without --xctest, without --skip-test-swiftpm, etc.

Right now I'm doing a run with just --swiftpm=1 --libicu=1 -R to see if maybe one of the other commands was responsible for SPM needing to build TSC. But it seems like a bug to me that if --xctest=1 or --xctest are specified then, it still can't find Xctest.

utils/build-script \
       --libicu=1 \
       --xctest \
       --libcxx \
       --llbuild \
       --lldb \
       --release-debuginfo \
       --foundation=1 \
       --libdispatch=1 \
       --swiftpm=1 \
       --build-swift-static-stdlib \
       --install-destdir=/ \
       --install-swift \
       --install-swiftpm \
       --install-lldb \
       --install-foundation \
       --install-libdispatch \
       --install-libicu \
       --install-libcxx \
       --install-llbuild \
       --skip-build-android \
       --skip-build-benchmarks \
       --skip-build-cygwin \
       --skip-build-freebsd \
       --skip-build-haiku \
       --skip-build-ios-device \
       --skip-build-ios-simulator \
       --skip-build-osx \
       --skip-build-tvos-device \
       --skip-build-tvos-simulator \
       --skip-build-watchos-device \
       --skip-build-watchos-simulator \
       --skip-test-android \
       --skip-test-android-host \
       --skip-test-cygwin \
       --skip-test-foundation=1 \
       --skip-test-freebsd \
       --skip-test-haiku \
       --skip-test-ios-32bit-simulator \
       --skip-test-ios-host \
       --skip-test-ios-simulator \
       --skip-test-linux \
       --skip-test-osx \
       --skip-test-swiftpm \
       --skip-test-tvos-host \
       --skip-test-tvos-simulator \
       --skip-test-watchos-host \
       --skip-test-watchos-simulator \
       --skip-test-benchmarks \
       --skip-test-sourcekit \
       --reconfigure \
       -j8

PS—I've tried building with the buildbot_linux but it always fails because I haven't specified an installable package path. But I'm not trying to make an installable package so I gave up on that.

You probably need --install-xctest. You might want to try the --infer option that @Michael_Gottesman added: [build-script] Automatic inferences of dependencies using new option: "--infer"

Alternatively, you could start with a preset and edit it to suit your needs. For example,

$ build-script --preset=buildbot_linux --expand-invocation install_destdir=/ installable_package=/fake2

will show what the preset expands to. If you don't want to build an installable package you can remove --installable-package /fake2 before building.

1 Like

I'm building Swift 5.2.4... is there a way to use --infer with 5.2.4 or would I have to cherry-pick build-script from master branch?

Thanks for the tips, will try these.

Ah, probably not.

You're probably best off using the preset and have it create an installable package, even if you don't use it (or you could just modify utils/build-presets.ini to not create an installable package for that preset, as Ben said).

If you really want to customize your build, your long command above can be minimized down to:

utils/build-script \
       --release-debuginfo \
       --libicu \
       --xctest \
       --libcxx \
       --llbuild \
       --lldb \
       --swiftpm \
       --build-swift-static-stdlib \
       --install-destdir=/ \
       --install-swift \
       --install-swiftpm \
       --install-lldb \
       --install-xctest \
       --install-foundation \
       --install-libdispatch \
       --install-libicu \
       --install-libcxx \
       --install-llbuild \    
       --reconfigure \
       -j8

Note that I added --install-xctest as Ben mentioned, without which you won't be able to build SwiftPM. All the --skip-build-* and --skip-test-* flags shouldn't be needed as those aren't built or tested by default. Foundation and libdispatch are implicitly built if XCTest is built.

As I mentioned in your other thread, this install will likely overwrite any libicu, lldb, clang, etc. packages you already have installed in /usr, so you may not want to override destdir if that's the case.