From 7a48fac5701f7676282767905935f3f9394fb9fb Mon Sep 17 00:00:00 2001 From: ekibun Date: Fri, 25 Sep 2020 01:12:46 -0700 Subject: [PATCH] ffi for ios (simulator) --- example/ios/Podfile.lock | 22 ++++++ example/ios/Runner.xcodeproj/project.pbxproj | 75 +++++++++++++++++++ .../contents.xcworkspacedata | 3 + ios/CMakeLists.txt | 19 ++++- ios/flutter_qjs.podspec | 4 +- ios/make.sh | 2 + lib/ffi.dart | 4 +- pubspec.yaml | 2 + 8 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 example/ios/Podfile.lock diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock new file mode 100644 index 0000000..440753f --- /dev/null +++ b/example/ios/Podfile.lock @@ -0,0 +1,22 @@ +PODS: + - Flutter (1.0.0) + - flutter_qjs (0.0.1): + - Flutter + +DEPENDENCIES: + - Flutter (from `Flutter`) + - flutter_qjs (from `.symlinks/plugins/flutter_qjs/ios`) + +EXTERNAL SOURCES: + Flutter: + :path: Flutter + flutter_qjs: + :path: ".symlinks/plugins/flutter_qjs/ios" + +SPEC CHECKSUMS: + Flutter: 0e3d915762c693b495b44d77113d4970485de6ec + flutter_qjs: b6da2d828ae64b2cc921a4521814bc91ff65e19d + +PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c + +COCOAPODS: 1.9.3 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index e09ea8b..c79b304 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 455CDD0A38C60135FAE4BE1E /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FEEA6A3F04CF4DEF054D0962 /* Pods_Runner.framework */; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; @@ -31,6 +32,7 @@ /* Begin PBXFileReference section */ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; + 177559F5E68C1612914EEE0E /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -42,6 +44,9 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + D8D4D9C385E355627AD72FDC /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; + ED4A476CBE8036EFA898796A /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; + FEEA6A3F04CF4DEF054D0962 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -49,12 +54,24 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 455CDD0A38C60135FAE4BE1E /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 96E397AA563FBD7DD2827B3F /* Pods */ = { + isa = PBXGroup; + children = ( + ED4A476CBE8036EFA898796A /* Pods-Runner.debug.xcconfig */, + 177559F5E68C1612914EEE0E /* Pods-Runner.release.xcconfig */, + D8D4D9C385E355627AD72FDC /* Pods-Runner.profile.xcconfig */, + ); + name = Pods; + path = Pods; + sourceTree = ""; + }; 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( @@ -72,6 +89,8 @@ 9740EEB11CF90186004384FC /* Flutter */, 97C146F01CF9000F007C117D /* Runner */, 97C146EF1CF9000F007C117D /* Products */, + 96E397AA563FBD7DD2827B3F /* Pods */, + C1B25DCE3059ACFD6A761EB2 /* Frameworks */, ); sourceTree = ""; }; @@ -98,6 +117,14 @@ path = Runner; sourceTree = ""; }; + C1B25DCE3059ACFD6A761EB2 /* Frameworks */ = { + isa = PBXGroup; + children = ( + FEEA6A3F04CF4DEF054D0962 /* Pods_Runner.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -105,12 +132,14 @@ isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( + 9ED59B3EDDF0CCD362B298B6 /* [CP] Check Pods Manifest.lock */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + D88E1FA61D2123552360E924 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -197,6 +226,52 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; }; + 9ED59B3EDDF0CCD362B298B6 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + D88E1FA61D2123552360E924 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", + "${PODS_ROOT}/../Flutter/Flutter.framework", + "${PODS_ROOT}/../.symlinks/plugins/flutter_qjs/ios/build/Debug-iphonesimulator/ffiquickjs.framework", + "${PODS_ROOT}/../.symlinks/plugins/flutter_qjs/ios/build/Debug-iphonesimulator/ffiquickjs.framework.dSYM", + "${BUILT_PRODUCTS_DIR}/flutter_qjs/flutter_qjs.framework", + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ffiquickjs.framework", + "${DWARF_DSYM_FOLDER_PATH}/ffiquickjs.framework.dSYM", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_qjs.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/example/ios/Runner.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcworkspace/contents.xcworkspacedata index 1d526a1..21a3cc1 100644 --- a/example/ios/Runner.xcworkspace/contents.xcworkspacedata +++ b/example/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -4,4 +4,7 @@ + + diff --git a/ios/CMakeLists.txt b/ios/CMakeLists.txt index 7f04fc7..8608ef0 100644 --- a/ios/CMakeLists.txt +++ b/ios/CMakeLists.txt @@ -4,4 +4,21 @@ project(ffiquickjs LANGUAGES CXX) include("${CMAKE_CURRENT_SOURCE_DIR}/../cxx/quickjs.cmake") add_library(ffiquickjs SHARED ${CXX_LIB_DIR}/ffi.cpp) -target_link_libraries(ffiquickjs PRIVATE quickjs) \ No newline at end of file +target_link_libraries(ffiquickjs PRIVATE quickjs) + +# IOSTODO change to your team id +set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "6SA4A2R2GU" CACHE INTERNAL "") + +set_target_properties(ffiquickjs PROPERTIES + FRAMEWORK TRUE + FRAMEWORK_VERSION A + MACOSX_FRAMEWORK_IDENTIFIER soko.ekibun.ffiquickjs +# MACOSX_FRAMEWORK_INFO_PLIST Info.plist +# "current version" in semantic format in Mach-O binary file + VERSION 1.0.0 +# "compatibility version" in semantic format in Mach-O binary file + SOVERSION 1.0.0 + PUBLIC_HEADER ffi.h + XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Apple Development" + # RESOURCE "${RESOURCE_FILES}" +) \ No newline at end of file diff --git a/ios/flutter_qjs.podspec b/ios/flutter_qjs.podspec index 52de5de..f3278c6 100644 --- a/ios/flutter_qjs.podspec +++ b/ios/flutter_qjs.podspec @@ -19,6 +19,8 @@ A new flutter plugin project. # Flutter.framework does not contain a i386 slice. s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } - s.vendored_libraries = 'build/Debug/libffiquickjs.dylib' + # IOSTODO for simulators use Debug-iphonesimulator, for real devices use Debug-iphoneos + s.vendored_frameworks = 'build/Debug-iphoneos/ffiquickjs.framework' + s.static_framework = false s.swift_version = '5.0' end diff --git a/ios/make.sh b/ios/make.sh index 3408d58..7169319 100644 --- a/ios/make.sh +++ b/ios/make.sh @@ -7,5 +7,7 @@ ### mkdir build cd build + +# IOSTODO -DPLATFORM: for simulators use SIMULATOR64, for real devices use OS64COMBINED cmake .. -G Xcode -DCMAKE_TOOLCHAIN_FILE=../ios.toolchain.cmake -DPLATFORM=OS64COMBINED cmake --build . --config Debug diff --git a/lib/ffi.dart b/lib/ffi.dart index 6e61473..e11e0bf 100644 --- a/lib/ffi.dart +++ b/lib/ffi.dart @@ -59,7 +59,9 @@ final DynamicLibrary qjsLib = Platform.environment['FLUTTER_TEST'] == 'true' ? DynamicLibrary.open("flutter_qjs_plugin.dll") : Platform.isAndroid ? DynamicLibrary.open("libqjs.so") - : DynamicLibrary.process()); + : Platform.isIOS + ? DynamicLibrary.open("ffiquickjs.framework/ffiquickjs") + : DynamicLibrary.process()); /// JSValue *jsThrowInternalError(JSContext *ctx, char *message) final Pointer Function( diff --git a/pubspec.yaml b/pubspec.yaml index 668c5e8..eff5cfe 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -41,6 +41,8 @@ flutter: package: soko.ekibun.flutter_qjs macos: pluginClass: FlutterQjsPlugin + ios: + pluginClass: FlutterQjsPlugin # ------------------- # To add assets to your plugin package, add an assets section, like this: