Add iOS cross-compilation support#2
Open
Maxnflaxl wants to merge 2 commits into
Open
Conversation
Build libipfs-bindings.a + libasio-ipfs.a for iOS (arm64 device + arm64 and x86_64 simulators), mirroring the existing Android path. The Go cgo build is driven from CMake by setting GOOS=ios and a CC value of `<xcrun clang> -target <triple> -isysroot <sdk>` resolved at configure time; the host-arch Darwin Go 1.16.10 tarball already used by the macOS build is reused. - CMakeLists.txt: detect CMAKE_SYSTEM_NAME=iOS, enforce single-arch slices, skip Boost find_package on iOS (header-only via BOOST_ROOT / BOOST_ROOT_IOS, matching the Beam iOS wallet build), add an iOS-specific add_custom_command using cmake -E env to dodge shell- quoting headaches with the multi-word CC, extend the imported- library + CoreFoundation/Security framework block to cover iOS. - scripts/build-ios.sh: build all three slices and combine into ipfs-bindings.xcframework + asio-ipfs.xcframework via xcodebuild -create-xcframework. - README.md: iOS cross-compilation section.
CI fail mode: net/cgo_bsd.go, os/user/cgo_lookup_unix.go and plugin/plugin_dlopen.go errored with `'netdb.h' / 'unistd.h' / 'dlfcn.h' file not found` even though our CC string carried `-isysroot <iphoneos.sdk>`. Root cause: Go's cgo treats CC as a "program" when composing the internal compile commands for std-library cgo glue. Anything past the first token (-target, -isysroot, ...) gets silently dropped on that path, so clang ran without a sysroot and couldn't find POSIX headers. The cgo glue for our own package was fine because that path does respect the multi-word CC, which masked the issue until the std-lib packages were compiled. Fix: keep CC as the bare clang binary and ship the iOS target / sysroot through CGO_CFLAGS / CGO_CXXFLAGS / CGO_LDFLAGS. Those are appended verbatim to every cgo invocation, so the iOS cross-compile flags reach the std-library compiles too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds iOS cross-compile paths so callers (e.g. the Beam iOS wallet) can build
libipfs-bindings.a+libasio-ipfs.aforarm64device andarm64/x86_64simulator slices, mirroring the existing Android path. The Go cgo build is driven from CMake by settingGOOS=iosand bridging the Xcode SDK viaxcrun. The Go 1.16.10 Darwin tarball this repo already pins is reused — itsc-archivemode handles iOS cross-compile when given the right env vars.Changes
CMAKE_SYSTEM_NAME=iOS, infer device-vs-simulator fromCMAKE_OSX_SYSROOTand target arch fromCMAKE_OSX_ARCHITECTURES; enforce one slice per invocation. Resolve the Xcode SDK path + clang binary viaxcrunat configure time and bake them intoCGO_CFLAGS/CGO_CXXFLAGS/CGO_LDFLAGSso the iOS target + sysroot reach every cgo compile (including Go's std-library cgo glue —net,os/user,plugin). Skip Boostfind_packageon iOS (header-only path viaBOOST_ROOT/BOOST_ROOT_IOS, matching Beam's existing iOS wallet convention). Extend the imported-library +CoreFoundation/Securityframework block to cover iOS.ipfs-bindings.xcframework+asio-ipfs.xcframeworkviaxcodebuild -create-xcframework, lipo-ing the two simulator arches first.Why two commits
c7f2db2initially passed the iOS target/sysroot via a multi-wordCCvalue. That works for asio-ipfs's own cgo glue but fails on Go's std-library cgo compiles (net/cgo_bsd.go,os/user/cgo_lookup_unix.go,plugin/plugin_dlopen.go) — Go's internal compile path uses only the first token ofCCas the program and silently drops the rest.beded1bmoves the flags intoCGO_CFLAGS/CGO_LDFLAGSinstead, which Go appends verbatim to every cgo invocation.Verification
cmake -S . -B build/ios-device -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_ARCHITECTURES=arm64 -DBOOST_ROOT=…configures cleanly; generated build files referencexcrun-resolved SDK + correctarm64-apple-ios<deployment>triple.CMAKE_OSX_SYSROOT=iphonesimulatorwitharm64andx86_64arches (-simulatortriple suffix).BEAM_IPFS_SUPPORT=Onfor iOS in CI.Caveats / follow-ups
GOOS=iossince 1.16, including Apple-Silicon simulator via the-target arm64-apple-ios<ver>-simulatorclang flag we set. A future bump to a newer Go would tighten iOS handling further but isn't required for this PR.