Search code examples
iosswiftxcodecarthagebitcode

Bitcode disabled on Carthage dependencies


Scenario

My project (codebase shared for iOS/watchOS/tvOS ) has build settings with ENABLE_BITCODE = YES and takes advantage of fundamental libraries which are not yet supporting bitcode, although quoting Apple documentation in App Thinning

Bitcode is the default, but optional. For watchOS and tvOS apps, bitcode is required. If you provide bitcode, all apps and frameworks in the app bundle (all targets in the project) need to include bitcode

I am currently integrating those fundamental libraries with Carthage.

Problem

In order to have a clean build process, I tried to submit some pull requests to the respective owners for enabling the bitcode but, due to the complexity of their codebases, which are working for multiple operating systems/architectures, my pull requests are still in pending: so, to be able to build my own project, I still have to change manually their build settings.

Question

How can I short-circuit the Carthage process for injecting specific build settings (in this case ENABLE_BITCODE = YES) into the relevant libraries?


Solution

  • I found a solution by making a shell script able to erase the disabling of bitcode, in case someone is facing or curious to solve a similar problem, the script is this:

    carthage update --platform ios
    for D in ./Carthage/Checkouts/*; do
      if [ -d "${D}" ]; then
        find $D -type d -name \*.xcodeproj -print0 |
          while IFS= read -r -d $'\0' folder; do
            sed -i '' 's/ENABLE_BITCODE = NO;//g' $folder/project.pbxproj
          done
        fi
    done
    carthage build --platform ios
    

    so basically the script's mechanism is:

    1. downloading all the dependencies
    2. for each dependency, find thepbxproj living inside xcodeproj and cut off the string ENABLE_BITCODE = NO
    3. finally building the dependencies to make the .framework