Swift 4: Support for static libs / modular development.

I'm not fully aware of the state of discussion, so sorry if it is already
being addressed. I wanted to bring some feedback and awareness about the
need of a supported way to build app components as *static libraries* in
Swift.

We've moved most of our new developments to Swift 3. Our apps are complex,
making use of 10's of internal libraries and/or open source ones. We've
done that for years now, creating reusable components that are built in
Obj-C as static libraries. Static libraries are great for apps: no runtime
cost, stripped to what's really needed (smaller binary). Using tons of
dylibs/frameworks does not make much sense when it comes to building apps
(see below for when they actually make sense).

Swift in its current state (v3) does not support making static libs from
Xcode. This is a major problem for large apps that need to be built on
reusable components.

There are dirty tricks that we use right now (like creating static libs
from object files through specific Xcode phase, or directly importing
source in the app target). Dylibs don't scale. Even more so with Swift. We
see so many tiny bits of code implementing one collection type or specific
algorithms. This is fine, makes a lot of sense, but dylibs don't scale for
that (app launch time). We can't have one dylib per sorting algorithm for
instance.

The case where dylib / frameworks make sense still exist through: system
libraries, or internal app libraries that enables the same feature in both
the app itself and its extensions (in iOS sense). Even in that case, the
best way to handle this situation is that those "large, feature" framework
are themselve built on 10's of smaller static libraries.

Not using dylibs but instead directly importing source in the app target
has its own share of problems. Like the absence of namespace that creates
conflicts because so many developers want to use elegant small names that
Swift rightfully encourages.

Note that ABI stability is orthogonal to this discussion, as the libs
(static, dylibs) I'm mentioning above are built all together with the same
compiler as components of the final product. The way apps are typically
built. ABI stability still makes sense for system libraries / distributed
libraries, but this is another topic.

To summarise, I'd really like to see some official support for building
static libs directly in Xcode / Swift 4 toolchain, as it's really a
limitation currently to build complex apps even though Swift appears to be
a great language to tackle that.

Raphael

Part of the recently accepted (for Swift 4) SE-0146 "Package Manager Product Definitions" [1] is support for static library products in the Swift Package Manager.

SwiftPM is not Xcode, of course. I just thought I'd mention it.

[1]: https://github.com/apple/swift-evolution/blob/master/proposals/0146-package-manager-product-definitions.md

ยทยทยท

On 17 Feb 2017, at 10:28, Raphael Sebbe via swift-evolution <swift-evolution@swift.org> wrote:

I'm not fully aware of the state of discussion, so sorry if it is already being addressed. I wanted to bring some feedback and awareness about the need of a supported way to build app components as *static libraries* in Swift.

Sure, thank you. If SwiftPM gets a working integration in Xcode 9, that
could do it.

Raphael

ยทยทยท

On Fri, Feb 17, 2017 at 1:50 PM Ole Begemann <ole@oleb.net> wrote:

> On 17 Feb 2017, at 10:28, Raphael Sebbe via swift-evolution < > swift-evolution@swift.org> wrote:
>
> I'm not fully aware of the state of discussion, so sorry if it is
already being addressed. I wanted to bring some feedback and awareness
about the need of a supported way to build app components as *static
libraries* in Swift.

Part of the recently accepted (for Swift 4) SE-0146 "Package Manager
Product Definitions" [1] is support for static library products in the
Swift Package Manager.

SwiftPM is not Xcode, of course. I just thought I'd mention it.

[1]:
https://github.com/apple/swift-evolution/blob/master/proposals/0146-package-manager-product-definitions.md

I'd like to add a +1 for this request/discussion starter.
We're on the same boat, with 70+ dynamic libraries, facing the same
challenges as Raphael mentioned.

Jacek Suliga | Flagship Infra

ยทยทยท

On Fri, Feb 17, 2017 at 10:02 AM, Raphael Sebbe via swift-evolution < swift-evolution@swift.org> wrote:

Sure, thank you. If SwiftPM gets a working integration in Xcode 9, that
could do it.

Raphael

On Fri, Feb 17, 2017 at 1:50 PM Ole Begemann <ole@oleb.net> wrote:

> On 17 Feb 2017, at 10:28, Raphael Sebbe via swift-evolution < >> swift-evolution@swift.org> wrote:
>
> I'm not fully aware of the state of discussion, so sorry if it is
already being addressed. I wanted to bring some feedback and awareness
about the need of a supported way to build app components as *static
libraries* in Swift.

Part of the recently accepted (for Swift 4) SE-0146 "Package Manager
Product Definitions" [1] is support for static library products in the
Swift Package Manager.

SwiftPM is not Xcode, of course. I just thought I'd mention it.

[1]: GitHub - apple/swift-evolution: This maintains proposals for changes and user-visible enhancements to the Swift Programming Language.
proposals/0146-package-manager-product-definitions.md

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Until we have native support for this in Xcode (or some sort of SwiftPM
integration that would help with this), I found a workaround to allow
you to trick Xcode into building static frameworks, so you can sidestep
the dynamic framework issues.
You can find it here: GitHub - keith/swift-staticlibs: Scripts to allow Swift static libraries to be compiled in Xcode

ยทยทยท

--
Keith Smiley

On Thu, Mar 9, 2017, at 10:34, Jacek Suliga via swift-evolution wrote:

I'd like to add a +1 for this request/discussion starter.
We're on the same boat, with 70+ dynamic libraries, facing the same
challenges as Raphael mentioned.>
Jacek Suliga | Flagship Infra

On Fri, Feb 17, 2017 at 10:02 AM, Raphael Sebbe via swift-evolution
<swift-evolution@swift.org> wrote:>> Sure, thank you. If SwiftPM gets a working integration in Xcode 9,

that could do it.>>
Raphael

On Fri, Feb 17, 2017 at 1:50 PM Ole Begemann <ole@oleb.net> wrote:

> On 17 Feb 2017, at 10:28, Raphael Sebbe via swift-evolution <swift- >>> > evolution@swift.org> wrote:>>> >
> I'm not fully aware of the state of discussion, so sorry if it is
> already being addressed. I wanted to bring some feedback and
> awareness about the need of a supported way to build app
> components as *static libraries* in Swift.>>>
Part of the recently accepted (for Swift 4) SE-0146 "Package
Manager Product Definitions" [1] is support for static library
products in the Swift Package Manager.>>>
SwiftPM is not Xcode, of course. I just thought I'd mention it.

[1]: https://github.com/apple/swift-evolution/blob/master/proposals/0146-package-manager-product-definitions.md&gt;&gt;&gt;

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_________________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

1 Like