xcodebuild hits "error deserializing an individual record" when building XCTest w/ Foundation

Hello all!

I've been stumped by a compiler assertion I'm hitting in
Asynchronous testing API [AsyncXCTest 6/6] by modocache · Pull Request #43 · apple/swift-corelibs-xctest · GitHub, and was wondering
if anyone could offer some insight.

The pull request has swift-corelibs-xctest depend upon
swift-corelibs-foundation (I'll refer to these as XCTest and Foundation in
this email).

On Linux, this works like a dream. All it takes is linking Foundation when
building XCTest:

$ swiftc -emit-library path/to/XCTest.o \
    -L path/to/Foundation \
    -lswiftGlibc -lswiftCore -lFoundation -lm

On OS X, I use an Xcode workspace that includes XCTest.xcodeproj and
Foundation.xcodeproj. In the "Link Binary with Libraries" step, I link
SwiftFoundation.framework. However, when compiling the project I encounter
the following stack trace:

The problem appears to be in swift::ModuleFile::resolveCrossReference,
where an assertion is hit: "error deserializing an individual record".
Looking at the resolveCrossReference method, it appears error() is called
when a BitstreamCursor encounters an entry that is not a kind
of lvm::BitstreamEntry::Record. I guess there's some sort of malformed
bitcode getting generated somewhere?

This is about as far as I've gotten. I seem to recall a conversation in
Merge pull request #50 from hpux735/gold · apple/swift-corelibs-xctest@6a1e783 · GitHub,
in which people commented that Foundation is always built in Debug mode.
Could that be causing this?

Any advice would be much appreciated!

- Brian Gesiak