google / flatbuffers

FlatBuffers: Memory Efficient Serialization Library
https://flatbuffers.dev/
Apache License 2.0
22.52k stars 3.19k forks source link

Request to Add `BUILD_LIBRARY_FOR_DISTRIBUTION` to FlatBuffers.podspec and Update CocoaPods Distribution Version #8329

Open km-steve-ham opened 3 weeks ago

km-steve-ham commented 3 weeks ago

Description: I am writing to request the addition of the following configuration to the FlatBuffers.podspec file to ensure ABI stability and proper framework distribution:

s.pod_target_xcconfig = {
  'BUILD_LIBRARY_FOR_DISTRIBUTION' => 'YES'
}

Issue: The latest version of FlatBuffers distributed to CocoaPods is 22.9.24, even though the FlatBuffers.podspec in the GitHub repository shows the version as 24.3.25. The actual distributed FlatBuffers need to have the above code added to ensure proper functionality and avoid runtime errors.

Crash Log: Due to the missing BUILD_LIBRARY_FOR_DISTRIBUTION = YES setting, there are issues with ABI stability, causing the following crash:

dyld[84037]: Symbol not found: _$s11FlatBuffers0A12BufferObjectP8__bufferAA04ByteC0VSgvgTq
  Referenced from: <6F79C456-C006-385E-AF9D-404B6D8F4386> /private/var/containers/Bundle/Application/55C0094C-F405-4EF0-8A8A-B2F10AE60E89/HelloWorld.app/Frameworks/KMLocationSDK.framework/KMLocationSDK
  Expected in:     <45E32326-5129-37E5-AFBC-68F64E132C9E> /private/var/containers/Bundle/Application/55C0094C-F405-4EF0-8A8A-B2F10AE60E89/HelloWorld.app/Frameworks/FlatBuffers.framework/FlatBuffers

Steps to Reproduce:

  1. Install and run a project that uses FlatBuffers as a dependency.
  2. Integrate the FlatBuffers framework without the BUILD_LIBRARY_FOR_DISTRIBUTION setting enabled.
  3. Observe the runtime crash due to missing symbols.

Proposed Solution: Please update the FlatBuffers.podspec to include the following configuration:

s.pod_target_xcconfig = {
  'BUILD_LIBRARY_FOR_DISTRIBUTION' => 'YES'
}

This change will ensure ABI stability and prevent runtime crashes related to missing symbols.

Thank you for considering this request. Ensuring ABI stability is crucial for the smooth integration and functionality of projects relying on FlatBuffers.


Thank you for submitting an issue!

Please make sure you include the names of the affected language(s), compiler version(s), operating system version(s), and FlatBuffers version(s) in your issue title.

This helps us get the correct maintainers to look at your issue. Here are examples of good titles:

Include other details as appropriate.

Thanks!

mustiikhalil commented 3 weeks ago

Hey,

@km-steve-ham Thanks for opening an issue.

Looking at this issue in the CocoaPods repo, it seems that you can manually set it with a post_install. The Flatbuffers.podspec file follows what other repositories do with their podspec files, and thus we will try to keep it to minimal changes.

It might look like this:

post_install do |installer|
  ...
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      # maybe check if the lib is flatbuffers
      config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
    end
  end
end

Regarding the version, https://github.com/google/flatbuffers/pull/8328 should fix it. When it's merged I'll publish a newer version of the lib.

km-steve-ham commented 3 weeks ago

Thank you for the quick response and for addressing the version issue with #8328.

However, I would like to clarify that the proposed change to add BUILD_LIBRARY_FOR_DISTRIBUTION to the FlatBuffers.podspec is crucial for ABI stability. The lack of this setting has been causing runtime crashes due to symbol resolution issues, as shown in the crash log I provided.

While I understand that you prefer to keep the podspec minimal and suggest using a post-install script, this approach places an additional burden on users and increases the risk of these issues being overlooked. Including the following configuration directly in the FlatBuffers.podspec would ensure that all users benefit from the necessary ABI stability without requiring manual intervention:

s.pod_target_xcconfig = {
  'BUILD_LIBRARY_FOR_DISTRIBUTION' => 'YES'
}

Could you please reconsider adding this to the podspec to prevent potential runtime issues for all users?

Thank you for your attention to this matter.