Skip to content

Commit

Permalink
Merge pull request #2100 from fzyzcjy/feat/12337
Browse files Browse the repository at this point in the history
  • Loading branch information
fzyzcjy authored Jun 19, 2024
2 parents 39c1f80 + 95e11b2 commit 43ba8a2
Show file tree
Hide file tree
Showing 213 changed files with 10,467 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .all-contributors-custom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
- jsonmona: Add import.
- MateusHBR: Add pub get.
- codercengiz: Fix mirroring bug.
- aran: Fix map + mirror. Fix pubspec. Upgrde ffigen. Replace to js_interop. Bump version. Fix typo.
- Michael-F-Bryan: Detect broken bindings.
- patmuk: Set MSRV. Fail fast. Improve message. Improve docs.
- aran: Fix map + mirror. Fix pubspec. Upgrde ffigen. Bump version. Fix typo.
- phlip9: Fix no-serde compilation.
- SilverMira: Fix StreamSink.
- h3x4d3c1m4l: Fix when outside folder.
Expand Down
18 changes: 9 additions & 9 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,15 @@
"code"
]
},
{
"login": "aran",
"name": "Aran Donohue",
"avatar_url": "https://avatars.githubusercontent.com/u/5295?v=4",
"profile": "https://github.com/aran",
"contributions": [
"code"
]
},
{
"login": "Michael-F-Bryan",
"name": "Michael Bryan",
Expand All @@ -450,15 +459,6 @@
"code"
]
},
{
"login": "aran",
"name": "Aran Donohue",
"avatar_url": "https://avatars.githubusercontent.com/u/5295?v=4",
"profile": "https://github.com/aran",
"contributions": [
"code"
]
},
{
"login": "phlip9",
"name": "Philip Kannegaard Hayes",
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ jobs:
- frb_example--integrate_third_party
- frb_example--flutter_via_create
- frb_example--flutter_via_integrate
- frb_example--flutter_package
exclude:
- { image: windows-2019, package: frb_example--deliberate_bad }
- { image: macos-11, package: frb_example--deliberate_bad }
Expand Down Expand Up @@ -754,6 +755,7 @@ jobs:
matrix:
package:
- frb_example--flutter_via_create
- frb_example--flutter_package--example
# no `frb_example--flutter_via_integrate` since it is similar to `flutter_via_create`
device:
- "pixel"
Expand Down Expand Up @@ -819,6 +821,7 @@ jobs:
matrix:
package:
- frb_example--flutter_via_create
- frb_example--flutter_package--example
# no `frb_example--flutter_via_integrate` since it is similar to `flutter_via_create`
device:
- "iPad (10th generation) Simulator (17.2)"
Expand Down Expand Up @@ -866,6 +869,17 @@ jobs:
- image: ubuntu-latest
platform: linux
package: frb_example--flutter_via_create

- image: windows-2019
platform: windows
package: frb_example--flutter_package--example
- image: macos-13
platform: macos
package: frb_example--flutter_package--example
- image: ubuntu-latest
platform: linux
package: frb_example--flutter_package--example

# only slightly test `flutter_via_integrate` since quite similar to `flutter_via_create`
- image: ubuntu-latest
platform: linux
Expand Down Expand Up @@ -909,6 +923,7 @@ jobs:
matrix:
package:
- frb_example--flutter_via_create
# no `frb_example--flutter_package--example` yet
# no `frb_example--flutter_via_integrate` since it is similar to `flutter_via_create`
- frb_example--gallery

Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## Unreleased

* Please refer to https://fzyzcjy.github.io/flutter_rust_bridge/guides/miscellaneous/whats-new for what's changed in V2.
* Use dart.library.js_interop rather than dart.library.html #2113 (thanks @aran)
* Auto skip methods in trait definitions that has Self as inputs because it cannot be translated to Dart #2099
* Add type_64bit_int to config #2096
* Improve namespace choices for opaque types #2096
* Hint users when having references in output type, hint when wrong rust_input, and improve docs #2100
* Improve warning message #2098
* Experiment more about translating whole audio crate#2096
* Improve internal code #2096

## 2.0.0-dev.40

* Please refer to https://fzyzcjy.github.io/flutter_rust_bridge/guides/miscellaneous/whats-new for what's changed in V2.
Expand Down
29 changes: 15 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
[workspace]
members = [
"frb_codegen",
"frb_macros",
"frb_rust",
"frb_codegen",
"frb_macros",
"frb_rust",
]
exclude = [
# Exclude example packages to ensure the example mimics how a typical user will use it.
# For example, the `target` directory is different with and without workspaces.
"frb_example/dart_minimal/rust",
"frb_example/deliberate_bad/rust",
"frb_example/flutter_via_create/rust",
"frb_example/flutter_via_integrate/rust",
"frb_example/dart_build_rs/rust",
"frb_example/gallery/rust",
"frb_example/pure_dart/rust",
"frb_example/pure_dart_pde/rust",
"frb_example/integrate_third_party/rust",
# Exclude example packages to ensure the example mimics how a typical user will use it.
# For example, the `target` directory is different with and without workspaces.
"frb_example/dart_minimal/rust",
"frb_example/deliberate_bad/rust",
"frb_example/flutter_via_create/rust",
"frb_example/flutter_via_integrate/rust",
"frb_example/flutter_package/rust",
"frb_example/dart_build_rs/rust",
"frb_example/gallery/rust",
"frb_example/pure_dart/rust",
"frb_example/pure_dart_pde/rust",
"frb_example/integrate_third_party/rust",
]
resolver = "2"

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ Secondly, thanks goes to these wonderful contributors ([emoji key](https://allco
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jsonmona"><img src="https://avatars.githubusercontent.com/u/105187344?v=4?s=100" width="100px;" alt="jsonmona"/><br /><sub><b>jsonmona</b></sub></a><br /><a href="https://github.com/fzyzcjy/flutter_rust_bridge/commits?author=jsonmona" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/MateusHBR"><img src="https://avatars.githubusercontent.com/u/13079483?v=4?s=100" width="100px;" alt="mtz"/><br /><sub><b>mtz</b></sub></a><br /><a href="https://github.com/fzyzcjy/flutter_rust_bridge/commits?author=MateusHBR" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/codercengiz"><img src="https://avatars.githubusercontent.com/u/45819755?v=4?s=100" width="100px;" alt="codercengiz"/><br /><sub><b>codercengiz</b></sub></a><br /><a href="https://github.com/fzyzcjy/flutter_rust_bridge/commits?author=codercengiz" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/aran"><img src="https://avatars.githubusercontent.com/u/5295?v=4?s=100" width="100px;" alt="Aran Donohue"/><br /><sub><b>Aran Donohue</b></sub></a><br /><a href="https://github.com/fzyzcjy/flutter_rust_bridge/commits?author=aran" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://adventures.michaelfbryan.com/"><img src="https://avatars.githubusercontent.com/u/17380079?v=4?s=100" width="100px;" alt="Michael Bryan"/><br /><sub><b>Michael Bryan</b></sub></a><br /><a href="https://github.com/fzyzcjy/flutter_rust_bridge/commits?author=Michael-F-Bryan" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://patrick.mukherjee.de"><img src="https://avatars.githubusercontent.com/u/2045440?v=4?s=100" width="100px;" alt="Patrick Mukherjee"/><br /><sub><b>Patrick Mukherjee</b></sub></a><br /><a href="https://github.com/fzyzcjy/flutter_rust_bridge/commits?author=patmuk" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/aran"><img src="https://avatars.githubusercontent.com/u/5295?v=4?s=100" width="100px;" alt="Aran Donohue"/><br /><sub><b>Aran Donohue</b></sub></a><br /><a href="https://github.com/fzyzcjy/flutter_rust_bridge/commits?author=aran" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://phlip9.com"><img src="https://avatars.githubusercontent.com/u/918989?v=4?s=100" width="100px;" alt="Philip Kannegaard Hayes"/><br /><sub><b>Philip Kannegaard Hayes</b></sub></a><br /><a href="https://github.com/fzyzcjy/flutter_rust_bridge/commits?author=phlip9" title="Code">💻</a></td>
</tr>
<tr>
Expand Down Expand Up @@ -361,9 +361,9 @@ More specifically, thanks for all these contributions:
* [jsonmona](https://github.com/jsonmona): Add import.
* [MateusHBR](https://github.com/MateusHBR): Add pub get.
* [codercengiz](https://github.com/codercengiz): Fix mirroring bug.
* [aran](https://github.com/aran): Fix map + mirror. Fix pubspec. Upgrde ffigen. Replace to js_interop. Bump version. Fix typo.
* [Michael-F-Bryan](https://github.com/Michael-F-Bryan): Detect broken bindings.
* [patmuk](https://github.com/patmuk): Set MSRV. Fail fast. Improve message. Improve docs.
* [aran](https://github.com/aran): Fix map + mirror. Fix pubspec. Upgrde ffigen. Bump version. Fix typo.
* [phlip9](https://github.com/phlip9): Fix no-serde compilation.
* [SilverMira](https://github.com/SilverMira): Fix StreamSink.
* [h3x4d3c1m4l](https://github.com/h3x4d3c1m4l): Fix when outside folder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub(super) fn compute_rust_path_info(
) -> anyhow::Result<RustInputInfo> {
let rust_input_namespace_prefixes_raw =
compute_rust_input_namespace_prefixes_raw(&migrated_rust_input.rust_input);
sanity_check_rust_input_namespace_prefixes(&rust_input_namespace_prefixes_raw);
let rust_crate_dir = compute_rust_crate_dir(base_dir, &migrated_rust_input.rust_root)?;
let rust_output_path = compute_rust_output_path(config_rust_output, base_dir, &rust_crate_dir)?;

Expand All @@ -44,6 +45,17 @@ pub(super) fn compute_rust_path_info(
})
}

fn sanity_check_rust_input_namespace_prefixes(rust_input_namespace_prefixes_raw: &[Namespace]) {
if !(rust_input_namespace_prefixes_raw.iter()).any(|x| x.joined_path.contains("crate")) {
// We do not care about codecov for this, since it is just a sanity check warning
// frb-coverage:ignore-start
log::warn!(
"Reminder: `rust_input` field usually looks like `crate::api`, but no `crate` word is detected. \
This is not a problem if the first-party crate is really not scanned.");
// frb-coverage:ignore-end
}
}

fn compute_rust_input_namespace_prefixes_raw(raw_rust_input: &str) -> Vec<Namespace> {
raw_rust_input
.split(',')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ pub(crate) fn parse(
.flatten()
.collect_vec();

auto_accessor_checker::report(
&infos
.iter()
.flat_map(|x| x.sanity_check_hint.clone())
.collect_vec(),
);
if parse_mode != ParseMode::Early {
auto_accessor_checker::report(
&infos
.iter()
.flat_map(|x| x.sanity_check_hint.clone())
.collect_vec(),
);
}

Ok(infos
.into_iter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> {
Ok(create_output_skip(func, IgnoreBecauseSelfTypeNotAllowed))
} else {
Err(e)
}
};
}
};
info = info.merge(arg_info)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ impl<'a, 'b> FunctionParser<'a, 'b> {
attributes: &FrbAttributes,
) -> anyhow::Result<FunctionPartialInfo> {
Ok(match &sig.output {
ReturnType::Type(_, ty) => remove_reference_type(remove_primitive_unit(
self.parse_fn_output_type(ty, owner, context, attributes)?,
)),
ReturnType::Type(_, ty) => remove_reference_type(
remove_primitive_unit(self.parse_fn_output_type(ty, owner, context, attributes)?),
&sig.ident.to_string(),
),
ReturnType::Default => Default::default(),
})
}
Expand Down Expand Up @@ -56,14 +57,20 @@ fn remove_primitive_unit(info: FunctionPartialInfo) -> FunctionPartialInfo {
info
}

fn remove_reference_type(info: FunctionPartialInfo) -> FunctionPartialInfo {
fn remove_reference_type(
info: FunctionPartialInfo,
debug_function_name: &str,
) -> FunctionPartialInfo {
if let Some(MirType::RustAutoOpaqueImplicit(MirTypeRustAutoOpaqueImplicit {
ownership_mode,
..
})) = &info.ok_output
{
if *ownership_mode != OwnershipMode::Owned {
log::debug!("remove_reference_type: detect output type is a reference, thus set to unit (info={:?})", info);
log::info!(
"Output type of `{debug_function_name}` is a reference, thus currently set to unit type. \
The \"lifetimes\" section in doc may be interesting."
);
return FunctionPartialInfo {
ok_output: None,
..info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::codegen::ir::mir::ty::MirType;
use crate::codegen::parser::mir::parser::lifetime_extractor::LifetimeExtractor;
use crate::codegen::parser::mir::parser::lifetime_replacer::replace_lifetimes_to_static;
use crate::codegen::parser::mir::parser::ty::TypeParserWithContext;
use crate::codegen::parser::mir::ParseMode;
use crate::utils::namespace::Namespace;
use syn::Type;

Expand Down Expand Up @@ -47,7 +48,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> {
}

fn maybe_log_not_enable_lifetime(&mut self) {
if !self.inner.has_logged_lifetimeable {
if !self.inner.has_logged_lifetimeable && self.context.parse_mode != ParseMode::Early {
log::info!("To handle some types, `enable_lifetime: true` may need to be set. \
Please visit https://fzyzcjy.github.io/flutter_rust_bridge/guides/lifetimes for more details");
}
Expand Down
29 changes: 29 additions & 0 deletions frb_example/flutter_package/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

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

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
build/
5 changes: 5 additions & 0 deletions frb_example/flutter_package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Flutter package example for `flutter_rust_bridge`

Example of making a Flutter package.

Please visit the main documentation or open an issue for more information.
28 changes: 28 additions & 0 deletions frb_example/flutter_package/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/lints.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
9 changes: 9 additions & 0 deletions frb_example/flutter_package/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.cxx
Loading

0 comments on commit 43ba8a2

Please sign in to comment.