Skip to content

Commit 2743aae

Browse files
committed
Add rust package for plugin system
1 parent ba8e47a commit 2743aae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+5779
-11
lines changed

app/lib/main.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import 'package:setonix/theme.dart';
1919
import 'package:shared_preferences/shared_preferences.dart';
2020
import 'package:flutter_localized_locales/flutter_localized_locales.dart';
2121
import 'package:window_manager/window_manager.dart';
22+
import 'package:setonix_plugin/setonix_plugin.dart';
2223

2324
import 'bloc/settings.dart';
2425
import 'pages/settings/page.dart';
@@ -44,6 +45,11 @@ Future<void> main(List<String> args) async {
4445
await networkService.init();
4546

4647
await setup(settingsCubit);
48+
49+
await initPluginSystem();
50+
if (kDebugMode) {
51+
print('6 + 8 = ${await simpleAdderTwinNormal(a: 6, b: 8)}');
52+
}
4753
runApp(
4854
MultiBlocProvider(
4955
providers: [

app/linux/flutter/generated_plugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
1212
)
1313

1414
list(APPEND FLUTTER_FFI_PLUGIN_LIST
15+
rust_lib_setonix_plugin
1516
)
1617

1718
set(PLUGIN_BUNDLED_LIBRARIES)

app/pubspec.lock

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ packages:
9494
url: "https://pub.dev"
9595
source: hosted
9696
version: "2.4.2"
97+
build_cli_annotations:
98+
dependency: transitive
99+
description:
100+
name: build_cli_annotations
101+
sha256: b59d2769769efd6c9ff6d4c4cede0be115a566afc591705c2040b707534b1172
102+
url: "https://pub.dev"
103+
source: hosted
104+
version: "2.1.0"
97105
build_config:
98106
dependency: transitive
99107
description:
@@ -454,6 +462,14 @@ packages:
454462
url: "https://pub.dev"
455463
source: hosted
456464
version: "0.7.5"
465+
flutter_rust_bridge:
466+
dependency: "direct main"
467+
description:
468+
name: flutter_rust_bridge
469+
sha256: "35c257fc7f98e34c1314d6c145e5ed54e7c94e8a9f469947e31c9298177d546f"
470+
url: "https://pub.dev"
471+
source: hosted
472+
version: "2.7.0"
457473
flutter_secure_storage:
458474
dependency: "direct main"
459475
description:
@@ -520,6 +536,14 @@ packages:
520536
description: flutter
521537
source: sdk
522538
version: "0.0.0"
539+
freezed_annotation:
540+
dependency: transitive
541+
description:
542+
name: freezed_annotation
543+
sha256: c2e2d632dd9b8a2b7751117abcfc2b4888ecfe181bd9fca7170d9ef02e595fe2
544+
url: "https://pub.dev"
545+
source: hosted
546+
version: "2.4.4"
523547
frontend_server_client:
524548
dependency: transitive
525549
description:
@@ -614,10 +638,10 @@ packages:
614638
dependency: transitive
615639
description:
616640
name: js
617-
sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf
641+
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
618642
url: "https://pub.dev"
619643
source: hosted
620-
version: "0.7.1"
644+
version: "0.6.7"
621645
json_annotation:
622646
dependency: transitive
623647
description:
@@ -960,6 +984,13 @@ packages:
960984
url: "https://pub.dev"
961985
source: hosted
962986
version: "3.0.2"
987+
rust_lib_setonix_plugin:
988+
dependency: "direct main"
989+
description:
990+
path: rust_builder
991+
relative: true
992+
source: path
993+
version: "0.0.1"
963994
rxdart:
964995
dependency: "direct main"
965996
description:
@@ -1023,6 +1054,13 @@ packages:
10231054
relative: true
10241055
source: path
10251056
version: "0.2.0"
1057+
setonix_plugin:
1058+
dependency: "direct main"
1059+
description:
1060+
path: "../plugin"
1061+
relative: true
1062+
source: path
1063+
version: "1.0.0"
10261064
share_plus:
10271065
dependency: transitive
10281066
description:

app/pubspec.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ dependencies:
8989
markdown: ^7.2.2
9090
bloc_concurrency: ^0.2.5
9191
idb_shim: ^2.6.1+7
92+
rust_lib_setonix_plugin:
93+
path: rust_builder
94+
setonix_plugin:
95+
path: ../plugin
96+
flutter_rust_bridge: 2.7.0
9297
dependency_overrides:
9398
tiled:
9499
git:

app/rust_builder/.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
26+
/pubspec.lock
27+
**/doc/api/
28+
.dart_tool/
29+
build/

app/rust_builder/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Please ignore this folder, which is just glue to build Rust with Flutter.

app/rust_builder/android/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.cxx

app/rust_builder/android/build.gradle

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// The Android Gradle Plugin builds the native code with the Android NDK.
2+
3+
group 'com.flutter_rust_bridge.rust_lib_setonix_plugin'
4+
version '1.0'
5+
6+
buildscript {
7+
repositories {
8+
google()
9+
mavenCentral()
10+
}
11+
12+
dependencies {
13+
// The Android Gradle Plugin knows how to build native code with the NDK.
14+
classpath 'com.android.tools.build:gradle:7.3.0'
15+
}
16+
}
17+
18+
rootProject.allprojects {
19+
repositories {
20+
google()
21+
mavenCentral()
22+
}
23+
}
24+
25+
apply plugin: 'com.android.library'
26+
27+
android {
28+
if (project.android.hasProperty("namespace")) {
29+
namespace 'com.flutter_rust_bridge.rust_lib_setonix_plugin'
30+
}
31+
32+
// Bumping the plugin compileSdkVersion requires all clients of this plugin
33+
// to bump the version in their app.
34+
compileSdkVersion 33
35+
36+
// Use the NDK version
37+
// declared in /android/app/build.gradle file of the Flutter project.
38+
// Replace it with a version number if this plugin requires a specfic NDK version.
39+
// (e.g. ndkVersion "23.1.7779620")
40+
ndkVersion android.ndkVersion
41+
42+
compileOptions {
43+
sourceCompatibility JavaVersion.VERSION_1_8
44+
targetCompatibility JavaVersion.VERSION_1_8
45+
}
46+
47+
defaultConfig {
48+
minSdkVersion 19
49+
}
50+
}
51+
52+
apply from: "../cargokit/gradle/plugin.gradle"
53+
cargokit {
54+
manifestDir = "../../../plugin/rust"
55+
libname = "rust_lib_setonix_plugin"
56+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'rust_lib_setonix'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.flutter_rust_bridge.rust_lib_setonix">
3+
</manifest>

app/rust_builder/cargokit/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
target
2+
.dart_tool
3+
*.iml
4+
!pubspec.lock

app/rust_builder/cargokit/LICENSE

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/// This is copied from Cargokit (which is the official way to use it currently)
2+
/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
3+
4+
Copyright 2022 Matej Knopp
5+
6+
================================================================================
7+
8+
MIT LICENSE
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"), to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14+
of the Software, and to permit persons to whom the Software is furnished to do
15+
so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in all
18+
copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
22+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
23+
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
25+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
27+
================================================================================
28+
29+
APACHE LICENSE, VERSION 2.0
30+
31+
Licensed under the Apache License, Version 2.0 (the "License");
32+
you may not use this file except in compliance with the License.
33+
You may obtain a copy of the License at
34+
35+
http://www.apache.org/licenses/LICENSE-2.0
36+
37+
Unless required by applicable law or agreed to in writing, software
38+
distributed under the License is distributed on an "AS IS" BASIS,
39+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40+
See the License for the specific language governing permissions and
41+
limitations under the License.
42+

app/rust_builder/cargokit/README

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// This is copied from Cargokit (which is the official way to use it currently)
2+
/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
3+
4+
Experimental repository to provide glue for seamlessly integrating cargo build
5+
with flutter plugins and packages.
6+
7+
See https://matejknopp.com/post/flutter_plugin_in_rust_with_no_prebuilt_binaries/
8+
for a tutorial on how to use Cargokit.
9+
10+
Example plugin available at https://github.com/irondash/hello_rust_ffi_plugin.
11+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/sh
2+
set -e
3+
4+
BASEDIR=$(dirname "$0")
5+
6+
# Workaround for https://github.com/dart-lang/pub/issues/4010
7+
BASEDIR=$(cd "$BASEDIR" ; pwd -P)
8+
9+
# Remove XCode SDK from path. Otherwise this breaks tool compilation when building iOS project
10+
NEW_PATH=`echo $PATH | tr ":" "\n" | grep -v "Contents/Developer/" | tr "\n" ":"`
11+
12+
export PATH=${NEW_PATH%?} # remove trailing :
13+
14+
env
15+
16+
# Platform name (macosx, iphoneos, iphonesimulator)
17+
export CARGOKIT_DARWIN_PLATFORM_NAME=$PLATFORM_NAME
18+
19+
# Arctive architectures (arm64, armv7, x86_64), space separated.
20+
export CARGOKIT_DARWIN_ARCHS=$ARCHS
21+
22+
# Current build configuration (Debug, Release)
23+
export CARGOKIT_CONFIGURATION=$CONFIGURATION
24+
25+
# Path to directory containing Cargo.toml.
26+
export CARGOKIT_MANIFEST_DIR=$PODS_TARGET_SRCROOT/$1
27+
28+
# Temporary directory for build artifacts.
29+
export CARGOKIT_TARGET_TEMP_DIR=$TARGET_TEMP_DIR
30+
31+
# Output directory for final artifacts.
32+
export CARGOKIT_OUTPUT_DIR=$PODS_CONFIGURATION_BUILD_DIR/$PRODUCT_NAME
33+
34+
# Directory to store built tool artifacts.
35+
export CARGOKIT_TOOL_TEMP_DIR=$TARGET_TEMP_DIR/build_tool
36+
37+
# Directory inside root project. Not necessarily the top level directory of root project.
38+
export CARGOKIT_ROOT_PROJECT_DIR=$SRCROOT
39+
40+
FLUTTER_EXPORT_BUILD_ENVIRONMENT=(
41+
"$PODS_ROOT/../Flutter/ephemeral/flutter_export_environment.sh" # macOS
42+
"$PODS_ROOT/../Flutter/flutter_export_environment.sh" # iOS
43+
)
44+
45+
for path in "${FLUTTER_EXPORT_BUILD_ENVIRONMENT[@]}"
46+
do
47+
if [[ -f "$path" ]]; then
48+
source "$path"
49+
fi
50+
done
51+
52+
sh "$BASEDIR/run_build_tool.sh" build-pod "$@"
53+
54+
# Make a symlink from built framework to phony file, which will be used as input to
55+
# build script. This should force rebuild (podspec currently doesn't support alwaysOutOfDate
56+
# attribute on custom build phase)
57+
ln -fs "$OBJROOT/XCBuildData/build.db" "${BUILT_PRODUCTS_DIR}/cargokit_phony"
58+
ln -fs "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}" "${BUILT_PRODUCTS_DIR}/cargokit_phony_out"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// This is copied from Cargokit (which is the official way to use it currently)
2+
/// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
3+
4+
A sample command-line application with an entrypoint in `bin/`, library code
5+
in `lib/`, and example unit test in `test/`.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This is copied from Cargokit (which is the official way to use it currently)
2+
# Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin
3+
4+
# This file configures the static analysis results for your project (errors,
5+
# warnings, and lints).
6+
#
7+
# This enables the 'recommended' set of lints from `package:lints`.
8+
# This set helps identify many issues that may lead to problems when running
9+
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
10+
# style and format.
11+
#
12+
# If you want a smaller set of lints you can change this to specify
13+
# 'package:lints/core.yaml'. These are just the most critical lints
14+
# (the recommended set includes the core lints).
15+
# The core lints are also what is used by pub.dev for scoring packages.
16+
17+
include: package:lints/recommended.yaml
18+
19+
# Uncomment the following section to specify additional rules.
20+
21+
linter:
22+
rules:
23+
- prefer_relative_imports
24+
- directives_ordering
25+
26+
# analyzer:
27+
# exclude:
28+
# - path/to/excluded/files/**
29+
30+
# For more information about the core and recommended set of lints, see
31+
# https://dart.dev/go/core-lints
32+
33+
# For additional information about configuring this file, see
34+
# https://dart.dev/guides/language/analysis-options

0 commit comments

Comments
 (0)