Skip to content

Commit

Permalink
Flutter native on Linux started for ayfStarter
Browse files Browse the repository at this point in the history
  • Loading branch information
hkbinaurics committed May 27, 2024
1 parent 9ae2784 commit 3887106
Show file tree
Hide file tree
Showing 9 changed files with 352 additions and 17 deletions.
2 changes: 1 addition & 1 deletion flutter/ayf_pack/lib/ayf_init_host_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:ayf_ffihost/ayf_ffihost.dart' as ffihost;
String ayf_init_host_options(Map<String, dynamic> configArgs,
{bool forceFfiHost = false, bool forceWebHost = false, dynamic corePack}) {
String initRoute = '/';
bool ffiHost = Platform.isWindows;
bool ffiHost = Platform.isWindows || Platform.isLinux;
if (forceWebHost) {
ffiHost = false;
}
Expand Down
29 changes: 21 additions & 8 deletions sources/sub-projects/ayfstarter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ set(AYF_STARTER_AUDIONODE
)
jvx_addSubdirs("Configuring shared library for ayfstarter audio node" "${AYF_STARTER_AUDIONODE}" "${JVX_FOLDER_HIERARCHIE_BASE}/AudioNode")


if(NOT JVX_RELEASE_SDK)
set(AYF_STARTER_APPLICATION "")
if(JVX_USE_PART_WEBSERVER)
Expand Down Expand Up @@ -53,20 +54,32 @@ if(NOT JVX_RELEASE_SDK)
endif()
endif()
else()

if(JVX_FLUTTER_UI)
set(AYFSTARTER_HOSTCONF_DLL "${CMAKE_INSTALL_PREFIX}/${INSTALL_PATH_BIN}/ayfstarter-native-config_import.dll")
set(AYFSTARTER_FFI_DLL "${CMAKE_INSTALL_PREFIX}/${INSTALL_PATH_BIN}/jvx-flutter-native-shared_import.dll")
set(AYFSTARTER_FFI_PRELOAD_DLLS "${CMAKE_INSTALL_PREFIX}/${INSTALL_PATH_BIN}/zlib.dll,${CMAKE_INSTALL_PREFIX}/${INSTALL_PATH_BIN}/libfftw3-3.dll")
# configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ayfbinrender/.ayfbinrender.env.in ${CMAKE_CURRENT_SOURCE_DIR}/ayfbinrender/.ayfbinrender.env @ONLY)

if(${JVX_OS} MATCHES "windows")
message("Flutter code generation for Windows")
set(AYFSTARTER_HOSTCONF_DLL "${CMAKE_INSTALL_PREFIX}/${INSTALL_PATH_BIN}/ayfstarter-native-config_import.dll")
set(AYFSTARTER_FFI_DLL "${CMAKE_INSTALL_PREFIX}/${INSTALL_PATH_BIN}/jvx-flutter-native-shared_import.dll")
set(AYFSTARTER_FFI_PRELOAD_DLLS "${CMAKE_INSTALL_PREFIX}/${INSTALL_PATH_BIN}/zlib.dll,${CMAKE_INSTALL_PREFIX}/${INSTALL_PATH_BIN}/libfftw3-3.dll")
elseif(${JVX_OS} MATCHES "linux")
message("Flutter code generation for linux")
set(AYFSTARTER_FFI_DLL "${CMAKE_INSTALL_PREFIX}/${INSTALL_PATH_BIN}/libjvx-flutter-native-shared_import.so")
set(AYFSTARTER_FFI_PRELOAD_DLLS "")
else()
message(FATAL_ERROR "Error: Platform ${JVX_OS} currently not supported!")
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flutter/starter_app/example/.starter_app.env.in ${CMAKE_CURRENT_SOURCE_DIR}/flutter/starter_app/example/.starter_app.env @ONLY)

message("${CMAKE_CURRENT_SOURCE_DIR}/flutter/starter_app/example/.starter_app.env.in -> ${CMAKE_CURRENT_SOURCE_DIR}/flutter/starter_app/example/.starter_app.env")

set(AYF_FLUTTER_WORKDIR ${CMAKE_INSTALL_PREFIX}/${INSTALL_PATH_RUNTIME})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flutter/starter_app/launch.json.in ${CMAKE_CURRENT_SOURCE_DIR}/flutter/starter_app/.vscode/launch.json @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flutter/starter_app/launch.json.in ${CMAKE_CURRENT_SOURCE_DIR}/flutter/starter_app/.vscode/launch.json @ONLY)
message("${CMAKE_CURRENT_SOURCE_DIR}/flutter/starter_app/launch.json.in -> ${CMAKE_CURRENT_SOURCE_DIR}/flutter/starter_app/.vscode/launch.json")
endif()
endif()

set(AYF_STARTER_APPLICATION ${AYF_STARTER_APPLICATION} ${CMAKE_CURRENT_SOURCE_DIR}/sources/Applications/ayfstarter-native-config)
jvx_addSubdirs("Configuring application ayfstarter " "${AYF_STARTER_APPLICATION}" "${JVX_FOLDER_HIERARCHIE_BASE}/Application")

# message(FATAL_ERROR "Hier -- JVX_FLUTTER_UI = ${JVX_FLUTTER_UI} -- AYFSTARTER_SIMPLE_INSTALLER = ${AYFSTARTER_SIMPLE_INSTALLER}")
# message(FATAL_ERROR "Hier -- JVX_FLUTTER_UI = ${JVX_FLUTTER_UI} -- AYFSTARTER_SIMPLE_INSTALLER = ${AYFSTARTER_SIMPLE_INSTALLER}")
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,50 @@ cmake_minimum_required(VERSION 3.10)
set(PROJECT_NAME "ayfcorepack")
project(${PROJECT_NAME} LANGUAGES CXX)

set(AYF_PROJECT ayfstarter-native-config)
set(AYF_VERBOSE_INFO TRUE)
set(AYF_CORE_PACK_LIB lib${AYF_PROJECT}_import.so)
set(AYF_CORE_PACK_INCLUDE ${AYF_PROJECT})

# This value is used when generating builds using this plugin, so it must
# not be changed.
set(PLUGIN_NAME "ayfcorepack_plugin")

# =======================================================
# Link to ayf sdk
# =======================================================
if(AYF_VERBOSE_INFO)
message("Module <${PROJECT_NAME}> in folder ${CMAKE_CURRENT_SOURCE_DIR}")
endif()

if(NOT DEFINED ENV{AYF_SDK_PATH})
message(FATAL_ERROR "Environment variable AYF_SDK_PATH not set.")
endif()
set(AYF_SDK_PATH $ENV{AYF_SDK_PATH})

cmake_path(CONVERT ${AYF_SDK_PATH} TO_CMAKE_PATH_LIST AYF_SDK_PATH)
if(NOT EXISTS ${AYF_SDK_PATH})
message(FATAL_ERROR "SDK folder ${AYF_SDK_PATH} does not exist!!")
else()
if(AYF_VERBOSE_INFO)
message("----> Linking with SDK folder ${AYF_SDK_PATH}!!")
endif()
endif()

list(APPEND PLUGIN_SOURCES
"ayfcorepack_plugin.cc"
"include/ayfcorepack/ayfcorepack_plugin.h"
"../common/ayf-sdk-local-headers.h"
"${AYF_SDK_PATH}/software/codeFragments/jvxApplications/native-config/exports/windows/exports-flutter-native-config.def"
"${AYF_SDK_PATH}/include/${AYF_CORE_PACK_INCLUDE}/include/ayfstarter-native-config.h"
)

# Define the plugin library target. Its name must not be changed (see comment
# on PLUGIN_NAME above).
#
# Any new source files that you add to the plugin should be added here.
add_library(${PLUGIN_NAME} SHARED
"ayfcorepack_plugin.cc"
${PLUGIN_SOURCES}
)

# Apply a standard set of build settings that are configured in the
Expand All @@ -38,10 +72,43 @@ target_include_directories(${PLUGIN_NAME} INTERFACE
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter)
target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK)

include(${AYF_SDK_PATH}/cmake/cmake-sdk/cmake-ayf-minimal-header-includes.cmake)
get_property(AYF_MINIMAL_SDK_HEADER_INCLUDES GLOBAL PROPERTY AYF_MINIMAL_SDK_HEADER_INCLUDES)
if(AYF_VERBOSE_INFO)
message("----> Found the following headers for linking libraries in the SDK: AYF_MINIMAL_SDK_HEADER_INCLUDES = ${AYF_MINIMAL_SDK_HEADER_INCLUDES}")
endif()

target_include_directories(${PLUGIN_NAME} PRIVATE
${AYF_MINIMAL_SDK_HEADER_INCLUDES}
${AYF_SDK_PATH}/include/${AYF_CORE_PACK_INCLUDE}/include
../common
)

target_link_directories(${PLUGIN_NAME} PRIVATE
"${AYF_SDK_PATH}/lib"
"${AYF_SDK_PATH}/bin"
"${AYF_SDK_PATH}/lib/jvxComponents-static"
)

target_link_libraries(${PLUGIN_NAME} PRIVATE

# This is the minimum package libs aggregation:
${AYF_CORE_PACK_LIB}
)

set(AYF_COPY_DLLS
"${AYF_SDK_PATH}/bin/${AYF_CORE_PACK_LIB}"
)
if(AYF_VERBOSE_INFO)
message("----> Copying dlls ${AYF_COPY_DLLS}")
endif()


# List of absolute paths to libraries that should be bundled with the plugin.
# This list could contain prebuilt libraries, or libraries created by an
# external build triggered from this build file.
set(ayfcorepack_bundled_libraries
""
${AYF_COPY_DLLS}
PARENT_SCOPE
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include "ayf-sdk-local-headers.h"

#include "include/ayfcorepack/ayfcorepack_plugin.h"

#include <flutter_linux/flutter_linux.h>
#include <gtk/gtk.h>
#include <sys/utsname.h>

#include <cstring>

#define AYFCOREPACK_PLUGIN(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), ayfcorepack_plugin_get_type(), \
AyfcorepackPlugin))

struct _AyfcorepackPlugin {
GObject parent_instance;
};

G_DEFINE_TYPE(AyfcorepackPlugin, ayfcorepack_plugin, g_object_get_type())

// Called when a method call is received from Flutter.
static void ayfcorepack_plugin_handle_method_call(
AyfcorepackPlugin* self,
FlMethodCall* method_call) {
g_autoptr(FlMethodResponse) response = nullptr;

const gchar* method = fl_method_call_get_name(method_call);

if (strcmp(method, "getPlatformVersion") == 0) {
struct utsname uname_data = {};
uname(&uname_data);
g_autofree gchar *version = g_strdup_printf("Linux %s", uname_data.version);
g_autoptr(FlValue) result = fl_value_new_string(version);
response = FL_METHOD_RESPONSE(fl_method_success_response_new(result));
}
else if (strcmp(method, "getEntryPoints") == 0)
{
g_autoptr(FlValue) mapReturn = fl_value_new_map();
//flutter::EncodableMap retMap;

fl_value_set(mapReturn, fl_value_new_string("loadedModule"),
fl_value_new_string("123"));//ayfcorepack::AyfcorepackPlugin::fileNameModule.c_str()));
// retMap[flutter::EncodableValue("loadedModule")] = flutter::EncodableValue(ayfcorepack::AyfcorepackPlugin::fileNameModule);

fl_value_set(mapReturn, fl_value_new_string("moduleEntryAddress"), fl_value_new_int((intptr_t)flutter_config_open));
//retMap[flutter::EncodableValue("moduleEntryAddress")] = flutter::EncodableValue((intptr_t)flutter_config_open);

fl_value_set(mapReturn, fl_value_new_string("moduleEntrySymbol"), fl_value_new_string("flutter_config_open"));
// retMap[flutter::EncodableValue("moduleEntrySymbol")] = flutter::EncodableValue("flutter_config_open");

//result->Success(retMap);
response = FL_METHOD_RESPONSE(fl_method_success_response_new(mapReturn));
}
else {
response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
}

fl_method_call_respond(method_call, response, nullptr);
}

static void ayfcorepack_plugin_dispose(GObject* object) {
G_OBJECT_CLASS(ayfcorepack_plugin_parent_class)->dispose(object);
}

static void ayfcorepack_plugin_class_init(AyfcorepackPluginClass* klass) {
G_OBJECT_CLASS(klass)->dispose = ayfcorepack_plugin_dispose;
}

static void ayfcorepack_plugin_init(AyfcorepackPlugin* self) {}

static void method_call_cb(FlMethodChannel* channel, FlMethodCall* method_call,
gpointer user_data) {
AyfcorepackPlugin* plugin = AYFCOREPACK_PLUGIN(user_data);
ayfcorepack_plugin_handle_method_call(plugin, method_call);
}

void ayfcorepack_plugin_register_with_registrar(FlPluginRegistrar* registrar) {
AyfcorepackPlugin* plugin = AYFCOREPACK_PLUGIN(
g_object_new(ayfcorepack_plugin_get_type(), nullptr));

g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
g_autoptr(FlMethodChannel) channel =
fl_method_channel_new(fl_plugin_registrar_get_messenger(registrar),
"ayfcorepack",
FL_METHOD_CODEC(codec));
fl_method_channel_set_method_call_handler(channel, method_call_cb,
g_object_ref(plugin),
g_object_unref);

g_object_unref(plugin);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef FLUTTER_PLUGIN_AYFCOREPACK_PLUGIN_H_
#define FLUTTER_PLUGIN_AYFCOREPACK_PLUGIN_H_

#include <flutter_linux/flutter_linux.h>

G_BEGIN_DECLS

#ifdef FLUTTER_PLUGIN_IMPL
#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
#else
#define FLUTTER_PLUGIN_EXPORT
#endif

typedef struct _AyfcorepackPlugin AyfcorepackPlugin;
typedef struct {
GObjectClass parent_class;
} AyfcorepackPluginClass;

FLUTTER_PLUGIN_EXPORT GType ayfcorepack_plugin_get_type();

FLUTTER_PLUGIN_EXPORT void ayfcorepack_plugin_register_with_registrar(
FlPluginRegistrar* registrar);

G_END_DECLS

#endif // FLUTTER_PLUGIN_AYFCOREPACK_PLUGIN_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1) Renamed folder "ayf_starter_corpack" to "ayfcorepack".
2) Ran "flutter create --template=plugin --platforms=linux"
3) Copied file "CMakeLists.txt" from "templates" to "linux"
4) Renamed "ayfcorepack" to "ayf_starter_corpack"

34 changes: 27 additions & 7 deletions sources/sub-projects/ayfstarter/flutter/starter_app/launch.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "0.2.0",
"configurations": [
{
"name": "starter_app (debug)",
"name": "starter_app (debug;windows)",
"request": "launch",
"type": "dart",
"program": "example/lib/main.dart",
Expand Down Expand Up @@ -46,14 +46,34 @@
// "cwd": "C:\\jvxrt\\build.audio.all\\release\\runtime", <- this does not work since the interpreter can not find the main.dart script
"flutterMode": "debug",
},
{
"name": "fernlive (profile mode)",
{
"name": "starter_app (debug;linux)",
"request": "launch",
"type": "dart",
"program": "example/lib/main.dart",
"deviceId": "linux",

// https://stackoverflow.com/questions/55004302/how-do-you-pass-arguments-from-command-line-to-main-in-flutter-dart
// https://dartcode.org/docs/launch-configuration/
"args": [
"--dart-define", "MY_VAR=foo"
// Make sure that the sofa folder is in the runtime or the sdk folder - it often is the SDK output folder!!
"--dart-entrypoint-args", "--workdir",
"--dart-entrypoint-args", "@AYF_FLUTTER_WORKDIR@",
"--dart-entrypoint-args", "--preload",
"--dart-entrypoint-args", "@AYF_FLUTTER_WORKDIR@/bin/zlib.dll",
"--dart-entrypoint-args", "--preload",
"--dart-entrypoint-args", "@AYF_FLUTTER_WORKDIR@/bin/libfftw3-3.dll",
"--dart-entrypoint-args", "--jvxdir",
"--dart-entrypoint-args", "jvxComponents",
"--dart-entrypoint-args", "--config",
"--dart-entrypoint-args", "ayfstarter.jvx",
"--dart-entrypoint-args", "--textlog",
"--dart-entrypoint-args", "--verbose_dll",
"--dart-entrypoint-args", "--textloglev",
"--dart-entrypoint-args", "10"
],
"flutterMode": "profile"
}
]
// "cwd": "C:\\jvxrt\\build.audio.all\\release\\runtime", <- this does not work since the interpreter can not find the main.dart script
"flutterMode": "debug",
},
]
}
Loading

0 comments on commit 3887106

Please sign in to comment.