swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.76k stars 1.35k forks source link

Linker _sometimes_ fails at the first `swift build` but succeeds after several trials in a certain repository. #8064

Open YOCKOW opened 1 month ago

YOCKOW commented 1 month ago

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

Description

I don't know the implementation detail of Package Manager, but it seems to build 'libFoo-tool.dylib' and then emits 'libFoo.dylib' during swift build. However, under some conditions (which I'm not sure), swift build instructs the linker to link 'libFoo.dylib' before it is emitted.

Expected behavior

swift build always succeeds.

Actual behavior

error: link command failed with exit code 1 (use -v to see invocation)
ld: library 'Foo' not found

Steps to reproduce

(Sorry, but I couldn't reduce the problem. These steps use my repository as is.)

  1. cd $(mktemp -d)
  2. git clone https://github.com/YOCKOW/SwiftPQ.git
  3. cd SwiftPQ/
  4. git checkout 8bda04dd47316a52fb7c0a127e0db3091d2bd38f
  5. swift build

Result (nondeterministic)

error: link command failed with exit code 1 (use -v to see invocation)
ld: library 'SwiftUnicodeSupplement' not found

(GitHub Actions Log: https://github.com/YOCKOW/SwiftPQ/actions/runs/11400394868/job/31860480405#step:8:14 )

or

error: link command failed with exit code 1 (use -v to see invocation)
ld: library 'SwiftNetworkGear' not found

or

Build complete!

Swift Package Manager version/commit hash

Swift Package Manager - Swift 6.0.1-dev

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

Apple Swift version 6.0.1 (swift-6.0.1-RELEASE)
Target: arm64-apple-macosx15.0

Darwin yockow.local 24.0.0 Darwin Kernel Version 24.0.0: Tue Sep 24 23:39:07 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6000 arm64