Skip to content

swift package does not accept the --swift-static-stdlib flag #8424

Open
@euanh

Description

@euanh

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI. The description text must include reproduction steps with either of command-line SwiftPM commands, swift build, swift test, swift package etc.

Description

On Linux, or when cross-compiling, swift build --static-swift-stdlib links the Swift runtime libraries into the binary so that the binary's only runtime dependencies are on the C and C++ runtime libraries and the Linux loader. swift package does not accept this flag.

Expected behavior

swift package --static-swift-stdlib <plugin invocation> should build the same binary as swift build --static-swift-stdlib, which can then be processed by the plugin.

Actual behavior

The --static-swift-stdlib flag causes an error.

Steps to reproduce

With swift build:

bash-5.1# swift package init --type executable
bash-5.1# swift build --static-swift-stdlib
Building for debugging...
[7/7] Linking example
Build complete! (0.45s)
bash-5.1# ldd .build/aarch64-unknown-linux-gnu/debug/example
	linux-vdso.so.1 (0x0000ffffa3ca9000)
	libstdc++.so.6 => /lib64/libstdc++.so.6 (0x0000ffffa33cc000)
	libm.so.6 => /lib64/libm.so.6 (0x0000ffffa3bcb000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000ffffa339b000)
	libc.so.6 => /lib64/libc.so.6 (0x0000ffffa31ed000)
	/lib/ld-linux-aarch64.so.1 (0x0000ffffa3c6c000)

With swift package:

# Install a plugin which uses the binary.  The specific plugin is not important
bash-5.1# swift package add-dependency https://github.com/apple/swift-container-plugin --from 0.4.1
Updating package manifest at Package.swift... done.
bash-5.1# swift package --static-swift-stdlib build-container-image --repository localhost:5555/example
error: Unknown option '--static-swift-stdlib'

Workaround - use -Xswiftc -static-stdlib

bash-5.1# swift package -Xswiftc -static-stdlib build-container-image --repository localhost:5555/example
Plugin ‘ContainerImageBuilder’ wants permission to allow all network connections on all ports.
Stated reason: “This command publishes images to container registries over the network”.
Allow this plugin to allow all network connections on all ports? (yes/no) yes
Building for debugging...
...
bash-5.1# ldd .build/aarch64-unknown-linux-gnu/debug/example
	linux-vdso.so.1 (0x0000ffffa4045000)
	libstdc++.so.6 => /lib64/libstdc++.so.6 (0x0000ffffa37cc000)
	libm.so.6 => /lib64/libm.so.6 (0x0000ffffa372b000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000ffffa3fd7000)
	libc.so.6 => /lib64/libc.so.6 (0x0000ffffa357d000)
	/lib/ld-linux-aarch64.so.1 (0x0000ffffa4008000)

Swift Package Manager version/commit hash

6.0.3

Swift & OS version (output of swift --version ; uname -a)

Swift version 6.0.3 (swift-6.0.3-RELEASE)
Target: aarch64-unknown-linux-gnu

Linux 0527dce5b4de 6.1.68 #1 SMP Fri Nov 22 18:05:17 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions