flutter and macos work

This commit is contained in:
John Smith
2022-06-10 17:07:10 -04:00
parent 86567ea78d
commit 5931f1254f
33 changed files with 312 additions and 96 deletions

View File

@@ -7,7 +7,7 @@ Future<VeilidConfig> getDefaultVeilidConfig() async {
return VeilidConfig(
programName: "Veilid Plugin Test",
namespace: "",
logLevel: VeilidConfigLogLevel.info,
apiLogLevel: VeilidConfigLogLevel.info,
capabilities: VeilidConfigCapabilities(
protocolUDP: !kIsWeb,
protocolConnectTCP: !kIsWeb,

View File

@@ -36,8 +36,28 @@ LogOptions getLogOptions(LogLevel? level) {
);
}
VeilidConfigLogLevel convertToVeilidConfigLogLevel(LogLevel? level) {
if (level == null) {
return VeilidConfigLogLevel.off;
}
switch (level) {
case LogLevel.error:
return VeilidConfigLogLevel.error;
case LogLevel.warning:
return VeilidConfigLogLevel.warn;
case LogLevel.info:
return VeilidConfigLogLevel.info;
case LogLevel.debug:
return VeilidConfigLogLevel.debug;
case traceLevel:
return VeilidConfigLogLevel.trace;
}
return VeilidConfigLogLevel.off;
}
void setRootLogLevel(LogLevel? level) {
Loggy('').level = getLogOptions(level);
Veilid.instance.changeApiLogLevel(convertToVeilidConfigLogLevel(level));
}
void initLoggy() {
@@ -138,7 +158,7 @@ class _MyAppState extends State<MyApp> with UiLoggy {
if (update is VeilidUpdateLog) {
await processUpdateLog(update);
} else {
loggy.trace("Update: " + update.toString());
loggy.trace("Update: " + update.json.toString());
}
}
}

View File

@@ -6,6 +6,9 @@ list(APPEND FLUTTER_PLUGIN_LIST
veilid
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST
)
set(PLUGIN_BUNDLED_LIBRARIES)
foreach(plugin ${FLUTTER_PLUGIN_LIST})
@@ -14,3 +17,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin)
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)

View File

@@ -21,8 +21,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424
path_provider_macos: 160cab0d5461f0c0e02995469a98f24bdb9a3f1f
veilid: f6b04d095ac7058ddf9c00215eb2699de8cc4673
veilid: 6bed3adec63fd8708a2ace498e0e17941c9fc32b
PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c
COCOAPODS: 1.11.2
COCOAPODS: 1.11.3

View File

@@ -49,7 +49,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
cupertino_icons:
dependency: "direct main"
description:
@@ -63,7 +63,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
ffi:
dependency: transitive
description:
@@ -113,7 +113,7 @@ packages:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
version: "0.6.4"
lints:
dependency: transitive
description:
@@ -141,7 +141,7 @@ packages:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
version: "0.1.4"
meta:
dependency: transitive
description:
@@ -155,7 +155,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.1"
path_provider:
dependency: transitive
description:
@@ -244,7 +244,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
stack_trace:
dependency: transitive
description:
@@ -279,21 +279,14 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.8"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "0.4.9"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "2.1.2"
veilid:
dependency: "direct main"
description:
@@ -316,5 +309,5 @@ packages:
source: hosted
version: "0.2.0+1"
sdks:
dart: ">=2.16.1 <3.0.0"
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.8.0"

View File

@@ -6,6 +6,9 @@ list(APPEND FLUTTER_PLUGIN_LIST
veilid
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST
)
set(PLUGIN_BUNDLED_LIBRARIES)
foreach(plugin ${FLUTTER_PLUGIN_LIST})
@@ -14,3 +17,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin)
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)

View File

@@ -33,8 +33,8 @@ Veilid Network Plugin
s.script_phase = {
:name => 'Cargo Build',
:script => File.join(File.dirname(__dir__), 'rust', 'ios_build.sh'),
:execution_position => :before_compile,
:output_files => [ File.join(cargo_target_dir, 'ios_lib', 'libveilid_flutter.a') ]
:execution_position => :before_compile
# :output_files => [ File.join(cargo_target_dir, 'ios_lib', 'libveilid_flutter.a') ]
}
end

View File

@@ -815,6 +815,7 @@ abstract class VeilidUpdate {
}
}
}
Map<String, dynamic> get json;
}
class VeilidUpdateLog implements VeilidUpdate {
@@ -822,12 +823,29 @@ class VeilidUpdateLog implements VeilidUpdate {
final String message;
//
VeilidUpdateLog(this.logLevel, this.message);
@override
Map<String, dynamic> get json {
return {
'kind': "Log",
'log_level': logLevel.json,
'message': message,
};
}
}
class VeilidUpdateAttachment implements VeilidUpdate {
final AttachmentState state;
//
VeilidUpdateAttachment(this.state);
@override
Map<String, dynamic> get json {
return {
'kind': "Attachment",
'state': state.json,
};
}
}
class VeilidUpdateNetwork implements VeilidUpdate {
@@ -836,6 +854,16 @@ class VeilidUpdateNetwork implements VeilidUpdate {
final int bpsUp;
//
VeilidUpdateNetwork(this.started, this.bpsDown, this.bpsUp);
@override
Map<String, dynamic> get json {
return {
'kind': "Network",
'started': started,
'bps_down': bpsDown,
'bps_up': bpsUp
};
}
}
//////////////////////////////////////

View File

@@ -300,7 +300,9 @@ class VeilidFFI implements Veilid {
@override
Future<void> changeApiLogLevel(VeilidConfigLogLevel logLevel) async {
var nativeLogLevel = logLevel.json.toNativeUtf8();
var nativeLogLevel =
jsonEncode(logLevel.json, toEncodable: veilidApiToEncodable)
.toNativeUtf8();
final recvPort = ReceivePort("change_api_log_level");
final sendPort = recvPort.sendPort;
_changeApiLogLevel(sendPort.nativePort, nativeLogLevel);

View File

@@ -27,8 +27,8 @@ Veilid Network Plugin
s.script_phase = {
:name => 'Cargo Build',
:script => File.join(File.dirname(__dir__), 'rust', 'macos_build.sh'),
:execution_position => :before_compile,
:output_files => [ File.join(cargo_target_dir, 'macos_lib', 'libveilid_flutter.dylib') ]
:execution_position => :before_compile
#:output_files => [ File.join(cargo_target_dir, 'macos_lib', 'libveilid_flutter.dylib') ]
}
end

View File

@@ -1,11 +1,13 @@
#!/bin/bash
set -e
echo Running veilid-flutter rust iOS build script
# Setup varaiables
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
FLUTTER_DIR=$(dirname `which flutter`)
HOMEBREW_DIR=$(dirname `which brew`)
CARGO_DIR=$(dirname `which cargo`)
CARGO_MANIFEST_PATH=$(python -c "import os; print(os.path.realpath(\"$SCRIPTDIR/Cargo.toml\"))")
CARGO_MANIFEST_PATH=$(python3 -c "import os; print(os.path.realpath(\"$SCRIPTDIR/Cargo.toml\"))")
TARGET_DIR=$(dirname `cargo locate-project --message-format plain`)/target
# Configure outputs
@@ -30,7 +32,8 @@ do
if [ "$arch" == "arm64" ]; then
echo arm64
CARGO_TARGET=aarch64-apple-ios
CARGO_TOOLCHAIN=+ios-arm64-1.57.0
#CARGO_TOOLCHAIN=+ios-arm64-1.57.0
CARGO_TOOLCHAIN=
elif [ "$arch" == "x86_64" ]; then
echo x86_64
CARGO_TARGET=x86_64-apple-ios

View File

@@ -1,11 +1,13 @@
#!/bin/bash
set -e
echo Running veilid-flutter rust MacOS build script
# Setup varaiables
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
FLUTTER_DIR=$(dirname `which flutter`)
HOMEBREW_DIR=$(dirname `which brew`)
CARGO_DIR=$(dirname `which cargo`)
CARGO_MANIFEST_PATH=$(python -c "import os; print(os.path.realpath(\"$SCRIPTDIR/Cargo.toml\"))")
CARGO_MANIFEST_PATH=$(python3 -c "import os; print(os.path.realpath(\"$SCRIPTDIR/Cargo.toml\"))")
TARGET_DIR=$(dirname `cargo locate-project --message-format plain`)/target
# Configure outputs

View File

@@ -54,6 +54,7 @@ macro_rules! check_err_json {
/////////////////////////////////////////
// Initializer
#[no_mangle]
#[instrument]
pub extern "C" fn initialize_veilid_flutter(dart_post_c_object_ptr: ffi::DartPostCObjectFnType) {
unsafe {
store_dart_post_cobject(dart_post_c_object_ptr);
@@ -91,6 +92,7 @@ pub extern "C" fn initialize_veilid_flutter(dart_post_c_object_ptr: ffi::DartPos
/// C-compatible FFI Functions
#[no_mangle]
#[instrument]
pub extern "C" fn startup_veilid_core(port: i64, config: FfiStr) {
let config = config.into_opt_string();
let stream = DartIsolateStream::new(port);
@@ -141,6 +143,7 @@ pub extern "C" fn get_veilid_state(port: i64) {
}
#[no_mangle]
#[instrument(level = "debug")]
pub extern "C" fn change_api_log_level(port: i64, log_level: FfiStr) {
let log_level = log_level.into_opt_string();
DartIsolateWrapper::new(port).spawn_result_json(async move {
@@ -153,6 +156,7 @@ pub extern "C" fn change_api_log_level(port: i64, log_level: FfiStr) {
}
#[no_mangle]
#[instrument]
pub extern "C" fn shutdown_veilid_core(port: i64) {
DartIsolateWrapper::new(port).spawn_result_json(async move {
let veilid_api = take_veilid_api().await?;
@@ -184,6 +188,7 @@ pub struct VeilidVersion {
}
#[no_mangle]
#[instrument]
pub extern "C" fn veilid_version() -> VeilidVersion {
let (major, minor, patch) = veilid_core::veilid_version();
VeilidVersion {

View File

@@ -1,6 +1,7 @@
pub use allo_isolate::ffi::DartCObject;
pub use allo_isolate::IntoDart;
use allo_isolate::Isolate;
use core::fmt::Debug;
use core::future::Future;
use parking_lot::Mutex;
use serde::*;
@@ -31,8 +32,8 @@ impl DartIsolateWrapper {
pub fn spawn_result<F, T, E>(self, future: F)
where
F: Future<Output = Result<T, E>> + Send + 'static,
T: IntoDart,
E: Serialize,
T: IntoDart + Debug,
E: Serialize + Debug,
{
async_std::task::spawn(async move {
self.result(future.await);
@@ -42,21 +43,24 @@ impl DartIsolateWrapper {
pub fn spawn_result_json<F, T, E>(self, future: F)
where
F: Future<Output = Result<T, E>> + Send + 'static,
T: Serialize,
E: Serialize,
T: Serialize + Debug,
E: Serialize + Debug,
{
async_std::task::spawn(async move {
self.result_json(future.await);
});
}
pub fn result<T: IntoDart, E: Serialize>(self, result: Result<T, E>) -> bool {
pub fn result<T: IntoDart + Debug, E: Serialize + Debug>(self, result: Result<T, E>) -> bool {
match result {
Ok(v) => self.ok(v),
Err(e) => self.err_json(e),
}
}
pub fn result_json<T: Serialize, E: Serialize>(self, result: Result<T, E>) -> bool {
pub fn result_json<T: Serialize + Debug, E: Serialize + Debug>(
self,
result: Result<T, E>,
) -> bool {
match result {
Ok(v) => self.ok_json(v),
Err(e) => self.err_json(e),
@@ -67,19 +71,19 @@ impl DartIsolateWrapper {
.post(vec![MESSAGE_OK.into_dart(), value.into_dart()])
}
pub fn ok_json<T: Serialize>(self, value: T) -> bool {
pub fn ok_json<T: Serialize + Debug>(self, value: T) -> bool {
self.isolate.post(vec![
MESSAGE_OK_JSON.into_dart(),
veilid_core::serialize_json(value).into_dart(),
])
}
// pub fn err<E: IntoDart>(self, error: E) -> bool {
// pub fn err<E: IntoDart + Debug>(self, error: E) -> bool {
// self.isolate
// .post(vec![MESSAGE_ERR.into_dart(), error.into_dart()])
// }
pub fn err_json<E: Serialize>(self, error: E) -> bool {
pub fn err_json<E: Serialize + Debug>(self, error: E) -> bool {
self.isolate.post(vec![
MESSAGE_ERR_JSON.into_dart(),
veilid_core::serialize_json(error).into_dart(),
@@ -122,7 +126,7 @@ impl DartIsolateStream {
// }
// }
pub fn item_json<T: Serialize>(&self, value: T) -> bool {
pub fn item_json<T: Serialize + Debug>(&self, value: T) -> bool {
let inner = self.inner.lock();
if let Some(isolate) = &inner.isolate {
isolate.post(vec![
@@ -134,7 +138,7 @@ impl DartIsolateStream {
}
}
// pub fn abort<E: IntoDart>(self, error: E) -> bool {
// pub fn abort<E: IntoDart + Debug>(self, error: E) -> bool {
// let mut inner = self.inner.lock();
// if let Some(isolate) = inner.isolate.take() {
// isolate.post(vec![MESSAGE_STREAM_ABORT.into_dart(), error.into_dart()])
@@ -143,7 +147,7 @@ impl DartIsolateStream {
// }
// }
pub fn abort_json<E: Serialize>(self, error: E) -> bool {
pub fn abort_json<E: Serialize + Debug>(self, error: E) -> bool {
let mut inner = self.inner.lock();
if let Some(isolate) = inner.isolate.take() {
isolate.post(vec![