Skip to content

Commit

Permalink
chore: update flutter-template to latest rid api (#25)
Browse files Browse the repository at this point in the history
- updated dep versions
- removed no longer needed ffigen config
- improved setup script to consider OS and detect android support via
  `cargo ndk`
  • Loading branch information
thlorenz authored Sep 5, 2021
1 parent cced639 commit e87a757
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 31 deletions.
12 changes: 2 additions & 10 deletions rid-template-flutter/flutter/plugin/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@ description: Plugin to provide a bridge to Rust.
version: 0.0.1

environment:
sdk: ">=2.12.0 <=3.0.0"
sdk: ">=2.13.0 <3.0.0"
flutter: ">=2.0.0"

ffigen:
name: plugin
description: Plugin to provide a bridge to Rust.
output: 'lib/generated/ffigen_binding.dart'
headers:
entry-points:
- 'lib/generated/bindings.h'

dependencies:
ffi: ^1.0.0
ffigen: ^2.4.2
ffigen: 4.0.0-dev.2

flutter:
sdk: flutter
Expand Down
2 changes: 1 addition & 1 deletion rid-template-flutter/flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.13.0 <3.0.0"

dependencies:
flutter:
Expand Down
11 changes: 9 additions & 2 deletions rid-template-flutter/rust/rid_build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use rid_build::{build, BuildConfig, BuildTarget, FlutterConfig, FlutterPlatform, Project};
use rid_build::{
build, BuildConfig, BuildTarget, FlutterConfig, FlutterPlatform, Project,
};
use std::env;

fn main() {
Expand All @@ -16,9 +18,14 @@ fn main() {
project: Project::Flutter(FlutterConfig {
plugin_name: "plugin".to_string(),
platforms: vec![
// NOTE: Remove any of the below platforms that you don't support

// Mobile
FlutterPlatform::ios(),
FlutterPlatform::macos(),
FlutterPlatform::android(),
// Desktop
FlutterPlatform::macos(),
FlutterPlatform::linux(),
],
}),
lib_name,
Expand Down
38 changes: 29 additions & 9 deletions rid-template-flutter/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,42 @@ perl -pi -w -e "s/<package>/$APP_NAME/;" $APP_ROOT/pubspec.yaml

cp $TEMPLATE_ROOT/flutter/lib/main.dart $APP_ROOT/lib/main.dart

echo .DS_Store >> $APP_ROOT/.gitignore
echo .dart_tool/ >> $APP_ROOT/.gitignore
echo .packages >> $APP_ROOT/.gitignore
echo .pub/ >> $APP_ROOT/.gitignore
echo build/ >> $APP_ROOT/.gitignore
# gitignore
cp $TEMPLATE_ROOT/gitignore $APP_ROOT/.gitignore

# Build all Targets and have binding files copied and setup flutter plugin to hook things up
# Build all Targets that are most likely supported on the host OS
# and have binding files copied and setup flutter plugin to hook things up
$APP_ROOT/sh/bindgen

$APP_ROOT/sh/android
$APP_ROOT/sh/ios
$APP_ROOT/sh/macos
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
$APP_ROOT/sh/linux
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
$APP_ROOT/sh/ios
$APP_ROOT/sh/macos
fi

# Android builds are supported as long as the cargo ndk and the supporting Android sdk are
# installed
if command -v cargo-ndk &> /dev/null
then
$APP_ROOT/sh/android
else
echo "Not initializing Android build since the cargo-ndk dependency was not found."
echo "Install it following instructions here:"
echo " https://github.com/bbqsrc/cargo-ndk"
echo
echo "Install the Android NDK following one of the below instructions:"
echo " https://developers.google.com/ar/develop/c/quickstart"
echo " https://mozilla.github.io/firefox-browser-architecture/experiments/2017-09-21-rust-on-android.html"
fi

cd $APP_ROOT/plugin
flutter clean && flutter create .
rm -rf plugin.dart example test CHANGELOG.md README.md .idea

cd $APP_ROOT
flutter pub get

$APP_ROOT/sh/bindgen
3 changes: 1 addition & 2 deletions rid-template-flutter/sh/bindgen
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

cd $DIR/.. && cargo run rid_build && \
cd $DIR/../plugin && flutter pub run ffigen --verbose severe
cd $DIR/.. && cargo run rid_build
6 changes: 2 additions & 4 deletions rid-template-flutter/sh/ios
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@ FLUTTER_IOS_DIR="$DIR/../plugin/ios"
LIB_SOURCE_FILE="$UNIVERSAL_DEBUG_DIR/$LIB_NAME"
LIB_TARGET_FILE="$FLUTTER_IOS_DIR/$LIB_NAME"

cargo lipo \
--targets $IOS_TARGETS

cp $LIB_SOURCE_FILE $LIB_TARGET_FILE
cargo lipo --targets $IOS_TARGETS && \
cp $LIB_SOURCE_FILE $LIB_TARGET_FILE
5 changes: 2 additions & 3 deletions rid-template-flutter/sh/macos
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ FLUTTER_MACOS_DIR="$DIR/../plugin/macos"
LIB_SOURCE_FILE="$UNIVERSAL_DEBUG_DIR/$LIB_NAME"
LIB_TARGET_FILE="$FLUTTER_MACOS_DIR/$LIB_NAME"

cargo build

cp $LIB_SOURCE_FILE $LIB_TARGET_FILE
cargo build && \
cp $LIB_SOURCE_FILE $LIB_TARGET_FILE

0 comments on commit e87a757

Please sign in to comment.