aws-sdk-ios icon indicating copy to clipboard operation
aws-sdk-ios copied to clipboard

OCMock binary is not compatible with Apple Silicon M1 Macs

Open brennanMKE opened this issue 3 years ago • 2 comments

Describe the bug

The OCMock binary (libOCMock.a) has not been built for modern Apple Silicon and is included in the repo as a binary. It will need to be updated to include a slice for arm64 for Apple Silicon.

To Reproduce Steps to reproduce the behavior:

  1. Clone SDK repo to M1 Mac
  2. Build
  3. Run tests
  4. See error

Since this binary has not been updated in a while and the header files are in the OCMock folder it will require finding the version originally used for this build or update the SDK to use a newer version of OCMock. Below are the build commands which could b used once the right version is selected. It may be close to v3.0.

CONFIGURATION=Release

xcodebuild -project Source/OCMock.xcodeproj clean
xcodebuild -project Source/OCMock.xcodeproj -scheme OCMockLib -sdk iphoneos15.0 -configuration ${CONFIGURATION} build
xcodebuild -project Source/OCMock.xcodeproj -scheme OCMockLib -sdk iphonesimulator15.0 -configuration ${CONFIGURATION} build

brennanMKE avatar Dec 09 '21 23:12 brennanMKE

Here is the full script.

#!/bin/sh

# git clone [email protected]:erikdoe/ocmock.git ocmock
# git checkout tags/v3.0 -b v3.0-branch

OUTPUT_DIR="./Output"

if [ -d "${OUTPUT_DIR}" ]; then
    rm -rf "${OUTPUT_DIR}"
fi

CONFIGURATION=Release

xcodebuild -project Source/OCMock.xcodeproj clean
xcodebuild -project Source/OCMock.xcodeproj -scheme OCMockLib -sdk iphoneos15.0 -configuration ${CONFIGURATION} build
xcodebuild -project Source/OCMock.xcodeproj -scheme OCMockLib -sdk iphonesimulator15.0 -configuration ${CONFIGURATION} build

BUILD_PATH=$(locate-build-path)

PLATFORMS="iphoneos iphonesimulator"

mkdir -p "${OUTPUT_DIR}"

for PLATFORM in ${PLATFORMS}; do
    LIBRARY_PATH="${BUILD_PATH}/Build/Products/${CONFIGURATION}-${PLATFORM}/libOCMock.a"
    if [ -f "${LIBRARY_PATH}" ]; then
        mkdir -p "${OUTPUT_DIR}/${PLATFORM}"
        cp "${LIBRARY_PATH}" "${OUTPUT_DIR}/${PLATFORM}"
    fi
    if [ "iphoneos" == "${PLATFORM}" ]; then
        HEADERS_PATH="${BUILD_PATH}/Build/Products/${CONFIGURATION}-${PLATFORM}/OCMock"
        if [ -d "${HEADERS_PATH}" ]; then
            cp -rp "${HEADERS_PATH}" "${OUTPUT_DIR}"
        fi
    fi
done

Since libOCMock.a is linked directly by many test targets the most minimal change would be to replace that binary. I do not know if a FAT binary will work in this case since arm64 for Macs may be different than it is for iPhones which are also arm64. If a single binary can work for Intel and M1 Macs to build and run tests that would be the option which has the fewest changes.

brennanMKE avatar Dec 09 '21 23:12 brennanMKE

Related https://github.com/aws-amplify/aws-sdk-ios/commits/stehlib.3939-ocmock

lawmicha avatar Apr 15 '22 17:04 lawmicha

Why not to build OCmock as xcframework? that should resolve the issue no? O I see it was already added in the artifacts https://github.com/erikdoe/ocmock/releases

MikePendo avatar Dec 29 '22 17:12 MikePendo