# Building CoreFoundation for Darwin

**URL:** <https://forums.swift.org/t/building-corefoundation-for-darwin/23463>\
**Category:** Core Libraries\
**Created:** [April 22, 2019, 1:20am UTC](https://forums.swift.org/t/building-corefoundation-for-darwin/23463 "2019-04-22T01:20:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![libsystem-ethan](https://avatars.discourse-cdn.com/v4/letter/l/8797f3/32.png) [@libsystem-ethan](https://forums.swift.org/u/libsystem-ethan)\
**Post date:** [April 22, 2019, 1:20am UTC](https://forums.swift.org/t/building-corefoundation-for-darwin/23463/1 "2019-04-22T01:20:29Z")

</div>

Firstly, I know that questions similar this have been asked in [a previous thread](https://forums.swift.org/t/relation-between-darwin-and-swift-core-foundation/9882) but I didn't want to bump a 1+ year old thread, so I shall ramble here - I do apologise if this is the wrong place to post.

In the aforementioned thread it is said that tarballs of CF are no longer shipped to [opensource.apple.com](https://opensource.apple.com), instead they've are imported into the GitHub project. It also said that the Darwin CF is a superset of the `swift-corelibs-foundation` - and I was wondering if it would at all be possible if [the "old" CF build system](https://opensource.apple.com/source/CF/CF-1153.18/Makefile.auto.html) could be brought down into `swift-corelibs-foundation` - or at least be republished back to the Apple Open Source portal. Doing so would make it significantly easier for us at PureDarwin to build a functioning CF framework, as the current project is very intertwined with Swift - I can't even seem to build the CF from the Swift 5.0 release without `DEPLOYMENT_RUNTIME_SWIFT` defined.

I've tried many was around this - firstly by creating a target for CoreFoundation as a shared framework in Xcode and attempting to copy as many of the target setting over (which just lead to a bit of a mess, and after teasing out lots of build errors, I was left segfaults in the library that was built), and using CMake, however neither the Xcode build system nor CMake seem to be suited to building a (near) drop-in replacement for `/System/Library/Frameworks/CoreFoundation.framework`.

If anyone has any pointers on anything that can be done, that would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![Tony\_Parker](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tony_parker/32/273_2.png) [@Tony\_Parker](https://forums.swift.org/u/Tony_Parker)\
**Post date:** [April 29, 2019, 9:30pm UTC](https://forums.swift.org/t/building-corefoundation-for-darwin/23463/2 "2019-04-29T21:30:01Z")

</div>

Hi @libsystem-ethan,

We do want to support a kind of 'stand-alone' CF build with the same sources as are used for Swift. There is a "runtime swift" concept that would need to be turned off in this mode - when built for Swift we use the Swift runtime for things like `CFRetain` and `CFRelease`.

@millenomi was working on this project at one point, but it's been prioritized behind completing some of the higher level work.

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [April 30, 2019, 12:40am UTC](https://forums.swift.org/t/building-corefoundation-for-darwin/23463/3 "2019-04-30T00:40:57Z")

</div>

@libsystem-ethan, having done the work to port the build system for CoreFoundation to CMake, I am curious what in the current system is insufficient for your needs. I did spend a fair amount of effort trying to retain the ability to build CoreFoundation standalone, without the Swift runtime, and as a framework.

If there are specific issues, perhaps those can be resolved to avoid recreating more competing build systems which diverge.

---

<div class="post-metadata">

**Author:** ![millenomi](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/millenomi/32/2922_2.png) [@millenomi](https://forums.swift.org/u/millenomi)\
**Post date:** [May 6, 2019, 10:42pm UTC](https://forums.swift.org/t/building-corefoundation-for-darwin/23463/4 "2019-05-06T22:42:39Z")

</div>

@libsystem-ethan: while I haven't explored the functionality of the build setup, CF should build correctly the way you desire if you use its CMakeLists.txt file without setting the `CF_DEPLOYMENT_SWIFT` variable. That will cause the build to be standalone.

ETA: ["Its" CMakeLists.txt](https://github.com/apple/swift-corelibs-foundation/blob/master/CoreFoundation/CMakeLists.txt) file is the one in the CoreFoundation directory of the swift-corelibs-foundation repository.
