Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Commit fd25783

Browse files
liamappelbekevmoo
andauthored
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 <[email protected]>
1 parent 544b12b commit fd25783

40 files changed

+969
-1
lines changed

.github/workflows/test-package.yml

+64
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,67 @@ jobs:
8282
- run: dart pub upgrade
8383
- run: dart run wasm:setup
8484
- run: dart test
85+
86+
flutter_analyze:
87+
runs-on: ubuntu-latest
88+
defaults:
89+
run:
90+
working-directory: flutter_wasm
91+
steps:
92+
- uses: actions/checkout@v2
93+
- uses: actions/setup-java@v1
94+
with:
95+
java-version: '12.x'
96+
- uses: subosito/[email protected]
97+
with:
98+
flutter-version: '2.5.0'
99+
- id: install
100+
run: |
101+
flutter pub upgrade
102+
flutter pub upgrade --directory example
103+
- run: flutter format --output=none --set-exit-if-changed .
104+
if: always() && steps.install.outcome == 'success'
105+
- run: flutter analyze --fatal-infos
106+
if: always() && steps.install.outcome == 'success'
107+
108+
flutter_test:
109+
runs-on: ubuntu-latest
110+
defaults:
111+
run:
112+
working-directory: flutter_wasm
113+
steps:
114+
- uses: actions/checkout@v2
115+
- uses: actions/setup-java@v1
116+
with:
117+
java-version: '12.x'
118+
- uses: subosito/[email protected]
119+
with:
120+
flutter-version: '2.5.0'
121+
- run: flutter pub upgrade
122+
- run: flutter pub run wasm:setup
123+
- run: flutter test
124+
125+
flutter_example_test:
126+
runs-on: ubuntu-latest
127+
defaults:
128+
run:
129+
working-directory: flutter_wasm/example
130+
steps:
131+
- uses: actions/checkout@v2
132+
- uses: actions/setup-java@v1
133+
with:
134+
java-version: '12.x'
135+
- uses: android-actions/[email protected]
136+
- uses: nttld/setup-ndk@v1
137+
with:
138+
ndk-version: r21e
139+
add-to-path: true
140+
- run: echo "ndk.dir=$(dirname $(which ndk-build))" >> android/local.properties
141+
- uses: subosito/[email protected]
142+
with:
143+
flutter-version: '2.5.0'
144+
- run: flutter pub upgrade
145+
- run: flutter pub run wasm:setup
146+
- run: flutter test
147+
- run: flutter build apk
148+
- run: flutter build appbundle

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ These packages provide utilities for loading and running WASM modules.
44

55
Runs WASM modules in Dart native.
66

7-
## flutter_wasm (coming soon)
7+
## [flutter_wasm](https://github.com/dart-lang/wasm/blob/main/flutter_wasm/README.md)
88

99
Runs WASM modules in Flutter.

flutter_wasm/.gitignore

+29
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+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
25+
/pubspec.lock
26+
**/doc/api/
27+
.dart_tool/
28+
.packages
29+
build/

flutter_wasm/.metadata

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: d5396898bed65dacfb355fb6e52ec7ccf76746d9
8+
channel: unknown
9+
10+
project_type: plugin

flutter_wasm/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.0.1
2+
3+
- Initial version

flutter_wasm/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Provides utilities for loading and running WASM modules in Flutter apps.
2+
Currently only Android is supported.
3+
4+
This is a wrapper around [package:wasm](https://github.com/dart-lang/wasm/blob/main/wasm/README.md).
5+
See that package for more information and documentation. The basic
6+
usage is mostly the same as in that package. The main thing this plugin does is
7+
run `wasm:setup` for your target device during app compilation.
8+
9+
## Usage
10+
11+
1. Add a dependency to *both* package `wasm` and `flutter_wasm` in
12+
`pubspec.yaml` and run `flutter pub get`. [#52](https://github.com/dart-lang/wasm/issues/52)
13+
14+
1. Next run `flutter run wasm:setup` to build the Wasmer runtime for your host
15+
machine. This does not build the runtime for your target device. It will take a
16+
few minutes.
17+
18+
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).
19+
20+
1. Run your app using `flutter run`. If you see an error at runtime saying
21+
"libwasmer.so not found", just try rebuiling. The first build sometimes fails.
22+
[#51](https://github.com/dart-lang/wasm/issues/51)

flutter_wasm/android/.gitignore

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

flutter_wasm/android/build.gradle

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
group 'dev.dart.flutter_wasm'
6+
version '1.0-SNAPSHOT'
7+
8+
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
9+
10+
buildscript {
11+
ext.kotlin_version = '1.3.50'
12+
repositories {
13+
google()
14+
mavenCentral()
15+
}
16+
17+
dependencies {
18+
classpath 'com.android.tools.build:gradle:4.1.0'
19+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
20+
}
21+
}
22+
23+
rootProject.allprojects {
24+
repositories {
25+
google()
26+
mavenCentral()
27+
}
28+
}
29+
30+
apply plugin: 'com.android.library'
31+
apply plugin: 'kotlin-android'
32+
33+
android {
34+
compileSdkVersion 30
35+
36+
compileOptions {
37+
sourceCompatibility JavaVersion.VERSION_1_8
38+
targetCompatibility JavaVersion.VERSION_1_8
39+
}
40+
41+
kotlinOptions {
42+
jvmTarget = '1.8'
43+
}
44+
45+
sourceSets {
46+
main.java.srcDirs += 'src/main/kotlin'
47+
}
48+
49+
defaultConfig {
50+
minSdkVersion 16
51+
}
52+
53+
def hostOs = DefaultNativePlatform.currentOperatingSystem.getName().toLowerCase()
54+
def hostArch = DefaultNativePlatform.currentArchitecture.getName().replaceAll('-', '_')
55+
def ndkBinDir = "${android.ndkDirectory}/toolchains/llvm/prebuilt/${hostOs}-${hostArch}/bin"
56+
def projectProperties = new Properties()
57+
projectProperties.load(project.rootProject.file('local.properties').newDataInputStream())
58+
def flutterDir = projectProperties.getProperty('flutter.sdk')
59+
def platformVersion = -1
60+
fileTree("${android.ndkDirectory}/platforms").visit { FileVisitDetails details ->
61+
if (details.isDirectory() && details.name.startsWith("android-")) {
62+
platformVersion = Math.max(platformVersion, details.name.substring(8) as int)
63+
}
64+
}
65+
if (platformVersion < 0) {
66+
throw new Exception("Can't find any valid platforms in ${android.ndkDirectory}/platforms")
67+
}
68+
69+
tasks.register('wasm-pub-get') {
70+
doLast {
71+
exec {
72+
workingDir '..'
73+
commandLine "${flutterDir}/bin/flutter", 'pub', 'get'
74+
}
75+
}
76+
}
77+
78+
def architectures = [
79+
['arm64-v8a', 'aarch64-linux-android', 'aarch64-linux-android', 'aarch64-linux-android', 'arch-arm64'],
80+
['x86', 'i686-linux-android', 'i686-linux-android', 'i686-linux-android', 'arch-x86'],
81+
82+
// TODO(#53,#54): Enable these when they're supported by Wasmer.
83+
// ['armeabi-v7a', 'armv7a-linux-androideabi', 'arm-linux-androideabi', 'armv7-linux-androideabi', 'arch-arm'],
84+
// ['x86_64', 'x86_64-linux-android', 'x86_64-linux-android', 'x86_64-linux-android', 'arch-x86_64'],
85+
]
86+
for (arch in architectures) {
87+
def abi = arch[0]
88+
def clangPrefix = "${arch[1]}${platformVersion}"
89+
def arPrefix = arch[2]
90+
def rustTriple = arch[3]
91+
def sysroot = arch[4]
92+
def sysrootDir = "${android.ndkDirectory}/platforms/android-${platformVersion}/${sysroot}"
93+
def outDir = "${rootDir}/../build/app/intermediates/stripped_native_libs/debug/out/lib/${abi}/"
94+
95+
tasks.register("wasm-lib-${abi}") {
96+
// Specify inputs and outputs so that incremental build works properly.
97+
inputs.property('platformVersion', platformVersion)
98+
inputs.property('abi', abi)
99+
outputs.file("${outDir}/libwasmer.so")
100+
101+
dependsOn('wasm-pub-get')
102+
103+
doLast {
104+
exec {
105+
workingDir '..'
106+
commandLine "${flutterDir}/bin/flutter", 'pub', 'run', 'wasm:setup',
107+
'--sysroot', sysrootDir,
108+
'--target', rustTriple,
109+
'--clang', "${ndkBinDir}/${clangPrefix}-clang",
110+
'--clangpp', "${ndkBinDir}/${clangPrefix}-clang++",
111+
'--ar', "${ndkBinDir}/${arPrefix}-ar",
112+
'-o', outDir
113+
}
114+
}
115+
}
116+
}
117+
118+
tasks.withType(JavaCompile) { compileTask ->
119+
for (arch in architectures) {
120+
def abi = arch[0]
121+
compileTask.dependsOn("wasm-lib-${abi}")
122+
}
123+
}
124+
}
125+
126+
dependencies {
127+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
128+
}

flutter_wasm/android/settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'flutter_wasm'
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="dev.dart.flutter_wasm">
3+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
package dev.dart.flutter_wasm
6+
7+
import androidx.annotation.NonNull
8+
9+
import io.flutter.embedding.engine.plugins.FlutterPlugin
10+
11+
/** FlutterWasmPlugin */
12+
class FlutterWasmPlugin: FlutterPlugin {
13+
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {}
14+
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {}
15+
}

flutter_wasm/example/.gitignore

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
**/ios/Flutter/.last_build_id
26+
.dart_tool/
27+
.flutter-plugins
28+
.flutter-plugins-dependencies
29+
.packages
30+
.pub-cache/
31+
.pub/
32+
/build/
33+
34+
# Web related
35+
lib/generated_plugin_registrant.dart
36+
37+
# Symbolication related
38+
app.*.symbols
39+
40+
# Obfuscation related
41+
app.*.map.json
42+
43+
# Android Studio will place build artifacts here
44+
/android/app/debug
45+
/android/app/profile
46+
/android/app/release

flutter_wasm/example/.metadata

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: d5396898bed65dacfb355fb6e52ec7ccf76746d9
8+
channel: unknown
9+
10+
project_type: app

flutter_wasm/example/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# flutter_wasm_example
2+
3+
Demonstrates how to use the flutter_wasm plugin.
4+
5+
## Getting Started
6+
7+
This project is a starting point for a Flutter application.
8+
9+
A few resources to get you started if this is your first Flutter project:
10+
11+
- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
12+
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)
13+
14+
For help getting started with Flutter, view our
15+
[online documentation](https://flutter.dev/docs), which offers tutorials,
16+
samples, guidance on mobile development, and a full API reference.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
gradle-wrapper.jar
2+
/.gradle
3+
/captures/
4+
/gradlew
5+
/gradlew.bat
6+
/local.properties
7+
GeneratedPluginRegistrant.java
8+
9+
# Remember to never publicly share your keystore.
10+
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11+
key.properties
12+
**/*.keystore
13+
**/*.jks

0 commit comments

Comments
 (0)