diff --git a/README.md b/README.md index efaed10..edec132 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,25 @@ Alternatively, you can install it via the .NET CLI: dotnet add package LightningDB ``` +### iOS + +The package ships iOS binaries in two forms (minimum iOS 12.0; the arm64 +simulator slice requires iOS 14.0): + +- **.NET for iOS / MAUI**: works automatically. The dylibs under + `runtimes/ios-arm64` and `runtimes/iossimulator-*` carry an + `@rpath/lmdb.dylib` install name and an ad-hoc signature; the .NET iOS SDK + embeds them in the app bundle and re-signs them with your app identity at + build time. +- **Unity (and other Xcode-based pipelines)**: use the bundled + `ios/lmdb.xcframework`. A nupkg is a zip archive, so extract + `ios/lmdb.xcframework` from it and copy it into `Assets/Plugins/iOS` + (Unity 2021.3+ imports xcframework plugins directly). In the plugin + importer, enable the iOS platform and "Add to Embedded Binaries" so Xcode + embeds and re-signs the framework during the app build — required for + release/App Store builds. On older Unity versions, use the device slice + (`ios-arm64/lmdb.framework`) on its own instead. + ## Basic Usage Here's a simple example demonstrating how to create an environment, open a database, and perform basic put and get operations: diff --git a/lmdb/compile-lmdb-macos.sh b/lmdb/compile-lmdb-macos.sh index dc69eb4..201d310 100755 --- a/lmdb/compile-lmdb-macos.sh +++ b/lmdb/compile-lmdb-macos.sh @@ -16,9 +16,9 @@ git apply ../../../mingw-win32-fixes.patch declare -A build_outputs declare -A supported_targets=( - [ios-arm64/native/liblmdb.dylib]="make CC='xcrun --sdk iphoneos --toolchain iphoneos clang -arch arm64' LDFLAGS='-s' XCFLAGS='-DNDEBUG' VERSION_OPT='-Wl,-current_version,1.0'" - [iossimulator-arm64/native/liblmdb.dylib]="make CC='xcrun --sdk iphonesimulator --toolchain iphoneos clang -arch arm64' LDFLAGS='-s' XCFLAGS='-DNDEBUG' VERSION_OPT='-Wl,-current_version,1.0'" - [iossimulator-x64/native/liblmdb.dylib]="make CC='xcrun --sdk iphonesimulator --toolchain iphoneos clang -arch x86_64' LDFLAGS='-s' XCFLAGS='-DNDEBUG' VERSION_OPT='-Wl,-current_version,1.0'" + [ios-arm64/native/lmdb.dylib]="make CC='xcrun --sdk iphoneos clang -arch arm64 -miphoneos-version-min=12.0' LDFLAGS='-s' XCFLAGS='-DNDEBUG' VERSION_OPT='-Wl,-current_version,1.0'" + [iossimulator-arm64/native/lmdb.dylib]="make CC='xcrun --sdk iphonesimulator clang -arch arm64 -mios-simulator-version-min=12.0' LDFLAGS='-s' XCFLAGS='-DNDEBUG' VERSION_OPT='-Wl,-current_version,1.0'" + [iossimulator-x64/native/lmdb.dylib]="make CC='xcrun --sdk iphonesimulator clang -arch x86_64 -mios-simulator-version-min=12.0' LDFLAGS='-s' XCFLAGS='-DNDEBUG' VERSION_OPT='-Wl,-current_version,1.0'" [osx-arm64/native/lmdb.dylib]="make LDFLAGS='-s' XCFLAGS='-DNDEBUG' VERSION_OPT='-Wl,-current_version,1.0'" [osx/native/lmdb.dylib]="make CC='clang -mmacosx-version-min=10.15 -arch x86_64' LDFLAGS='-s' XCFLAGS='-DNDEBUG' VERSION_OPT='-Wl,-current_version,1.0'" [linux-arm/native/liblmdb.so]="docker run --mount type=bind,source=$(pwd),target=/lmdb --rm --platform=linux/arm/7 -w /lmdb gcc:latest make LDFLAGS='-s' XCFLAGS='-DNDEBUG'" @@ -51,6 +51,110 @@ function compile_lib() { #seems to be a stateful race condition on the docker run processes so this allows everything to succeed } +RUNTIMES_DIR=../../../../src/LightningDB/runtimes +IOS_DIR=../../../../src/LightningDB/ios + +function write_framework_plist() { + # $1 = framework dir, $2 = supported platform (iPhoneOS | iPhoneSimulator) + cat > "$1/Info.plist" < + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + lmdb + CFBundleIdentifier + io.github.coreykaylor.lmdb + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + lmdb + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0.0 + CFBundleVersion + 1.0.0 + CFBundleSupportedPlatforms + + $2 + + MinimumOSVersion + 12.0 + + +PLIST +} + +# iOS requires @rpath install names and code signatures; bare dylibs with the +# Makefile's default liblmdb.so install name load in dev but fail release builds. +function package_apple_artifacts() { + for rid in ios-arm64 iossimulator-arm64 iossimulator-x64; do + install_name_tool -id @rpath/lmdb.dylib "$RUNTIMES_DIR/$rid/native/lmdb.dylib" + codesign --force --sign - "$RUNTIMES_DIR/$rid/native/lmdb.dylib" + done + + local scratch + scratch=$(mktemp -d) + mkdir -p "$scratch/device/lmdb.framework" "$scratch/simulator/lmdb.framework" + cp "$RUNTIMES_DIR/ios-arm64/native/lmdb.dylib" "$scratch/device/lmdb.framework/lmdb" + lipo -create \ + "$RUNTIMES_DIR/iossimulator-arm64/native/lmdb.dylib" \ + "$RUNTIMES_DIR/iossimulator-x64/native/lmdb.dylib" \ + -output "$scratch/simulator/lmdb.framework/lmdb" + write_framework_plist "$scratch/device/lmdb.framework" iPhoneOS + write_framework_plist "$scratch/simulator/lmdb.framework" iPhoneSimulator + for fw in "$scratch/device/lmdb.framework" "$scratch/simulator/lmdb.framework"; do + install_name_tool -id @rpath/lmdb.framework/lmdb "$fw/lmdb" + codesign --force --sign - "$fw" + done + + rm -rf "$IOS_DIR/lmdb.xcframework" + mkdir -p "$IOS_DIR" + xcodebuild -create-xcframework \ + -framework "$scratch/device/lmdb.framework" \ + -framework "$scratch/simulator/lmdb.framework" \ + -output "$IOS_DIR/lmdb.xcframework" + rm -rf "$scratch" +} + +function verify_apple_artifacts() { + local failed=0 + local binaries=( + "$RUNTIMES_DIR/ios-arm64/native/lmdb.dylib" + "$RUNTIMES_DIR/iossimulator-arm64/native/lmdb.dylib" + "$RUNTIMES_DIR/iossimulator-x64/native/lmdb.dylib" + "$IOS_DIR"/lmdb.xcframework/*/lmdb.framework/lmdb + ) + for bin in "${binaries[@]}"; do + if ! otool -D "$bin" | grep -q "@rpath/lmdb"; then + echo "FAIL: $bin install name is not @rpath-based: $(otool -D "$bin" | tail -1)" + failed=1 + fi + # arm64 simulator slices are floored at 14.0 by the toolchain (no arm64 + # simulators existed before iOS 14), so accept either minimum. + if ! otool -l "$bin" | grep -A4 LC_BUILD_VERSION | grep -Eq "minos (12|14)\.0"; then + echo "FAIL: $bin minos is not 12.0/14.0" + failed=1 + fi + if ! codesign -dv "$bin" 2>/dev/null; then + echo "FAIL: $bin is not code signed" + failed=1 + fi + done + if ! lipo -info "$IOS_DIR"/lmdb.xcframework/ios-*-simulator/lmdb.framework/lmdb | grep -q "x86_64 arm64"; then + echo "FAIL: simulator framework slice is not a fat x86_64+arm64 binary" + failed=1 + fi + if [ $failed -eq 0 ]; then + echo "All iOS artifacts verified (install names, minos, signatures, simulator archs)" + else + exit 1 + fi +} + for key in "${!supported_targets[@]}"; do compile_lib "${supported_targets[$key]}" $key done @@ -60,3 +164,6 @@ if [ ${#supported_targets[@]} -eq ${#build_outputs[@]} ]; then else echo "Not all supported targets have produced unique output" fi + +package_apple_artifacts +verify_apple_artifacts diff --git a/src/LightningDB/LightningDB.csproj b/src/LightningDB/LightningDB.csproj index 7c3ebaa..b3ef677 100644 --- a/src/LightningDB/LightningDB.csproj +++ b/src/LightningDB/LightningDB.csproj @@ -32,6 +32,7 @@ runtimes + diff --git a/src/LightningDB/ios/lmdb.xcframework/Info.plist b/src/LightningDB/ios/lmdb.xcframework/Info.plist new file mode 100644 index 0000000..8e7ed88 --- /dev/null +++ b/src/LightningDB/ios/lmdb.xcframework/Info.plist @@ -0,0 +1,44 @@ + + + + + AvailableLibraries + + + BinaryPath + lmdb.framework/lmdb + LibraryIdentifier + ios-arm64_x86_64-simulator + LibraryPath + lmdb.framework + SupportedArchitectures + + arm64 + x86_64 + + SupportedPlatform + ios + SupportedPlatformVariant + simulator + + + BinaryPath + lmdb.framework/lmdb + LibraryIdentifier + ios-arm64 + LibraryPath + lmdb.framework + SupportedArchitectures + + arm64 + + SupportedPlatform + ios + + + CFBundlePackageType + XFWK + XCFrameworkFormatVersion + 1.0 + + diff --git a/src/LightningDB/ios/lmdb.xcframework/ios-arm64/lmdb.framework/Info.plist b/src/LightningDB/ios/lmdb.xcframework/ios-arm64/lmdb.framework/Info.plist new file mode 100644 index 0000000..266cfd7 --- /dev/null +++ b/src/LightningDB/ios/lmdb.xcframework/ios-arm64/lmdb.framework/Info.plist @@ -0,0 +1,28 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + lmdb + CFBundleIdentifier + io.github.coreykaylor.lmdb + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + lmdb + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0.0 + CFBundleVersion + 1.0.0 + CFBundleSupportedPlatforms + + iPhoneOS + + MinimumOSVersion + 12.0 + + diff --git a/src/LightningDB/ios/lmdb.xcframework/ios-arm64/lmdb.framework/_CodeSignature/CodeResources b/src/LightningDB/ios/lmdb.xcframework/ios-arm64/lmdb.framework/_CodeSignature/CodeResources new file mode 100644 index 0000000..df0a55c --- /dev/null +++ b/src/LightningDB/ios/lmdb.xcframework/ios-arm64/lmdb.framework/_CodeSignature/CodeResources @@ -0,0 +1,101 @@ + + + + + files + + Info.plist + + aeShFzK6fTG2/+0zy/ZOSx9k9DY= + + + files2 + + rules + + ^.* + + ^.*\.lproj/ + + optional + + weight + 1000 + + ^.*\.lproj/locversion.plist$ + + omit + + weight + 1100 + + ^Base\.lproj/ + + weight + 1010 + + ^version.plist$ + + + rules2 + + .*\.dSYM($|/) + + weight + 11 + + ^(.*/)?\.DS_Store$ + + omit + + weight + 2000 + + ^.* + + ^.*\.lproj/ + + optional + + weight + 1000 + + ^.*\.lproj/locversion.plist$ + + omit + + weight + 1100 + + ^Base\.lproj/ + + weight + 1010 + + ^Info\.plist$ + + omit + + weight + 20 + + ^PkgInfo$ + + omit + + weight + 20 + + ^embedded\.provisionprofile$ + + weight + 20 + + ^version\.plist$ + + weight + 20 + + + + diff --git a/src/LightningDB/ios/lmdb.xcframework/ios-arm64/lmdb.framework/lmdb b/src/LightningDB/ios/lmdb.xcframework/ios-arm64/lmdb.framework/lmdb new file mode 100755 index 0000000..43dc07d Binary files /dev/null and b/src/LightningDB/ios/lmdb.xcframework/ios-arm64/lmdb.framework/lmdb differ diff --git a/src/LightningDB/ios/lmdb.xcframework/ios-arm64_x86_64-simulator/lmdb.framework/Info.plist b/src/LightningDB/ios/lmdb.xcframework/ios-arm64_x86_64-simulator/lmdb.framework/Info.plist new file mode 100644 index 0000000..80201e4 --- /dev/null +++ b/src/LightningDB/ios/lmdb.xcframework/ios-arm64_x86_64-simulator/lmdb.framework/Info.plist @@ -0,0 +1,28 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + lmdb + CFBundleIdentifier + io.github.coreykaylor.lmdb + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + lmdb + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0.0 + CFBundleVersion + 1.0.0 + CFBundleSupportedPlatforms + + iPhoneSimulator + + MinimumOSVersion + 12.0 + + diff --git a/src/LightningDB/ios/lmdb.xcframework/ios-arm64_x86_64-simulator/lmdb.framework/_CodeSignature/CodeResources b/src/LightningDB/ios/lmdb.xcframework/ios-arm64_x86_64-simulator/lmdb.framework/_CodeSignature/CodeResources new file mode 100644 index 0000000..2021f26 --- /dev/null +++ b/src/LightningDB/ios/lmdb.xcframework/ios-arm64_x86_64-simulator/lmdb.framework/_CodeSignature/CodeResources @@ -0,0 +1,101 @@ + + + + + files + + Info.plist + + Zfl1UgFfGCIyOtY8Hsj2erYyd90= + + + files2 + + rules + + ^.* + + ^.*\.lproj/ + + optional + + weight + 1000 + + ^.*\.lproj/locversion.plist$ + + omit + + weight + 1100 + + ^Base\.lproj/ + + weight + 1010 + + ^version.plist$ + + + rules2 + + .*\.dSYM($|/) + + weight + 11 + + ^(.*/)?\.DS_Store$ + + omit + + weight + 2000 + + ^.* + + ^.*\.lproj/ + + optional + + weight + 1000 + + ^.*\.lproj/locversion.plist$ + + omit + + weight + 1100 + + ^Base\.lproj/ + + weight + 1010 + + ^Info\.plist$ + + omit + + weight + 20 + + ^PkgInfo$ + + omit + + weight + 20 + + ^embedded\.provisionprofile$ + + weight + 20 + + ^version\.plist$ + + weight + 20 + + + + diff --git a/src/LightningDB/ios/lmdb.xcframework/ios-arm64_x86_64-simulator/lmdb.framework/lmdb b/src/LightningDB/ios/lmdb.xcframework/ios-arm64_x86_64-simulator/lmdb.framework/lmdb new file mode 100755 index 0000000..19cc284 Binary files /dev/null and b/src/LightningDB/ios/lmdb.xcframework/ios-arm64_x86_64-simulator/lmdb.framework/lmdb differ diff --git a/src/LightningDB/runtimes/ios-arm64/native/liblmdb.dylib b/src/LightningDB/runtimes/ios-arm64/native/lmdb.dylib similarity index 79% rename from src/LightningDB/runtimes/ios-arm64/native/liblmdb.dylib rename to src/LightningDB/runtimes/ios-arm64/native/lmdb.dylib index 3651177..8b8b2a3 100755 Binary files a/src/LightningDB/runtimes/ios-arm64/native/liblmdb.dylib and b/src/LightningDB/runtimes/ios-arm64/native/lmdb.dylib differ diff --git a/src/LightningDB/runtimes/iossimulator-arm64/native/liblmdb.dylib b/src/LightningDB/runtimes/iossimulator-arm64/native/lmdb.dylib similarity index 65% rename from src/LightningDB/runtimes/iossimulator-arm64/native/liblmdb.dylib rename to src/LightningDB/runtimes/iossimulator-arm64/native/lmdb.dylib index 7694a1c..665e150 100755 Binary files a/src/LightningDB/runtimes/iossimulator-arm64/native/liblmdb.dylib and b/src/LightningDB/runtimes/iossimulator-arm64/native/lmdb.dylib differ diff --git a/src/LightningDB/runtimes/iossimulator-x64/native/liblmdb.dylib b/src/LightningDB/runtimes/iossimulator-x64/native/lmdb.dylib similarity index 57% rename from src/LightningDB/runtimes/iossimulator-x64/native/liblmdb.dylib rename to src/LightningDB/runtimes/iossimulator-x64/native/lmdb.dylib index 04045fb..e117367 100755 Binary files a/src/LightningDB/runtimes/iossimulator-x64/native/liblmdb.dylib and b/src/LightningDB/runtimes/iossimulator-x64/native/lmdb.dylib differ