Skip to content

Command plugin with dynamically linked dependencies fails #9062

@supersonicbyte

Description

@supersonicbyte

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

When a command plugin has an executable target as a dependency which has an dependency that is being dynamically linked it fails to execute. An example of such structure:

command-plugin-dynamic-linking/
├── Package.swift                           # Main package manifest
├── Sources/
│   └── Core/
│       └── Core.swift                      # Executable target that uses DynamicLib
├── Plugins/
│   └── command-plugin-dynamic-linking.swift # Swift Package Manager command plugin
├── LocalPackages/
│   ├── Client/ # Client package which consumes the swift command plugin
│   │   ├── Package.swift
│   │   └── Sources/
│   │       └── main.swift
│   └── DynamicLib/
│       ├── Package.swift
│       ├── Sources/
│       │   └── DynamicLib/
│       │       └── DynamicLib.swift        # Dynamic library implementation
│       └── Tests/
│           └── DynamicLibTests/
│               └── DynamicLibTests.swift

Running command plugin swift package command_plugin_dynamic_linking gives the following error:

Building for debugging...
error: link command failed with exit code 1 (use -v to see invocation)
ld: library 'DynamicLib' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[11/13] Linking Core-tool
error: fatalError

For some reason the DynamicLib is being built as libDynamicLib-tool.dylib but the compiler is searching for libDynamicLib.dylib and thus we get the mentioned error.

The repository highliting this issue can be found here.

Expected behavior

Expected behavior is that command plugin doesn't fail.

Actual behavior

Actual behavior is that the command plugin fails not being able to find the library that is being linked dynamically.

Steps to reproduce

Clone the repo: https://github.com/supersonicbyte/command-plugin-dynamic-linking

Navigate to Client package:
cd LocalPackages/Client

Run the command plugin:

swift package command_plugin_dynamic_linking

Swift Package Manager version/commit hash

6.1

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

swift-driver version: 1.120.5 Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
Target: arm64-apple-macosx15.0
Darwin Ucanbarlics-MacBook-Pro.local 24.6.0 Darwin Kernel Version 24.6.0: Mon Jul 14 11:28:30 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6030 arm64

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