Cogosense / iOSBoostFramework

Boost library framework for iOS
25 stars 13 forks source link

Building Boost Library From Source and Packaging The Framework #10

Open JasonCoombs opened 1 year ago

JasonCoombs commented 1 year ago

Thank you for your excellent work FOR MANY YEARS helping all of us build Boost for use in Xcode projects targeting iOS, the iOS Simulator, and macOS.

Your latest version seems to change directions, making it possible for us to include Boost as a Swift Framework far easier than ever before, because now there is a package manager in Swift that accepts the URL to your precompiled Framework package and that's all there is to it, mission accomplished!

The problem is, doing it this way means that any malicious third-party who gains control over your GitHub repo can deliver arbitrary compiled code to all of our development machines and to every mobile device that runs our Apps.

You don't seem to be better-positioned than anyone else to operate a trusted package manager repository as you are now doing, respectfully, so it does not seem reasonable for anyone to accept your offer of a free hosted compiled (out-of-date) Boost Framework package.

What we all need, instead, is to build Boost from source as we always did in the past, urging the Boost development team to do a better job of making Boost buildable with cmake and deliverable like framework packages through Swift package manager from the trusted source repository we choose or from our own deployment staging server.

Will you please update your documentation and your Makefile to explain the final step required to create the Swift Framework Package.swift file required after building Boost with B2, Jam and clang in the ordinary manner, producing the compiled boost library files from the portions of Boost that must be compiled for each target ARCHitecture?

Your latest version of the iOSBoostFramework Makefile https://github.com/Cogosense/iOSBoostFramework/blob/fa36286d14194049276ce9c1a30fca2a6f9d9b2f/Makefile builds everything up to but not including the Swift Framework Package.swift file because, apparently, you found it simpler to deliver the already-compiled Framework zip file hosted here on GitHub as a pre-compiled Framework Release, which clearly DOES simplify this entire process for everyone and we CAN do it that way, thanks to Swift Package Manager's new support for adding your precompiled Framework as a remote-hosted dependency.

I think you will agree that is not the perfect solution, it is merely the easiest one and it usually works.

These are the steps I took in my attempt to implement a more perfect solution, which did not work as expected but got me close enough to figure the rest out on my own eventually.

(1) Edited your Makefile to retrieve the latest Boost source code:

# library to be built
NAME = boost
BOOST_VERSION = 1_83_0
#
# Release version on GitHub - bump last digit to make new
# GitHub release with same Boost version.
VERSION =  1.83.0

#
# Download location URL
#
TARBALL = $(NAME)_$(BOOST_VERSION).tar.bz2
DOWNLOAD_URL = https://boostorg.jfrog.io/artifactory/main/release/1.83.0/source/boost_1_83_0.tar.bz2

(2) Deleted your Package.swift file, which if left in place ignores my local build and retrieves your precompiled Framework hosted here on GitHub instead because of:

url: "https://github.com/Cogosense/iOSBoostFramework/releases/download/\(version)/\(moduleName).xcframework.zip",

https://github.com/Cogosense/iOSBoostFramework/blob/fa36286d14194049276ce9c1a30fca2a6f9d9b2f/Package.swift#L23

(3) Used the make SDK commands from your README and the final build step make xcframework to produce the expected single framework zip containing binaries for each ARCH:

% make SDK=macosx                                                            
Commencing debug build for SDK:macosx ARCHS:"arm64 x86_64" framework: boost
downloading https://boostorg.jfrog.io/artifactory/main/release/1.83.0/source/boost_1_83_0.tar.bz2
tar -C /Users/jasonc/iOSBoostFramework/build/Maker/Sources -xmf /Users/jasonc/iOSBoostFramework/build/Maker/Archives/boost_1_83_0.tar.bz2
...
[macosx-x86_64] extracting... thread program_options atomic random date_time test_exec_monitor system exception locale prg_exec_monitor regex wserialization unit_test_framework filesystem chrono serialization 
creating /Users/jasonc/iOSBoostFramework/build/Maker/Intermediate/macosx/boost.framework.zip
boost.framework for macosx saved to archive /Users/jasonc/iOSBoostFramework/build/Maker/Intermediate/macosx/boost.framework.zip
Completed debug build for SDK:macosx ARCHS:"arm64 x86_64" framework: boost

% make SDK=iphoneos                                                                                                    
Commencing debug build for SDK:iphoneos ARCHS:"arm64" framework: boost
...
[iphoneos-arm64] extracting... thread program_options atomic random date_time test_exec_monitor system exception locale prg_exec_monitor regex wserialization unit_test_framework filesystem chrono serialization 
creating /Users/jasonc/iOSBoostFramework/build/Maker/Intermediate/iphoneos/boost.framework.zip
boost.framework for iphoneos saved to archive /Users/jasonc/iOSBoostFramework/build/Maker/Intermediate/iphoneos/boost.framework.zip
Completed debug build for SDK:iphoneos ARCHS:"arm64" framework: boost

% make SDK=iphonesimulator                                                                                             
Commencing debug build for SDK:iphonesimulator ARCHS:"arm64 x86_64" framework: boost
...
[iphonesimulator-x86_64] extracting... thread program_options atomic random date_time test_exec_monitor system exception locale prg_exec_monitor regex wserialization unit_test_framework filesystem chrono serialization 
creating /Users/jasonc/iOSBoostFramework/build/Maker/Intermediate/iphonesimulator/boost.framework.zip
boost.framework for iphonesimulator saved to archive /Users/jasonc/iOSBoostFramework/build/Maker/Intermediate/iphonesimulator/boost.framework.zip
Completed debug build for SDK:iphonesimulator ARCHS:"arm64 x86_64" framework: boost

% make xcframework                                                                                                     
xcframework successfully written out to: /Users/jasonc/iOSBoostFramework/build/boost.xcframework
creating boost.xcframework.tar.bz2
boost.xcframework saved to archive boost.xcframework.tar.bz2
creating boost.xcframework.zip
boost.xcframework saved to archive boost.xcframework.zip

% cd boost.xcframework

boost.xcframework % find . -type f -name boost -exec ls -l {} \;
-rw-r--r--  1 jasonc  staff  13578952 Aug 13 12:49 ./macos-arm64_x86_64/boost.framework/boost
-rw-r--r--  1 jasonc  staff  13575520 Aug 13 13:14 ./ios-arm64_x86_64-simulator/boost.framework/boost
-rw-r--r--  1 jasonc  staff  6697648 Aug 13 13:02 ./ios-arm64/boost.framework/boost

(4) But these three steps left me with no Package.swift file (obviously I can learn how to edit the one you provided to maybe use my local zip file, or I can publish my zip file to GitHub and modify the URL and checksum, which is how your Makefile reads and appears to work for you when you publish a new release).

(5) Your instructions imply that I should be able to drag-and-drop the resulting Framework, built without using your Xcode project, similar to the Carthage instructions https://github.com/Carthage/Carthage#adding-frameworks-to-an-application for adding a Framework which you reference in your README, or by Apple's instructions which are similar https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app but again that appears to work only if I leave your Package.swift file which then causes Xcode to retrieve your binary instead of using the one I built myself from Boost source with your very helpful Makefile.

(6) While feeling like it is wrong to ask you to give away the rest of your secret knowledge for free, offering only thanks in return (at the moment) but hoping you are frequently asked by paying clients to help them at high hourly rates in recognition of your significant skill and contribution to open source development worldwide, will you please correct the final step in this process, either with documentation or a modified Makefile, so that whatever I end up doing myself might be corrected later by your superior solution to this problem?

If not, then I suggest that you make it more clear in your README hosted here that you have stopped supporting any deployment scenario other than the one in which Swift Package Manager retrieves your precompiled Boost library using your Package.swift file, and remove your Makefile and the instructions which make it appear that following these steps will have the expected end-result of NOT trusting you and GitHub to be the blindly-trusted package repository to the Boost-on-Mac-and-iOS C++ developer world.

UPDATE: drag-and-drop DOES appear to work, when the boost.xcframework folder is dragged rather than dragging the zip file or the iOSBoostFramework parent folder containing your Package.swift file (or, rather, NOT containing that file after I deleted it to avoid adding a remote dependency on your precompiled Framework zip file).

image image

UPDATE 2: this is now working exactly as expected in Xcode for my project, which now builds successfully and links Boost through the Framework, but I had to switch from Embed to Do Not Embed because this is a static library and can only be embedded if it is a dynamic one.

image

See: https://stackoverflow.com/questions/57687170/do-not-embed-embed-sign-embed-without-signing-what-are-they-what-th

Also: https://holyswift.app/frameworks-embed-or-not-embed-thats-the-question/

Also Also: https://developer.apple.com/library/archive/technotes/tn2435/_index.html

bitbytedog commented 1 year ago

I will take a look at this soon. Sorry been busy on other projects.