How to exclude standard but unused libswift*.dylib's from macOS app bundle and reduce bundle size
Asked Answered
S

2

6

When I build my simple menubar cocoa application written in Swift 4 with Xcode 9, a lot of libswift*.dylib libraries are linked/downloaded/embedded into .app bundle,into Frameworks folder as seen below:

libswift

I am only using import Cocoa and import Foundation in my project, and some @objc functions as selector to timer functions. I really don't think my very simple menubar app would need some 3D rendering Metal library functions or any SwiftOnoneSupport, so I would like them to be removed from the .app bundle. (Same libraries are also included in the helper app for launch at login feature, which makes even the helper app over 10 MB)

I would have thought Xcode would just copy whatever is neccessary by default actually. Some similar questions were asked here and here but I don't think there is a fulfilling and up-to-date answer to both.

What I have tried so far

I set ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES to NO in Build Settings. It doesn't seem to have any effect.

I set LINK_WITH_STANDARD_LIBRARIES to NO in Build Settings. It ruined everything and couldn't make it build even though I tried to add some frameworks(Cocoa, Foundation) on my own under Linked Frameworks and Libraries section.

Smithson answered 27/8, 2018 at 22:19 Comment(4)
Note that things like libSwiftMetal are just Swift's overlay on the underlying framework that ships with the OS, and should therefore be fairly lightweight. For me, building a sample Cocoa app, the embedded frameworks come to 11.1MB, with 9.7MB of that being libSwiftCore + libSwiftFoundation. So unless a couple of extra MBs on top of that is a problem, I wouldn't worry about it. Though the situation will be much better once Swift reaches ABI stability in Swift 5, as then the stdlib can ship as a part of the OS.Villose
(though why overlays like libSwiftMetal are included when you're not using the underlying framework, I'm not sure)Villose
thanks for clarifications and infos @Hamish, I'll probably just let it be like this thenSmithson
#56611479Overbold
N
3

Simply put, it's not possible to exclude the standard libraries that Swift automatically includes with an app and expect it to work. Currently any application created with Swift bundles its own version of the Swift Dynamic Library. Swift doesn’t live on the OS, rather it lives within each app bundle. What this means is that any app that is using Swift 4.1 for example bundles in the Swift 4.1 Dynamic Library (containing the 4.1 ABI), and so forth.

One of the things on the Swift project roadmap is to eventually have ABI Stability. If Swift becomes ABI Stable, Swift will live within the OS and it’s ABI will be compatible with every version of Swift.

Nidifugous answered 27/8, 2018 at 23:6 Comment(0)
P
0

From iOS v12.2 ABI[About] Stability for iOS is on. That is why your target will not include Swift standard library[About] because it is a part of OS

Punctilious answered 26/9, 2022 at 19:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.