# Package+Module visibility (for libraries)

**URL:** <https://forums.swift.org/t/package-module-visibility-for-libraries/37896>\
**Category:** Using Swift\
**Tags:** packagemanager\
**Created:** [June 25, 2020, 4:52am UTC](https://forums.swift.org/t/package-module-visibility-for-libraries/37896 "2020-06-25T04:52:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexanderUV](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@alexanderUV](https://forums.swift.org/u/alexanderUV)\
**Post date:** [June 25, 2020, 4:52am UTC](https://forums.swift.org/t/package-module-visibility-for-libraries/37896/1 "2020-06-25T04:52:56Z")

</div>

Hi, I'm trying to build a Swift package which exposes certain functionality in a multi-platform way. Different platforms will have specific implementations of protocols defined at the core. I would like, however, that whoever is consuming my library - is able to use just ONE single import. I see that if I follow my structure, the user app would have to import my internal modules/targets independently, which is not desired.

I have:

- Core Protocols and Structures ("CoreLib" target) - bottom layer

Then I define implementations that are platform-specific: middle layer

- macOS + iOS implementations ("AppleLib" target)
- Linux implementations ("LinuxLib" target)

Finally I have a top layer which depends on Core + (compile time conditional on platform Lib). This is my "LibX"

So, I expect that if my user app wants to consume these APIs, they should be able to just use

```swift
import LibX

```

rather than

```swift
import CoreLib // this should be an implementation detail
import LibX

```

The internal structure of my modules/targets should be an implementation detail that shouldn't be exposed to the consumers of the library. This would be very handy if in the future I refactor my library without breaking the APIs and signatures.

Is this supported or planned?

---

<div class="post-metadata">

**Author:** ![taylorswift](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/taylorswift/32/43413_2.png) [@taylorswift](https://forums.swift.org/u/taylorswift)\
**Post date:** [June 25, 2020, 5:30am UTC](https://forums.swift.org/t/package-module-visibility-for-libraries/37896/2 "2020-06-25T05:30:45Z")

</div>

```swift
#if os(Linux)
#elseif os(macOS)
#else
#endif

```

---

<div class="post-metadata">

**Author:** ![NeoNacho](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/neonacho/32/1368_2.png) [@NeoNacho](https://forums.swift.org/u/NeoNacho)\
**Post date:** [June 25, 2020, 5:42am UTC](https://forums.swift.org/t/package-module-visibility-for-libraries/37896/3 "2020-06-25T05:42:39Z")

</div>

I would suggest combining the "AppleLib" and "LinuxLib" targets into one "LibX" target which uses conditionals (e.g. `#if os(Linux)`). As long as clients don't need to directly call API of `CoreLib` which seems like they should not if it is truly an implementation detail, only `import LibX` will be needed in client code.

---

<div class="post-metadata">

**Author:** ![alexanderUV](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@alexanderUV](https://forums.swift.org/u/alexanderUV)\
**Post date:** [June 26, 2020, 4:05am UTC](https://forums.swift.org/t/package-module-visibility-for-libraries/37896/4 "2020-06-26T04:05:37Z")

</div>

Yes, that would work. The only "impractical" aspect of this approach is that I would have to add conditionals in many files.  
I guess it's the lesser evil as I would have to "republish" certain types under LibX to make it work otherwise (probably via typealiases - that would be dirty...).

Thanks @taylorswift and @NeoNacho!

---

<div class="post-metadata">

**Author:** ![ddddxxx](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ddddxxx/32/3237_2.png) [@ddddxxx](https://forums.swift.org/u/ddddxxx)\
**Post date:** [June 26, 2020, 4:43am UTC](https://forums.swift.org/t/package-module-visibility-for-libraries/37896/5 "2020-06-26T04:43:41Z")

</div>

`@_exported import CoreLib` from LibX should be sufficient. This doesn't prevent users from manually `import CoreLib` however.
