Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
serges147 opened this issue Aug 6, 2022 · 13 comments
Labels
enhancement New feature or request

Comments

@serges147
Copy link

serges147 commented Aug 6, 2022

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 serges147 added the enhancement New feature or request label Aug 6, 2022
@lorentey
Copy link
Member

lorentey commented Aug 8, 2022

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?

@serges147
Copy link
Author

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

@gaetanzanella
Copy link

gaetanzanella commented Nov 1, 2022

👋 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

@vykut
Copy link

vykut commented Nov 10, 2022

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

@SimplyKyra
Copy link

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.

@MarcusSmith
Copy link

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.

@keisukeYamagishi
Copy link

Hello,

I have the same issue too, but different Xcode version

Xcode 13.4.1
macOS 12.6.1
M1 Pro Macbook Pro

@keisukeYamagishi
Copy link

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

@imthath-m
Copy link

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
Copy link

imthath-m commented Feb 9, 2023

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

@lorentey
Copy link
Member

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
Copy link
Member

Getting rid of the C module with something along the lines of #74 would likely also get rid of these issues. However, this will require some Swift compiler & stdlib work, so it will take time.

@joshgalvan
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants