Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Commit

Permalink
Bootstrap 'medea_jason' Flutter plugin (#190, #182)
Browse files Browse the repository at this point in the history
- create 'medea_jason' Flutter plugin template
- setup Flutter toolchain in Makefile and on CI workflow
  • Loading branch information
evdokimovs authored Apr 20, 2021
1 parent 2cba373 commit 663a294
Show file tree
Hide file tree
Showing 44 changed files with 864 additions and 9 deletions.
98 changes: 96 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
components: clippy
- uses: Swatinem/rust-cache@v1
if: ${{ !contains(github.event.head_commit.message, '[fresh ci]') }}
- run: make rustup.android
- run: make lint

rustfmt:
Expand Down Expand Up @@ -57,6 +58,31 @@ jobs:
- uses: azure/setup-helm@v1
- run: make helm.lint chart=${{ matrix.chart }}

dartfmt:
if: ${{ github.ref == 'refs/heads/master'
|| startsWith(github.ref, 'refs/tags/medea-')
|| !contains(github.event.head_commit.message, '[skip ci]') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v1
with:
channel: stable
- run: make flutter.fmt check=yes

dartanalyzer:
if: ${{ github.ref == 'refs/heads/master'
|| startsWith(github.ref, 'refs/tags/medea-')
|| !contains(github.event.head_commit.message, '[skip ci]') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v1
with:
channel: stable
- run: make flutter
- run: make flutter.lint




Expand Down Expand Up @@ -217,15 +243,61 @@ jobs:

- run: make test.integration up=yes dockerized=no

test-flutter:
name: Flutter Android tests
if: ${{ github.ref == 'refs/heads/master'
|| startsWith(github.ref, 'refs/tags/medea-jason-')
|| !contains(github.event.head_commit.message, '[skip ci]') }}
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: i686-linux-android
- uses: Swatinem/rust-cache@v1
if: ${{ !contains(github.event.head_commit.message, '[fresh ci]') }}

- uses: actions-rs/install@v0.1
with:
crate: cargo-ndk
use-tool-cache: true
- uses: subosito/flutter-action@v1
with:
channel: stable

- name: Parse Android NDK versions
id: ndk-version
run: |
echo ::set-output name=min::$(make flutter.android.version.min)
echo ::set-output name=target::$(make flutter.android.version.compile)
- name: Compile shared object
run: make cargo.build crate=medea-jason platform=android targets=x86

- uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ steps.ndk-version.outputs.min }}
target: google_apis
profile: Nexus 6
script: make test.flutter
- uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ steps.ndk-version.outputs.target }}
target: google_apis
profile: Nexus 6
script: make test.flutter




############
# Building #
############

crate-jason:
name: Build medea-jason
crate-jason-web:
name: Build medea-jason for web platform
if: ${{ !startsWith(github.ref, 'refs/tags/medea-')
&& (github.ref == 'refs/heads/master'
|| !contains(github.event.head_commit.message, '[skip ci]')) }}
Expand All @@ -242,6 +314,28 @@ jobs:
- uses: jetli/wasm-pack-action@v0.3.0
- run: make cargo.build crate=medea-jason dockerized=no debug=yes

crate-jason-android:
name: Build medea-jason shared object for Android platform
if: ${{ !startsWith(github.ref, 'refs/tags/medea-')
&& (github.ref == 'refs/heads/master'
|| !contains(github.event.head_commit.message, '[skip ci]')) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- uses: Swatinem/rust-cache@v1
if: ${{ !contains(github.event.head_commit.message, '[fresh ci]') }}
- uses: actions-rs/install@v0.1
with:
crate: cargo-ndk
use-tool-cache: true
- run: make rustup.android
- run: make cargo.build crate=medea-jason platform=android
dockerized=no debug=yes

crate-medea:
name: Build medea
if: ${{ !startsWith(github.ref, 'refs/tags/medea-')
Expand Down
166 changes: 159 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ RUST_VER := 1.51
CHROME_VERSION := 89.0
FIREFOX_VERSION := 87.0

CARGO_NDK_VER := 2.2.0-ndkr22b-rust$(RUST_VER)
ANDROID_NDK_TARGETS := arm64-v8a \
armeabi-v7a \
x86 \
x86_64
ANDROID_RUST_TARGETS := aarch64-linux-android \
armv7-linux-androideabi \
i686-linux-android \
x86_64-linux-android
ANDROID_SDK_COMPILE_VERSION := $(strip \
$(shell grep compileSdkVersion jason/flutter/android/build.gradle \
| awk '{print $$2}'))
ANDROID_SDK_MIN_VERSION := $(strip \
$(shell grep minSdkVersion jason/flutter/android/build.gradle \
| awk '{print $$2}'))

crate-dir = .
ifeq ($(crate),medea-jason)
crate-dir = jason
Expand Down Expand Up @@ -70,15 +86,17 @@ build.medea:


build.jason:
@make cargo.build crate=medea-jason debug=$(debug) dockerized=$(dockerized)
@make cargo.build crate=medea-jason \
platform=$(platform) targets=$(targets) \
debug=$(debug) dockerized=$(dockerized)


# Resolve all project dependencies.
#
# Usage:
# make deps

deps: cargo yarn
deps: cargo flutter yarn


docs: docs.rust
Expand Down Expand Up @@ -208,16 +226,24 @@ cargo:
# Build medea's related crates.
#
# Usage:
# make cargo.build [crate=(@all|medea|medea-jason)]
# [debug=(yes|no)]
# [dockerized=(no|yes)]
# make cargo.build
# [( [crate=@all]
# | crate=medea
# | crate=medea-jason [debug=(yes|no)] [dockerized=(no|yes)]
# [( [platform=web]
# | platform=android
# [targets=($(ANDROID_NDK_TARGETS)|<t1>[,<t2>...])] )] )]

cargo-build-crate = $(if $(call eq,$(crate),),@all,$(crate))
cargo-build-platform = $(if $(call eq,$(platform),),web,$(platform))
cargo-build-targets = $(strip \
$(if $(call eq,$(targets),),$(ANDROID_NDK_TARGETS),$(targets)))

cargo.build:
ifeq ($(cargo-build-crate),@all)
@make build crate=medea
@make build crate=medea-jason
@make build crate=medea-jason platform=web
@make build crate=medea-jason platform=android targets=$(targets)
endif
ifeq ($(cargo-build-crate),medea)
ifeq ($(dockerized),yes)
Expand All @@ -233,6 +259,7 @@ endif
endif
ifeq ($(cargo-build-crate),medea-jason)
ifeq ($(dockerized),yes)
ifeq ($(cargo-build-platform),web)
docker run --rm --network=host -v "$(PWD)":/app -w /app \
-u $(shell id -u):$(shell id -g) \
-v "$(HOME)/.cargo/registry":/usr/local/cargo/registry \
Expand All @@ -242,14 +269,42 @@ ifeq ($(dockerized),yes)
make cargo.build crate=$(cargo-build-crate) \
debug=$(debug) dockerized=no \
pre-install=yes
endif
ifeq ($(cargo-build-platform),android)
docker run --rm --network=host -v "$(PWD)":/app -w /app \
-u $(shell id -u):$(shell id -g) \
-v "$(HOME)/.cargo/registry":/usr/local/cargo/registry \
-v "$(HOME):$(HOME)" \
-e XDG_CACHE_HOME=$(HOME) \
instrumentisto/cargo-ndk:$(CARGO_NDK_VER) \
make cargo.build crate=$(cargo-build-crate) \
debug=$(debug) dockerized=no \
platform=$(platform) targets=$(targets)
endif
else
ifeq ($(cargo-build-platform),web)
ifeq ($(pre-install),yes)
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
endif
@rm -rf $(crate-dir)/pkg/
wasm-pack build -t web $(crate-dir) $(if $(call eq,$(debug),no),,--dev)
endif
ifeq ($(cargo-build-platform),android)
$(foreach target,$(subst $(comma), ,$(cargo-build-targets)),\
$(call cargo.build.medea-jason.android,$(target),$(debug)))
endif
endif
endif
# TODO: Replace with actual `medea-jason` crate.
define cargo.build.medea-jason.android
$(eval target := $(strip $(1)))
$(eval debug := $(strip $(2)))
cd jason/jason-dummy/ && \
cargo ndk -p $(ANDROID_SDK_COMPILE_VERSION) -t $(target) \
-o ../flutter/android/src/main/jniLibs \
--manifest-path=Cargo.toml \
build $(if $(call eq,$(debug),no),--release,)
endef


# Show permalink to CHANGELOG of a concrete version of project's Cargo crate.
Expand Down Expand Up @@ -294,6 +349,14 @@ endif

cargo.lint:
cargo clippy --all -- -D clippy::pedantic -D warnings
$(foreach target,$(subst $(comma), ,$(ANDROID_RUST_TARGETS)),\
$(call cargo.lint.medea-jason.android,$(target)))
# TODO: Replace with actual `medea-jason` crate.
define cargo.lint.medea-jason.android
$(eval target := $(strip $(1)))
cd jason/jason-dummy/ && \
cargo clippy --target=$(target) -- -D clippy::pedantic -D warnings
endef


# Show version of project's Cargo crate.
Expand All @@ -305,6 +368,79 @@ cargo.version:
@printf "$(crate-ver)"


# Install or upgrade project's Android targets for Rust.
#
# Usage:
# make rustup.android

rustup.android:
rustup target add $(ANDROID_RUST_TARGETS)




####################
# Flutter commands #
####################

# Show Android SDK compile API version of medea_jason Flutter plugin.
#
# Usage:
# make flutter.android.compile_api_version

flutter.android.version.compile:
@printf "$(ANDROID_SDK_COMPILE_VERSION)"


# Show Android SDK minimal API version of medea_jason Flutter plugin.
#
# Usage:
# make flutter.android.version.min

flutter.android.version.min:
@printf "$(ANDROID_SDK_MIN_VERSION)"


# Resolve Flutter project dependencies.
#
# Usage:
# make flutter [cmd=(pub get|<flutter-cmd>)]

flutter:
cd jason/flutter && \
flutter $(if $(call eq,$(cmd),),pub get,$(cmd))


# Format Flutter Dart sources with dartfmt.
#
# Usage:
# make flutter.fmt [check=(no|yes)]

flutter.fmt:
flutter format $(if $(call eq,$(check),yes),-n --set-exit-if-changed,) \
jason/flutter/


# Lint Flutter Dart sources with dartanalyzer.
#
# Usage:
# make flutter.lint

flutter.lint:
flutter analyze jason/flutter/


# Runs medea_jason Flutter plugin example app on attached device.
#
# Usage:
# make flutter.run [debug=(yes|no)] [device=<device-id>]

flutter.run:
cd jason/flutter/example/ && \
flutter run $(if $(call eq,$(debug),no),--release,) \
$(if $(call eq,$(device),),,-d $(device))




#################
Expand Down Expand Up @@ -488,6 +624,18 @@ ifeq ($(up),yes)
endif


# Runs Flutter plugin integration tests on an attached device.
#
# Usage:
# make test.flutter [device=<device-id>]

test.flutter:
cd jason/flutter/example/ && \
flutter drive --driver=test_driver/integration_test.dart \
--target=integration_test/jason.dart \
$(if $(call eq,$(device),),,-d $(device))




####################
Expand Down Expand Up @@ -1096,11 +1244,15 @@ endef
docker.up.medea docker.up.webdriver \
docs docs.rust \
down down.control down.coturn down.demo down.dev down.medea \
flutter flutter.fmt flutter.lint flutter.run flutter.test \
flutter.android.compile_api_version \
flutter.android.min_api_version \
helm helm.dir helm.down helm.lint helm.list \
helm.package helm.package.release helm.up \
minikube.boot \
release release.crates release.helm release.npm \
test test.e2e test.integration test.unit \
rustup.android \
test test.e2e test.flutter test.integration test.unit \
up up.control up.coturn up.demo up.dev up.jason up.medea \
wait.port \
yarn yarn.version
Loading

0 comments on commit 663a294

Please sign in to comment.