Using the Static Linux SDK produces very large binaries

Hello,
I recently started using the Static Linux SDK for building distributable Linux executables using Swift.

My experience has been really awesome!

The only downside of using it is that the build process produces really large binaries. I’ve built a simple command line tool with a single file (~20 LOC) that uses the swift-argument-parser package.

Debug builds produce an 100MB plus executable for this simple program, while release builds with stripping enabled and the -Osize flag produce a 53MB binary, which is still quite large for a simple command line tool to be distributed to Linux users.

Is there anything I can do to reduce the binary size (even for Release builds only) when using the Static Linux SDk?

Thank you!

2 Likes

There was a ~40MB size penalty on Apple platforms before Swift got abi stable there. Hello world is around that size with the static Linux sdk. Swift-argument-parser is known to add a lot to the binary size. So there is nothing unexpected about it.

Just don't "import Foundation" if you don't want to add an extra ~100MB.

1 Like

This may help with that

2 Likes

Have you tried link time optimization (LTO)?

$ swift build --experimental-lto-mode=full  # for full optimization
$ swift build --experimental-lto-mode=thin  # for shorter build time
2 Likes

I tried importing FoundationEssentials instead of Foundation, but still got binaries that are tens of MBs of size when compiling against the Static Linux SDK, even without using swift-argument-parser.

Is there a way to produce smaller binaries, but still use imports from Foundation/FoundationEssentials?

Thank you!

Binaries are still the same size for me :frowning_with_open_mouth:
About 53MB.

Thank you!

Actually, I couldn’t build a Static Linux SDK executable with LTO, the build fails when enabling it.

Thank you!

You are right, even the hello world example in the doc is massive:

> ~/swift-6.0.1-RELEASE-fedora39/usr/bin/swift build -c release --swift-sdk x86_64-swift-linux-musl -Xlinker --verbose
Building for production...
clang: warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/crt1.o
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/crti.o
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/clang/lib/linux/clang_rt.crtbegin-x86_64.o
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++abi.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/linux-static/x86_64/swiftrt.o
ld.lld: /home/finagolfin/new/.build/x86_64-swift-linux-musl/release/new.build/main.swift.o
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/linux-static/libswiftCore.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/linux-static/libswift_Concurrency.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/linux-static/libswift_StringProcessing.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/linux-static/libswiftCore.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/linux-static/libswift_RegexParser.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/linux-static/libdispatch.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/linux-static/libBlocksRuntime.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libpthread.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libdl.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc++.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libm.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/clang/lib/linux/libclang_rt.builtins-x86_64.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libunwind.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libc.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/clang/lib/linux/clang_rt.crtend-x86_64.o
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/crtn.o
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libpthread.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libpthread.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libpthread.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libpthread.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libpthread.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libpthread.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libpthread.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libdl.a
ld.lld: /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/libpthread.a
[5/5] Linking new
Build complete! (0.60s)

> du -sk .build/x86_64-swift-linux-musl/release/new
41600   .build/x86_64-swift-linux-musl/release/new

This is most likely because of the unusually large libswiftCore.a in the static linux SDK, around 80 MBs:

> ls -l /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/linux-static/libswiftCore.a
-rw-r--r--. 1 finagolfin finagolfin 80758182 Oct 25 06:32 /home/finagolfin/.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/linux-static/libswiftCore.a

By comparison, the Glibc version of that Swift runtime library is only 15 MBs and produces an executable linked statically against the Swift stdlib that is only 20% the size of the Musl executable:

> ls -l ~/swift-6.0.1-RELEASE-fedora39/usr/lib/swift_static/linux/libswiftCore.a
-rw-r--r--. 1 finagolfin finagolfin 15336134 Sep 24 00:19 /home/finagolfin/swift-6.0.1-RELEASE-fedora39/usr/lib/swift_static/linux/libswiftCore.a

> ~/swift-6.0.1-RELEASE-fedora39/usr/bin/swift build -c release --static-swift-stdlib -Xlinker --verbose -Xswiftc -use-ld=lld                Building for production...
ld.lld: /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/Scrt1.o
ld.lld: /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/crti.o
ld.lld: /usr/lib/gcc/x86_64-redhat-linux/14/crtbeginS.o
ld.lld: /home/finagolfin/swift-6.0.1-RELEASE-fedora39/usr/lib/swift_static/linux/x86_64/swiftrt.o
ld.lld: /home/finagolfin/new/.build/x86_64-unknown-linux-gnu/release/new.build/main.swift.o
ld.lld: /home/finagolfin/swift-6.0.1-RELEASE-fedora39/usr/lib/swift_static/linux/libswiftCore.a
ld.lld: /home/finagolfin/swift-6.0.1-RELEASE-fedora39/usr/lib/swift_static/linux/libswift_Concurrency.a
ld.lld: /home/finagolfin/swift-6.0.1-RELEASE-fedora39/usr/lib/swift_static/linux/libswift_StringProcessing.a
ld.lld: /home/finagolfin/swift-6.0.1-RELEASE-fedora39/usr/lib/swift_static/linux/libswift_RegexParser.a
ld.lld: /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/libdl.a
ld.lld: /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/libpthread.a
ld.lld: /home/finagolfin/swift-6.0.1-RELEASE-fedora39/usr/lib/swift_static/linux/libswiftCore.a
ld.lld: /home/finagolfin/swift-6.0.1-RELEASE-fedora39/usr/lib/swift_static/linux/libdispatch.a
ld.lld: /home/finagolfin/swift-6.0.1-RELEASE-fedora39/usr/lib/swift_static/linux/libBlocksRuntime.a
ld.lld: /usr/lib/gcc/x86_64-redhat-linux/14/libstdc++.so
ld.lld: /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/libm.so
ld.lld: /lib64/libm.so.6
ld.lld: /lib64/libmvec.so.1
ld.lld: /usr/lib/gcc/x86_64-redhat-linux/14/libgcc.a
ld.lld: /usr/lib/gcc/x86_64-redhat-linux/14/libgcc_s.so
ld.lld: /lib64/libgcc_s.so.1
ld.lld: /usr/lib/gcc/x86_64-redhat-linux/14/libgcc.a
ld.lld: /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/libc.so
ld.lld: /lib64/libc.so.6
ld.lld: /usr/lib64/libc_nonshared.a
ld.lld: /lib64/ld-linux-x86-64.so.2
ld.lld: /usr/lib/gcc/x86_64-redhat-linux/14/libgcc.a
ld.lld: /usr/lib/gcc/x86_64-redhat-linux/14/libgcc_s.so
ld.lld: /lib64/libgcc_s.so.1
ld.lld: /usr/lib/gcc/x86_64-redhat-linux/14/libgcc.a
ld.lld: /usr/lib/gcc/x86_64-redhat-linux/14/crtendS.o
ld.lld: /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/crtn.o
[5/5] Linking new
Build complete! (0.51s)

> du -sk .build/x86_64-unknown-linux-gnu/release/new
8176    .build/x86_64-unknown-linux-gnu/release/new

Not an exact apples-to-apples comparison as the Musl SDK produces a fully static executable linked against the Musl libc and libc++ also, but I don't think that's the reason for the 5X size difference in simple executables.

@al45tair, any idea what's going on here?

1 Like

Just checking, but did you actually strip the binary, i.e. did you run

strip my-program-here

on a Linux system after the build?

Just doing a release build is not enough here; it will still include debug information (from the libraries) unless it's explicitly stripped.

I'd like to make the Static SDK itself use LTO, but when I last tried that it didn't build successfully and I haven't yet had time to work out why or how to fix that. Enabling LTO would likely reduce the total size considerably.

1 Like

A lot of the difference with the commands you ran above will be debug information, I suspect. I'd try explicitly stripping both binaries and see how much the sizes change.

1 Like

@al45tair

Yeah, I did run strip on the executable built with the Static Linux SDK and that got it from around 100MB to 53MB.

I also couldn’t build a Static Linux SDK executable with LTO, the build fails when enabling it.

Thank you!

1 Like

it would be helpful to share the error you hit, its possible theres a general problem we need to fix in the LTO implementation in SwiftPM.

1 Like

@rauhul

Sure thing!

This is the code I'm trying to build:

import ArgumentParser

@main
struct Repeat: ParsableCommand {
    @Flag(help: "Include a counter with each repetition.")
    var includeCounter = false

    @Option(name: .shortAndLong, help: "The number of times to repeat 'phrase'.")
    var count: Int? = nil

    @Argument(help: "The phrase to repeat.")
    var phrase: String

    mutating func run() throws {
        let repeatCount = count ?? 2

        for i in 1...repeatCount {
            if includeCounter {
                print("\(i): \(phrase)")
            } else {
                print(phrase)
            }
        }
    }
}

This is the command I ran to build the code:
swift build --swift-sdk x86_64-swift-linux-musl -c release --experimental-lto-mode=full

And this is the output with the build error:

Building for production...
clang: warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]
definition subprograms cannot be nested within DICompositeType when enabling ODR
!60684 = distinct !DISubprogram(name: "swift_test_main", linkageName: "swift_test_main", scope: !60685, file: !596, line: 1, type: !60686, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !595)
LLVM ERROR: Broken module found, compilation aborted!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/ld.lld --sysroot=/Users/yuvaldolev/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64 --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -static -o /Users/yuvaldolev/tmp/swift_test/.build/x86_64-swift-linux-musl/release/swift_test /Users/yuvaldolev/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/crt1.o /Users/yuvaldolev/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/crti.o /Users/yuvaldolev/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/clang/lib/linux/clang_rt.crtbegin-x86_64.o -L/Users/yuvaldolev/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/linux-static -L/Users/yuvaldolev/tmp/swift_test/.build/x86_64-swift-linux-musl/release -L/Users/yuvaldolev/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib -plugin-opt=mcpu=x86-64 -lc++abi -z nostart-stop-gc /Users/yuvaldolev/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/linux-static/x86_64/swiftrt.o --start-group /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/Argument-554943.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/ArgumentDecoder-1687f3.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/ArgumentDefinition-38872e.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/ArgumentDiscussion-e7c81b.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/ArgumentHelp-0731fb.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/ArgumentSet-7ee0f4.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/ArgumentVisibility-8ce45d.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/AsyncParsableCommand-74f080.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/BashCompletionsGenerator-cea9e0.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/CollectionExtensions-ee442e.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/CommandConfiguration-1235d9.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/CommandGroup-880f27.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/CommandParser-06b1ef.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/CompletionKind-5ef9db.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/CompletionsGenerator-0e2f29.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/DumpHelpGenerator-ac9c68.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/EnumerableFlag-fd44e6.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/Errors-05853c.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/ExpressibleByArgument-5bb377.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/FishCompletionsGenerator-5a7b2f.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/Flag-e86a4e.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/HelpCommand-c80e51.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/HelpGenerator-ace90c.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/InputKey-1c238a.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/InputOrigin-9c351a.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/MessageInfo-775bb1.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/Name-4d42e1.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/NameSpecification-a7142e.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/Option-aa77fa.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/OptionGroup-8f1dd3.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/ParsableArguments-f85351.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/ParsableArgumentsValidation-9ed07b.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/ParsableCommand-8e4ba8.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/Parsed-cf7621.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/ParsedValues-8c1b66.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/ParserError-58fcef.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/Platform-cc7676.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/SequenceExtensions-8a2d59.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/SplitArguments-9cad7b.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/StringExtensions-fd5cec.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/Tree-c99e22.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/UsageGenerator-745251.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/ZshCompletionsGenerator-f81cc0.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/ToolInfo-1b9a4c.o /var/folders/wy/w70cpdtd3kg05mf61232y0ph0000gn/T/main-75fb2c.o --end-group -lswiftCore -lswift_RegexParser -undefined=pthread_self -undefined=pthread_once -undefined=pthread_key_create -ldispatch -lBlocksRuntime -lpthread -ldl -lc++ -lm --gc-sections --defsym main=swift_test_main -rpath=$ORIGIN --start-group /Users/yuvaldolev/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/clang/lib/linux/libclang_rt.builtins-x86_64.a -l:libunwind.a -lc --end-group /Users/yuvaldolev/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/clang/lib/linux/clang_rt.crtend-x86_64.o /Users/yuvaldolev/Library/org.swift.swiftpm/swift-sdks/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0.1-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/crtn.o
 #0 0x0000000104c02e14 (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x1000eee14)
 #1 0x0000000104c01484 (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x1000ed484)
 #2 0x0000000104c0346c (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x1000ef46c)
 #3 0x000000018ea54184 (/usr/lib/system/libsystem_platform.dylib+0x180484184)
 #4 0x000000018ea1ef70 (/usr/lib/system/libsystem_pthread.dylib+0x18044ef70)
 #5 0x000000018e92b908 (/usr/lib/system/libsystem_c.dylib+0x18035b908)
 #6 0x0000000104b70cd4 (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x10005ccd4)
 #7 0x0000000104b70b1c (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x10005cb1c)
 #8 0x00000001072def98 (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x1027caf98)
 #9 0x00000001072b6808 (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x1027a2808)
#10 0x0000000105d3cc60 (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x101228c60)
#11 0x0000000105d3d37c (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x10122937c)
#12 0x0000000105d30048 (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x10121c048)
#13 0x0000000105d2f6fc (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x10121b6fc)
#14 0x0000000104d55914 (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x100241914)
#15 0x0000000104cf1730 (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x1001dd730)
#16 0x0000000104cee8cc (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x1001da8cc)
#17 0x0000000104ce5c38 (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x1001d1c38)
#18 0x0000000104ce4928 (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x1001d0928)
#19 0x0000000104c14eb4 (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x100100eb4)
#20 0x0000000104b19b18 (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x100005b18)
#21 0x0000000104b1a0ec (/Library/Developer/Toolchains/swift-6.0.1-RELEASE.xctoolchain/usr/bin/lld+0x1000060ec)
#22 0x000000018e69c274
clang: error: unable to execute command: Abort trap: 6
clang: error: linker command failed due to signal (use -v to see invocation)
[6/7] Linking swift_test
1 Like

You're right, stripping the binaries gets both down to 5-6 MBs. I thought the Swift runtime libraries were built in release-no-assert mode and wouldn't have any debug info, so I didn't even check for it. That is the problem I was seeing above with your "hello world" example, and stripping the binaries solves it. :smiling_face:

I built your example and am able to reproduce, even after applying Tim's submitted pull above to the checked-out ArgumentParser source. However, if I simply build a "hello world" executable instead that doesn't use ArgumentParser, that executable only links against FoundationEssentials:

import FoundationEssentials

URL(fileURLWithPath: "/tmp", isDirectory: true).appendingPathComponent("testfile-\(UUID().uuidString)")
print("Hey, crazy!")

If I simply add the ArgumentParser dependency to this executable's package manifest, it starts linking against the large FoundationInternationalization/ICU libraries, despite this executable not importing ArgumentParser and Tim trying to get ArgumentParser to only use FoundationEssentials.

Looking at the ArgumentParser object files, they all appear to link against FoundationInternationalization/ICU even after Tim's patch:

> strings .build/x86_64-swift-linux-musl/release/ArgumentParser.build/Tree.swift.o | ag lFoundation
-lFoundation
-lFoundationInternationalization
-lFoundationEssentials

This is all reproducible with the shared and static libraries in the linux Glibc SDK that ships with the linux toolchain, so there is nothing specific to the Musl SDK here.

Something is going wrong with the Swift toolchain when trying to get dependencies like ArgumentParser to only use FoundationEssentials. @jmschonfeld, any clue?

There are a few places in the ArgumentParser that still use Foundation but these are limited to the tools and package plugins that shouldn't be bundled into an app when pulling it in as a library

I would use the linker option to strip, so your build flow can stay the same if you want to cross-compile, the regular x86_64 strip command doesn't recognize arm64 binaries.

-Xlinker -s is the strip everything option, -Xlinker -S is the strip debugging symbols option.

Sure, but leaving aside those plugins and tools, the object files in the base library still pull in libFoundationInternationalization and the massive lib_FoundationICU even after your pull.

For example, if I simply build the example executable roll directly in the swift-argument-parser repo against the static default Glibc SDK in the official toolchain, this is the last linker command run on Fedora 40 x86_64, pulling in lib_FoundationICU also:

> ~/swift-6.0.1-RELEASE-fedora39/usr/bin/swift build -c release --product roll --static-swift-stdlib -v
--- snipped a bunch of other commands from the verbose output ---
"/usr/bin/ld.gold" -pie --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/roll /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/Scrt1.o /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/14/crtbeginS.o -L/home/finagolfin/swift-6.0.1-RELEASE-fedora39/usr/lib/swift_static/linux -L/home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release -L/usr/lib/gcc/x86_64-redhat-linux/14 -L/usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/lib -L/usr/lib /home/finagolfin/swift-6.0.1-RELEASE-fedora39/usr/lib/swift_static/linux/x86_64/swiftrt.o --start-group /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/Argument.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/ArgumentDecoder.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/ArgumentDefinition.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/ArgumentDiscussion.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/ArgumentHelp.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/ArgumentSet.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/ArgumentVisibility.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/AsyncParsableCommand.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/BashCompletionsGenerator.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/CollectionExtensions.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/CommandConfiguration.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/CommandGroup.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/CommandParser.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/CompletionKind.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/CompletionsGenerator.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/DumpHelpGenerator.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/EnumerableFlag.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/Errors.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/ExpressibleByArgument.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/FishCompletionsGenerator.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/Flag.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/HelpCommand.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/HelpGenerator.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/InputKey.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/InputOrigin.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/MessageInfo.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/Name.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/NameSpecification.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/Option.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/OptionGroup.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/ParsableArguments.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/ParsableArgumentsValidation.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/ParsableCommand.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/Parsed.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/ParsedValues.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/ParserError.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/Platform.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/SequenceExtensions.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/SplitArguments.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/StringExtensions.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/Tree.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/UsageGenerator.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParser.build/ZshCompletionsGenerator.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/ArgumentParserToolInfo.build/ToolInfo.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/roll.build/SplitMix64.swift.o /home/finagolfin/swift-argument-parser/.build/x86_64-unknown-linux-gnu/release/roll.build/main.swift.o -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -l_FoundationICU -lswiftSynchronization -lFoundationInternationalization -l_FoundationCShims -lFoundationEssentials -l_FoundationCollections -lswiftCore -lswift_Concurrency -lswift_StringProcessing -lswift_RegexParser -lswiftGlibc -lBlocksRuntime -ldispatch -lDispatchStubs -lswiftDispatch -lCoreFoundation -lFoundation -lm -lpthread -lutil -ldl --end-group -ldl -lpthread -lswiftCore -ldispatch -lBlocksRuntime -lstdc++ -lm -export-dynamic --exclude-libs ALL --gc-sections --defsym main=roll_main "-rpath=\$ORIGIN" -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/14/crtendS.o /usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/crtn.o

The resulting stripped executable roll is 54 MB, just as Yuval says for his own external example. This is with your pull applied, so for whatever reason, your pull didn't succeed in convincing the Swift toolchain that FoundationEssentials is enough.

Obviously this has nothing to do with the Musl SDK, since it's reproducible with the official linux Glibc toolchain, but appears to be a more fundamental flaw in the work to separate out the Foundation rewrite into FoundationEssentials and FoundationInternationalization portions.

Oh yeah it's definitely an issue, was just wondering if the compiler was adding too much because of it was required somewhere in a dependency for those who have more knowledge and want to debug

Hmm this is definitely strange but I don't quite know what would be causing this. Given @0xTim's comment:

I wonder if this is a SwiftPM issue? I know I've seen in the past that targets that depend on macros can end up actually linking the macro dylib when they're not supposed to (Tests fail to link on Windows when macros are present · Issue #7174 · swiftlang/swift-package-manager · GitHub) but the ArgumentParser target doesn't actually have a dependency in the package manifest on any of the tools so it doesn't seem like it's quite the same scenario. @dschaefer2 not sure if you've come across anything in SwiftPM that might explain this behavior? I don't think we've reproduced this behavior when just building a standalone file outside of SwiftPM, but it's possible something has changed since I last tried that.

Ah, this might be related to the recent Swift 6 versioning issues? It appears building with SwiftPM 6.0.1 doesn't use Tim's modified FoundationEssentials imports, but the subsequent #elseif swift(>=5.10) imports of the old Foundation module, as one would expect from the Swift 6 compiler sticking with language version 5 by default now.