jedisct1/swift-sodium

Is it possible to use the Pod without `use_frameworks!`?

ph4r05 opened this issue ยท 4 comments

I have a Cocoapod project that for some reason does not use use_frameworks! directive (legacy, react-native had issues with the frameworks).

Compilation fails with linking errors for Sodium 0.9.1.

Undefined symbols for architecture arm64:
"_sodium_unpad", referenced from:
    Sodium.Utils.unpad(bytes: inout [Swift.UInt8], blockSize: Swift.Int) -> ()? in libSodium.a(Utils.o)
    Sodium.Utils.unpad(bytes: inout [Swift.UInt8], blockSize: Swift.Int) -> ()? in libsodium.a(Utils.o)
"_sodium_base64_encoded_len", referenced from:
    Sodium.Utils.bin2base64(_: [Swift.UInt8], variant: Sodium.Utils.Base64Variant) -> Swift.String? in libSodium.a(Utils.o)
    Sodium.Utils.bin2base64(_: [Swift.UInt8], variant: Sodium.Utils.Base64Variant) -> Swift.String? in 

I was wondering whether it is possible to use this Sodium pod without using use_frameworks! or using the framework is a fundamental requirement for the Sodium pod.

It is easy to reproduce with pod spec lint on this repository:

The following Lint passes:

pod spec lint --no-clean --verbose --use-modular-headers --private  

The following does not. The error is the same as when I am using Sodium in my project.

pod spec lint --no-clean --verbose --use-modular-headers --private --use-libraries 

I've created a simple demo project depending on Sodium 0.9.1: https://github.com/ph4r05/SodiumPoc

When use_frameworks! is present in https://github.com/ph4r05/SodiumPoc/blob/main/Example/Podfile it builds, otherwise not.

  • It works also with use_frameworks! :linkage => :static
  • use_modular_headers! alone does not work

I'm also working on a React Native app and was having problems with use_frameworks!. I was able to solve my issue (at least for now) with cocoapods-user-defined-build-types.

I did this by:

  1. Running sudo gem install cocoapods-user-defined-build-types
  2. Adding
plugin 'cocoapods-user-defined-build-types'`
enable_user_defined_build_types!

right after the second require_relative in the Podfile
3. Adding pod 'Sodium', :build_type => :dynamic_framework under the app target.
4. Running npx pod-install ios in the root project directory

At this point, once I tried building the project, I was getting errors about swiftWebKit not being found, so I added a File.swift to the iOS Xcode Project and created a bridging header when Xcode asked. Cleaning and running after that worked for me.

@flash76 I got back to this problem and your solution works, thanks a lot!

I am working on a react-native application with Flipper, which does not work with use_frameworks! from some reason.

There are also several workarounds, e.g.. having selected libraries marked as static, but it runs into a problems if any of selected Flipper deps are also transitive dependencies of other dependencies and are expected to be built as frameworks.

So thanks for this! Reversed approach having only selected pods built as Frameworks works much better!