mirror of
https://github.com/jmcnamara/libxlsxwriter.git
synced 2026-05-15 14:15:54 -06:00
[PR #44] [CLOSED] Add Framework subspec for building the pod as a framework. #406
Labels
No labels
awaiting user feedback
bug
cmake
cmake
docs
feature request
in progress
long term
medium term
medium term
pull-request
question
question
ready to close
short term
under investigation
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/libxlsxwriter#406
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/jmcnamara/libxlsxwriter/pull/44
Author: @lrossi
Created: 2/3/2016
Status: ❌ Closed
Base:
master← Head:cocoapods-1.0.0📝 Commits (1)
6631db0Add Framework subspec for building the pod as a framework.📊 Changes
1 file changed (+31 additions, -5 deletions)
View changed files
📝
libxlsxwriter.podspec(+31 -5)📄 Description
Adding support for CocoaPods'
use_frameworks!Ok, here we are: sorry this took longer than I expected and almost drove me crazy 😜
The quest for building as a framework
So, CocoaPods 1.0.0 is almost there (currently in its
second beta—actually it seems while I was writing the third beta came out, see The bottom line), and it fixes the main problem (#13) that was preventing this pod from being built as a framework.Full of hope I installed the CocoaPods beta and tried to include the pod with the
use_frameworks!directive. Build fails with error:Hmm, so it seems even though the include directory structure is now preserved in the framework (I was able to verify that), the compiler is still puzzled about where to find the headers. Since the correct structure exists on disk, I solved this error by adding a line in the Podspec:
Now a new problem arose in the umbrella header generated by CocoaPods:
The error is a bit misleading since it basically means that with the current Podspec the
xlsxwriter.hheader doesn't get copied in the framework: that file is inside theincludedirectory, but with these lines:we are just preserving the
xlsxwriterdirectory that is a subdirectory ofinclude, effectively leaving out thexlsxwriter.hheader.My first naive attempt was to preserve the whole
includedirectory, like this:This removes the
non-modularerror, however it leads to another error in libxlsxwriter'sapp.hwhen building the iOS target that includes the pod:I think this is because at this point (i.e. when building the iOS app and not the pod), the compiler relies on the headers that are bundled within the framework, that now have this structure:
while when going back to:
the structure is like this:
Even though this latter structure leaves out the
xlsxwriter.hheader, for some reason it allows all the other includes such as#include "xlsxwriter/workbook.h"to succeed (possibly becausexlsxwritergets recognized as the name of the framework).So now it comes my, ahem, “brillant” idea: moving the
xlsxwriter.hheader inside of thexlsxwriterdirectory. This is accomplished with these lines in the Podspec:I renamed the file to
xlsxwriter_module.hto further reduce the probability of clashes with existing headers inside thexlsxwriter, since for the purpose of building the framework the actual file name doesn't matter (it automatically gets included in the generated umbrella header). This is kind of an hack that I don't like very much, but you know what... It works:All that glitters is not gold
But wait a minute... Didn't we just break the old-fashioned way of building the pod as a static library? Of course we did, since now when building the pod the good ol' way, instead of importing it with the comforting (and standard):
we must use the crazy:
Even relaxing my name clashing obsession, it's still:
This means: to the best of my knowledge, there is no easy way of writing a plain Podspec that works both with and without
use_frameworks!without touching the main code.So what?
A new beginning
In these cases, it seems to be an accepted practice to define multiple subspecs addressing specific configuration needs. For example, the Chameleon pod has a
ChameleonFramework/Swiftsubspec so that to add the pod to an Objective-C project you do:while with a Swift project you do:
Subspecs seem the way to go, however there is one last caveat: they can't contain
prepare_commandstatements. Thus this is what I ended up with:This excerpt from the Podspec means there are now two subspecs:
Defaultsubspec is marked as default by settingdefault_subspecs, thus it can be imported in a project with the usualpod 'libxlsxwriter'in the Podfile. It is used to build the pod as a static library (exactly as it was before).Frameworksubspec can be imported in a project withpod 'libxlsxwriter/Framework'in the Podfile. It is used to build the pod as a framework (i.e. when the Podfile contains theuse_frameworks!directive).In a libxlsxwriter user's shoes
Good news is a libxlsxwriter user doesn't need to be aware of all this machinery. In order to import the pod as a static library, one can simply add this to the Podfile (as usual):
and then import the pod in project's source files like this (as usual):
On the other hand, in order to import the pod as a framework, one can add this to the Podfile:
and then import the pod in project's source files in Swift:
or in Objective-C:
The bottom line
First of all, thanks for reading this far. I tried to explain the whole process so that someone can possibly suggests any way to improve it. This is the best solution I came up with so far, but it would be great to get rid of some of the machinery involved, if possible. Otherwise, the current solution is working and I'm not seeing major side effects (with my own eyes, at least). I have tested the current solution with my example projects in a dedicated branch.
In any case, I would recommend waiting for the final CocoaPods 1.0.0 release before merging this PR.
Credit where credit is due
Many thanks to @atomiix for spotting the original issue and for providing a patch in the meantime.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.