# 🥺 Hard to debug/develop SwiftFoundation

**URL:** <https://forums.swift.org/t/hard-to-debug-develop-swiftfoundation/59135>\
**Category:** Core Libraries\
**Tags:** foundation\
**Created:** [July 22, 2022, 1:02am UTC](https://forums.swift.org/t/hard-to-debug-develop-swiftfoundation/59135 "2022-07-22T01:02:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![YOCKOW](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/yockow/32/20636_2.png) [@YOCKOW](https://forums.swift.org/u/YOCKOW)\
**Post date:** [July 22, 2022, 1:02am UTC](https://forums.swift.org/t/hard-to-debug-develop-swiftfoundation/59135/1 "2022-07-22T01:02:12Z")

</div>

Once upon a time, we were able to develop SwiftFoundation only with Xcode, latest toolchain, swift-corelibs-xctest repo, and swift-corelibs-foundation repo.  
Nowadays, we can't do so because:

- [SR-12177](https://github.com/apple/swift-corelibs-foundation/issues/3271) hinders our using latest toolchain to run TestFoundation.

- Xcode's default toolchain lacks some(all?) SPIs and can't compile SwiftFoundation. (For example, "Cannot find '\_forEachField' in scope" errors occur because `@_spi(Reflection) import Swift` imports no SPI symbols.)

- TestFoundation can't be compiled with any toolchain using Xcode which tries to load duplicately modulemaps of CoreFoundation. [[Forum topic #50360](https://forums.swift.org/t/cant-run-testfoundation-target-in-swift-corelibs-foundation-repository/50360)] [[GitHub issue #4608](https://github.com/apple/swift-corelibs-foundation/issues/4608)]

Thus we must checkout swift repo and related repos and run 'swift/utils/build-script' to test SwiftFoundation.  
How do we regain the past condition?  
I have no idea.

---

<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:** [July 25, 2022, 4:06pm UTC](https://forums.swift.org/t/hard-to-debug-develop-swiftfoundation/59135/2 "2022-07-25T16:06:54Z")

</div>

I haven't had the chance to try it myself yet, but do you think the improvements in Swift 5.7 for module aliasing could help with the CoreFoundation import issue?

> <https://github.com/apple/swift-evolution/blob/main/proposals/0339-module-aliasing-for-disambiguation.md>

For the `_forEachField` thing, I think the ultimate resolution is to find a way to get reflection to be a first class Swift feature. `AttributedString` needs to use it to get the API surface we wanted, unfortunately.

---

<div class="post-metadata">

**Author:** ![YOCKOW](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/yockow/32/20636_2.png) [@YOCKOW](https://forums.swift.org/u/YOCKOW)\
**Post date:** [July 27, 2022, 8:12am UTC](https://forums.swift.org/t/hard-to-debug-develop-swiftfoundation/59135/3 "2022-07-27T08:12:11Z")

</div>

> [@Tony\_Parker](#):
>
> do you think the improvements in Swift 5.7 for module aliasing could help with the CoreFoundation import issue?

IIUC, CoreFoundation is a simple clang module that is not supported by SE-0339, isn't it?

> - Only pure Swift modules allowed for aliasing: no ObjC/C/C++/Asm due to potential symbol collision.

* * *

> [@Tony\_Parker](#):
>
> For the `_forEachField` thing, I think the ultimate resolution is to find a way to get reflection to be a first class Swift feature. `AttributedString` needs to use it to get the API surface we wanted, unfortunately.

I agree.  
However, as mentioned above, the overlay also requires `@_spi` feature, so that the problem is more general.

---

<div class="post-metadata">

**Author:** ![Fidetro](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/fidetro/32/21912_2.png) [@Fidetro](https://forums.swift.org/u/Fidetro)\
**Post date:** [July 30, 2022, 5:44pm UTC](https://forums.swift.org/t/hard-to-debug-develop-swiftfoundation/59135/4 "2022-07-30T17:44:28Z")

</div>

I've been trying to debug SwiftFoundation recently and have run into the same problem.  
I'm trying other ways to debug SwiftFoundation,actually not ideal.  
Can you tell me more about "Thus we must checkout swift repo and related repos and run 'swift/utils/build-script' to test SwiftFoundation."?  
Thanks

---

<div class="post-metadata">

**Author:** ![YOCKOW](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/yockow/32/20636_2.png) [@YOCKOW](https://forums.swift.org/u/YOCKOW)\
**Post date:** [August 1, 2022, 3:47am UTC](https://forums.swift.org/t/hard-to-debug-develop-swiftfoundation/59135/5 "2022-08-01T03:47:40Z")

</div>

> [@Fidetro](#):
>
> Can you tell me more about "Thus we must checkout swift repo and related repos and run 'swift/utils/build-script' to test SwiftFoundation."?

Sorry, but I think I should have added "on Linux" to that sentence... 🙊  
'build-script' seems not to build TestFoundation on macOS.

---

<div class="post-metadata">

**Author:** ![Fidetro](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/fidetro/32/21912_2.png) [@Fidetro](https://forums.swift.org/u/Fidetro)\
**Post date:** [August 4, 2022, 6:31pm UTC](https://forums.swift.org/t/hard-to-debug-develop-swiftfoundation/59135/6 "2022-08-04T18:31:23Z")

</div>

I'm disappointed that it looks like the problem of not being able to compile with Xcode has been around for a long time,And I don't see any official Apple developers providing us with answers or working on solutions.

---

<div class="post-metadata">

**Author:** ![vidugloeck](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/vidugloeck/32/29299_2.png) [@vidugloeck](https://forums.swift.org/u/vidugloeck)\
**Post date:** [March 26, 2023, 7:18am UTC](https://forums.swift.org/t/hard-to-debug-develop-swiftfoundation/59135/7 "2023-03-26T07:18:54Z")

</div>

I am encountering the same issue. Is there currently any way to run TestFoundation in Xcode?  
Any help would be much appreciated. 🙏🏽

---

<div class="post-metadata">

**Author:** ![ahs1](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ahs1/32/34974_2.png) [@ahs1](https://forums.swift.org/u/ahs1)\
**Post date:** [April 18, 2024, 8:50am UTC](https://forums.swift.org/t/hard-to-debug-develop-swiftfoundation/59135/8 "2024-04-18T08:50:31Z")

</div>

Same issue here. Hard to understand that compiling such base of swift is so hard on the preferred platform [macOS] for this language.
