I'm currently trying to take two simulator MyFramework.framework (arm64 and x86) and merge then together into a fat framework to embed into a xcframework. The current steps are simple lipo the binaries and copy the swift module(x86_64 and arm64) files to a single folder.
However Framework-Swift.h are separated and generated with arch check #elif defined(__x86_64__) && __x86_64__ which had to be modified for it to work.
With a simple string replacement sed -i '' 's/defined(__x86_64__) \&\& __x86_64__/defined(__x86_64__) \&\& __x86_64__ || defined(__arm64__) \&\& __arm64__/g'/x86_64/MyFramework.framework/Headers/MyFramework-Swift.h everything seems work fine since they are both built in the same step by the exact same compiler.
Considered also copy the contents under #elif defined(__arm64__) \&\& __arm64__ from one file to the other which seems to be better, but the content appears to be the same so it was simpler to just extend the check.
But the question is if there is a better way to merge those both together without a hand written script?
And also the current solution seems fine to me, but I have limited knowledge on that so a second question is to confirm if that could be considered incorrect or cause any unexpected issues?
There’s no guarantee that the two generated headers are the same, even though 99% of the time they will be, so if you’re doing something automated concatenation is probably the best idea. (I believe that’s what Xcode does.)
I've been trying to do the same thing, but indeed I can't find a simple way to merge headers as Xcode does. In my case I don't want to create a xcframework, I just need to lipo together two swift modules built as static libraries, and then merge their respective generated interop headers.
When you look at an xcode build of a multi-arch project, it has a step "SwiftMergeGeneratedHeaders" which internally calls "builtin-swiftHeaderTool", which seems to be doing exactly what we want here.
Unfortunately so far, I can't find a way to do the same operation (or call the same tool) from command line.
I'll try more things, as concatenation is not a valid solution here, as, indeed, in that case, arm64 and x86_64 headers are 100% the same, but that's not a valid assumption.
Hope that helps, and don't hesitate if you make any progress on your side :)
Yes, I think the ideal would be if we were able to invoke the tool
But that is what I endup with at the end as well, I wrote a python script that finds the whole arch block from one file, copy that and then insert into resulting file for the fat .framework. It was kind of ~150 loc in python that were maybe specific to our case(merging only arm64 and x84), but we were able to put in our pipelines to automate the process, and at the end result worked fine.