What's the right way to distinguish between corelibs frameworks from Apple propreitary ones?

Concrete example: I'm writing some code that relies on some internal APIs of Apple's proprietary XCTest implementation, which aren't available in the open source "corelibs" implementation.

What's the correct way to discriminate between the two cases?

Currently I'm using:

#if _runtime(_ObjC)
    print("We're probably using the proprietary implementation of XCTest")
#elseif _runtime(_Native)
    print("We're probably using the open source implementation of XCTest")
#else
    #error("Unrecognized runtime")
#endif

But this seems indirect, and perhaps error-prone. E.g. can a person " crisscross" things and use the open source XCTest on a Mac?

1 Like

As far as I understand, they shouldn't, even if they theoretically can. Especially if they're doing that in a library that can then be linked with an application linking with the core libraries shipped with the OS. That will cause duplicate symbol collisions most probably.

If you aren't working on the Swift toolchain and SDK on Apple's platforms, you're very highly unlikely to stumble upon an open-source implementation of XCTest or Foundation. So it's better to assume that all core libraries on Darwin are coming bundled with the OS, unlike on other platforms.

Understood.

Given that, which platform condition would be best to check? _platform, os, canImport(Darwin), or something else?

seems to be the shortest for me, and should be valid on all Apple platforms, so I'd pick that one. But I bet there are people who are much more knowledgeable in the topic of bundled core libs on Apple platforms than me, I hope they correct me if I'm wrong.

1 Like
Terms of Service

Privacy Policy

Cookie Policy