Skip to content
Snippets Groups Projects
Commit ebc23172 authored by Shady Khalifa's avatar Shady Khalifa Committed by Éloïs
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 635 additions and 0 deletions
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# VS Code
.vscode/
# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/
# Web related
lib/generated_plugin_registrant.dart
# Exceptions to above rules.
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
# Rust things ...
/target
# Autogenerated binding code
native/dubp-ffi/binding.h
packages/dubp_rs/lib/ffi.dart
# 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: f139b11009aeb8ed2a3a3aa8b0066e482709dde3
channel: stable
project_type: app
This diff is collapsed.
[workspace]
members = ["native/*"]
[profile.release]
lto = true
codegen-units = 1
debug = true
\ No newline at end of file
This diff is collapsed.
[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS = ["native/dubp-ffi"]
ANDROID_PLATFORM_VERSION = "28"
LIB_OUT_DIR = "debug"
TARGET_OS = "unknown"
DEV = true
RELEASE = false
[env.release]
RELEASE = true
DEV = false
LIB_OUT_DIR = "release"
[tasks.test-flow]
disabled = true
[tasks.android-dev32]
description = "development android i686 emulator"
category = "Build"
dependencies = [
"setup-crate-type-android",
"pre-android",
"android-i686",
"android-i686-release",
"post-android-i686",
"post-android",
]
[tasks.android-dev]
description = "development android x86_64 emulator"
category = "Build"
dependencies = [
"setup-crate-type-android",
"pre-android",
"android-x86_64",
"android-x86_64-release",
"post-android-x86_64",
"post-android",
]
[tasks.android-arm]
description = "build android ARM64 for actual device"
category = "Build"
dependencies = [
"setup-crate-type-android",
"pre-android",
"android-aarch64",
"android-aarch64-release",
"post-android-aarch64",
"post-android",
]
[tasks.build]
description = "Runs the rust compiler."
category = "Build"
dependencies = ["android"]
[tasks.build.mac]
description = "Runs the rust compiler."
category = "Build"
dependencies = ["android", "ios"]
[tasks.ios]
description = "build iOS targets"
category = "Build"
dependencies = ["ios-build", "ios-release", "post-ios"]
[tasks.ios-build]
condition = { platforms = ["mac"], env_true = ["DEV"] }
description = "Build ios targets."
category = "Build"
command = "cargo"
args = ["lipo"]
dependencies = [
"setup-crate-type-ios",
]
[tasks.ios-release]
condition = { platforms = ["mac"], env_true = ["RELEASE"] }
description = "Build ios targets."
category = "Build"
command = "cargo"
args = ["lipo", "--release"]
dependencies = [
"setup-crate-type-ios",
]
[tasks.post-ios]
script_runner = "@duckscript"
condition = { platforms = ["mac"] }
script = [
"""
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/universal/${LIB_OUT_DIR}/lib${CARGO_MAKE_CRATE_FS_NAME}.a \
${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/packages/${CARGO_MAKE_CRATE_FS_NAME}/ios/lib${CARGO_MAKE_CRATE_FS_NAME}.a
""",
"""
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/native/${CARGO_MAKE_CRATE_CURRENT_WORKSPACE_MEMBER}/binding.h \
${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/packages/${CARGO_MAKE_CRATE_FS_NAME}/ios/Classes/binding.h
""",
]
dependencies = ["restore-crate-type"]
[tasks.android]
description = "Build android targets."
category = "Build"
dependencies = [
"setup-crate-type-android",
"pre-android",
"android-aarch64",
"android-aarch64-release",
"post-android-aarch64",
"android-armv7",
"android-armv7-release",
"post-android-armv7",
"android-i686",
"android-i686-release",
"post-android-i686",
"android-x86_64",
"android-x86_64-release",
"post-android-x86_64",
"post-android"
]
[tasks.android-build]
private = true
condition = { env_true = ["DEV"], env_set = ["ANDROID_TARGET"] }
command = "cargo"
args = [
"ndk",
"--platform",
"${ANDROID_PLATFORM_VERSION}",
"--target",
"${ANDROID_TARGET}",
"build",
]
[tasks.android-build-release]
private = true
condition = { env_true = ["RELEASE"], env_set = ["ANDROID_TARGET"] }
command = "cargo"
args = [
"ndk",
"--platform",
"${ANDROID_PLATFORM_VERSION}",
"--target",
"${ANDROID_TARGET}",
"build",
"--release"
]
[tasks.android-aarch64]
private = true
condition = { env_true = ["DEV"] }
env = { ANDROID_TARGET = "aarch64-linux-android" }
run_task = "android-build"
[tasks.android-armv7]
private = true
condition = { env_true = ["DEV"] }
env = { ANDROID_TARGET = "armv7-linux-androideabi" }
run_task = "android-build"
[tasks.android-i686]
private = true
condition = { env_true = ["DEV"] }
env = { ANDROID_TARGET = "i686-linux-android" }
run_task = "android-build"
[tasks.android-x86_64]
private = true
condition = { env_true = ["DEV"] }
env = { ANDROID_TARGET = "x86_64-linux-android" }
run_task = "android-build"
[tasks.android-aarch64-release]
private = true
condition = { env_true = ["RELEASE"] }
env = { ANDROID_TARGET = "aarch64-linux-android" }
run_task = "android-build-release"
[tasks.android-armv7-release]
private = true
condition = { env_true = ["RELEASE"] }
env = { ANDROID_TARGET = "armv7-linux-androideabi" }
run_task = "android-build-release"
[tasks.android-i686-release]
private = true
condition = { env_true = ["RELEASE"] }
env = { ANDROID_TARGET = "i686-linux-android" }
run_task = "android-build-release"
[tasks.android-x86_64-release]
private = true
condition = { env_true = ["RELEASE"] }
env = { ANDROID_TARGET = "x86_64-linux-android" }
run_task = "android-build-release"
[tasks.pre-android]
private = true
script_runner = "@duckscript"
script = [
"mkdir ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/packages/${CARGO_MAKE_CRATE_FS_NAME}/android/src/main/jniLibs/arm64-v8a",
"mkdir ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/packages/${CARGO_MAKE_CRATE_FS_NAME}/android/src/main/jniLibs/armeabi-v7a",
"mkdir ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/packages/${CARGO_MAKE_CRATE_FS_NAME}/android/src/main/jniLibs/x86",
"mkdir ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/packages/${CARGO_MAKE_CRATE_FS_NAME}/android/src/main/jniLibs/x86_64",
]
[tasks.copy-lib]
private = true
condition = { env_set = ["ANDROID_TARGET", "JNI_LIB_DIR"] }
script_runner = "@duckscript"
script = [
"""
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/${ANDROID_TARGET}/${LIB_OUT_DIR}/lib${CARGO_MAKE_CRATE_FS_NAME}.so \
${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/packages/${CARGO_MAKE_CRATE_FS_NAME}/android/src/main/jniLibs/${JNI_LIB_DIR}/lib${CARGO_MAKE_CRATE_FS_NAME}.so
""",
]
[tasks.post-android-aarch64]
private = true
env = { ANDROID_TARGET = "aarch64-linux-android", JNI_LIB_DIR = "arm64-v8a" }
run_task = "copy-lib"
[tasks.post-android-armv7]
private = true
env = { ANDROID_TARGET = "armv7-linux-androideabi", JNI_LIB_DIR = "armeabi-v7a" }
run_task = "copy-lib"
[tasks.post-android-i686]
private = true
env = { ANDROID_TARGET = "i686-linux-android", JNI_LIB_DIR = "x86" }
run_task = "copy-lib"
[tasks.post-android-x86_64]
private = true
env = { ANDROID_TARGET = "x86_64-linux-android", JNI_LIB_DIR = "x86_64" }
run_task = "copy-lib"
[tasks.post-android]
dependencies = ["restore-crate-type"]
[tasks.setup-crate-type-android]
private = true
env = { TARGET_OS = "android" }
run_task = "setup-crate-type"
[tasks.setup-crate-type-ios]
private = true
env = { TARGET_OS = "ios" }
run_task = "setup-crate-type"
[tasks.setup-crate-type]
private = true
script_runner = "@duckscript"
script = [
"""
toml = readfile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/native/${CARGO_MAKE_CRATE_CURRENT_WORKSPACE_MEMBER}/Cargo.toml
crate_type = set ""
os = get_env TARGET_OS
is_android = eq ${os} "android"
is_ios = eq ${os} "ios"
if ${is_android}
crate_type = set "cdylib"
elseif ${is_ios}
crate_type = set "staticlib"
else
crate_type = set "rlib"
end
val = replace ${toml} "rlib" ${crate_type}
result = writefile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/native/${CARGO_MAKE_CRATE_CURRENT_WORKSPACE_MEMBER}/Cargo.toml ${val}
assert ${result}
""",
]
[tasks.restore-crate-type]
private = true
script_runner = "@duckscript"
script = [
"""
toml = readfile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/native/${CARGO_MAKE_CRATE_CURRENT_WORKSPACE_MEMBER}/Cargo.toml
crate_type = set ""
os = get_env TARGET_OS
is_android = eq ${os} "android"
is_ios = eq ${os} "ios"
if ${is_android}
crate_type = set "cdylib"
elseif ${is_ios}
crate_type = set "staticlib"
else
crate_type = set "rlib"
end
val = replace ${toml} ${crate_type} "rlib"
result = writefile ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/native/${CARGO_MAKE_CRATE_CURRENT_WORKSPACE_MEMBER}/Cargo.toml ${val}
assert ${result}
""",
]
\ No newline at end of file
README.md 0 → 100644
# dubp-rs-flutter
Flutter + Rust = :heart:
Rust binding of [dubp-rs-libs] for flutter. Forked from template [flutterust].
## How to use it
See [dart plugin `dubp_rs` README](packages/dubp_rs/README.md).
## How it works?
The simple idea here is that we build our rust code for all supported targets
then build a Flutter Package that uses these targets.
For more details, see [flutterust] README.
[dubp-rs-libs]: https://git.duniter.org/libs/dubp-rs-libs
[flutterust]: https://github.com/shekohex/flutterust
## Project Structure
```tree
.
├── android
├── ios
├── lib <- The Flutter App Code
├── native <- Containes all the Rust Code
│ └── dubp-ffi
├── packages <- Containes all the Dart Packages that bind to the Rust Code
│ └── dubp-ffi
├── target <- The compiled rust code for every arch
│ ├── aarch64-apple-ios
│ ├── aarch64-linux-android
│ ├── armv7-linux-androideabi
│ ├── i686-linux-android
│ ├── x86_64-apple-ios
│ └── x86_64-linux-android
```
## Contribute
### Prerequisites
* Android SDK
* Android NDK
* Rust and cargo
* Cargo plugin cargo-make: `cargo install cargo-make`
* LLVM/Clang (see dedicated section below)
You will also need to add targets for all Android architectures:
```sh
rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android
```
If you develop on mac, you can also add targets for iOS:
```sh
rustup target add aarch64-apple-ios x86_64-apple-ios
```
### LLVM/Clang
The project use [`dart-bindgen`](https://github.com/sunshine-protocol/dart-bindgen) which requires LLVM/Clang. Install LLVM (10+) in the following way:
#### ubuntu/linux
1. Install libclangdev - `sudo apt-get install libclang-dev`.
#### Windows
1. Install Visual Studio with C++ development support.
2. Install [LLVM](https://releases.llvm.org/download.html) or `winget install -e --id LLVM.LLVM`.
#### MacOS
1. Install Xcode.
2. Install LLVM - `brew install llvm`.
## Build and Run
### Compile Rust
In the Root of the project simply run:
```sh
cargo make
```
WARNING: This will take a lot of time because the Rust code will have to be recompiled for each different architecture, 4 times for android and 2 times for iOS!
**To reduce the compilation time of the Rust code** during your development, you can **compile only for the target corresponding to your android emulator**. Here is how to do it **depending on the architecture of your emulator**:
* 32bit emulator (`x86`/`i686` architecture)
```sh
cargo make android-dev32
```
* 64bit emulator (`x86_64` architecture)
```sh
cargo make android-dev
```
### Create emulator
To test the project, you need a smartphone connected to your development computer. If you don't want to use a real physical smartphone, you can create an emulator:
```sh
flutter emulators --create
```
### Run flutter app
Then run flutter app normally:
```sh
flutter run
```
gradle-wrapper.jar
/.gradle
/captures/
/gradlew
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "me.librelois.dubp_flutter_example"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.librelois.dubp_flutter_example">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.librelois.dubp_flutter_example">
<uses-permission android:name="android.permission.INTERNET"/>
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="flutterust"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
package me.librelois.dubp_flutter_example
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" />
<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
android/app/src/main/res/mipmap-hdpi/ic_launcher.png

544 B

android/app/src/main/res/mipmap-mdpi/ic_launcher.png

442 B

android/app/src/main/res/mipmap-xhdpi/ic_launcher.png

721 B

android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png

1.01 KiB

android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png

1.41 KiB

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
</resources>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.librelois.dubp_flutter_example">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment