Skip to content

Commit

Permalink
feat: add ability to call rust from flutter/dart
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbillman committed Feb 13, 2025
1 parent f780fc6 commit 726064a
Show file tree
Hide file tree
Showing 114 changed files with 6,378 additions and 79 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
.svn/
.swiftpm/
migrate_working_dir/
.hermit/
.build/

# IntelliJ related
*.iml
Expand Down
8 changes: 8 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
_help:
@just -l


# Run the Flutter app
run:
Expand All @@ -9,6 +11,8 @@ get:
#!/bin/bash
echo "Getting dependencies for main project"
flutter pub get
cd rust_builder
dart pub get

# Clean the project
clean:
Expand Down Expand Up @@ -37,3 +41,7 @@ coverage:
flutter test --coverage
genhtml coverage/lcov.info -o coverage/html
open coverage/html/index.html

# Generate the Rust bindings
generate-rust:
flutter_rust_bridge_codegen generate
1 change: 1 addition & 0 deletions bin/.rustup-1.25.2.pkg
1 change: 1 addition & 0 deletions bin/cargo
1 change: 1 addition & 0 deletions bin/cargo-clippy
1 change: 1 addition & 0 deletions bin/cargo-fmt
1 change: 1 addition & 0 deletions bin/cargo-miri
1 change: 1 addition & 0 deletions bin/clippy-driver
1 change: 1 addition & 0 deletions bin/rls
1 change: 1 addition & 0 deletions bin/rust-analyzer
1 change: 1 addition & 0 deletions bin/rust-gdb
1 change: 1 addition & 0 deletions bin/rust-gdbgui
1 change: 1 addition & 0 deletions bin/rust-lldb
1 change: 1 addition & 0 deletions bin/rustc
1 change: 1 addition & 0 deletions bin/rustdoc
1 change: 1 addition & 0 deletions bin/rustfmt
1 change: 1 addition & 0 deletions bin/rustup
3 changes: 3 additions & 0 deletions flutter_rust_bridge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rust_input: crate::api
rust_root: rust/
dart_output: lib/generated/rust
13 changes: 13 additions & 0 deletions integration_test/simple_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// import 'package:flutter_test/flutter_test.dart';
// import 'package:gosling/main.dart';
// import 'package:gosling/src/rust/frb_generated.dart';
// import 'package:integration_test/integration_test.dart';

// void main() {
// IntegrationTestWidgetsFlutterBinding.ensureInitialized();
// setUpAll(() async => await RustLib.init());
// testWidgets('Can call rust function', (WidgetTester tester) async {
// await tester.pumpWidget(const App());
// expect(find.textContaining('Result: `Hello, Tom!`'), findsOneWidget);
// });
// }
1 change: 1 addition & 0 deletions ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
44 changes: 44 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Uncomment this line to define a global platform for your project
platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
28 changes: 28 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
PODS:
- Flutter (1.0.0)
- integration_test (0.0.1):
- Flutter
- rust_lib_gosling (0.0.1):
- Flutter

DEPENDENCIES:
- Flutter (from `Flutter`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)
- rust_lib_gosling (from `.symlinks/plugins/rust_lib_gosling/ios`)

EXTERNAL SOURCES:
Flutter:
:path: Flutter
integration_test:
:path: ".symlinks/plugins/integration_test/ios"
rust_lib_gosling:
:path: ".symlinks/plugins/rust_lib_gosling/ios"

SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
integration_test: 4a889634ef21a45d28d50d622cf412dc6d9f586e
rust_lib_gosling: 1f11f1eec61a455deafbad34b6581582fba8f9d4

PODFILE CHECKSUM: 7be2f5f74864d463a8ad433546ed1de7e0f29aef

COCOAPODS: 1.16.2
Loading

0 comments on commit 726064a

Please sign in to comment.