Sharing.framework symbol not found

Question or problem

This issue was originally reported by @kaioelfke on Slack:

@kaioelfke You can also use try using SwiftPM’s moduleAliases to make the name of the Pointfree library more unique if the mismatch with the Apple’s Sharing.framework is causing the issue here.

Thank you for the suggestion. How would I apply moduleAliass? As far as I know it’s used within SPM for a Target.Dependency, but with Tuist you usually only define Package.Dependency. I’m also still trying to see, if I can make vanilla SPM / Xcode sample without Tuist.

How would I apply moduleAliases? As far as I know it’s used within SPM for a Target.Dependency, but with Tuist you usually only define Package.Dependency

Right, my bad.

We don’t have a first-class support for moduleAliases but you should be able to create one by adding -module-alias Sharing=PointfreeSharing OTHER_SWIFT_FLAGS of the target that uses the Sharing library (such as an app target) and renaming the PRODUCT_NAME of Sharing in PackageSettings. I described how module aliases work under the hood in this PR: Add support for SPM moduleAliases by fortmarek · Pull Request #6685 · tuist/tuist · GitHub

I think what would be worth trying out first is to rename the Sharing library directly in its Package.swift through a fork and seeing if that fixes the issue in the first place.

I’m also still trying to see, if I can make vanilla SPM / Xcode sample without Tuist.

One prerequisite would be that you’d need to force swift-sharing to be linked dynamically which is a decision made by Xcode.

1 Like

I think what would be worth trying out first is to rename the Sharing library directly in its Package.swift through a fork and seeing if that fixes the issue in the first place.

Good idea. I did that and it works. So it’s a name collision. I’ll try the swift flags next.

One prerequisite would be that you’d need to force swift-sharing to be linked dynamically which is a decision made by Xcode.

Yeah I know, it seems a bit tricky.

Good idea. I did that and it works. So it’s a name collision. I’ll try the swift flags next.

We could consider to support moduleAliases as part of PackageSettings in the future to make it a bit more convenient to set that up instead of tinkering with those flags yourself.

You can again use a fork to force the product type of Sharing to be .dynamic instead of the default .automatic.

1 Like

I was trying .dynamic in a different manifest, which depended on swift-sharing, but got linker errors. Directly using .dynamic in the fork is much easier. This also breaks it then. So this is not a Tuist issue. But swift-sharing doesn’t work when dynamically linked on certain platforms.

The module alias approach works. I’ll use this as a workaround for now.

We could consider to support moduleAliases as part of PackageSettings in the future to make it a bit more convenient to set that up instead of tinkering with those flags yourself.

I don’t know how common such issues are, but it would make it easier to configure I guess.

Unfortunately, some libraries assume they would be static, but they don’t make that explicit in their Package.swift manifests.

Would you mind posting the exact steps you did to make that work for future reference? :pray:

Unfortunately, some libraries assume they would be static, but they don’t make that explicit in their Package.swift manifests.

I let them know via Slack about the issue. I guess it didn’t come up yet as the framework only recently got released as a standalone framework with this new name. And most people don’t support iOS 16 or end up with static frameworks via SPM.

Would you mind posting the exact steps you did to make that work for future reference?

Sure. I used PFSharing as alias, but this could be something else.

In Tuist/Package.swift for:

The target setting for ComposableArchitecture is only needed, if used. If just using swift-sharing alone it’s not needed.

let packageSettings = PackageSettings(
  targetSettings: [
      "ComposableArchitecture": [
        "OTHER_SWIFT_FLAGS": ["-module-alias", "Sharing=PFSharing"]
      ],
      "Sharing": ["PRODUCT_NAME": "PFSharing"]
    ]
)

In Project.swift for each target depending on Sharing add the setting to the manifest.

settings: .init().otherSwiftFlags(["-module-alias", "Sharing=PFSharing"]