CF on platforms other than Darwin has been a topic on which there has been a consistent response, but that consistent response always included the caveat that things were in a transitory state. The commitment I've echoed so far has been that:
Core Foundation is an implementation detail of Foundation outside of Darwin.
To underline this, you cannot use CF API if you do
import Foundation(which you can do on Darwin).
However, due to a set of implementation details, we needed to ship the CF module. This meant that code that did
import CoreFoundationexplicitly could still use CF on Linux.
This has proven a considerable implementation headache. Several features of CF you would reasonably expect to work simply do not or do not do so reliably or correctly (most notably, custom allocators when paired with objects specifically) in a non-Darwin world.
To mitigate this, I've been working with some port maintainers to make sure that Core Foundation is not available to use on platforms we ship anew. Most of this enforcement has been by preventing the linker from seeing CF symbols, which is not ideal and still poses some complications (as the CF module still needs to be shipped even on platforms where it is unusable).
I've been working on a plan to formalize this unavailability over time without breaking any current code today*. However, the plan does have an eventual endpoint in the middle future where
import CoreFoundation will be a hard error in your source code.
(* On platforms for which we distribute build products — the ones listed at https://swift.org/download.)
(This aside contains a rough timeline of this change.)
- Newly brought-up platforms (like Windows) mark all Core Foundation symbols as not exported or private — you cannot link your code to these symbols on those platforms.
Foundation moves CF under
@_implementationOnly, preventing it from being reexported, in most of its files and all of its implementation (that is — even files that aren't
@_implementationOnlyare rewritten as much as possible to work as if
@_implementationOnlywas used). I have just merged this one.
On platforms other than Linux, we force all Foundation files to import CF only through
@_implementationOnly. I merged this one too.
Once this lands today, port maintainers can start removing the CoreFoundation module (again: on platforms other than Linux where this module was available but never worked.)
In the future:
We cover needs that CF has API for but the cross-platform subset of Foundation doesn't with experimental or new definitive API, or implementation of missing API (such as
Linux has a warning period about removal, and then a hard removal at some point.
This only applies to Linux specifically; Darwin continues to have access to CF going forward.
There's no change to the open-source nature of CF or the fact it underpins Foundation under this plan — only its availability for direct use by outside code.
Before I commit to this, I wanted to ask:
Does your code rely on Core Foundation outside of Darwin? (Most importantly, do you do so on Linux?) And, if so: what parts of Core Foundation do you rely on, if you can share?
Please let me know; I want to only commit to this course of action if we know that your needs will be supported going forward.
ETA: All changes marked ‘Today’ in the timeline are now in master.