Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions .github/workflows/check_and_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ jobs:

Flutter:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./core/dart
steps:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v1
with:
channel: 'master'
- run: flutter pub get
- run: flutter format --output=none --set-exit-if-changed .
- run: flutter analyze
- run: flutter test
channel: "master"
- name: Install Melos
run: flutter pub global activate melos
- name: Melos Boostrap
run: melos bootstrap
- name: Flutter Format
run: melos exec -c 1 flutter format . --output=none --set-exit-if-changed
- name: Flutter Analyze
run: melos exec -c 1 flutter analyze
- name: Futter Test
run: melos exec -c 1 flutter test

Rustfmt:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -51,6 +54,9 @@ jobs:
- name: Install GTK
if: (matrix.os == 'ubuntu-latest')
run: sudo apt-get update && sudo apt-get install libgtk-3-dev
- name: Update rust
if: (matrix.os == 'ubuntu-latest')
run: rustup update
- uses: actions/checkout@v2
- name: Install clippy
run: rustup component add clippy
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ Cargo.lock
pubspec.lock
.flutter-plugins
.flutter-plugins-dependencies

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/<your program>",
"args": [],
"cwd": "${workspaceFolder}"
}
]
}
16 changes: 12 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
{
// "rust-analyzer.cargo.target": "aarch64-apple-ios",
"rust-analyzer.cargo.target": "aarch64-linux-android",
"rust-analyzer.runnableEnv": {
"RUST_TEST_THREADS": 1,
},
"rust-analyzer.cargo.allFeatures": false,
// "rust-analyzer.checkOnSave.allTargets": false,
"rust-analyzer.checkOnSave.command": "clippy",
"rust-analyzer.checkOnSave.allTargets": false,
// "rust-analyzer.cargo.unsetTest": [
// "nativeshell_core",
// ],
"rust-analyzer.cargo.features": [
"mock"
]
}
// "mock"
],
"dart.runPubGetOnPubspecChanges": "never"
}
35 changes: 35 additions & 0 deletions 0001-Fix-panic-in-finalizer.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
From 1505b454ce65d94b5fff83d6be437fd446a1bbfe Mon Sep 17 00:00:00 2001
From: Matej Knopp <matej.knopp@gmail.com>
Date: Sun, 17 Jul 2022 23:01:00 +0100
Subject: [PATCH 1/2] Fix panic in finalizer

---
core/rust/src/finalizable_handle.rs | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/core/rust/src/finalizable_handle.rs b/core/rust/src/finalizable_handle.rs
index 3e796c8..007b471 100644
--- a/core/rust/src/finalizable_handle.rs
+++ b/core/rust/src/finalizable_handle.rs
@@ -244,12 +244,12 @@ pub(crate) mod finalizable_handle_native {
state.objects.remove(&handle)
};
if let Some(mut object_state) = object_state {
- let mut finalizer = object_state
- .finalizer
- .take()
- .expect("Finalizer executed more than once");
- let finalizer = finalizer.take().unwrap();
- finalizer();
+ let finalizer = object_state.finalizer.take();
+ // Finalizer may have been removed in FinalizableHandle::drop
+ if let Some(mut finalizer) = finalizer {
+ let finalizer = finalizer.take().unwrap();
+ finalizer();
+ }
}
}

--
2.32.1 (Apple Git-133)

25 changes: 25 additions & 0 deletions 0002-Make-clippy-happy.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 1ee31acf95ae38e4b1db99a819ee991970b24d77 Mon Sep 17 00:00:00 2001
From: Matej Knopp <matej.knopp@gmail.com>
Date: Sun, 17 Jul 2022 23:05:34 +0100
Subject: [PATCH 2/2] Make clippy happy

---
core/rust/src/platform/darwin/run_loop.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/rust/src/platform/darwin/run_loop.rs b/core/rust/src/platform/darwin/run_loop.rs
index 93f9c51..a9dcd1d 100644
--- a/core/rust/src/platform/darwin/run_loop.rs
+++ b/core/rust/src/platform/darwin/run_loop.rs
@@ -330,7 +330,7 @@ impl PlatformRunLoop {
];

// To stop event loop immediately, we need to post event.
- let () = msg_send![app, postEvent: dummy_event atStart: YES];
+ let _: () = msg_send![app, postEvent: dummy_event atStart: YES];
}
}

--
2.32.1 (Apple Git-133)

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
[workspace]

members = [
"core/rust",
"core/rust_derive",
"core/rust",
"engine_context/rust",
"jni_context",
]

[patch.crates-io]
nativeshell_jni_context = { path = "jni_context" }
2 changes: 1 addition & 1 deletion core/rust/src/message_channel/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl<'a> Reader<'a> {
} else {
let v = &self.buf[self.pos..self.pos + len];
self.pos += len;
String::from_utf8_lossy(v).to_owned().to_string()
String::from_utf8_lossy(v).into()
}
}
fn align_to(&mut self, align: usize) {
Expand Down
3 changes: 3 additions & 0 deletions engine_context/dart/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0

* Initial release.
20 changes: 20 additions & 0 deletions engine_context/dart/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2022 Matej Knopp and the contributors

MIT LICENSE

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 changes: 28 additions & 0 deletions engine_context/dart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# flutter_engine_context

Flutter plugin that provides access to Flutter engine components (like view or texture registrar) from native code.

## Example

Dart code:
```dart
final handle = await FlutterEngineContext.instance.getEngineHandle();
// pass the handle native code (i.e. through FFI).
nativeMethod(handle);
```

Rust code:
```rust
let context = FlutterEngineContext::new();
let flutter_view = context.get_flutter_view(handle);
let texture_registry = contet.get_texture_registry(handle);
```

Rust code for Android:
```rust
let context = FlutterEngineContext::new(&jni_env, class_loader);
let flutter_view = context.get_flutter_view(handle);
let texture_registry = contet.get_texture_registry(handle);
```

On Android the `FlutterEngineContext` needs to be initialized with JNI environment and class loader used to load Flutter plugin (or application code).
4 changes: 4 additions & 0 deletions engine_context/dart/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
9 changes: 9 additions & 0 deletions engine_context/dart/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.cxx
35 changes: 35 additions & 0 deletions engine_context/dart/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
group 'dev.nativeshell.flutter_engine_context'
version '1.0'

buildscript {
repositories {
google()
mavenCentral()
}

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

rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 31

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion 16
}
}
1 change: 1 addition & 0 deletions engine_context/dart/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'flutter_engine_context'
3 changes: 3 additions & 0 deletions engine_context/dart/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.engine_context">
</manifest>
Loading