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

Cocoapods misleadingly detects Mergable Libraries as static frameworks #12388

Open
1 task done
abarisain opened this issue May 20, 2024 · 4 comments
Open
1 task done

Comments

@abarisain
Copy link

Report

We distribute our framework via a precompiled, vendored XCFramework.
Starting with out latest release, we ship as a dynamic XCFramework with support for Mergable Libraries

However, on installation, CocoaPods fails to detect that the XCFramework is dynamic, which means that it's not included in Pods-<target>-frameworks-Release-input-files.xcfilelist and not copied during build. The app crashes on start as dyld can't find the framework.

I pinpointed this to this code: https://github.com/CocoaPods/CocoaPods/blob/master/lib/cocoapods/xcode/linkage_analyzer.rb

When ruby-macho fails to open a dylib, CocoaPods assumes that it is a static library.
Problem is, mergable libraries come with a new Load command: LC_ATOM_INFO.
ruby-macho does not support this (even in its latest version, 4.0.1).

The following ruby program:

require 'macho'

@libpath = '/Users/arnaud/dev/playground/cocoapods/tests/Pods/Batch/XCFrameworks/Batch.xcframework/ios-arm64/Batch.framework/Batch'

MachO.open(@libpath).dylib

prints

/Users/arnaud/dev/playground/machotest/vendor/bundle/ruby/2.6.0/gems/ruby-macho-4.0.1/lib/macho/macho_file.rb:598:in `block in populate_load_commands': Unrecognized Mach-O load command: 0x36 (MachO::LoadCommandError)

0x36 being the code for LC_ATOM_INFO

As Podspecs do not allow us to bypass the auto detection, we have no choice but to make a specific build for CocoaPods without mergable library support.

What did you do?

  • Make an empty project
  • Add a pod that is a vendored xcframework that is a mergable library (pod 'Batch', '2.0.0')
  • Build and run: The app crashes as the framework is missing at runtime
dyld[64690]: Library not loaded: @rpath/Batch.framework/Batch

What did you expect to happen?

CocoaPods properly detects our dynamic mergable library and copies it in the app bundle.

On an unrelated issue, I also expect cocoapods to copy the XCFramework properly rather than manually handling slices, as this breaks code signing, but I will open another issue for that.

What happened instead?

CocoaPods believes that our framework is a static library and does not copy it on build.
To work around this, we have to manually tell Xcode about the framework and not rely on CocoaPods' automatic linking.

CocoaPods Environment

Stack

   CocoaPods : 1.15.2
        Ruby : ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23]
    RubyGems : 3.0.3.1
        Host : macOS 14.4.1 (23E224)
       Xcode : 15.3 (15E204a)
         Git : git version 2.39.3 (Apple Git-146)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib
Repositories : cocoapods - git - https://github.com/CocoaPods/Specs @ b1b1a3aac20e54bc22f1344a311c138a6ec6bdb6

               trunk - CDN - https://cdn.cocoapods.org/

Installation Source

Executable Path: /usr/local/bin/pod

Plugins

cocoapods-deintegrate : 1.0.5
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.1
cocoapods-trunk       : 1.6.0
cocoapods-try         : 1.2.0

Project that demonstrates the issue

Requires Xcode 15.3

batch_cocoapods_repro.zip

@abarisain
Copy link
Author

abarisain commented May 20, 2024

ruby-macho issue: Homebrew/ruby-macho#609

EDIT: they merged a fix

@goncg007
Copy link

I am experiencing the same problem on my end. Is there any update on this?

@abarisain
Copy link
Author

FYI our workaround was to make a special framework for our cocoapods release.

We have two postprocessing steps:

  • use "strip -x -no_atom_info" on all the binaries of your xcframework (that's one per slice)
  • remove codesignature, as it gets broken both by strip and cocoapods's slicing

@goncg007
Copy link

I setup a local version of cocoapods pointing to master branch of ruby-macho and all works fine.
I am waiting for Ruby-Macho to release a version. After that we should be able to update Cocoapods to point to that version.

That will be it.

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

No branches or pull requests

2 participants