From 491d8c60950ccfb417eaf7494ced8e7e874448c6 Mon Sep 17 00:00:00 2001 From: Jackson Coxson Date: Tue, 3 Jun 2025 10:26:50 -0600 Subject: [PATCH] Build libplist into an xcframework --- .gitmodules | 3 ++ ffi/libplist | 1 + justfile | 114 +++++++++++++++++++++++++++++++++++++++++++- swift/Package.swift | 8 ++++ 4 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 ffi/libplist diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..1cffb04 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "ffi/libplist"] + path = ffi/libplist + url = https://github.com/libimobiledevice/libplist.git diff --git a/ffi/libplist b/ffi/libplist new file mode 160000 index 0000000..cf5897a --- /dev/null +++ b/ffi/libplist @@ -0,0 +1 @@ +Subproject commit cf5897a71ea412ea2aeb1e2f6b5ea74d4fabfd8c diff --git a/justfile b/justfile index e9d0239..39eb2e4 100644 --- a/justfile +++ b/justfile @@ -3,7 +3,7 @@ check-features: cargo hack check --feature-powerset --no-dev-deps cd .. -xcframework: # apple-build +xcframework: apple-build rm -rf swift/IDevice.xcframework rm -rf swift/libs cp ffi/idevice.h swift/include/idevice.h @@ -41,3 +41,115 @@ apple-build: # requires a Mac # macOS (native) – no special env needed cargo build --release --target aarch64-apple-darwin cargo build --release --target x86_64-apple-darwin + +lib_name := "plist" +src_dir := "ffi/libplist" + +ios_out := "build/ios" +sim_out := "build/sim" +x86_64_sim_out := "build/x86_64_sim" +mac_out := "build/mac" +x86_64_mac_out := "build/x86_64_mac" + +plist_xcframework: build_plist_ios build_plist_sim build_plist_x86_64_sim build_plist_mac build_plist_x86_64_mac merge_archs + rm -rf {{lib_name}}.xcframework + xcodebuild -create-xcframework \ + -library {{ios_out}}/lib/libplist-2.0.dylib -headers {{ios_out}}/include \ + -library build/universal-sim/libplist-2.0.dylib -headers {{sim_out}}/include \ + -library build/universal-mac/libplist-2.0.dylib -headers {{mac_out}}/include \ + -output swift/{{lib_name}}.xcframework + +merge_archs: + # Merge simulator dylibs (arm64 + x86_64) + mkdir -p build/universal-sim + lipo -create \ + {{sim_out}}/lib/libplist-2.0.dylib \ + {{x86_64_sim_out}}/lib/libplist-2.0.dylib \ + -output build/universal-sim/libplist-2.0.dylib + + # Merge macOS dylibs (arm64 + x86_64) + mkdir -p build/universal-mac + lipo -create \ + {{mac_out}}/lib/libplist-2.0.dylib \ + {{x86_64_mac_out}}/lib/libplist-2.0.dylib \ + -output build/universal-mac/libplist-2.0.dylib + +build_plist_ios: + rm -rf {{ios_out}} build/build-ios + mkdir -p {{ios_out}} + mkdir -p build/build-ios && cd build/build-ios && \ + ../../ffi/libplist/autogen.sh \ + --host=arm-apple-darwin \ + --prefix="$(pwd)/../../{{ios_out}}" \ + --without-cython \ + --without-tools \ + CC="$(xcrun --sdk iphoneos --find clang)" \ + CFLAGS="-arch arm64 -isysroot $(xcrun --sdk iphoneos --show-sdk-path)" \ + CXX="$(xcrun --sdk iphoneos --find clang++)" \ + CXXFLAGS="-arch arm64 -isysroot $(xcrun --sdk iphoneos --show-sdk-path)" \ + LDFLAGS="-arch arm64 -isysroot $(xcrun --sdk iphoneos --show-sdk-path)" && \ + make clean && make -j$(sysctl -n hw.ncpu) && make install + +build_plist_sim: + rm -rf {{sim_out}} build/build-sim + mkdir -p {{sim_out}} + mkdir -p build/build-sim && cd build/build-sim && \ + ../../ffi/libplist/autogen.sh \ + --host=arm-apple-darwin \ + --prefix="$(pwd)/../../{{sim_out}}" \ + --without-cython \ + --without-tools \ + CC="$(xcrun --sdk iphonesimulator --find clang)" \ + CFLAGS="-arch arm64 -isysroot $(xcrun --sdk iphonesimulator --show-sdk-path)" \ + CXX="$(xcrun --sdk iphonesimulator --find clang++)" \ + CXXFLAGS="-arch arm64 -isysroot $(xcrun --sdk iphonesimulator --show-sdk-path)" \ + LDFLAGS="-arch arm64 -isysroot $(xcrun --sdk iphonesimulator --show-sdk-path)" && \ + make clean && make -j$(sysctl -n hw.ncpu) && make install + +build_plist_x86_64_sim: + rm -rf {{x86_64_sim_out}} build/build-sim + mkdir -p {{x86_64_sim_out}} + mkdir -p build/build-sim && cd build/build-sim && \ + ../../ffi/libplist/autogen.sh \ + --host=x86_64-apple-darwin \ + --prefix="$(pwd)/../../{{x86_64_sim_out}}" \ + --without-cython \ + --without-tools \ + CC="$(xcrun --sdk iphonesimulator --find clang)" \ + CFLAGS="-arch x86_64 -isysroot $(xcrun --sdk iphonesimulator --show-sdk-path)" \ + CXX="$(xcrun --sdk iphonesimulator --find clang++)" \ + CXXFLAGS="-arch x86_64 -isysroot $(xcrun --sdk iphonesimulator --show-sdk-path)" \ + LDFLAGS="-arch x86_64 -isysroot $(xcrun --sdk iphonesimulator --show-sdk-path)" && \ + make clean && make -j$(sysctl -n hw.ncpu) && make install + +build_plist_mac: + rm -rf {{mac_out}} build/build-mac + mkdir -p {{mac_out}} + mkdir -p build/build-mac && cd build/build-mac && \ + ../../ffi/libplist/autogen.sh \ + --host=aarch64-apple-darwin \ + --prefix="$(pwd)/../../{{mac_out}}" \ + --without-cython \ + --without-tools \ + CC="$(xcrun --sdk macosx --find clang)" \ + CFLAGS="-arch arm64 -isysroot $(xcrun --sdk macosx --show-sdk-path)" \ + CXX="$(xcrun --sdk macosx --find clang++)" \ + CXXFLAGS="-arch arm64 -isysroot $(xcrun --sdk macosx --show-sdk-path)" \ + LDFLAGS="-arch arm64 -isysroot $(xcrun --sdk macosx --show-sdk-path)" && \ + make clean && make -j$(sysctl -n hw.ncpu) && make install + +build_plist_x86_64_mac: + rm -rf {{x86_64_mac_out}} build/build-mac + mkdir -p {{x86_64_mac_out}} + mkdir -p build/build-mac && cd build/build-mac && \ + ../../ffi/libplist/autogen.sh \ + --host=x86_64-apple-darwin \ + --prefix="$(pwd)/../../{{x86_64_mac_out}}" \ + --without-cython \ + --without-tools \ + CC="$(xcrun --sdk macosx --find clang)" \ + CFLAGS="-arch x86_64 -isysroot $(xcrun --sdk macosx --show-sdk-path)" \ + CXX="$(xcrun --sdk macosx --find clang++)" \ + CXXFLAGS="-arch x86_64 -isysroot $(xcrun --sdk macosx --show-sdk-path)" \ + LDFLAGS="-arch x86_64 -isysroot $(xcrun --sdk macosx --show-sdk-path)" && \ + make clean && make -j$(sysctl -n hw.ncpu) && make install diff --git a/swift/Package.swift b/swift/Package.swift index ae8accd..e2623b1 100644 --- a/swift/Package.swift +++ b/swift/Package.swift @@ -14,11 +14,19 @@ let package = Package( name: "IDevice", targets: ["IDevice"] ), + .library( + name: "plist", + targets: ["plist"], + ), ], targets: [ .binaryTarget( name: "IDevice", path: "IDevice.xcframework" ), + .binaryTarget( + name: "plist", + path: "plist.xcframework" + ), ] )