Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add linux desktop support. #887

Merged
merged 48 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3ce66bf
Create example_build.yml
cnryb Nov 11, 2021
e79d4d5
Update example_build.yml
cnryb Nov 11, 2021
712db00
Update example_build.yml
cnryb Nov 11, 2021
81e5786
Update example_build.yml
cnryb Nov 11, 2021
dc65b03
Update example_build.yml
cnryb Nov 11, 2021
b208860
Update example_build.yml
cnryb Nov 16, 2021
143eee4
Create example_build.yml
cnryb Nov 17, 2021
c834199
feat: add linux desktop support.
andycall Nov 18, 2021
accbfe7
Committing clang-format changes
Nov 18, 2021
3e5ad57
feat: disable http cache for windows and linux.
andycall Nov 18, 2021
3c50ab7
Committing clang-format changes
Nov 18, 2021
851e49e
fix: should cancel fetch request if kraken page disposed.
andycall Nov 18, 2021
f2cbf1e
fix: reset kraken module when page reload.
andycall Nov 18, 2021
04f222d
:bug: fix: empty of textNode should not attach the render object to p…
answershuto Nov 17, 2021
9e15060
:bug: fix: modify the data of textNode need to devide whether attach …
answershuto Nov 17, 2021
7f7c4ed
:recycle: chore: use empty to replace symbol.
answershuto Nov 17, 2021
8207b45
:white_check_mark: test: createTextNode should not has height when th…
answershuto Nov 17, 2021
c95ff6b
:white_check_mark: test: delete fix.
answershuto Nov 17, 2021
6fd5f6c
:white_check_mark: test: TextNode empty string of textNode set data s…
answershuto Nov 17, 2021
787d3d6
:recycle: chore: modify attachTo.
answershuto Nov 17, 2021
55d6025
:bug: fix: attach should judge whether isRendererAttached.
answershuto Nov 17, 2021
91bc6f8
:bulb: doc: modify comment.
answershuto Nov 17, 2021
4f1e0fc
chore: add todo
andycall Nov 18, 2021
c358adf
Merge branch 'fix/http-cache' into feat/linux_support
andycall Nov 18, 2021
23a863d
Merge remote-tracking branch 'origin/main' into feat/linux_support
andycall Nov 19, 2021
010b59c
Committing clang-format changes
Nov 19, 2021
45b73e3
Merge pull request #2 from cnryb/main
cnryb Nov 19, 2021
e129009
Update example_build.yml
cnryb Nov 19, 2021
3d24c05
Update example_build.yml
cnryb Nov 19, 2021
71fc291
Update example_build.yml
cnryb Nov 19, 2021
5217169
Merge branch 'openkraken:main' into main
cnryb Nov 20, 2021
8e4792c
Merge pull request #3 from cnryb/main
cnryb Nov 20, 2021
23add20
Update and rename example_build.yml to example_build_linux.yml
cnryb Nov 20, 2021
bee6435
Update example_build_linux.yml
cnryb Nov 20, 2021
6038392
build
zpferyb Nov 22, 2021
7335ed9
Update example_build.yml
cnryb Nov 22, 2021
7aaa62d
Merge branch 'example-build' into feat/linux_support
cnryb Nov 22, 2021
22b5940
android & ios build
cnryb Nov 22, 2021
fd337ca
Merge branch 'feat/linux_support' into example_build
cnryb Nov 22, 2021
b9f39d5
linux app build
cnryb Nov 22, 2021
55d672a
revert code
cnryb Nov 23, 2021
b6497da
refactor
cnryb Nov 23, 2021
2a0fdbb
edit annotation
cnryb Nov 24, 2021
32f0851
Merge remote-tracking branch 'origin/main' into feat/linux_support
andycall Nov 30, 2021
76af3c7
Merge remote-tracking branch 'origin/main' into example_build
andycall Nov 30, 2021
4802977
Merge pull request #882 from openkraken/example_build
wssgcg1213 Dec 1, 2021
2b6e213
Merge remote-tracking branch 'origin/main' into feat/linux_support
andycall Jan 12, 2022
355b035
fix: fix flutter version
andycall Jan 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
121 changes: 121 additions & 0 deletions .github/workflows/example_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: example build

on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

env:
nodeVersion: "16"
cmakeVersion: "3.22.x"
flutterVersion: "2.5.3"

jobs:
build_android-app_in_macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
# Set up the bridge compilation environment
- uses: actions/setup-node@v2
with:
node-version: ${{ env.nodeVersion }}
- uses: jwlawson/actions-setup-cmake@v1.11
with:
cmake-version: ${{ env.cmakeVersion }}
- run: npm i
- run: npm run build:bridge:android:release

# Install Flutter SDK
- uses: subosito/flutter-action@v1
with:
flutter-version: ${{ env.flutterVersion }}
- run: flutter doctor -v

- name: android app build
run: |
cd kraken/
flutter pub get
cd example/
flutter build apk --release

build_ios-app_in_macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ env.nodeVersion }}
- uses: jwlawson/actions-setup-cmake@v1.11
with:
cmake-version: ${{ env.cmakeVersion }}
- run: npm i
- run: npm run build:bridge:ios:release

- uses: subosito/flutter-action@v1
with:
flutter-version: ${{ env.flutterVersion }}
- run: flutter doctor -v

- name: ios app build
run: |
cd kraken/
flutter pub get
cd example/
flutter build ios --release --no-codesign

build_macos-app_in_macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ env.nodeVersion }}
- uses: jwlawson/actions-setup-cmake@v1.11
with:
cmake-version: ${{ env.cmakeVersion }}
- run: npm i
- run: npm run build:bridge:macos:release

- uses: subosito/flutter-action@v1
with:
flutter-version: ${{ env.flutterVersion }}
- run: flutter config --enable-macos-desktop
- run: flutter doctor -v

- name: macos app build
run: |
cd kraken/
flutter pub get
cd example/
flutter build macos --release

build_linux-app_in_ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ env.nodeVersion }}
- uses: jwlawson/actions-setup-cmake@v1.11
with:
cmake-version: ${{ env.cmakeVersion }}

- run: npm i
- run: npm run build:bridge:linux:release

- uses: subosito/flutter-action@v1
with:
flutter-version: ${{ env.flutterVersion }}
- run: flutter config --enable-linux-desktop
- run: |
sudo apt-get update
sudo apt-get install ninja-build pkg-config libgtk-3-dev -y
- run: flutter doctor -v
- name: linux app build
run: |
cd kraken/
flutter pub get
cd example/
flutter build linux --release
3 changes: 3 additions & 0 deletions bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ set(QUICKJS_PUBLIC_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/third_party/quickjs/quickjs-opcode.h
)

if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
add_compile_options(-fPIC)
endif()

if (ENABLE_ASAN)
add_compile_options(-fsanitize=address -fno-omit-frame-pointer -O1)
Expand Down
2 changes: 1 addition & 1 deletion kraken/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:4.1.0'
}
}

Expand Down
2 changes: 1 addition & 1 deletion kraken/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
2 changes: 1 addition & 1 deletion kraken/example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:4.1.0'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
1 change: 1 addition & 0 deletions kraken/example/linux/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flutter/ephemeral
116 changes: 116 additions & 0 deletions kraken/example/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
cmake_minimum_required(VERSION 3.10)
project(runner LANGUAGES CXX)

set(BINARY_NAME "kraken_example")
set(APPLICATION_ID "com.example.kraken")

cmake_policy(SET CMP0063 NEW)

set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")

# Root filesystem for cross-building.
if(FLUTTER_TARGET_PLATFORM_SYSROOT)
set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT})
set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
endif()

# Configure build options.
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Debug" CACHE
STRING "Flutter build mode" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Profile" "Release")
endif()

# Compilation settings that should be applied to most targets.
function(APPLY_STANDARD_SETTINGS TARGET)
target_compile_features(${TARGET} PUBLIC cxx_std_14)
target_compile_options(${TARGET} PRIVATE -Wall -Werror)
target_compile_options(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O3>")
target_compile_definitions(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")
endfunction()

set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")

# Flutter library and tool build rules.
add_subdirectory(${FLUTTER_MANAGED_DIR})

# System-level dependencies.
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)

add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")

# Application build
add_executable(${BINARY_NAME}
"main.cc"
"my_application.cc"
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
)
apply_standard_settings(${BINARY_NAME})
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
add_dependencies(${BINARY_NAME} flutter_assemble)
# Only the install-generated bundle's copy of the executable will launch
# correctly, since the resources must in the right relative locations. To avoid
# people trying to run the unbundled copy, put it in a subdirectory instead of
# the default top-level location.
set_target_properties(${BINARY_NAME}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
)

# Generated plugin build rules, which manage building the plugins and adding
# them to the application.
include(flutter/generated_plugins.cmake)


# === Installation ===
# By default, "installing" just makes a relocatable bundle in the build
# directory.
set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
endif()

# Start with a clean build bundle directory every time.
install(CODE "
file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
" COMPONENT Runtime)

set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")

install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
COMPONENT Runtime)

install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
COMPONENT Runtime)

install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)

if(PLUGIN_BUNDLED_LIBRARIES)
install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)
endif()

# Fully re-copy the assets directory on each build to avoid having stale files
# from a previous install.
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
install(CODE "
file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
" COMPONENT Runtime)
install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)

# Install the AOT library on non-Debug builds only.
if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)
endif()
87 changes: 87 additions & 0 deletions kraken/example/linux/flutter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
cmake_minimum_required(VERSION 3.10)

set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")

# Configuration provided via flutter tool.
include(${EPHEMERAL_DIR}/generated_config.cmake)

# TODO: Move the rest of this into files in ephemeral. See
# https://github.com/flutter/flutter/issues/57146.

# Serves the same purpose as list(TRANSFORM ... PREPEND ...),
# which isn't available in 3.10.
function(list_prepend LIST_NAME PREFIX)
set(NEW_LIST "")
foreach(element ${${LIST_NAME}})
list(APPEND NEW_LIST "${PREFIX}${element}")
endforeach(element)
set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE)
endfunction()

# === Flutter Library ===
# System-level dependencies.
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)

set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")

# Published to parent scope for install step.
set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)

list(APPEND FLUTTER_LIBRARY_HEADERS
"fl_basic_message_channel.h"
"fl_binary_codec.h"
"fl_binary_messenger.h"
"fl_dart_project.h"
"fl_engine.h"
"fl_json_message_codec.h"
"fl_json_method_codec.h"
"fl_message_codec.h"
"fl_method_call.h"
"fl_method_channel.h"
"fl_method_codec.h"
"fl_method_response.h"
"fl_plugin_registrar.h"
"fl_plugin_registry.h"
"fl_standard_message_codec.h"
"fl_standard_method_codec.h"
"fl_string_codec.h"
"fl_value.h"
"fl_view.h"
"flutter_linux.h"
)
list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")
add_library(flutter INTERFACE)
target_include_directories(flutter INTERFACE
"${EPHEMERAL_DIR}"
)
target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")
target_link_libraries(flutter INTERFACE
PkgConfig::GTK
PkgConfig::GLIB
PkgConfig::GIO
)
add_dependencies(flutter flutter_assemble)

# === Flutter tool backend ===
# _phony_ is a non-existent file to force this command to run every time,
# since currently there's no way to get a full input/output list from the
# flutter tool.
add_custom_command(
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
${CMAKE_CURRENT_BINARY_DIR}/_phony_
COMMAND ${CMAKE_COMMAND} -E env
${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
VERBATIM
)
add_custom_target(flutter_assemble DEPENDS
"${FLUTTER_LIBRARY}"
${FLUTTER_LIBRARY_HEADERS}
)
13 changes: 13 additions & 0 deletions kraken/example/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Generated file. Do not edit.
//

#include "generated_plugin_registrant.h"

#include <kraken/kraken_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) kraken_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "KrakenPlugin");
kraken_plugin_register_with_registrar(kraken_registrar);
}
13 changes: 13 additions & 0 deletions kraken/example/linux/flutter/generated_plugin_registrant.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Generated file. Do not edit.
//

#ifndef GENERATED_PLUGIN_REGISTRANT_
#define GENERATED_PLUGIN_REGISTRANT_

#include <flutter_linux/flutter_linux.h>

// Registers Flutter plugins.
void fl_register_plugins(FlPluginRegistry* registry);

#endif // GENERATED_PLUGIN_REGISTRANT_