Opting out of automatic Foundation linking on macOS?

I'm working on a cross platform codebase where my principle development is being done on macOS in SPM. Things are going fairly smoothly, but on a few occasions I've discovered issues in our usage of Foundation once I start testing my code on Linux. Is there a way to "opt out" of apple's foundation implementation on macOS (at least in debug and or test builds) to help catch these issues earlier?

Thanks,
mike

The most effective way I've found to catch that sort of issue is with a CI that just double-checks by building and testing with a Linux container or VM instead. YMMV - not sure if that's an option for you or not.

Since it's integrated into the compiler, SwiftSyntax has a unit test that verifies that only a precise set of libraries are linked into its targets. Would adapting something like that to assert that Foundation isn't linked work for you?

1 Like

That's what I'm doing now... was hoping to never write the bad code though.

2 Likes

You can use VSCode Dev Containers to build and run the test on Linux to ensure you don't hit any Foundation landmines.

This should all be solved with the new OSS Foundation soon :tm:

2 Likes

I'm trying to think through how that might work, because linking foundation is fine... it's the differences between apple's foundation and the swift community one. (The most recent thing that bit me was FoundationXML being split out). None of these things are horribly painful to fix once the CI pipeline catches them... but it's a fairly constant source of churn in my git history. My hope was that I could force SPM to use the community Foundation while building on macOS as well.

3 Likes

Yea, it seems CI is the best course of action at the moment.

I've been following the new foundation conversation, but I don't see how this will improve the situation at all. There will still be two sources of truth, one on macOS and one everywhere else correct? Or is swift going to target the OSS version on all platforms?

2 Likes

It sounds like the intention is for the new open source, Swift implementation of Foundation to be used on all platforms. If Apple can figure out the binary compatibility on their platforms at least. And I wouldn't expect it any time soon.

It wouldn’t solve the FoundationXML import problem, though, because Foundation-on-Apple-platforms has to continue behaving how it always has for source compatibility there. So it won’t be a panacea.

I thought the idea was to have the same modules everywhere, with Foundation as an umbrella and for compatibility.

Ah, maybe if you eschew import Foundation and always use the specific sub-projects. But import Foundation has to continue doing things like re-exporting CoreFoundation on Apple platforms.

So I guess we've come full circle... this is likely to remain a problem for development on xplat software on macOS for the foreseeable future.

Is there a feature request here? Should SPM have an option to use swift-corelibs-foundation on macOS? Would that even work and if so, would it be useful for catching these kind of build issues?

mike

Every time this has come up before we've been told it's not generally possible. I don't think that's changed.

This recent thread seems relevant, even though it may not be 100% the same thing:

Swift 5.7 on macOS Catalina and a toolchain for macOS:

1 Like