This repository was archived by the owner on Jul 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Initial commit of package:flutter_wasm #55
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
004b75b
Initial commit of flutter plugin
liamappelbe 468d50a
Clean up
liamappelbe cbeccd8
Add analysis github action for flutter_wasm
liamappelbe c541b8b
Add flutter tests, and use flutter for flutter_analyze
liamappelbe 50a8f4e
Loosen Dart SDK requirements
liamappelbe c206b6c
Comments
liamappelbe de811db
Switch from SSH to HTTPS git deps`
liamappelbe bcc7722
Relative path
liamappelbe 8326511
Switch to flutter for analyze action
liamappelbe ab64e36
also in example!
kevmoo 5a35279
Run setup script
liamappelbe ccf6b52
Install NDK
liamappelbe 31c71dc
Try the android SDK instead
liamappelbe f56652e
Both NDK and SDK?
liamappelbe b034244
Trying newer versions of tools
liamappelbe e0d1f01
Trying a different NDK install action
liamappelbe 0d73f37
Fix yaml
liamappelbe 980a6c5
Fix arch
liamappelbe c1662f0
Force install
liamappelbe d3fec90
Try adding ndkVersion
liamappelbe e62d439
Try add-to-path flag
liamappelbe 8ba697c
Add NDK to local.properties
liamappelbe 2681e01
Remove probably unnecessary flag from gradle file
liamappelbe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,3 +82,67 @@ jobs: | |
- run: dart pub upgrade | ||
- run: dart run wasm:setup | ||
- run: dart test | ||
|
||
flutter_analyze: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: flutter_wasm | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-java@v1 | ||
with: | ||
java-version: '12.x' | ||
- uses: subosito/[email protected] | ||
with: | ||
flutter-version: '2.5.0' | ||
- id: install | ||
run: | | ||
flutter pub upgrade | ||
flutter pub upgrade --directory example | ||
- run: flutter format --output=none --set-exit-if-changed . | ||
if: always() && steps.install.outcome == 'success' | ||
- run: flutter analyze --fatal-infos | ||
if: always() && steps.install.outcome == 'success' | ||
|
||
flutter_test: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: flutter_wasm | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-java@v1 | ||
with: | ||
java-version: '12.x' | ||
- uses: subosito/[email protected] | ||
with: | ||
flutter-version: '2.5.0' | ||
- run: flutter pub upgrade | ||
- run: flutter pub run wasm:setup | ||
- run: flutter test | ||
|
||
flutter_example_test: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: flutter_wasm/example | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-java@v1 | ||
with: | ||
java-version: '12.x' | ||
- uses: android-actions/[email protected] | ||
- uses: nttld/setup-ndk@v1 | ||
with: | ||
ndk-version: r21e | ||
add-to-path: true | ||
- run: echo "ndk.dir=$(dirname $(which ndk-build))" >> android/local.properties | ||
- uses: subosito/[email protected] | ||
with: | ||
flutter-version: '2.5.0' | ||
- run: flutter pub upgrade | ||
- run: flutter pub run wasm:setup | ||
- run: flutter test | ||
- run: flutter build apk | ||
- run: flutter build appbundle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
/pubspec.lock | ||
**/doc/api/ | ||
.dart_tool/ | ||
.packages | ||
build/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: d5396898bed65dacfb355fb6e52ec7ccf76746d9 | ||
channel: unknown | ||
|
||
project_type: plugin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.0.1 | ||
|
||
- Initial version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Provides utilities for loading and running WASM modules in Flutter apps. | ||
Currently only Android is supported. | ||
|
||
This is a wrapper around [package:wasm](https://github.com/dart-lang/wasm/blob/main/wasm/README.md). | ||
See that package for more information and documentation. The basic | ||
usage is mostly the same as in that package. The main thing this plugin does is | ||
run `wasm:setup` for your target device during app compilation. | ||
|
||
## Usage | ||
|
||
1. Add a dependency to *both* package `wasm` and `flutter_wasm` in | ||
`pubspec.yaml` and run `flutter pub get`. [#52](https://github.com/dart-lang/wasm/issues/52) | ||
|
||
1. Next run `flutter run wasm:setup` to build the Wasmer runtime for your host | ||
machine. This does not build the runtime for your target device. It will take a | ||
few minutes. | ||
|
||
1. Load your wasm code in your app. See the [example app](https://github.com/dart-lang/wasm/blob/main/flutter_wasm/example/lib/main.dart). | ||
|
||
1. Run your app using `flutter run`. If you see an error at runtime saying | ||
"libwasmer.so not found", just try rebuiling. The first build sometimes fails. | ||
[#51](https://github.com/dart-lang/wasm/issues/51) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
group 'dev.dart.flutter_wasm' | ||
version '1.0-SNAPSHOT' | ||
|
||
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform | ||
|
||
buildscript { | ||
ext.kotlin_version = '1.3.50' | ||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
classpath 'com.android.tools.build:gradle:4.1.0' | ||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||
} | ||
} | ||
|
||
rootProject.allprojects { | ||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
|
||
android { | ||
compileSdkVersion 30 | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
|
||
sourceSets { | ||
main.java.srcDirs += 'src/main/kotlin' | ||
} | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
} | ||
|
||
def hostOs = DefaultNativePlatform.currentOperatingSystem.getName().toLowerCase() | ||
def hostArch = DefaultNativePlatform.currentArchitecture.getName().replaceAll('-', '_') | ||
def ndkBinDir = "${android.ndkDirectory}/toolchains/llvm/prebuilt/${hostOs}-${hostArch}/bin" | ||
def projectProperties = new Properties() | ||
projectProperties.load(project.rootProject.file('local.properties').newDataInputStream()) | ||
def flutterDir = projectProperties.getProperty('flutter.sdk') | ||
def platformVersion = -1 | ||
fileTree("${android.ndkDirectory}/platforms").visit { FileVisitDetails details -> | ||
if (details.isDirectory() && details.name.startsWith("android-")) { | ||
platformVersion = Math.max(platformVersion, details.name.substring(8) as int) | ||
} | ||
} | ||
if (platformVersion < 0) { | ||
throw new Exception("Can't find any valid platforms in ${android.ndkDirectory}/platforms") | ||
} | ||
|
||
tasks.register('wasm-pub-get') { | ||
doLast { | ||
exec { | ||
workingDir '..' | ||
commandLine "${flutterDir}/bin/flutter", 'pub', 'get' | ||
} | ||
} | ||
} | ||
|
||
def architectures = [ | ||
['arm64-v8a', 'aarch64-linux-android', 'aarch64-linux-android', 'aarch64-linux-android', 'arch-arm64'], | ||
['x86', 'i686-linux-android', 'i686-linux-android', 'i686-linux-android', 'arch-x86'], | ||
|
||
// TODO(#53,#54): Enable these when they're supported by Wasmer. | ||
// ['armeabi-v7a', 'armv7a-linux-androideabi', 'arm-linux-androideabi', 'armv7-linux-androideabi', 'arch-arm'], | ||
// ['x86_64', 'x86_64-linux-android', 'x86_64-linux-android', 'x86_64-linux-android', 'arch-x86_64'], | ||
] | ||
for (arch in architectures) { | ||
def abi = arch[0] | ||
def clangPrefix = "${arch[1]}${platformVersion}" | ||
def arPrefix = arch[2] | ||
def rustTriple = arch[3] | ||
def sysroot = arch[4] | ||
def sysrootDir = "${android.ndkDirectory}/platforms/android-${platformVersion}/${sysroot}" | ||
def outDir = "${rootDir}/../build/app/intermediates/stripped_native_libs/debug/out/lib/${abi}/" | ||
|
||
tasks.register("wasm-lib-${abi}") { | ||
// Specify inputs and outputs so that incremental build works properly. | ||
inputs.property('platformVersion', platformVersion) | ||
inputs.property('abi', abi) | ||
outputs.file("${outDir}/libwasmer.so") | ||
|
||
dependsOn('wasm-pub-get') | ||
|
||
doLast { | ||
exec { | ||
workingDir '..' | ||
commandLine "${flutterDir}/bin/flutter", 'pub', 'run', 'wasm:setup', | ||
'--sysroot', sysrootDir, | ||
'--target', rustTriple, | ||
'--clang', "${ndkBinDir}/${clangPrefix}-clang", | ||
'--clangpp', "${ndkBinDir}/${clangPrefix}-clang++", | ||
'--ar', "${ndkBinDir}/${arPrefix}-ar", | ||
'-o', outDir | ||
} | ||
} | ||
} | ||
} | ||
|
||
tasks.withType(JavaCompile) { compileTask -> | ||
for (arch in architectures) { | ||
def abi = arch[0] | ||
compileTask.dependsOn("wasm-lib-${abi}") | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootProject.name = 'flutter_wasm' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="dev.dart.flutter_wasm"> | ||
</manifest> |
15 changes: 15 additions & 0 deletions
15
flutter_wasm/android/src/main/kotlin/dev/dart/flutter_wasm/FlutterWasmPlugin.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
package dev.dart.flutter_wasm | ||
|
||
import androidx.annotation.NonNull | ||
|
||
import io.flutter.embedding.engine.plugins.FlutterPlugin | ||
|
||
/** FlutterWasmPlugin */ | ||
class FlutterWasmPlugin: FlutterPlugin { | ||
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {} | ||
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
**/doc/api/ | ||
**/ios/Flutter/.last_build_id | ||
.dart_tool/ | ||
.flutter-plugins | ||
.flutter-plugins-dependencies | ||
.packages | ||
.pub-cache/ | ||
.pub/ | ||
/build/ | ||
|
||
# Web related | ||
lib/generated_plugin_registrant.dart | ||
|
||
# Symbolication related | ||
app.*.symbols | ||
|
||
# Obfuscation related | ||
app.*.map.json | ||
|
||
# Android Studio will place build artifacts here | ||
/android/app/debug | ||
/android/app/profile | ||
/android/app/release |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: d5396898bed65dacfb355fb6e52ec7ccf76746d9 | ||
channel: unknown | ||
|
||
project_type: app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# flutter_wasm_example | ||
|
||
Demonstrates how to use the flutter_wasm plugin. | ||
|
||
## Getting Started | ||
|
||
This project is a starting point for a Flutter application. | ||
|
||
A few resources to get you started if this is your first Flutter project: | ||
|
||
- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab) | ||
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook) | ||
|
||
For help getting started with Flutter, view our | ||
[online documentation](https://flutter.dev/docs), which offers tutorials, | ||
samples, guidance on mobile development, and a full API reference. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
gradle-wrapper.jar | ||
/.gradle | ||
/captures/ | ||
/gradlew | ||
/gradlew.bat | ||
/local.properties | ||
GeneratedPluginRegistrant.java | ||
|
||
# Remember to never publicly share your keystore. | ||
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app | ||
key.properties | ||
**/*.keystore | ||
**/*.jks |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liamappelbe – now analyze is working – need to run upgrade in both dirs!