swift-atomics icon indicating copy to clipboard operation
swift-atomics copied to clipboard

xcodebuild archive fails with swift-atomics when BUILD_LIBRARY_FOR_DISTRIBUTION=YES due to missing _AtomicsShims module

Open fearless-taco opened this issue 6 months ago • 2 comments

When using swift-atomics (v1.0.0, 1.1.0, or 1.3.0) as a dependency in a Swift framework with BUILD_LIBRARY_FOR_DISTRIBUTION=YES, xcodebuild archive fails due to _AtomicsShims being referenced in the generated .swiftinterface, but not available at validation time.

This was discovered originally using 1.2, then detecting the a breaking change in 1.3. I tested backwards compatibility and found the issue exists on 1.0 and 1.1 as well.

✅ Works when: • BUILD_LIBRARY_FOR_DISTRIBUTION=NO • Using version 1.2.0 of the package • Archiving inside the Xcode UI

❌ Fails when: • Using CLI (xcodebuild archive) with library evolution enabled

Information

  • Package version: 1.3.0 (also fails on 1.0.0 and 1.1.0; only 1.2.0 works)
  • Platform version: macOS Sequoia 15.4.1
  • Swift version: 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

Checklist

  • [x] If possible, I've reproduced the issue using the main branch of this package.
  • [x] I've searched for existing reports of the same issue.

Steps to Reproduce

  1. Create an Xcode Project with an App
  2. Add Swift Atomics as a Package Dependency
  3. For the App target, add the Framework under 'Frameworks, Libraries, & Embedded Content'
  4. Run command xcodebuild archive with BUILD_LIBRARY_FOR_DISTRIBUTION=YES
xcodebuild archive -scheme App -configuration Release -archivePath output/App.xcarchive -sdk iphoneos BUILD_LIBRARY_FOR_DISTRIBUTION=YES

Expected behavior

The framework should archive successfully, as it does with version 1.2.0 of swift-atomics.

Actual behavior

The archive operation fails with the following errors:

 7 | import _AtomicsShims     
   |        `- error: no such module '_AtomicsShims'
 1 | // swift-interface-format-version: 1.0 
   | `- error: failed to verify module interface of 'Atomics' due to the errors above; the textual interface may be broken by project issues or a compiler bug
SwiftDriverJobDiscovery normal arm64 Compiling OptionalRawRepresentable.swift, RawRepresentable.swift, AtomicBool.swift, ...

fearless-taco avatar Jun 11 '25 11:06 fearless-taco

This may be partially related to issue: https://github.com/apple/swift-atomics/issues/57

fearless-taco avatar Jun 11 '25 11:06 fearless-taco

Unfortunately, importing Swift packages in ABI-stable contexts is tricky. It may be a good idea to double check with package manager engineers if this is expected to work at all. (For what it's worth, swift-atomics is definitely not ABI stable, and it is not a good idea to build it with library evolution enabled.)

That said, though: now that the actual atomic operations are no longer imported through _AtomicsShims, it may be possible to change its imports to internal import _AtomicsShims, which can potentially help this case. 🤔

lorentey avatar Jul 02 '25 00:07 lorentey