Skip to content

Commit

Permalink
feat: introduce bindings_flutter crate (#333)
Browse files Browse the repository at this point in the history
* feat: introduce bindings_flutter crate

* feat: expose user preference encrypt/decrypt for flutter
  • Loading branch information
dmccartney authored Jan 5, 2024
1 parent 063845a commit d28c187
Show file tree
Hide file tree
Showing 138 changed files with 7,198 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Hint that these are generated. Practically this means:
# - collapse diffs by default and
# - don't count these during language analysis
# https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github
**/generated/** linguist-generated=true
**/bridge_generated.* linguist-generated=true
104 changes: 104 additions & 0 deletions .github/workflows/test_bindings_flutter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: test bindings_flutter
on:
pull_request:
push:
branches:
- v2
jobs:
build_android:
runs-on: macos-latest
defaults:
run:
working-directory: ./bindings_flutter
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: '11'
- uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-linux-android,armv7-linux-androideabi,x86_64-linux-android,i686-linux-android
- uses: Swatinem/rust-cache@v2
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.13.9'
channel: 'stable'
- run: flutter pub get
- run: cargo install cargo-expand
- run: cargo install flutter_rust_bridge_codegen --version 1.82.4
- run: flutter_rust_bridge_codegen
- run: scripts/build-android.sh
- uses: actions/upload-artifact@v3
with:
name: xmtp_bindings_flutter.jniLibs.tar.gz
path: bindings_flutter/platform-build/xmtp_bindings_flutter.jniLibs.tar.gz
retention-days: 1
build_linux:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./bindings_flutter
steps:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-unknown-linux-gnu,x86_64-unknown-linux-gnu
- uses: Swatinem/rust-cache@v2
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.13.9'
channel: 'stable'
- uses: goto-bus-stop/setup-zig@v2
- run: flutter pub get
- run: cargo install cargo-expand
- run: cargo install flutter_rust_bridge_codegen --version 1.82.4
- run: flutter_rust_bridge_codegen
- run: scripts/build-linux.sh
- uses: actions/upload-artifact@v3
with:
name: xmtp_bindings_flutter.linux.tar.gz
path: bindings_flutter/platform-build/xmtp_bindings_flutter.linux.tar.gz
retention-days: 1
build_apple:
runs-on: macos-latest
defaults:
run:
working-directory: ./bindings_flutter
steps:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-apple-ios,x86_64-apple-ios,aarch64-apple-ios-sim,aarch64-apple-darwin,x86_64-apple-darwin
- uses: Swatinem/rust-cache@v2
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.13.9'
channel: 'stable'
- run: flutter pub get
- run: cargo install cargo-expand
- run: cargo install flutter_rust_bridge_codegen --version 1.82.4
- run: flutter_rust_bridge_codegen
- run: scripts/build-apple.sh
- uses: actions/upload-artifact@v3
with:
name: xmtp_bindings_flutter.xcframework.zip
path: bindings_flutter/platform-build/xmtp_bindings_flutter.xcframework.zip
retention-days: 1
# Ordinarily, our .podspec script (which is triggered by pod install)
# will try to download the corresponding xcframework.zip release artifact.
# But because this release hasn't been published yet we short-circuit that
# by moving the just-built artifact into place manually before pod install.
# This way the .podspec script thinks it already downloaded it and proceeds.
# See the file-exists check in the .podspec script for more details.
- run: cp platform-build/xmtp_bindings_flutter.xcframework.zip macos/Frameworks/xmtp_bindings_flutter.xcframework.zip
working-directory: ./bindings_flutter
- run: flutter pub get
working-directory: ./bindings_flutter/example
- run: pod install
working-directory: ./bindings_flutter/example/macos
- run: flutter test -d macos integration_test
working-directory: ./bindings_flutter/example
# TODO: build & publish artifacts in a release job
# TODO: ios/macos: update .podspec script to curl the release xcframework
# TODO: android: update gradle script to download the release jniLibs
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ members = [
# 2) moreover, bindings_swift and xmtp_dh need their own size-optimized profile
exclude = [
"bindings_ffi",
"bindings_flutter",
"bindings_js",
"bindings_swift",
"user_preferences_bindings_wasm",
Expand Down
14 changes: 14 additions & 0 deletions bindings_flutter/.flutter_rust_bridge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
rust_input:
- src/libxmtp_api.rs
rust_output:
- src/generated/bridge_generated.rs
dart_output:
- lib/src/generated/bridge_generated.dart
c_output:
- ios/Classes/bridge_generated.h
extra_c_output_path:
- macos/Classes
dart_decl_output: lib/src/generated/bridge_definitions.dart
dart_format_line_length: 80
wasm: false
skip_add_mod_to_lib: true
33 changes: 33 additions & 0 deletions bindings_flutter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# See `.flutter_rust_bridge.yml`
platform-build/

# See https://www.dartlang.org/guides/libraries/private-files

.flutter-plugins
.flutter-plugins-dependencies

# Files and directories created by pub
.dart_tool/
.packages
build/
# If you're building an application, you may want to check-in your pubspec.lock
pubspec.lock

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# Directory created by dartdoc
# If you don't generate documentation locally you can remove this line.
doc/api/

# Avoid committing generated Javascript files:
*.dart.js
*.info.json # Produced by the --dump-info flag.
*.js # When generated by dart2js. Don't specify *.js if your
# project includes source files written in JavaScript.
*.js_
*.js.deps
*.js.map
12 changes: 12 additions & 0 deletions bindings_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## 0.0.1-development.3
- expose `user_preferences_encrypt()` and `user_preferences_decrypt()`

## 0.0.1-development.2
- introduce setup script for artifacts during install

## 0.0.1-development.1
- include generated code in the published package

## 0.0.1-development
- initial packaging
- expose topic generator for preference storage
Loading

0 comments on commit d28c187

Please sign in to comment.