From 9bbb68441fa10623af294a59605d5ce7f79c86f8 Mon Sep 17 00:00:00 2001 From: ekibun Date: Thu, 21 Jan 2021 19:50:16 -0800 Subject: [PATCH] fix cmake build --- .gitignore | 1 + ios/pre.sh => cxx/prebuild.sh | 0 example/ios/Podfile.lock | 2 +- example/macos/Podfile.lock | 15 ++++++++------- .../macos/Runner.xcodeproj/project.pbxproj | 18 +++--------------- ios/flutter_qjs.podspec | 5 ++--- lib/ffi.dart | 2 +- macos/CMakeLists.txt | 7 ------- macos/flutter_qjs.podspec | 5 +++-- macos/make.sh | 12 ------------ test/CMakeLists.txt | 1 + test/flutter_qjs_test.dart | 19 +++++-------------- test/make.sh | 11 ----------- 13 files changed, 25 insertions(+), 73 deletions(-) rename ios/pre.sh => cxx/prebuild.sh (100%) delete mode 100644 macos/CMakeLists.txt delete mode 100644 macos/make.sh delete mode 100644 test/make.sh diff --git a/.gitignore b/.gitignore index 87669ee..f7d7689 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ build/ .vscode/settings.json ios/cxx +macos/cxx \ No newline at end of file diff --git a/ios/pre.sh b/cxx/prebuild.sh similarity index 100% rename from ios/pre.sh rename to cxx/prebuild.sh diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 47f8d32..8850d93 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -15,7 +15,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c - flutter_qjs: 9bb46bb262be81b7c50e4a1a117d5a602d69691f + flutter_qjs: 00a5691bdef3079061466f6fd88cd7d6986fb8b6 PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c diff --git a/example/macos/Podfile.lock b/example/macos/Podfile.lock index 229d14e..83d8abc 100644 --- a/example/macos/Podfile.lock +++ b/example/macos/Podfile.lock @@ -1,22 +1,23 @@ PODS: - flutter_qjs (0.0.1): - FlutterMacOS - - FlutterMacOS (1.0.0) + - FlutterMacOS (1.22.4) DEPENDENCIES: - flutter_qjs (from `Flutter/ephemeral/.symlinks/plugins/flutter_qjs/macos`) - - FlutterMacOS (from `Flutter/ephemeral/.symlinks/flutter/darwin-x64`) + +SPEC REPOS: + trunk: + - FlutterMacOS EXTERNAL SOURCES: flutter_qjs: :path: Flutter/ephemeral/.symlinks/plugins/flutter_qjs/macos - FlutterMacOS: - :path: Flutter/ephemeral/.symlinks/flutter/darwin-x64 SPEC CHECKSUMS: - flutter_qjs: f88ea7f9672fdb5fa0ad0aa2aadc4da8c0308880 - FlutterMacOS: 15bea8a44d2fa024068daa0140371c020b4b6ff9 + flutter_qjs: 1a3a4a23a9bb18d0583b5ee44d09ed9383a36e9f + FlutterMacOS: ac210ef71944b3f04789076d70d4c72c7ec0c619 PODFILE CHECKSUM: d8ba9b3e9e93c62c74a660b46c6fcb09f03991a7 -COCOAPODS: 1.9.3 +COCOAPODS: 1.10.1 diff --git a/example/macos/Runner.xcodeproj/project.pbxproj b/example/macos/Runner.xcodeproj/project.pbxproj index 8acead3..fffb43e 100644 --- a/example/macos/Runner.xcodeproj/project.pbxproj +++ b/example/macos/Runner.xcodeproj/project.pbxproj @@ -26,11 +26,7 @@ 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; }; 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; }; 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 */ /* Begin PBXContainerItemProxy section */ @@ -50,8 +46,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - D73912F222F3801D000D13A0 /* App.framework in Bundle Framework */, - 33D1A10522148B93006C7A3E /* FlutterMacOS.framework in Bundle Framework */, ); name = "Bundle Framework"; runOnlyForDeploymentPostprocessing = 0; @@ -70,7 +64,6 @@ 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Debug.xcconfig"; sourceTree = ""; }; 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Release.xcconfig"; sourceTree = ""; }; 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = "Flutter-Generated.xcconfig"; path = "ephemeral/Flutter-Generated.xcconfig"; sourceTree = ""; }; - 33D1A10322148B71006C7A3E /* FlutterMacOS.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FlutterMacOS.framework; path = Flutter/ephemeral/FlutterMacOS.framework; sourceTree = SOURCE_ROOT; }; 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 = ""; }; @@ -78,7 +71,6 @@ 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 */ @@ -88,8 +80,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - D73912F022F37F9E000D13A0 /* App.framework in Frameworks */, - 33D1A10422148B71006C7A3E /* FlutterMacOS.framework in Frameworks */, 8A0E1E523547DDE6AEEAA187 /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -145,8 +135,6 @@ 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */, 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */, 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */, - D73912EF22F37F9E000D13A0 /* App.framework */, - 33D1A10322148B71006C7A3E /* FlutterMacOS.framework */, ); path = Flutter; sourceTree = ""; @@ -303,7 +291,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.app_filename\n"; + shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.app_filename && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh embed\n"; }; 33CC111E2044C6BF0003C045 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; @@ -330,10 +318,10 @@ buildActionMask = 2147483647; files = ( ); - inputFileListPaths = ( + inputPaths = ( ); name = "[CP] Embed Pods Frameworks"; - outputFileListPaths = ( + outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; diff --git a/ios/flutter_qjs.podspec b/ios/flutter_qjs.podspec index 6234ea1..47e2697 100644 --- a/ios/flutter_qjs.podspec +++ b/ios/flutter_qjs.podspec @@ -14,13 +14,12 @@ This plugin is a simple js engine for flutter using the `quickjs` project. Plugi s.author = { 'ekibun' => 'soekibun@gmail.com' } s.source = { :path => '.' } s.compiler_flags = '-DDUMP_LEAKS' - s.source_files = ['Classes/**/*', 'cxx/*'] - s.public_header_files = 'Classes/**/*.h' + s.source_files = ['Classes/**/*', 'cxx/*.{c,cpp}'] 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.prepare_command = 'sh pre.sh' + s.prepare_command = 'sh ../cxx/prebuild.sh' s.swift_version = '5.0' end diff --git a/lib/ffi.dart b/lib/ffi.dart index dc4ef80..97f14d2 100644 --- a/lib/ffi.dart +++ b/lib/ffi.dart @@ -53,7 +53,7 @@ final DynamicLibrary qjsLib = Platform.environment['FLUTTER_TEST'] == 'true' ? (Platform.isWindows ? DynamicLibrary.open("test/build/Debug/ffiquickjs.dll") : Platform.isMacOS - ? DynamicLibrary.open("test/build/Debug/libffiquickjs.dylib") + ? DynamicLibrary.open("test/build/libffiquickjs.dylib") : DynamicLibrary.process()) : (Platform.isWindows ? DynamicLibrary.open("flutter_qjs_plugin.dll") diff --git a/macos/CMakeLists.txt b/macos/CMakeLists.txt deleted file mode 100644 index 7f04fc7..0000000 --- a/macos/CMakeLists.txt +++ /dev/null @@ -1,7 +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) \ No newline at end of file diff --git a/macos/flutter_qjs.podspec b/macos/flutter_qjs.podspec index 4cc0a1c..bf43bcf 100644 --- a/macos/flutter_qjs.podspec +++ b/macos/flutter_qjs.podspec @@ -13,12 +13,13 @@ 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/*.{c,cpp}'] s.dependency 'FlutterMacOS' s.platform = :osx, '10.11' s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } s.vendored_libraries = 'build/Debug/libffiquickjs.dylib' - s.prepare_command = 'sh make.sh' + s.prepare_command = 'sh ../cxx/prebuild.sh' s.swift_version = '5.0' end diff --git a/macos/make.sh b/macos/make.sh deleted file mode 100644 index 3d7370d..0000000 --- a/macos/make.sh +++ /dev/null @@ -1,12 +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_OSX_ARCHITECTURES=x86_64 -cmake --build . --config Debug -cd .. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7f04fc7..3eead7c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,4 +4,5 @@ project(ffiquickjs LANGUAGES CXX) include("${CMAKE_CURRENT_SOURCE_DIR}/../cxx/quickjs.cmake") add_library(ffiquickjs SHARED ${CXX_LIB_DIR}/ffi.cpp) +target_compile_features(ffiquickjs PUBLIC cxx_std_17) target_link_libraries(ffiquickjs PRIVATE quickjs) \ No newline at end of file diff --git a/test/flutter_qjs_test.dart b/test/flutter_qjs_test.dart index dbb6292..de61231 100644 --- a/test/flutter_qjs_test.dart +++ b/test/flutter_qjs_test.dart @@ -43,10 +43,11 @@ Future testEvaluate(qjs) async { } void main() async { - test('make.windows', () async { + test('make', () async { final utf8Encoding = Encoding.getByName('utf-8'); - final cmakePath = - "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe"; + final cmakePath = Platform.isWindows + ? "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe" + : "cmake"; final buildDir = "./build"; var result = Process.runSync( cmakePath, @@ -69,17 +70,7 @@ void main() async { stdout.write(result.stdout); stderr.write(result.stderr); expect(result.exitCode, 0); - }, testOn: 'windows'); - test('make.macos', () async { - var result = Process.runSync( - "sh", - ['./make.sh'], - workingDirectory: 'macos', - ); - stdout.write(result.stdout); - stderr.write(result.stderr); - expect(result.exitCode, 0); - }, testOn: 'mac-os'); + }); test('module', () async { final qjs = FlutterQjs( moduleHandler: (name) { diff --git a/test/make.sh b/test/make.sh deleted file mode 100644 index 9299f87..0000000 --- a/test/make.sh +++ /dev/null @@ -1,11 +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_OSX_ARCHITECTURES=x86_64 -cmake --build . --config Debug