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

Cannot use this package in a static library - `Missing required module '_AtomicsShims'` error.

Open serges147 opened this issue 2 years ago • 13 comments

In static library swift file, on attempt to import Atomics I'm getting Missing required module '_AtomicsShims' error.

This is structure of project in a nutshell:

  1. StaticLibA // has Atomics static SPM library as dependency (but NOT as "Link Binary with Libraries" phase)
  • foo.swift // needs atomic stuff, so does import Atomics which fails with the above error
  1. FrameworkB // links with StaticLibA
  • has some swift files which depend on StaticLibA types
  1. ExecutableC // links with StaticLibA, FrameworkB & Atomics
  • uses both the static lib and dynamic framework

The very same import Atomics works well and without errors when it's in a final executable swift files, so problem is specific for static library target only.

Note also that StaticLibA deliberately is NOT linked with Atomics - if I did so then step # 1 succeeds but then step # 3 fails with "ld: 465 duplicate symbols for architecture arm64". I believe it's b/c the very same symbols of Atomic lib comes to final executable from both StaticLibA and FrameworkB.

Could you please advice what could be wrong or missing? OR, is it just not supported yet configuration? Thanks!

serges147 avatar Aug 06 '22 22:08 serges147

Thanks for the report! Unfortunately the reproduction steps don't contain enough information to debug this problem -- could you please provide a sample project that exhibits this issue?

lorentey avatar Aug 08 '22 20:08 lorentey

Yup, I'll prepare the sample soon. Thanks!

serges147 avatar Aug 13 '22 06:08 serges147

👋 Any news regarding this issue? I encountered the same problem when adding some tests to my iOS app.

To reproduce the issue:

  1. Create an iOS app with unit tests in Xcode
  2. Add the swift-atomics package to your main target
  3. Try to execute the tests on your M1 Pro Macbook Pro (Xcode 14.0.1 / macOS 12.6 in my case)

test.zip

gaetanzanella avatar Nov 01 '22 14:11 gaetanzanella

Hello,

I have the same issue as @gaetanzanella mentioned above. The difference is that my project has the grpc-swift package dependency, which in turn uses swift-atomics.

Xcode 14.0.1 macOS 12.6.1 M1 Pro Macbook Pro

vykut avatar Nov 10 '22 13:11 vykut

I'm also getting this error. Running a Multiplatform app and when I go to test it I'm getting this error "_atomicsshims" on every imported module in the test. The swift_atomics package is included on my target because of another package I'm using.

SimplyKyra avatar Jan 10 '23 21:01 SimplyKyra

I'm also getting this error when trying to archive a Swift package (from the command line using xcodebuild archive) to convert my package into a framework.

The binary just looks to be absent after the first build step and it fails when trying to ld Swift Atomics. Sorry this is all pretty new to me - don't know what I don't know - happy to add any information that might be helpful here.

MarcusSmith avatar Jan 12 '23 23:01 MarcusSmith

Hello,

I have the same issue too, but different Xcode version

Xcode 13.4.1 macOS 12.6.1 M1 Pro Macbook Pro

keisukeYamagishi avatar Jan 23 '23 05:01 keisukeYamagishi

Hi🎉 I fix it㊗️ I imported it into the UITest bundle and was able to build it. Added Atomic to Link Binary With Libraries. Please see the attached photo. Screenshot 2023-01-24 at 12 56 05

keisukeYamagishi avatar Jan 24 '23 03:01 keisukeYamagishi

Thanks for sharing the fix @keisukeYamagishi . Unfortuately for me, the error kept repeating for different packages because of AsyncHttpClient (which depends on a handful of such packages including swift-atomics and was used in one of my dependencies). I was able to run the tests only after removing it.

imthath-m avatar Feb 09 '23 07:02 imthath-m

in case if anyone faces this issue recursively like me for multiple packages, then you can try the approach by duckduckgo/ios.

create a static framework in your project and add all Swift Packages to it. Then use that framework in all your targets. For tests, add the framework in your Build Phases like mentioned above by @keisukeYamagishi

imthath-m avatar Feb 09 '23 09:02 imthath-m

Quick update: @gaetanzanella's sample project has been very helpful in reproducing this. (Thank you!)

Unfortunately it's a tooling issue, so the package won't be able to fix it on its own.

A proper fix is in the pipeline, but it will need time. @keisukeYamagishi's or @imthath-m's suggestions are currently the best workarounds that I am aware of.

lorentey avatar Mar 18 '23 04:03 lorentey

Getting rid of the C module with something along the lines of https://github.com/apple/swift-atomics/pull/74 would likely also get rid of these issues. However, this will require some Swift compiler & stdlib work, so it will take time.

lorentey avatar Mar 20 '23 19:03 lorentey

In my case, async-http-client was a dependency to a package I'm using, OpenAIKit, which is dependent upon swift-atomics (as @imthath-m mentioned) and adding that to my UI and unit test build phases as @gaetanzanella did allowed my tests to build.

joshgalvan avatar Jun 25 '23 22:06 joshgalvan