cossacklabs / themis

Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.
https://www.cossacklabs.com/themis
Apache License 2.0
1.85k stars 143 forks source link

Xcode 12 / iOS14 compatibility with Carthage [EXCLUDE ARM64 SLICE, TEMP WORKAROUND] #713

Closed vixentael closed 3 years ago

vixentael commented 3 years ago

I'm creating this issue for history and our users, as they might stumble upon it.

The reason is https://github.com/Carthage/Carthage/issues/3019.

Describe the bug

When using Xcode 12 (beta or latest stable), Themis Carthage (0.34, 0.36) installation fails for iOS:

➜  carthage update --platform iOS                                 
*** Fetching themis
*** Downloading binary-only framework openssl-static-MacOSX at "https://raw.githubusercontent.com/cossacklabs/openssl-apple/cossacklabs/carthage/openssl-static-MacOSX.json"
*** Downloading binary-only framework openssl-static-iPhone at "https://raw.githubusercontent.com/cossacklabs/openssl-apple/cossacklabs/carthage/openssl-static-iPhone.json"
*** Checking out themis at "0.13.2"
*** xcodebuild output can be found in /var/folders/z1/t8trzl2d5tq_r_1tzqpkk8ww0000gp/T/carthage-xcodebuild.UO2Kbf.log
*** Downloading binary-only framework openssl-static-iPhone at "https://raw.githubusercontent.com/cossacklabs/openssl-apple/cossacklabs/carthage/openssl-static-iPhone.json"
*** Downloading binary-only framework openssl-static-MacOSX at "https://raw.githubusercontent.com/cossacklabs/openssl-apple/cossacklabs/carthage/openssl-static-MacOSX.json"
*** Building scheme "Themis (iOS)" in Themis.xcodeproj
Build Failed
    Task failed with exit code 65:
    /usr/bin/xcrun xcodebuild -project /docs/examples/swift/iOS-Carthage/Carthage/Checkouts/themis/Themis.xcodeproj -scheme Themis\ (iOS) -configuration Release -derivedDataPath ~/Library/Caches/org.carthage.CarthageKit/DerivedData/12.0_12A7209/themis/0.13.2 -sdk iphonesimulator -destination platform=iOS\ Simulator,id=871AFE86-3205-4E7A-BBE6-0CA9AAEE751F -destination-timeout 3 ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES build (launched in /docs/examples/swift/iOS-Carthage/Carthage/Checkouts/themis)

This usually indicates that project itself failed to compile. Please check the xcodebuild log for more details: /var/folders/z1/t8trzl2d5tq_r_1tzqpkk8ww0000gp/T/carthage-xcodebuild.UO2Kbf.log

Logs contain following:

/docs/examples/swift/iOS-Carthage/Carthage/Checkouts/themis/Carthage/Build/iOS/openssl.framework/Headers/opensslconf.h:26:3: error: Unable to determine target or target not included in OpenSSL build
# error Unable to determine target or target not included in OpenSSL build

The reason

The reason of this issue is the new Xcode 12 behaviour, which Carthage doesn't handle correctly right now. See https://github.com/Carthage/Carthage/issues/3019 for details.

The workaround

Tested for Xcode 12, Sept 25. You can push app to the App Store with this workaround.

~See the detailed workaround https://github.com/Carthage/Carthage/issues/3019#issuecomment-665136323 if you are building for Xcode beta, I'm providing a short description below.~

~UPD: this workaround is also a nice one https://github.com/Carthage/Carthage/issues/3019#issuecomment-699143260.~

UPD2: see this workaround for Xcode 12.0.1 and older https://github.com/Carthage/Carthage/issues/3019#issuecomment-699143260

  1. Create script carthage_tweaked_build.sh file with the following content:
#!/usr/bin/env bash

# carthage-build.sh
# Usage example: ./carthage-build.sh --platform iOS
# from https://github.com/Carthage/Carthage/issues/3019#issuecomment-699143260
# supports Xcode 12.0.1

set -euo pipefail

xcconfig=$(mktemp /tmp/static.xcconfig.XXXXXX)
trap 'rm -f "$xcconfig"' INT TERM HUP EXIT

# For Xcode 12 make sure EXCLUDED_ARCHS is set to arm architectures otherwise
# the build will fail on lipo due to duplicate architectures.

CURRENT_XCODE_VERSION=$(xcodebuild -version | grep "Build version" | cut -d' ' -f3)
echo "EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200__BUILD_$CURRENT_XCODE_VERSION = arm64 arm64e armv7 armv7s armv6 armv8" >> $xcconfig

echo 'EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200 = $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200__BUILD_$(XCODE_PRODUCT_BUILD_VERSION))' >> $xcconfig
echo 'EXCLUDED_ARCHS = $(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT)__XCODE_$(XCODE_VERSION_MAJOR))' >> $xcconfig

export XCODE_XCCONFIG_FILE="$xcconfig"
carthage build "$@"
  1. Run this script as if you were updating Carthage libs normally:
./carthage_tweaked_build.sh --platform iOS

*** xcodebuild output can be found in /var/folders/z1/t8trzl2d5tq_r_1tzqpkk8ww0000gp/T/carthage-xcodebuild.wEbBQV.log
*** Downloading binary-only framework openssl-static-iPhone at "https://raw.githubusercontent.com/cossacklabs/openssl-apple/cossacklabs/carthage/openssl-static-iPhone.json"
*** Downloading binary-only framework openssl-static-MacOSX at "https://raw.githubusercontent.com/cossacklabs/openssl-apple/cossacklabs/carthage/openssl-static-MacOSX.json"
*** Building scheme "Themis (iOS)" in Themis.xcodeproj
  1. Enjoy and follow https://github.com/Carthage/Carthage/issues/3019 for updates!

Environment (please complete the following information):

mmoloksher commented 3 years ago

Seems like this is now broken in Xcode 12.0.1 :(

vixentael commented 3 years ago

@mmoloksher thank you for notifying!

I've checked another workaround and it works for me for Xcode 12.0.1.

vixentael commented 3 years ago

I have this issue open for those who are looking...

Confirmed:

vixentael commented 3 years ago

I think, everyone already knows what's going on, but let me write again.

Xcode 12 has introduced Apple Silicon support on macOS. Since 0.13.4 Themis supports ARM64 architecture on macOS, but excludes ARM64-iphonesimulator architecture slice for iOS.

iOS: Excluded arm64-iphonesimulator architecture slice for now.

macOS: If you’re supporting x86_64 and arm64, use Themis 0.13.4 and later. Previous versions don’t contain arm64 slice.

As .framework cannot contain both arm64 slice and arm64-iphonesimulator slice, there's no easy fix for framework-based installation. We're looking at XCFrameworks now.