From 3262468a92aff26038ca4b304a3753de1829b9e2 Mon Sep 17 00:00:00 2001 From: John Smith Date: Sat, 29 Jan 2022 21:25:21 -0500 Subject: [PATCH] macos work --- Cargo.lock | 34 ++++++++-- external/keyring-manager | 2 +- .../native/utils/network_interfaces/apple.rs | 8 ++- veilid-flutter/.gitignore | 1 + .../example/ios/Flutter/Debug.xcconfig | 1 + .../example/ios/Flutter/Release.xcconfig | 1 + veilid-flutter/example/ios/Podfile | 41 ++++++++++++ .../macos/Flutter/Flutter-Debug.xcconfig | 1 + .../macos/Flutter/Flutter-Release.xcconfig | 1 + veilid-flutter/example/macos/Podfile | 40 ++++++++++++ veilid-flutter/example/macos/Podfile.lock | 22 +++++++ .../macos/Runner.xcodeproj/project.pbxproj | 62 ++++++++++++++++++- .../contents.xcworkspacedata | 3 + .../macos/Classes/VeilidPlugin.swift | 18 +++--- veilid-flutter/macos/veilid.podspec | 3 + veilid-flutter/rust/.gitignore | 4 ++ veilid-flutter/rust/ios_build.sh | 32 ++++++++++ veilid-flutter/rust/macos_build.sh | 31 ++++++++++ veilid-flutter/rust/src/bridge_generated.rs | 18 ++++++ veilid-flutter/setup_flutter.sh | 5 +- 20 files changed, 309 insertions(+), 19 deletions(-) create mode 100644 veilid-flutter/example/ios/Podfile create mode 100644 veilid-flutter/example/macos/Podfile create mode 100644 veilid-flutter/example/macos/Podfile.lock create mode 100755 veilid-flutter/rust/ios_build.sh create mode 100755 veilid-flutter/rust/macos_build.sh diff --git a/Cargo.lock b/Cargo.lock index 45ffc1ab..61d617ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,6 +125,15 @@ dependencies = [ "log", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "anyhow" version = "1.0.53" @@ -698,9 +707,13 @@ version = "2.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ + "ansi_term", + "atty", "bitflags", + "strsim 0.8.0", "textwrap 0.11.0", "unicode-width", + "vec_map", ] [[package]] @@ -713,7 +726,7 @@ dependencies = [ "bitflags", "indexmap", "os_str_bytes", - "strsim", + "strsim 0.10.0", "termcolor", "textwrap 0.14.2", ] @@ -1135,7 +1148,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", "syn", ] @@ -1887,8 +1900,8 @@ dependencies = [ "android_logger", "backtrace", "byteorder", - "cfg-if 1.0.0", - "clap 3.0.13", + "cfg-if 0.1.10", + "clap 2.34.0", "core-foundation 0.9.2", "core-foundation-sys 0.8.3", "directories", @@ -1899,6 +1912,7 @@ dependencies = [ "log", "ndk", "ndk-glue", + "owning_ref", "rpassword", "secret-service", "security-framework", @@ -3504,6 +3518,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + [[package]] name = "strsim" version = "0.10.0" @@ -3851,6 +3871,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + [[package]] name = "veilid-cli" version = "0.1.0" diff --git a/external/keyring-manager b/external/keyring-manager index 935ca957..3713e105 160000 --- a/external/keyring-manager +++ b/external/keyring-manager @@ -1 +1 @@ -Subproject commit 935ca957d7e223ef560a0b20b656730a325e0ba7 +Subproject commit 3713e10599c6078e058aab785ef46594420dc11b diff --git a/veilid-core/src/intf/native/utils/network_interfaces/apple.rs b/veilid-core/src/intf/native/utils/network_interfaces/apple.rs index ce635f8d..d8779db1 100644 --- a/veilid-core/src/intf/native/utils/network_interfaces/apple.rs +++ b/veilid-core/src/intf/native/utils/network_interfaces/apple.rs @@ -10,8 +10,10 @@ use std::ffi::CStr; use std::io; use std::os::raw::{c_int, c_uchar, c_ulong, c_ushort, c_void}; -//const SIOCGIFFLAGS:c_ulong = 0xC0206911; const SIOCGIFAFLAG_IN6: c_ulong = 0xC1206949; +const IN6_IFF_TENTATIVE: c_ushort = 0x0002; +const IN6_IFF_DUPLICATED: c_ushort = 0x0004; +const IN6_IFF_DETACHED: c_ushort = 0x0008; const IN6_IFF_TEMPORARY: c_ushort = 0x0080; const IN6_IFF_DEPRECATED: c_ushort = 0x0010; const IN6_IFF_DYNAMIC: c_ushort = 0x0100; @@ -392,7 +394,9 @@ impl PlatformSupportApple { Ok(AddressFlags { is_temporary: (flags & IN6_IFF_TEMPORARY) != 0, is_dynamic: (flags & IN6_IFF_DYNAMIC) != 0, - is_preferred: (flags & (IN6_IFF_TENTATIVE | IN6_IFF_DUPLICATED | IN6_IFF_DETACHED | IN6_IFF_DEPRECATED) ) == 0, + is_preferred: (flags + & (IN6_IFF_TENTATIVE | IN6_IFF_DUPLICATED | IN6_IFF_DETACHED | IN6_IFF_DEPRECATED)) + == 0, }) } diff --git a/veilid-flutter/.gitignore b/veilid-flutter/.gitignore index 9be145fd..d3e1dce8 100644 --- a/veilid-flutter/.gitignore +++ b/veilid-flutter/.gitignore @@ -27,3 +27,4 @@ .dart_tool/ .packages build/ +.flutter diff --git a/veilid-flutter/example/ios/Flutter/Debug.xcconfig b/veilid-flutter/example/ios/Flutter/Debug.xcconfig index 592ceee8..ec97fc6f 100644 --- a/veilid-flutter/example/ios/Flutter/Debug.xcconfig +++ b/veilid-flutter/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/veilid-flutter/example/ios/Flutter/Release.xcconfig b/veilid-flutter/example/ios/Flutter/Release.xcconfig index 592ceee8..c4855bfe 100644 --- a/veilid-flutter/example/ios/Flutter/Release.xcconfig +++ b/veilid-flutter/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/veilid-flutter/example/ios/Podfile b/veilid-flutter/example/ios/Podfile new file mode 100644 index 00000000..1e8c3c90 --- /dev/null +++ b/veilid-flutter/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/veilid-flutter/example/macos/Flutter/Flutter-Debug.xcconfig b/veilid-flutter/example/macos/Flutter/Flutter-Debug.xcconfig index c2efd0b6..4b81f9b2 100644 --- a/veilid-flutter/example/macos/Flutter/Flutter-Debug.xcconfig +++ b/veilid-flutter/example/macos/Flutter/Flutter-Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig" diff --git a/veilid-flutter/example/macos/Flutter/Flutter-Release.xcconfig b/veilid-flutter/example/macos/Flutter/Flutter-Release.xcconfig index c2efd0b6..5caa9d15 100644 --- a/veilid-flutter/example/macos/Flutter/Flutter-Release.xcconfig +++ b/veilid-flutter/example/macos/Flutter/Flutter-Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig" diff --git a/veilid-flutter/example/macos/Podfile b/veilid-flutter/example/macos/Podfile new file mode 100644 index 00000000..dade8dfa --- /dev/null +++ b/veilid-flutter/example/macos/Podfile @@ -0,0 +1,40 @@ +platform :osx, '10.11' + +# 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', 'ephemeral', '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 Flutter-Generated.xcconfig, then run \"flutter pub get\"" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_macos_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__)) +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_macos_build_settings(target) + end +end diff --git a/veilid-flutter/example/macos/Podfile.lock b/veilid-flutter/example/macos/Podfile.lock new file mode 100644 index 00000000..e823c012 --- /dev/null +++ b/veilid-flutter/example/macos/Podfile.lock @@ -0,0 +1,22 @@ +PODS: + - FlutterMacOS (1.0.0) + - veilid (0.0.1): + - FlutterMacOS + +DEPENDENCIES: + - FlutterMacOS (from `Flutter/ephemeral`) + - veilid (from `Flutter/ephemeral/.symlinks/plugins/veilid/macos`) + +EXTERNAL SOURCES: + FlutterMacOS: + :path: Flutter/ephemeral + veilid: + :path: Flutter/ephemeral/.symlinks/plugins/veilid/macos + +SPEC CHECKSUMS: + FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424 + veilid: 8d01491ca5ee1b58110c98f7778124c3ead89a7c + +PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c + +COCOAPODS: 1.11.2 diff --git a/veilid-flutter/example/macos/Runner.xcodeproj/project.pbxproj b/veilid-flutter/example/macos/Runner.xcodeproj/project.pbxproj index f4c86f5c..d752c1ab 100644 --- a/veilid-flutter/example/macos/Runner.xcodeproj/project.pbxproj +++ b/veilid-flutter/example/macos/Runner.xcodeproj/project.pbxproj @@ -26,6 +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 */; }; + 8526E2FC060241577E5281A0 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E89F2D855D7BDA4933E1A2EC /* Pods_Runner.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -52,9 +53,10 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 233B6A2BBF071AE96501823B /* 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 = ""; }; 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 /* veilid_example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "veilid_example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 33CC10ED2044A3C60003C045 /* veilid_example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = veilid_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 = ""; }; @@ -68,6 +70,9 @@ 33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; + B8606FB3C4AA619FC22C3115 /* 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 = ""; }; + E7AFD58527EF4CB477A3582A /* 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 = ""; }; + E89F2D855D7BDA4933E1A2EC /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -75,6 +80,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 8526E2FC060241577E5281A0 /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -99,6 +105,7 @@ 33CEB47122A05771004F2AC0 /* Flutter */, 33CC10EE2044A3C60003C045 /* Products */, D73912EC22F37F3D000D13A0 /* Frameworks */, + CB1628CFD484E4786F2B5B24 /* Pods */, ); sourceTree = ""; }; @@ -145,9 +152,21 @@ path = Runner; sourceTree = ""; }; + CB1628CFD484E4786F2B5B24 /* Pods */ = { + isa = PBXGroup; + children = ( + E7AFD58527EF4CB477A3582A /* Pods-Runner.debug.xcconfig */, + 233B6A2BBF071AE96501823B /* Pods-Runner.release.xcconfig */, + B8606FB3C4AA619FC22C3115 /* Pods-Runner.profile.xcconfig */, + ); + name = Pods; + path = Pods; + sourceTree = ""; + }; D73912EC22F37F3D000D13A0 /* Frameworks */ = { isa = PBXGroup; children = ( + E89F2D855D7BDA4933E1A2EC /* Pods_Runner.framework */, ); name = Frameworks; sourceTree = ""; @@ -159,11 +178,13 @@ isa = PBXNativeTarget; buildConfigurationList = 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( + 53C43C97D5A63C16E369AAE5 /* [CP] Check Pods Manifest.lock */, 33CC10E92044A3C60003C045 /* Sources */, 33CC10EA2044A3C60003C045 /* Frameworks */, 33CC10EB2044A3C60003C045 /* Resources */, 33CC110E2044A8840003C045 /* Bundle Framework */, 3399D490228B24CF009A79C7 /* ShellScript */, + 985C53EA7A19701CA562A7E5 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -270,6 +291,45 @@ shellPath = /bin/sh; shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire"; }; + 53C43C97D5A63C16E369AAE5 /* [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; + }; + 985C53EA7A19701CA562A7E5 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + 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/veilid-flutter/example/macos/Runner.xcworkspace/contents.xcworkspacedata b/veilid-flutter/example/macos/Runner.xcworkspace/contents.xcworkspacedata index 1d526a16..21a3cc14 100644 --- a/veilid-flutter/example/macos/Runner.xcworkspace/contents.xcworkspacedata +++ b/veilid-flutter/example/macos/Runner.xcworkspace/contents.xcworkspacedata @@ -4,4 +4,7 @@ + + diff --git a/veilid-flutter/macos/Classes/VeilidPlugin.swift b/veilid-flutter/macos/Classes/VeilidPlugin.swift index 8eb8768b..262676fc 100644 --- a/veilid-flutter/macos/Classes/VeilidPlugin.swift +++ b/veilid-flutter/macos/Classes/VeilidPlugin.swift @@ -3,17 +3,17 @@ import FlutterMacOS public class VeilidPlugin: NSObject, FlutterPlugin { public static func register(with registrar: FlutterPluginRegistrar) { - let channel = FlutterMethodChannel(name: "veilid", binaryMessenger: registrar.messenger) - let instance = VeilidPlugin() - registrar.addMethodCallDelegate(instance, channel: channel) + // let channel = FlutterMethodChannel(name: "veilid", binaryMessenger: registrar.messenger) + // let instance = VeilidPlugin() + // registrar.addMethodCallDelegate(instance, channel: channel) } public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { - switch call.method { - case "getPlatformVersion": - result("macOS " + ProcessInfo.processInfo.operatingSystemVersionString) - default: - result(FlutterMethodNotImplemented) - } + // switch call.method { + // case "getPlatformVersion": + // result("macOS " + ProcessInfo.processInfo.operatingSystemVersionString) + // default: + result(FlutterMethodNotImplemented) + // } } } diff --git a/veilid-flutter/macos/veilid.podspec b/veilid-flutter/macos/veilid.podspec index 88829270..6b277afe 100644 --- a/veilid-flutter/macos/veilid.podspec +++ b/veilid-flutter/macos/veilid.podspec @@ -19,4 +19,7 @@ Veilid Network s.platform = :osx, '10.11' s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } s.swift_version = '5.0' + + s.script_phase = { :name => 'Cargo Build', :script => '../rust/macos_build.sh', :execution_position => :before_compile } + end diff --git a/veilid-flutter/rust/.gitignore b/veilid-flutter/rust/.gitignore index 7e52fac0..15eb81b8 100644 --- a/veilid-flutter/rust/.gitignore +++ b/veilid-flutter/rust/.gitignore @@ -63,3 +63,7 @@ $RECYCLE.BIN/ target/ logs/ +### Flutter +.config/ +.dart/ +.flutter diff --git a/veilid-flutter/rust/ios_build.sh b/veilid-flutter/rust/ios_build.sh new file mode 100755 index 00000000..80fd1297 --- /dev/null +++ b/veilid-flutter/rust/ios_build.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +CARGO_MANIFEST_PATH=$SCRIPTDIR/Cargo.toml + +if [ "$CONFIGURATION" == "Debug" ]; then + EXTRA_CARGO_OPTIONS="$@" +else + EXTRA_CARGO_OPTIONS="$@ --release" +fi +ARCHS=${ARCHS:=arm64} +for arch in $ARCHS +do + if [ "$arch" == "arm64" ]; then + echo arm64 + CARGO_TARGET=aarch64-apple-ios + CARGO_TOOLCHAIN=+ios-arm64-1.57.0 + #CARGO_TOOLCHAIN= + elif [ "$arch" == "x86_64" ]; then + echo x86_64 + CARGO_TARGET=x86_64-apple-ios + CARGO_TOOLCHAIN= + else + echo Unsupported ARCH: $arch + continue + fi + HOMEBREW_DIR=$(dirname `which brew`) + FLUTTER_DIR=$(dirname `which flutter`) + env -i PATH=/usr/bin:/bin:/usr/local/bin:$HOMEBREW_DIR:$FLUTTER_DIR ~/.cargo/bin/cargo $CARGO_TOOLCHAIN build $EXTRA_CARGO_OPTIONS --target $CARGO_TARGET --manifest-path $CARGO_MANIFEST_PATH +done + diff --git a/veilid-flutter/rust/macos_build.sh b/veilid-flutter/rust/macos_build.sh new file mode 100755 index 00000000..324faac4 --- /dev/null +++ b/veilid-flutter/rust/macos_build.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +CARGO_MANIFEST_PATH=$SCRIPTDIR/Cargo.toml + +if [ "$CONFIGURATION" == "Debug" ]; then + EXTRA_CARGO_OPTIONS="$@" +else + EXTRA_CARGO_OPTIONS="$@ --release" +fi +ARCHS=${ARCHS:=arm64} +for arch in $ARCHS +do + if [ "$arch" == "arm64" ]; then + echo arm64 + CARGO_TARGET=aarch64-apple-darwin + CARGO_TOOLCHAIN= + elif [ "$arch" == "x86_64" ]; then + echo x86_64 + CARGO_TARGET=x86_64-apple-darwin + CARGO_TOOLCHAIN= + else + echo Unsupported ARCH: $arch + continue + fi + HOMEBREW_DIR=$(dirname `which brew`) + FLUTTER_DIR=$(dirname `which flutter`) + env -i PATH=/usr/bin:/bin:/usr/local/bin:$HOMEBREW_DIR:$FLUTTER_DIR ~/.cargo/bin/cargo $CARGO_TOOLCHAIN build $EXTRA_CARGO_OPTIONS --target $CARGO_TARGET --manifest-path $CARGO_MANIFEST_PATH +done + diff --git a/veilid-flutter/rust/src/bridge_generated.rs b/veilid-flutter/rust/src/bridge_generated.rs index bbb888f6..3fd8758d 100644 --- a/veilid-flutter/rust/src/bridge_generated.rs +++ b/veilid-flutter/rust/src/bridge_generated.rs @@ -532,3 +532,21 @@ pub extern "C" fn free_WireSyncReturnStruct(val: support::WireSyncReturnStruct) let _ = support::vec_from_leak_ptr(val.ptr, val.len); } } + + // ----------- DUMMY CODE FOR BINDGEN ---------- + + // copied from: allo-isolate + pub type DartPort = i64; + pub type DartPostCObjectFnType = unsafe extern "C" fn(port_id: DartPort, message: *mut std::ffi::c_void) -> bool; + #[no_mangle] pub unsafe extern "C" fn store_dart_post_cobject(ptr: DartPostCObjectFnType) { panic!("dummy code") } + + // copied from: frb_rust::support.rs + #[repr(C)] + pub struct WireSyncReturnStruct { + pub ptr: *mut u8, + pub len: i32, + pub success: bool, + } + + // --------------------------------------------- + \ No newline at end of file diff --git a/veilid-flutter/setup_flutter.sh b/veilid-flutter/setup_flutter.sh index 80c96b57..b8ab4610 100755 --- a/veilid-flutter/setup_flutter.sh +++ b/veilid-flutter/setup_flutter.sh @@ -69,8 +69,9 @@ elif [ "$OS" == "macos" ]; then fi sudo -H -u $BREW_USER brew install llvm echo "Must sudo to root to install CocoaPods gem:" - sudo gem install cocoapods - + sudo arch -x86_64 gem install ffi + sudo arch -x86_64 gem install cocoapods + # ensure platforms are enabled in flutter flutter config --enable-macos-desktop --enable-ios --no-enable-android fi