This repository has been archived by the owner on Jul 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of package:flutter_wasm (#55)
* Initial commit of flutter plugin * Clean up * Add analysis github action for flutter_wasm * Add flutter tests, and use flutter for flutter_analyze * Loosen Dart SDK requirements * Comments * Switch from SSH to HTTPS git deps` * Relative path * Switch to flutter for analyze action * also in example! * Run setup script * Install NDK * Try the android SDK instead * Both NDK and SDK? * Trying newer versions of tools * Trying a different NDK install action * Fix yaml * Fix arch * Force install * Try adding ndkVersion * Try add-to-path flag * Add NDK to local.properties * Remove probably unnecessary flag from gradle file Co-authored-by: Kevin Moore <kevmoo@google.com>
- Loading branch information
1 parent
544b12b
commit fd25783
Showing
40 changed files
with
969 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.