Where are the "headers" for a Swift dynamic library?

So I am trying to understand the Swift build process, and I'm struggling to understand how exactly dynamic libraries are handled.

So for instance, in the C/C++ world, if I am linking against a dynamic library, I would need to link the build artifact (.dylib) and I would also have to specify the header search paths (-I argument) so that the compiler can understand the public interface of the library.

Is there a Swift analog to this? For instance, if I look at the .build/debug directory for a SPM package which produced dynamic library products, I can see the .dylib artifacts there, but it's not clear to me where the interfaces are defined.

In your example, the .swiftmodule files are the compiled interfaces (automatically extracted from the .swift files).

1 Like

Interesting, thanks! Do you know how it works for mixed-language products? So for instance, it looks like each Swift target gets a .build directory, a .swiftdoc and a .swiftmodule, but C language targets only get a .build with a .d and a .o inside. Would the "include path" for those modules be the include dir in the original source location?

Yes, exactly.

You can do build -v if you want to see the nitty details passed to each compiler.

1 Like

Cool, good to know. Thank you!