libimobiledevice / libplist

A library to handle Apple Property List format in binary or XML
https://libimobiledevice.org
GNU Lesser General Public License v2.1
532 stars 304 forks source link

Catalyst Support #170

Closed Schlaubischlump closed 4 years ago

Schlaubischlump commented 4 years ago

This is most likely not a bug, but rather a help request for compiling libplist for macOS Catalyst. The source code should be compatible, because there is already an iOS port of libplist. I'm trying to compile it on macOS Big Sur with the following command:

MIN_IOS_VERSION="14.0"

build()
{
    make clean

    ARCH=$1
    TARGET=$2
    HOST=$3
    SDK=$4
    SDK_PATH=`xcrun -sdk ${SDK} --show-sdk-path`

    export PREFIX=$(pwd)/build/${ARCH}
    export CFLAGS="-arch ${ARCH} -target ${TARGET} -isysroot ${SDK_PATH} -iframework ${SDK_PATH}/System/iOSSupport/System/Library/Frameworks"
    export CXXFLAGS=${CFLAGS}
    export LDFLAGS="-arch ${ARCH} -iframework ${SDK_PATH}/System/iOSSupport/System/Library/Frameworks"
    export CC="$(xcrun --sdk ${SDK} -f clang) -arch ${ARCH} -isysroot ${SDK_PATH}"

    ./autogen.sh --disable-dependency-tracking --without-cython --host=${HOST} --prefix=${PREFIX}
    make -j 8
}

build "x86_64" "x86_64-apple-ios${MIN_IOS_VERSION}-macabi" "x86_64-apple-darwin" "macosx"

Which yields the error:

ld: building for macOS, but linking in object file built for Mac Catalyst, file '.libs/base64.o' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Does anybody know which flag I'm missing ?

Schlaubischlump commented 4 years ago

For anyone else wondering. This seems to work:

MIN_OSX_VERSION="11.0"
MIN_IOS_VERSION="14.0"

build()
{
    make clean

    ARCH=$1
    TARGET=$2
    HOST=$3
    SDK=$4
    SDK_PATH=`xcrun -sdk ${SDK} --show-sdk-path`

    export PREFIX=$(pwd)/build/${ARCH}
    export CFLAGS="-arch ${ARCH} -target ${TARGET} -isysroot ${SDK_PATH} -mmacosx-version-min=${MIN_OSX_VERSION} -Wno-overriding-t-option -fembed-bitcode"
    export CXXFLAGS=${CFLAGS}
    export LDFLAGS=${CFLAGS}
    export CC="$(xcrun --sdk ${SDK} -f clang) ${CFLAGS}"
    export CXX="$(xcrun --sdk ${SDK} -f clang++) ${CFLAGS}"
    export CCLD=$CC
    export CXXLD=$CXX

    echo $CC

    ./autogen.sh --disable-dependency-tracking --without-cython --host=${HOST} --prefix=${PREFIX}
    make -j 8
    #make install
}

# Catalyst
build "x86_64" "x86_64-apple-ios${MIN_IOS_VERSION}-macabi" "x86_64-apple-darwin" "macosx"

As you can see, the c++ part and the minimum macOS version was missing. It now compiles, I still need to test if it works. Some of these flags might not be required. If it does indeed work, I will close the issue.

droll2571 commented 1 year ago

@Schlaubischlump Do you know how to build all of the libimobiledevice dynamic libraries for MacCatalyst? I am a c# developer and this seems to be a big learning curve.

Schlaubischlump commented 1 year ago

Are static libraries okay as well ?

I have a (buggy) script (Repo: build-libimobiledevice) on my github profile that builds libimobiledevice for iOS (although it won't work on iOS, since usbmuxd does not exist). You should be able to adapt the script for MacCatalyst easily. Changing the platform or architecture or something like this should be enough. The script will output static libraries (.a files). You can then create XCFrameworks from the static libraries. You can find an example and a script on how to do this on my github as well (Repo: XCF).