diff --git a/.gitignore b/.gitignore index c131cf1..87669ee 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ build/ .idea/ .vscode/settings.json -publish.cmd +ios/cxx diff --git a/README.md b/README.md index b238633..a71c44f 100644 --- a/README.md +++ b/README.md @@ -142,25 +142,3 @@ try { Method `close` can destroy quickjs runtime that can be recreated again if you call `evaluate`. [This example](example/lib/main.dart) contains a complete demonstration on how to use this plugin. - -## For macOS & iOS developer - -I am new to Xcode and iOS developing, and I cannot find a better way to support both simulators and real devices without combining the binary frameworks. To reduce build size, change the `s.vendored_frameworks` in `ios/flutter_qjs.podspec` to the specific framework. - -For simulator, use: - -```podspec -s.vendored_frameworks = `build/Debug-iphonesimulator/ffiquickjs.framework` -``` - -For real device, use: - -```podspec -s.vendored_frameworks = `build/Debug-iphoneos/ffiquickjs.framework` -``` - -Two additional notes: - -1. quickjs built with `release` config has bug in resolving `Promise`. Please let me know if you know the solution. - -2. `ios/make.sh` limits the build architectures to avoid combining conflicts. Change the `make.sh` to support another architectures. \ No newline at end of file diff --git a/example/android/app/src/main/res/drawable-v21/launch_background.xml b/example/android/app/src/main/res/drawable-v21/launch_background.xml new file mode 100755 index 0000000..f74085f --- /dev/null +++ b/example/android/app/src/main/res/drawable-v21/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index bea7f86..47f8d32 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -14,9 +14,9 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/flutter_qjs/ios" SPEC CHECKSUMS: - Flutter: 0e3d915762c693b495b44d77113d4970485de6ec - flutter_qjs: 351b608d97711c8939aaba405af874e593ec2cb0 + Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c + flutter_qjs: 9bb46bb262be81b7c50e4a1a117d5a602d69691f PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c -COCOAPODS: 1.9.3 +COCOAPODS: 1.10.1 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index f775688..8051566 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -253,17 +253,12 @@ 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/ffiquickjs.framework", - "${BUILT_PRODUCTS_DIR}/flutter_qjs/flutter_qjs.framework", + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ffiquickjs.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/flutter_qjs.framework", + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; diff --git a/ios/.gitignore b/ios/.gitignore old mode 100644 new mode 100755 diff --git a/ios/Assets/.gitkeep b/ios/Assets/.gitkeep old mode 100644 new mode 100755 diff --git a/ios/CMakeLists.txt b/ios/CMakeLists.txt deleted file mode 100644 index 29826b1..0000000 --- a/ios/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -cmake_minimum_required(VERSION 3.7 FATAL_ERROR) -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) - -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 - MACOSX_FRAMEWORK_BUNDLE_VERSION 100 - MACOSX_FRAMEWORK_SHORT_VERSION_STRING 100 - XCODE_ATTRIBUTE_DYLIB_INSTALL_NAME_BASE "@rpath" - PUBLIC_HEADER ffi.h - XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Apple Development" - # RESOURCE "${RESOURCE_FILES}" -) diff --git a/ios/flutter_qjs.podspec b/ios/flutter_qjs.podspec index 6b285e3..6234ea1 100644 --- a/ios/flutter_qjs.podspec +++ b/ios/flutter_qjs.podspec @@ -13,14 +13,14 @@ This plugin is a simple js engine for flutter using the `quickjs` project. Plugi s.license = { :file => '../LICENSE' } s.author = { 'ekibun' => 'soekibun@gmail.com' } s.source = { :path => '.' } - s.source_files = 'Classes/**/*' + s.compiler_flags = '-DDUMP_LEAKS' + s.source_files = ['Classes/**/*', 'cxx/*'] + s.public_header_files = 'Classes/**/*.h' s.dependency 'Flutter' s.platform = :ios, '8.0' # Flutter.framework does not contain a i386 slice. s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' } - s.vendored_frameworks = 'build/ffiquickjs.framework' - s.static_framework = false - s.prepare_command = 'sh make.sh' + s.prepare_command = 'sh pre.sh' s.swift_version = '5.0' end diff --git a/ios/make.sh b/ios/make.sh deleted file mode 100644 index 5c0a680..0000000 --- a/ios/make.sh +++ /dev/null @@ -1,22 +0,0 @@ -### - # @Description: - # @Author: ekibun - # @Date: 2020-09-24 00:50:13 - # @LastEditors: ekibun - # @LastEditTime: 2020-09-24 00:51:43 -### -mkdir build -cd build - -cmake .. -G Xcode \ - -DCMAKE_SYSTEM_NAME=iOS \ - -DCMAKE_IOS_INSTALL_COMBINED=true \ - -DCMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH=NO -cmake --build . --config Debug -- -arch arm64 -cmake --build . --config Debug -- -sdk iphonesimulator -arch x86_64 - -mkdir ffiquickjs.framework -lipo -create 'Debug-iphoneos/ffiquickjs.framework/ffiquickjs' 'Debug-iphonesimulator/ffiquickjs.framework/ffiquickjs' -output 'ffiquickjs.framework/ffiquickjs' -cp -f 'Debug-iphoneos/ffiquickjs.framework/Info.plist' 'ffiquickjs.framework/Info.plist' - -cd .. \ No newline at end of file diff --git a/ios/pre.sh b/ios/pre.sh new file mode 100644 index 0000000..f98b5c0 --- /dev/null +++ b/ios/pre.sh @@ -0,0 +1,33 @@ +if [ -d "./cxx/" ];then + rm -r ./cxx +fi + +mkdir ./cxx + +sed 's/\#include \"quickjs\/quickjs.h\"/\#include \"quickjs.h\"/g' ../cxx/ffi.h > ./cxx/ffi.h +cp ../cxx/ffi.cpp ./cxx/ffi.cpp + +quickjs_version=$(cat ../cxx/quickjs/VERSION) + +sed '1i\ +\#define CONFIG_VERSION \"'$quickjs_version'\"\ +' ../cxx/quickjs/quickjs.c > ./cxx/quickjs.c + +quickjs_src=( + "list.h" + "cutils.c" + "libregexp.c" + "libunicode.c" + "cutils.h" + "libregexp.h" + "libunicode.h" + "quickjs.h" + "quickjs-atom.h" + "quickjs-opcode.h" + "libregexp-opcode.h" + "libunicode-table.h" +) +for item in ${quickjs_src[*]} +do + cp ../cxx/quickjs/$item ./cxx/$item +done \ No newline at end of file diff --git a/lib/ffi.dart b/lib/ffi.dart index c0db83d..dc4ef80 100644 --- a/lib/ffi.dart +++ b/lib/ffi.dart @@ -59,8 +59,6 @@ final DynamicLibrary qjsLib = Platform.environment['FLUTTER_TEST'] == 'true' ? DynamicLibrary.open("flutter_qjs_plugin.dll") : Platform.isAndroid ? DynamicLibrary.open("libqjs.so") - : Platform.isIOS - ? DynamicLibrary.open("ffiquickjs.framework/ffiquickjs") : DynamicLibrary.process()); /// JSValue *jsThrowInternalError(JSContext *ctx, char *message)