Introduction binaryTarget feature in swift package manager 5.3. provides a convenient way to add libraries from the C++ universe using Objective C or pure C wrapper as external dependencies. This is an elegant and simple way. Before that, I had to use git submodules and Xcode subprojects with bash scripts.
I’m trying to refactoring FastRTPSBridge project - wrapper over the FastRTPS library, which is actively used in the TridentCockpit project.
Ok, let’s get started.
git clone -b binaryTarget https://github.com/DimaRU/FastRTPSBridge.git cd FastRTPSBridge swift build
Tech is working for macOS.
Now try building for iOS Simulator. To do this, you will need to use xcodebuild.
xcodebuild -scheme FastRTPSBridge -destination ‘generic/platform=iOS Simulator’
Error, headers now found.
Okay, I guess maybe iOS isn’t fully supported yet.
Let’s try to build for macOS:
xcodebuild -scheme FastRTPSBridge -destination ‘generic/platform=macOS’
The same error, headers now found.
What is the difference between swift build and xcodebuild? Xcodebuild uses the ‘xcode new build system’, which makes extensive use of parallel builds.
Let’s try to investigate the error.
xcodebuild -scheme FastRTPSBridge -destination ‘generic/platform=macOS’ - IDEBuildingContinueBuildingAftererrors=YES
Error again, but compilation went further. Second run:
xcodebuild -scheme FastRTPSBridge -destination ‘generic/platform=macOS’ -IDEBuildingContinueBuildingAftererrors=YES
** BUILD SUCCEEDED **
The problem is that binaryTargets are processed in parallel with other tasks and simply do not have time to execute and create an environment for processing other targets.
If we force the build system to work after errors occur, then binaryTarget finishes processing and beginning from the second pass, the file structure is prepared for compiling the remaining targets.
This must be considered as logic flaw in xcodebuild system. All binaryTarget’s should be processed before all other targets!
The same problem is here: https://forums.swift.org/t/headers-not-found-for-an-xcframework-packaging-a-static-lib-for-ios-critical/41464 and may be here: https://forums.swift.org/t/packaging-static-library-in-spm-package-for-ios-executable/41245