How should I share code between modules (targets in Swift package terms) defined in Package.swift
while still exposing APIs from the shared code to library users? Another way to phrase this question is: How to share internal
API in module with specific other modules (other libraries) but not library users.
For example, say I have 2 libraries, Human and Dog, and users only need 1 of them (or use both if they want). I came up with 2 approaches:
target(sources:)
documented here. This actually throws an error if 1 source file is shared between 2 targets: target 'Library Human' has sources overlapping sources
.I think the 2nd option is better but it doesn't work. Perhaps there is a better option I don't know about?
The reason why they need to be in separate modules is because one (Human) depends on a rather large dependency which should not be required for Dog.
I originally posted this on Swift forums here, and will update here with a solution if I found one.
I solved this by doing the first method I listed in the question (4 modules):
I then in Library A and Library B, I have a file called Exports.swift
which has @_exported import Core
.