Added support for gradle 8.8+ and dependencies updated#3053
Added support for gradle 8.8+ and dependencies updated#3053sumitsharansatsangi wants to merge 31 commits intofzyzcjy:masterfrom
Conversation
When oxidized package is detected in pubspec.yaml dependencies: - Fallible Rust functions return Future<Result<T, E>> instead of Future<T> - Errors are returned as Err(...) instead of throwing exceptions - Panics still throw PanicException (bugs, not expected errors) Runtime (frb_dart): - Add decodeAsResult() to SimpleDecoder for Result-based decoding - Add decodeObjectAsResult/decodeWireSyncTypeAsResult to BaseCodec - Add executeNormalAsResult/executeSyncAsResult to BaseHandler - Export Result, Ok, Err from flutter_rust_bridge_for_generated_common.dart Codegen (frb_codegen): - Add has_dependency() to DartRepository - Add detect_oxidized_dependency() in generator_parser.rs - Add use_oxidized field to GeneratorApiDartInternalConfig - Wrap fallible function return types in Result<T, E> - Use executeNormalAsResult/executeSyncAsResult for fallible functions Tested with dart_minimal example: - Async functions: Future<Result<T, E>> - Sync functions: Result<T, E>
When a type alias like \`type Result<T> = std::result::Result<T, MyError>\` is used, FRB now correctly extracts the error type from the alias definition instead of falling back to AnyhowException. - Store generic type aliases separately in HirFlatTypeAlias - Look up generic Result aliases when parsing function return types - Substitute type parameters to resolve the actual error type
- Add example error types and functions using type aliases - Update generated Dart/Rust bindings with new test cases
…ed Result support
Traits marked with #[frb(ignore)] were being collected into src_traits but the ignore attribute was never checked, causing panics when the trait was used in Option<T> contexts. This mirrors how structs/enums handle the ignore attribute via parse_struct_or_enum_should_ignore. Amp-Thread-ID: https://ampcode.com/threads/T-019bf8ee-f69c-75eb-981d-55743289c99e Co-authored-by: Amp <amp@ampcode.com>
Add first-class support for serde_json::Value as a delegate type that serializes via JSON string across the FFI boundary, mapping to Dart's Object?. Supports all codecs (SSE, DCO, CST) and composite types (Option, Vec, HashMap, struct fields). Includes tests, documentation, and feature flag gated behind `serde_json`.
There was a problem hiding this comment.
Code Review
This pull request primarily focuses on updating dependencies across various projects, including updates to Android Gradle plugins, Flutter dependencies, and Dart packages. It also introduces improvements to the Cargokit build tool, such as better error handling with custom exceptions, more robust tool resolution, and updated documentation. My feedback highlights critical issues with non-existent Gradle versions and unsupported Android API levels, as well as suggestions for improving cross-platform compatibility in tests and shell scripts.
| dependencies { | ||
| // The Android Gradle Plugin knows how to build native code with the NDK. | ||
| classpath 'com.android.tools.build:gradle:7.3.0' | ||
| classpath 'com.android.tools.build:gradle:8.13.2' |
There was a problem hiding this comment.
The Android Gradle Plugin version 8.13.2 does not appear to exist in the official Google or Maven Central repositories. The current stable versions are in the 8.7.x range, and 8.8.0 was recently released. This will likely cause build failures as the dependency cannot be resolved. Please verify if this is a typo (perhaps for 8.3.2 or 8.7.2).
| // Bumping the plugin compileSdkVersion requires all clients of this plugin | ||
| // to bump the version in their app. | ||
| compileSdkVersion 33 | ||
| compileSdk 37 |
| Future<ProcessResult> _runCli(List<String> args) { | ||
| final dartExecutable = _dartExecutable(); | ||
| return Process.run( | ||
| '/bin/zsh', |
There was a problem hiding this comment.
Hardcoding /bin/zsh as the executable for running tests will cause failures on Windows environments where Zsh is not installed or located at that path. Since the project explicitly supports Windows (as seen in the CI configuration), consider using a more cross-platform approach, such as checking Platform.isWindows or invoking dart directly if a shell is not strictly required for the test environment.
| try { | ||
| // Compatibility: Flutter >=3.32.0-0.0.pre | ||
| platforms = com.flutter.gradle.FlutterPluginUtils.getTargetPlatforms(project).collect() | ||
| } catch (Exception e) { |
There was a problem hiding this comment.
Catching Exception will not handle NoClassDefFoundError, which is thrown if the com.flutter.gradle.FlutterPluginUtils class is missing (which happens when running on older Flutter versions). In Groovy/Gradle scripts, it is safer to catch Throwable to ensure the fallback logic in the catch block is executed correctly.
} catch (Throwable e) {
| shopt -s expand_aliases | ||
| alias shasum="sha1sum" |
There was a problem hiding this comment.
Using an alias in a shell script is generally discouraged as aliases are not expanded in non-interactive shells by default. Although shopt -s expand_aliases is used here, defining a function is more robust and idiomatic for providing command wrappers in shell scripts.
| shopt -s expand_aliases | |
| alias shasum="sha1sum" | |
| shasum() { | |
| sha1sum "$@" | |
| } |
| sourceCompatibility JavaVersion.VERSION_17 | ||
| targetCompatibility JavaVersion.VERSION_17 |
There was a problem hiding this comment.
There is an inconsistency in the Java version used across example projects. This file uses VERSION_17, while frb_example/flutter_package/android/build.gradle was updated to VERSION_21. It is recommended to standardize on one version (e.g., VERSION_17 for broader compatibility or VERSION_21 for the latest LTS) across all examples to maintain consistency.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the cargokit submodule to a personal fork, bumps Android SDK requirements (compileSdk to 37, minSdk to 24) and Java compatibility versions, and includes various dependency updates and refactorings in the build_tool package. My feedback highlights concerns regarding the use of a personal fork for the submodule, requests clarification on the breaking changes to Android SDK requirements, and suggests using the direct execution method for shell scripts to ensure proper interpreter usage.
| url = https://github.com/sumitsharansatsangi/cargokit.git | ||
| [submodule "frb_codegen/assets/integration_template/app/rust_builder/cargokit"] | ||
| path = frb_codegen/assets/integration_template/app/rust_builder/cargokit | ||
| url = https://github.com/fzyzcjy/cargokit | ||
| url = https://github.com/sumitsharansatsangi/cargokit.git |
There was a problem hiding this comment.
This PR changes the cargokit submodule to point to a personal fork (sumitsharansatsangi/cargokit.git). For long-term maintainability and to avoid potential issues if the personal fork becomes unavailable, it would be better to either:
- Get the necessary changes merged into the upstream
fzyzcjy/cargokitrepository. - Move the fork to a neutral organization repository if upstream merging is not feasible.
Could you clarify if this is a temporary change for the PR or intended to be permanent?
| compileOptions { | ||
| sourceCompatibility JavaVersion.VERSION_1_8 | ||
| targetCompatibility JavaVersion.VERSION_1_8 | ||
| sourceCompatibility JavaVersion.VERSION_21 | ||
| targetCompatibility JavaVersion.VERSION_21 | ||
| } | ||
|
|
||
| defaultConfig { | ||
| minSdkVersion 19 | ||
| minSdk 24 | ||
| } |
There was a problem hiding this comment.
These changes significantly increase the minimum requirements for Android projects using this template:
minSdkis increased from 19 to 24. This is a breaking change that will affect which devices can run applications using this template.sourceCompatibilityandtargetCompatibilityare updated toJavaVersion.VERSION_21fromVERSION_1_8.
These changes should be clearly communicated in the PR description and any relevant documentation.
I also noticed some inconsistencies across the updated build.gradle files in this PR:
frb_example/flutter_via_create/rust_builder/android/build.gradleupdates Java compatibility toVERSION_17.frb_example/flutter_via_integrate/rust_builder/android/build.gradledoesn't change Java compatibility orminSdk.
It would be good to align these for consistency.
| done | ||
|
|
||
| "$BASEDIR/run_build_tool.sh" build-pod "$@" | ||
| sh "$BASEDIR/run_build_tool.sh" build-pod "$@" |
There was a problem hiding this comment.
Using sh explicitly to run the script is a good practice for portability. However, since run_build_tool.sh has a #!/usr/bin/env bash shebang, it might be more robust to execute it directly without sh to ensure it's interpreted by bash as intended, especially if it uses bash-specific features.
| sh "$BASEDIR/run_build_tool.sh" build-pod "$@" | |
| "$BASEDIR/run_build_tool.sh" build-pod "$@" |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3053 +/- ##
===========================================
- Coverage 98.57% 72.67% -25.91%
===========================================
Files 464 465 +1
Lines 19202 13752 -5450
===========================================
- Hits 18928 9994 -8934
- Misses 274 3758 +3484 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Great job! there looks like a lot of diff, if this is not needed, maybe can firstly reset/merge your branch from the main master branch |
# Conflicts: # frb_dart/lib/src/codec/dco.dart # frb_dart/pubspec.yaml # frb_example/dart_minimal/pubspec.lock # frb_example/dart_minimal/pubspec.yaml # frb_example/dart_minimal/rust/src/frb_generated.rs
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for the "oxidized" Dart package, enabling fallible Rust functions to return Result types in Dart instead of throwing exceptions. It also implements robust support for generic type aliases, deep equality checks for collection types, and updates the integrated cargokit tool. Other notable changes include splitting the Naive time delegate into NaiveDate and NaiveDateTime, adding support for serde_json::Value, and performing extensive dependency updates. Feedback focuses on improving error handling by replacing a panic with a proper error result, removing redundant alias resolution logic, and extending generic parameter substitution to support additional Rust type variants.
| Some((type_name, args)) => { | ||
| // Check if this is a Result type directly OR a type alias that resolves to Result | ||
| let is_result = type_name == &"Result"; | ||
| let is_result_alias = !is_result && is_result_type_alias(type_parser, type_name); | ||
|
|
||
| if is_result || is_result_alias { | ||
| // Check if this might be a generic type alias like `type Result<T> = std::result::Result<T, MyError>` | ||
| // or `type WResult<T> = std::result::Result<T, MyError>` | ||
| // If we only have one arg, try to resolve the error type from the alias definition | ||
| let resolved_args = if args.len() == 1 { | ||
| resolve_generic_result_alias_args(type_parser, type_name, args) | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| let args_to_parse = resolved_args.as_deref().unwrap_or(args); | ||
| let parsed_args = (args_to_parse.iter()) | ||
| .map(|arg| type_parser.parse_type(arg, context)) | ||
| .collect::<anyhow::Result<Vec<_>>>()?, | ||
| ); | ||
| .collect::<anyhow::Result<Vec<_>>>()?; | ||
| return parse_type_result(&parsed_args); | ||
| } | ||
| } |
There was a problem hiding this comment.
This logic for resolving generic Result aliases is redundant because TypeParserWithContext::parse_type already resolves all type aliases (including generic ones) before calling parse_type_maybe_result. Furthermore, the local substitute_type_param implementation is less robust than the centralized one in ty.rs as it lacks recursion. This redundant logic should be removed to simplify the codebase.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Changes
Discussion 2987