From 71bb456140a84441801c302c2c1dd0364edaa3aa Mon Sep 17 00:00:00 2001 From: ekibun Date: Wed, 23 Sep 2020 22:32:11 -0700 Subject: [PATCH] (WIP) macos ffi --- android/.classpath | 12 +- android/.idea/.gitignore | 6 +- android/.idea/compiler.xml | 10 +- android/.idea/gradle.xml | 32 ++--- android/.idea/jarRepositories.xml | 58 ++++----- android/.idea/vcs.xml | 10 +- android/.project | 46 +++---- cxx/ffi.cpp | 31 ++--- cxx/ffi.h | 112 ++++++++++++++++++ example/ios/Flutter/Debug.xcconfig | 1 + example/ios/Flutter/Release.xcconfig | 1 + example/ios/Podfile | 41 +++++++ .../Flutter/GeneratedPluginRegistrant.swift | 2 + example/macos/Podfile.lock | 22 ++++ .../macos/Runner.xcodeproj/project.pbxproj | 60 +++++++++- .../contents.xcworkspacedata | 3 + lib/ffi.dart | 4 +- macos/CMakeLists.txt | 12 +- macos/flutter_qjs.podspec | 2 +- macos/make.sh | 2 +- 20 files changed, 351 insertions(+), 116 deletions(-) create mode 100644 cxx/ffi.h create mode 100644 example/ios/Podfile create mode 100644 example/macos/Podfile.lock diff --git a/android/.classpath b/android/.classpath index 4a04201..2c15594 100644 --- a/android/.classpath +++ b/android/.classpath @@ -1,6 +1,6 @@ - - - - - - + + + + + + diff --git a/android/.idea/.gitignore b/android/.idea/.gitignore index 26d3352..eaf91e2 100644 --- a/android/.idea/.gitignore +++ b/android/.idea/.gitignore @@ -1,3 +1,3 @@ -# Default ignored files -/shelf/ -/workspace.xml +# Default ignored files +/shelf/ +/workspace.xml diff --git a/android/.idea/compiler.xml b/android/.idea/compiler.xml index fb7f4a8..7d7ec2e 100644 --- a/android/.idea/compiler.xml +++ b/android/.idea/compiler.xml @@ -1,6 +1,6 @@ - - - - - + + + + + \ No newline at end of file diff --git a/android/.idea/gradle.xml b/android/.idea/gradle.xml index 611e7c8..ef13c2a 100644 --- a/android/.idea/gradle.xml +++ b/android/.idea/gradle.xml @@ -1,17 +1,17 @@ - - - - - - + + + + + + \ No newline at end of file diff --git a/android/.idea/jarRepositories.xml b/android/.idea/jarRepositories.xml index 2370474..f1b63f4 100644 --- a/android/.idea/jarRepositories.xml +++ b/android/.idea/jarRepositories.xml @@ -1,30 +1,30 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/.idea/vcs.xml b/android/.idea/vcs.xml index 6c0b863..2e3f692 100644 --- a/android/.idea/vcs.xml +++ b/android/.idea/vcs.xml @@ -1,6 +1,6 @@ - - - - - + + + + + \ No newline at end of file diff --git a/android/.project b/android/.project index fffdd44..2f31f74 100644 --- a/android/.project +++ b/android/.project @@ -1,23 +1,23 @@ - - - flutter_qjs - Project android created by Buildship. - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.buildship.core.gradleprojectbuilder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.buildship.core.gradleprojectnature - - + + + flutter_qjs + Project android created by Buildship. + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.buildship.core.gradleprojectnature + + diff --git a/cxx/ffi.cpp b/cxx/ffi.cpp index f2d9f3c..bc84494 100644 --- a/cxx/ffi.cpp +++ b/cxx/ffi.cpp @@ -5,20 +5,13 @@ * @LastEditors: ekibun * @LastEditTime: 2020-09-24 00:28:11 */ -#include "quickjs/quickjs.h" +#include "ffi.h" #include #include #include -#ifdef _MSC_VER -#define DLLEXPORT __declspec(dllexport) -#else -#define DLLEXPORT __attribute__((visibility("default"))) __attribute__((used)) -#endif - extern "C" { - typedef void *JSChannel(JSContext *ctx, const char *method, void *argv); DLLEXPORT JSValue *jsThrowInternalError(JSContext *ctx, char *message) { @@ -58,7 +51,7 @@ extern "C" return m; } - JSValue js_channel(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) + JSValue js_channel(JSContext *ctx, JSValueConst this_val, int32_t argc, JSValueConst *argv) { JSRuntime *rt = JS_GetRuntime(ctx); JSChannel *channel = (JSChannel *)JS_GetRuntimeOpaque(rt); @@ -105,7 +98,7 @@ extern "C" return JS_GetRuntime(ctx); } - DLLEXPORT JSValue *jsEval(JSContext *ctx, const char *input, size_t input_len, const char *filename, int eval_flags) + DLLEXPORT JSValue *jsEval(JSContext *ctx, const char *input, size_t input_len, const char *filename, int32_t eval_flags) { return new JSValue(JS_Eval(ctx, input, input_len, filename, eval_flags)); } @@ -125,7 +118,7 @@ extern "C" return JS_TAG_IS_FLOAT64(tag); } - DLLEXPORT JSValue *jsNewBool(JSContext *ctx, int val) + DLLEXPORT JSValue *jsNewBool(JSContext *ctx, int32_t val) { return new JSValue(JS_NewBool(ctx, val)); } @@ -235,8 +228,8 @@ extern "C" return new JSValue(JS_GetProperty(ctx, *this_obj, prop)); } - DLLEXPORT int jsDefinePropertyValue(JSContext *ctx, JSValueConst *this_obj, - JSAtom prop, JSValue *val, int flags) + DLLEXPORT int32_t jsDefinePropertyValue(JSContext *ctx, JSValueConst *this_obj, + JSAtom prop, JSValue *val, int32_t flags) { return JS_DefinePropertyValue(ctx, *this_obj, prop, *val, flags); } @@ -256,13 +249,13 @@ extern "C" return new JSValue(JS_AtomToValue(ctx, val)); } - DLLEXPORT int jsGetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab, - uint32_t *plen, JSValueConst *obj, int flags) + DLLEXPORT int32_t jsGetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab, + uint32_t *plen, JSValueConst *obj, int32_t flags) { return JS_GetOwnPropertyNames(ctx, ptab, plen, *obj, flags); } - DLLEXPORT JSAtom jsPropertyEnumGetAtom(JSPropertyEnum *ptab, int i) + DLLEXPORT JSAtom jsPropertyEnumGetAtom(JSPropertyEnum *ptab, int32_t i) { return ptab[i].atom; } @@ -278,12 +271,12 @@ extern "C" } DLLEXPORT JSValue *jsCall(JSContext *ctx, JSValueConst *func_obj, JSValueConst *this_obj, - int argc, JSValueConst *argv) + int32_t argc, JSValueConst *argv) { return new JSValue(JS_Call(ctx, *func_obj, *this_obj, argc, argv)); } - DLLEXPORT int jsIsException(JSValueConst *val) + DLLEXPORT int32_t jsIsException(JSValueConst *val) { return JS_IsException(*val); } @@ -293,7 +286,7 @@ extern "C" return new JSValue(JS_GetException(ctx)); } - DLLEXPORT int jsExecutePendingJob(JSRuntime *rt) + DLLEXPORT int32_t jsExecutePendingJob(JSRuntime *rt) { JSContext *ctx; return JS_ExecutePendingJob(rt, &ctx); diff --git a/cxx/ffi.h b/cxx/ffi.h new file mode 100644 index 0000000..90d6ca6 --- /dev/null +++ b/cxx/ffi.h @@ -0,0 +1,112 @@ +#include "quickjs/quickjs.h" + +#ifdef _MSC_VER +#define DLLEXPORT __declspec(dllexport) +#else +#define DLLEXPORT __attribute__((visibility("default"))) __attribute__((used)) +#endif + +extern "C" +{ + +typedef void *JSChannel(JSContext *ctx, const char *method, void *argv); + +JSValue *jsThrowInternalError(JSContext *ctx, char *message); + +JSValue *jsEXCEPTION(); + +JSValue *jsUNDEFINED(); + +JSValue *jsNULL(); + +JSRuntime *jsNewRuntime(JSChannel channel); + +void jsFreeRuntime(JSRuntime *rt); + +JSContext *jsNewContext(JSRuntime *rt); + +void jsFreeContext(JSContext *ctx); + +JSRuntime *jsGetRuntime(JSContext *ctx); + +JSValue *jsEval(JSContext *ctx, const char *input, size_t input_len, const char *filename, int32_t eval_flags); + +int32_t jsValueGetTag(JSValue *val); + +void *jsValueGetPtr(JSValue *val); + +int32_t jsTagIsFloat64(int32_t tag); + +JSValue *jsNewBool(JSContext *ctx, int32_t val); + +JSValue *jsNewInt64(JSContext *ctx, int64_t val); + +JSValue *jsNewFloat64(JSContext *ctx, double val); + +JSValue *jsNewString(JSContext *ctx, const char *str); + +JSValue *jsNewArrayBufferCopy(JSContext *ctx, const uint8_t *buf, size_t len); + +JSValue *jsNewArray(JSContext *ctx); + +JSValue *jsNewObject(JSContext *ctx); + +void jsFreeValue(JSContext *ctx, JSValue *v); + +void jsFreeValueRT(JSRuntime *rt, JSValue *v); + +JSValue *jsDupValue(JSContext *ctx, JSValueConst *v); + +JSValue *jsDupValueRT(JSRuntime *rt, JSValue *v); + +int32_t jsToBool(JSContext *ctx, JSValueConst *val); + +int64_t jsToInt64(JSContext *ctx, JSValueConst *val); + +double jsToFloat64(JSContext *ctx, JSValueConst *val); + +const char *jsToCString(JSContext *ctx, JSValueConst *val); + +void jsFreeCString(JSContext *ctx, const char *ptr); + +uint8_t *jsGetArrayBuffer(JSContext *ctx, size_t *psize, JSValueConst *obj); + +int32_t jsIsFunction(JSContext *ctx, JSValueConst *val); + +int32_t jsIsArray(JSContext *ctx, JSValueConst *val); + +void deleteJSValue(JSValueConst *val); + +JSValue *jsGetProperty(JSContext *ctx, JSValueConst *this_obj, + JSAtom prop); + +int32_t jsDefinePropertyValue(JSContext *ctx, JSValueConst *this_obj, + JSAtom prop, JSValue *val, int32_t flags); + +void jsFreeAtom(JSContext *ctx, JSAtom v); + +JSAtom jsValueToAtom(JSContext *ctx, JSValueConst *val); + +JSValue *jsAtomToValue(JSContext *ctx, JSAtom val); + +int32_t jsGetOwnPropertyNames(JSContext *ctx, JSPropertyEnum **ptab, + uint32_t *plen, JSValueConst *obj, int32_t flags); + +JSAtom jsPropertyEnumGetAtom(JSPropertyEnum *ptab, int32_t i); + +uint32_t sizeOfJSValue(); + +void setJSValueList(JSValue *list, uint32_t i, JSValue *val); + +JSValue *jsCall(JSContext *ctx, JSValueConst *func_obj, JSValueConst *this_obj, + int32_t argc, JSValueConst *argv); + +int32_t jsIsException(JSValueConst *val); + +JSValue *jsGetException(JSContext *ctx); + +int32_t jsExecutePendingJob(JSRuntime *rt); + +JSValue *jsNewPromiseCapability(JSContext *ctx, JSValue *resolving_funcs); + +} \ No newline at end of file diff --git a/example/ios/Flutter/Debug.xcconfig b/example/ios/Flutter/Debug.xcconfig index 592ceee..e8efba1 100644 --- a/example/ios/Flutter/Debug.xcconfig +++ b/example/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/example/ios/Flutter/Release.xcconfig b/example/ios/Flutter/Release.xcconfig index 592ceee..399e934 100644 --- a/example/ios/Flutter/Release.xcconfig +++ b/example/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/example/ios/Podfile b/example/ios/Podfile new file mode 100644 index 0000000..1e8c3c9 --- /dev/null +++ b/example/ios/Podfile @@ -0,0 +1,41 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '9.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/example/macos/Flutter/GeneratedPluginRegistrant.swift b/example/macos/Flutter/GeneratedPluginRegistrant.swift index cccf817..d058a0d 100644 --- a/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,6 +5,8 @@ import FlutterMacOS import Foundation +import flutter_qjs func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + FlutterQjsPlugin.register(with: registry.registrar(forPlugin: "FlutterQjsPlugin")) } diff --git a/example/macos/Podfile.lock b/example/macos/Podfile.lock new file mode 100644 index 0000000..01307f3 --- /dev/null +++ b/example/macos/Podfile.lock @@ -0,0 +1,22 @@ +PODS: + - flutter_qjs (0.0.1): + - FlutterMacOS + - FlutterMacOS (1.0.0) + +DEPENDENCIES: + - flutter_qjs (from `Flutter/ephemeral/.symlinks/plugins/flutter_qjs/macos`) + - FlutterMacOS (from `Flutter/ephemeral/.symlinks/flutter/darwin-x64`) + +EXTERNAL SOURCES: + flutter_qjs: + :path: Flutter/ephemeral/.symlinks/plugins/flutter_qjs/macos + FlutterMacOS: + :path: Flutter/ephemeral/.symlinks/flutter/darwin-x64 + +SPEC CHECKSUMS: + flutter_qjs: df517bcb1e7a68d630e4fe9454db7ab15bfdf425 + FlutterMacOS: 15bea8a44d2fa024068daa0140371c020b4b6ff9 + +PODFILE CHECKSUM: d8ba9b3e9e93c62c74a660b46c6fcb09f03991a7 + +COCOAPODS: 1.9.3 diff --git a/example/macos/Runner.xcodeproj/project.pbxproj b/example/macos/Runner.xcodeproj/project.pbxproj index 432249b..8acead3 100644 --- a/example/macos/Runner.xcodeproj/project.pbxproj +++ b/example/macos/Runner.xcodeproj/project.pbxproj @@ -28,6 +28,7 @@ 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; }; 33D1A10422148B71006C7A3E /* FlutterMacOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 33D1A10322148B71006C7A3E /* FlutterMacOS.framework */; }; 33D1A10522148B93006C7A3E /* FlutterMacOS.framework in Bundle Framework */ = {isa = PBXBuildFile; fileRef = 33D1A10322148B71006C7A3E /* FlutterMacOS.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 8A0E1E523547DDE6AEEAA187 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E845184DF4416AE932BDD596 /* Pods_Runner.framework */; }; D73912F022F37F9E000D13A0 /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D73912EF22F37F9E000D13A0 /* App.framework */; }; D73912F222F3801D000D13A0 /* App.framework in Bundle Framework */ = {isa = PBXBuildFile; fileRef = D73912EF22F37F9E000D13A0 /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; /* End PBXBuildFile section */ @@ -60,7 +61,7 @@ /* Begin PBXFileReference section */ 333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = ""; }; 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = ""; }; - 33CC10ED2044A3C60003C045 /* flutter_qjs_example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "flutter_qjs_example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 33CC10ED2044A3C60003C045 /* flutter_qjs_example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = flutter_qjs_example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Runner/Assets.xcassets; sourceTree = ""; }; 33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; @@ -73,9 +74,13 @@ 33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = ""; }; 33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = ""; }; 33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = ""; }; + 64B57AD34D7E83EE511DDCCF /* 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 = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; + 7E8A42D81EE399E35D3B1C49 /* 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 = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; D73912EF22F37F9E000D13A0 /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/ephemeral/App.framework; sourceTree = SOURCE_ROOT; }; + E845184DF4416AE932BDD596 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + ED16B55A7814C4FA5051DC2C /* 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 = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -85,6 +90,7 @@ files = ( D73912F022F37F9E000D13A0 /* App.framework in Frameworks */, 33D1A10422148B71006C7A3E /* FlutterMacOS.framework in Frameworks */, + 8A0E1E523547DDE6AEEAA187 /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -109,6 +115,7 @@ 33CEB47122A05771004F2AC0 /* Flutter */, 33CC10EE2044A3C60003C045 /* Products */, D73912EC22F37F3D000D13A0 /* Frameworks */, + F7F2688E6097307B6E7FBB0A /* Pods */, ); sourceTree = ""; }; @@ -160,10 +167,22 @@ D73912EC22F37F3D000D13A0 /* Frameworks */ = { isa = PBXGroup; children = ( + E845184DF4416AE932BDD596 /* Pods_Runner.framework */, ); name = Frameworks; sourceTree = ""; }; + F7F2688E6097307B6E7FBB0A /* Pods */ = { + isa = PBXGroup; + children = ( + 7E8A42D81EE399E35D3B1C49 /* Pods-Runner.debug.xcconfig */, + 64B57AD34D7E83EE511DDCCF /* Pods-Runner.release.xcconfig */, + ED16B55A7814C4FA5051DC2C /* Pods-Runner.profile.xcconfig */, + ); + name = Pods; + path = Pods; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -171,11 +190,13 @@ isa = PBXNativeTarget; buildConfigurationList = 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( + 1BC6EABFB22C790B61CFD12A /* [CP] Check Pods Manifest.lock */, 33CC10E92044A3C60003C045 /* Sources */, 33CC10EA2044A3C60003C045 /* Frameworks */, 33CC10EB2044A3C60003C045 /* Resources */, 33CC110E2044A8840003C045 /* Bundle Framework */, 3399D490228B24CF009A79C7 /* ShellScript */, + E193D3629E4189A7A2FB86DD /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -245,6 +266,28 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ + 1BC6EABFB22C790B61CFD12A /* [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; + }; 3399D490228B24CF009A79C7 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -282,6 +325,21 @@ shellPath = /bin/sh; shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire"; }; + E193D3629E4189A7A2FB86DD /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + ); + 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/macos/Runner.xcworkspace/contents.xcworkspacedata b/example/macos/Runner.xcworkspace/contents.xcworkspacedata index 1d526a1..21a3cc1 100644 --- a/example/macos/Runner.xcworkspace/contents.xcworkspacedata +++ b/example/macos/Runner.xcworkspace/contents.xcworkspacedata @@ -4,4 +4,7 @@ + + diff --git a/lib/ffi.dart b/lib/ffi.dart index 9284db9..c597963 100644 --- a/lib/ffi.dart +++ b/lib/ffi.dart @@ -57,7 +57,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 || Platform.isMacOS + ? DynamicLibrary.open("flutterqjs.framework/flutterqjs") + : DynamicLibrary.process()); /// JSValue *jsThrowInternalError(JSContext *ctx, char *message) final Pointer Function( diff --git a/macos/CMakeLists.txt b/macos/CMakeLists.txt index 7eb5bf6..8a6e55a 100644 --- a/macos/CMakeLists.txt +++ b/macos/CMakeLists.txt @@ -1,8 +1,8 @@ cmake_minimum_required(VERSION 3.7 FATAL_ERROR) -project(flutter_qjs LANGUAGES CXX) +project(flutterqjs LANGUAGES CXX) set(CXX_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../cxx) -add_library(flutter_qjs SHARED ${CXX_LIB_DIR}/ffi.cpp) +add_library(flutterqjs SHARED ${CXX_LIB_DIR}/ffi.cpp) # quickjs set(QUICK_JS_LIB_DIR ${CXX_LIB_DIR}/quickjs) @@ -22,18 +22,18 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/output/$ENV{ABI}) set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "6SA4A2R2GU" CACHE INTERNAL "") -target_link_libraries(flutter_qjs PRIVATE quickjs) +target_link_libraries(flutterqjs PRIVATE quickjs) -set_target_properties(flutter_qjs PROPERTIES +set_target_properties(flutterqjs PROPERTIES FRAMEWORK TRUE FRAMEWORK_VERSION A - MACOSX_FRAMEWORK_IDENTIFIER soko.ekibun.flutter_qjs + MACOSX_FRAMEWORK_IDENTIFIER soko.ekibun.flutterqjs # 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.cpp + PUBLIC_HEADER ffi.h XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Apple Development" # RESOURCE "${RESOURCE_FILES}" ) \ No newline at end of file diff --git a/macos/flutter_qjs.podspec b/macos/flutter_qjs.podspec index b1a6dd9..2b4c4b1 100644 --- a/macos/flutter_qjs.podspec +++ b/macos/flutter_qjs.podspec @@ -18,7 +18,7 @@ A new flutter plugin project. s.platform = :osx, '10.11' s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } - s.vendored_frameworks = 'build/release-iphoneos/flutter_qjs.framework' + s.vendored_frameworks = 'build/Release/flutterqjs.framework' s.static_framework = false s.swift_version = '5.0' end diff --git a/macos/make.sh b/macos/make.sh index 04ef561..5d619e2 100644 --- a/macos/make.sh +++ b/macos/make.sh @@ -7,5 +7,5 @@ ### mkdir build cd build -cmake .. -G Xcode -DCMAKE_TOOLCHAIN_FILE=../ios.toolchain.cmake -DPLATFORM=OS64COMBINED +cmake .. -G Xcode -DCMAKE_OSX_ARCHITECTURES=x86_64 cmake --build . --config Release