Closed Larpoux closed 5 months ago
Hmm that's weird. Some brainstorms:
Maybe an improvement is to stream the output of build_runner to the console, then we can see more information (e.g. whether it stucks or is outputing information saying some failure etc)
Oh I realize another thing (though seems unrelated to build_runner): Currently https://cjycode.com/flutter_rust_bridge/guides/lifetimes/overview is experimental and needs to use a flag to be enabled. (I think web-audio-api mostly does not need this but will double check.) Otherwise, its return type is translated to void.
Related: https://github.com/fzyzcjy/flutter_rust_bridge/issues/2083
I closed most of my other tasks (IDE, ...) because sometimes I am low on memory.
larpoux@Mac-mini:~/projmac/tau$ RUST_LOG=debug flutter_rust_bridge_codegen generate >/tmp/toto.log
[1.3s] Parse
└── [1.3s] Cargo expand & syn parse
└── [0.0s] Parse HIR
└── [0.0s] Parse MIR
[0.0s] Generate
[526.7s] Polish ⠈
└── [526.7s] Run Dart build_runner
Actually I don't try to generate the web-audio-api-rs lib. I just generate a very simple wrapper with less than 10 functions.
Ok then it looks like it is just stucked. Even frb_example/pure_dart which has several thousand tests do not need this long.
Then may try
flutter_rust_bridge_codegen generate --no-build-runner
(skip build runner and get other outputs ready)flutter pub run build_runner build --delete-conflicting-outputs --enable-experiment=class-modifiers
and see whether it stucksfalse alarm : I cleaned up several dummy rust files in my directory and now it generates OK. Sorry, this was probably my fault..
It's OK!
The stuck problem is related to this fn :
#[frb(sync)]
fn connect(&self, dest:&dyn AudioNode) ->&dyn AudioNode
{
dest.clone()
}
But my Rust knowledge is very poor.
#[frb(sync)]
fn connect(&self, dest:&impl AudioNode) ->&impl AudioNode
{
dest.clone()
}
is better (no stuck). But I get this dart :
import '../../frb_generated.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
// These functions have error during generation (see debug logs or enable `stop_on_error: true` for more details): `connect`, `connect`
abstract class AudioNode {
void getXNode();
}
Where must I set this boolean : stop_on_error: true
?
Where must I set this boolean : stop_on_error: true ?
On flutter_rust_bridge.yaml
impl AudioNode
IIRC this is not supported yet (that may be why it errors?). Only &dyn
is supported.
IT WORKS !!!! 👍 💯 👍 👍
Thank you!
larpoux@Mac-mini:~/projmac/tau$ flutter pub run build_runner build --delete-conflicting-outputs --enable-experiment=class-modifiers
Deprecated. Use `dart run` instead.
Building package executable... (1.7s)
Built build_runner:build_runner.
[INFO] Generating build script completed, took 616ms
[WARNING] Invalidated precompiled build script due to missing asset graph.
[INFO] Precompiling build script... completed, took 1.0s
[INFO] Building new asset graph completed, took 27.1s
[INFO] Checking for unexpected pre-existing outputs. completed, took 0ms
[INFO] Running build completed, took 3m 59s
[WARNING] No actions completed for 15.0s, waiting on:
[INFO] Caching finalized dependency graph completed, took 15.2s
[INFO] Succeeded after 4m 14s with 79 outputs (23560 actions)
larpoux@Mac-mini:~/projmac/tau$
You are welcome and happy to see it works!
The stuck problem is solved with build_runner: false
.
This problem is probably because my flutter project is a plugin and not an app.
Probably a note in the documentation is enough
I am trying to run frb on the real web-audio-api-rs (writing my own wrapper was not doable for me)
When I compile my dart, I have problems :
part 'context.freezed.dart';
but the file does not exist.
part 'frb_generated.freezed.dart';
but the file does not exist.
When I remove those two lines :
Error (Xcode): ../lib/src/rust/frb_generated.dart:26895:40: Error: Type '_$AudioNodeImplementor' not found.
Could not build the application for the simulator.
Error launching application on iPhone 15.
Is this because I do not run build_runner
?
UPDATE:
larpoux@Mac-mini:~/projmac/tau$ flutter pub run build_runner build --delete-conflicting-outputs --enable-experiment=class-modifiers
Deprecated. Use `dart run` instead.
Building package executable...
Built build_runner:build_runner.
[INFO] Generating build script completed, took 164ms
[INFO] Reading cached asset graph completed, took 6.1s
[INFO] Checking for updates since last build...
This is where the generation stuck .
This problem is probably because my flutter project is a plugin and not an app.
Hmm that should not have difference - we should support it imho.
Is this because I do not run build_runner ?
Yes, .freezed.dart
and .g.dart
is generated by build_runner.
This is where the generation stuck .
Hmm, what if trying
--verbose
and see more logsdart run
instead of flutter pub run
This morning, no stuck anymore. I am able to run build_runner without problem. This is better, even if I don't understand why yesterday it stucked. 👀
Yes,
.freezed.dart
and.g.dart
is generated by build_runner.This is where the generation stuck .
The files are still not there.
When I remove the two instructions part 'XXXX.freezed.dart
I have still this error during flutter compilation:
Failed to build iOS app
Error (Xcode): ../lib/src/rust/frb_generated.dart:26895:40: Error: Type '_$AudioNodeImplementor' not found.
Could not build the application for the simulator.
Error launching application on iPhone 15.
Hmm, could you please provide the code that errors (https://github.com/Canardoux/tau or another place?), then I can try to run it locally to see what is going on.
Sorry, there is a problem with github. Please wait a little bit
Take your time!
OK now : https://github.com/Canardoux/tau
Hmm it runs well in my machine:
But maybe this is related:
When I firstly run flutter pub get
, it complains freezed
2.5.3 it too high, thus I lower it to 2.5.2. In other words, modify pubspec.yaml
from freezed: ^2.5.3
to freezed: ^2.5.2
EDIT: Oops I forget to check the generated .freezed.dart, wait a minute.
EDIT 2: I modified flutter_rust_bridge.yaml
to remove build_runner: false
, then run codegen again.
It seems that the freezed files are there:
This is weird those two files are note generated on my machine 🙄
There is something bad on my environment machine : the Run Dart build_runner
stucks again when I remove build_runner: false
It stucks, and I cannot interrupt with Control-C :
larpoux@Mac-mini:~/projmac/tau$ dart run build_runner build --delete-conflicting-outputs --enable-experiment=class-modifiers --verbose
Building package executable...
Built build_runner:build_runner.
[INFO] Entrypoint:Generating build script...
[INFO] Entrypoint:Generating build script completed, took 253ms
[INFO] BuildDefinition:Initializing inputs
[INFO] BuildDefinition:Reading cached asset graph...
[INFO] BuildDefinition:Reading cached asset graph completed, took 9.6s
[INFO] BuildDefinition:Checking for updates since last build...
^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C
And when I run frb generate without doing build_runner
I get very few files :
cargo build
on flutter_rust_bridge/frb_codegen.~/projmac/flutter_rust_bridge/target/debug/flutter_rust_bridge_codegen generate
And I got these files:
Hmm, if a standalone dart run build_runner build --delete-conflicting-outputs --enable-experiment=class-modifiers --verbose
stucks, then maybe we can create an issue in Dart/Flutter. Since that is a normal and commonly used Dart command!
Forget the problem of stuck: I can run the generation under your project: flutter_rust_bridge/frb_example/integrate_third_party. No stuck with your project. I will try to understand later why it stucks some time in my project . But as I told you, the main problem is that the files generated cannot be compiled by dart. Even with your example.
part 'context.freezed.dart';
but the file does not exist. in frb_generated.dart :
part 'frb_generated.freezed.dart';
But the file doesn’t exist
That .freezed.dart is generated by build_runner (which calls Dart package freezed
). So if it is not generated (that's a problem!), then things will not compile.
When I use your example, after a git clone without any modification, the files are not generated. But the files are there before running flutter_rust_bridge generate
Hmm, then maybe delete many files and see whether they are re-generated. If not, then this looks like a problem.
Again, as suggested above, if running a standard dart run build_runner build
command on a standard Flutter/Dart project results in files not generated or stuck or something like that, then maybe we need to ask on Flutter repo / freezed
package repo.
larpoux@Mac-mini:~/projmac$ git clone https://github.com/fzyzcjy/flutter_rust_bridge.git
Cloning into 'flutter_rust_bridge'...
remote: Enumerating objects: 285706, done.
remote: Counting objects: 100% (32877/32877), done.
remote: Compressing objects: 100% (7686/7686), done.
remote: Total 285706 (delta 24485), reused 32304 (delta 24310), pack-reused 252829
Receiving objects: 100% (285706/285706), 243.41 MiB | 28.92 MiB/s, done.
Resolving deltas: 100% (217015/217015), done.
larpoux@Mac-mini:~/projmac$ cd flutter_rust_bridge/frb_example/
larpoux@Mac-mini:~/projmac/flutter_rust_bridge/frb_example$ cd integrate_third_party/
larpoux@Mac-mini:~/projmac/flutter_rust_bridge/frb_example/integrate_third_party$ ls -l lib/src/rust
total 6264
drwxr-xr-x 8 larpoux staff 256 Jun 19 10:47 .
drwxr-xr-x 3 larpoux staff 96 Jun 19 10:47 ..
drwxr-xr-x 5 larpoux staff 160 Jun 19 10:47 api
-rw-r--r-- 1 larpoux staff 1528438 Jun 19 10:47 frb_generated.dart
-rw-r--r-- 1 larpoux staff 1261698 Jun 19 10:47 frb_generated.freezed.dart
-rw-r--r-- 1 larpoux staff 226541 Jun 19 10:47 frb_generated.io.dart
-rw-r--r-- 1 larpoux staff 179909 Jun 19 10:47 frb_generated.web.dart
drwxr-xr-x 4 larpoux staff 128 Jun 19 10:47 third_party
larpoux@Mac-mini:~/projmac/flutter_rust_bridge/frb_example/integrate_third_party$ vi flutter_rust_bridge.yaml
larpoux@Mac-mini:~/projmac/flutter_rust_bridge/frb_example/integrate_third_party$ flutter_rust_bridge_codegen generate
[2024-06-19T08:58:09.448Z WARN /Volumes/mac-J/larpoux/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.0.0-dev.40/src/library/codegen/parser/hir/flat/transformer/merge_duplicate_transformer/mod.rs:72] There are still multiple objects with same key after merging, thus randomly pick one (key=("AudioParamValues < 'a >", "get"), objects={"namespace":"web_audio_api::render::processor","owner":{"StructOrEnum":{"impl_ty":"AudioParamValues < 'a >","trait_def_name":null}},"sources":["Normal"],"item_fn":"GeneralizedItemFn(name=get, vis=Some(Visibility::Public(Pub)), attrs=[# [doc = \" Get the computed values for the given [`crate::param::AudioParam`]\"], # [doc = \"\"], # [doc = \" For k-rate params or if the (a-rate) parameter is constant for this block, it will provide\"], # [doc = \" a slice of length 1. In other cases, i.e. a-rate param with scheduled automations it will\"], # [doc = \" provide a slice of length equal to the render quantum size (default: 128)\"], # [allow (clippy :: missing_panics_doc)]])"}, {"namespace":"web_audio_api::worklet","owner":{"StructOrEnum":{"impl_ty":"AudioParamValues < 'a >","trait_def_name":null}},"sources":["Normal"],"item_fn":"GeneralizedItemFn(name=get, vis=Some(Visibility::Public(Pub)), attrs=[# [doc = \" Get the computed values for the given [`AudioParam`]\"], # [doc = \"\"], # [doc = \" For k-rate params or if the (a-rate) parameter is constant for this block, it will provide\"], # [doc = \" a slice of length 1. In other cases, i.e. a-rate param with scheduled automations it will\"], # [doc = \" provide a slice of length equal to the render quantum size (default: 128)\"], # [allow (clippy :: missing_panics_doc)]])"})
[2024-06-19T08:58:09.468Z INFO /Volumes/mac-J/larpoux/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.0.0-dev.40/src/library/codegen/parser/mir/parser/ty/lifetimeable.rs:51] 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
[2024-06-19T08:58:09.529Z WARN /Volumes/mac-J/larpoux/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.0.0-dev.40/src/library/codegen/parser/mir/sanity_checker/auto_accessor_checker.rs:21] To use the automatically generated getters of the following fields of opaque types, it is suggested to read https://fzyzcjy.github.io/flutter_rust_bridge/guides/types/arbitrary/rust-auto-opaque/properties to know more details. (Related fields: web_audio_api::media_recorder::BlobEvent.blob, web_audio_api::media_recorder::BlobEvent.blob, web_audio_api::media_recorder::BlobEvent.event, web_audio_api::media_recorder::BlobEvent.event, web_audio_api::OfflineAudioCompletionEvent.rendered_buffer, web_audio_api::OfflineAudioCompletionEvent.rendered_buffer, web_audio_api::OfflineAudioCompletionEvent.event, web_audio_api::OfflineAudioCompletionEvent.event, web_audio_api::AudioProcessingEvent.input_buffer, web_audio_api::AudioProcessingEvent.input_buffer, web_audio_api::AudioProcessingEvent.output_buffer, web_audio_api::AudioProcessingEvent.output_buffer, web_audio_api::AudioRenderCapacityEvent.event, web_audio_api::AudioRenderCapacityEvent.event)
[2024-06-19T08:58:09.645Z INFO /Volumes/mac-J/larpoux/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.0.0-dev.40/src/library/codegen/parser/mir/parser/ty/lifetimeable.rs:51] 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
[2024-06-19T08:58:09.705Z WARN /Volumes/mac-J/larpoux/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.0.0-dev.40/src/library/codegen/parser/mir/sanity_checker/auto_accessor_checker.rs:21] To use the automatically generated getters of the following fields of opaque types, it is suggested to read https://fzyzcjy.github.io/flutter_rust_bridge/guides/types/arbitrary/rust-auto-opaque/properties to know more details. (Related fields: web_audio_api::AudioProcessingEvent.input_buffer, web_audio_api::AudioProcessingEvent.input_buffer, web_audio_api::AudioProcessingEvent.output_buffer, web_audio_api::AudioProcessingEvent.output_buffer, web_audio_api::media_recorder::BlobEvent.blob, web_audio_api::media_recorder::BlobEvent.blob, web_audio_api::media_recorder::BlobEvent.event, web_audio_api::media_recorder::BlobEvent.event, web_audio_api::OfflineAudioCompletionEvent.rendered_buffer, web_audio_api::OfflineAudioCompletionEvent.rendered_buffer, web_audio_api::OfflineAudioCompletionEvent.event, web_audio_api::OfflineAudioCompletionEvent.event, web_audio_api::AudioRenderCapacityEvent.event, web_audio_api::AudioRenderCapacityEvent.event)
[2024-06-19T08:58:14.103Z WARN /Volumes/mac-J/larpoux/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.0.0-dev.40/src/library/commands/command_runner.rs:153] command=cd "/Volumes/mac-J/larpoux/projmac/flutter_rust_bridge/frb_example/integrate_third_party" && FRB_SIMPLE_BUILD_SKIP="1" "sh" "-c" "\"flutter\" \"pub\" \"run\" \"build_runner\" \"build\" \"--delete-conflicting-outputs\" \"--enable-experiment=class-modifiers\"" stdout= stderr=Cannot open file, path = '.dart_tool/package_config.json' (OS Error: No such file or directory, errno = 2)
[2024-06-19T08:58:14.103Z WARN /Volumes/mac-J/larpoux/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.0.0-dev.40/src/library/codegen/polisher/mod.rs:89] Fail to execute_build_runner, but continue to run.
Error details: Err(Failed to run build_runner for "/Volumes/mac-J/larpoux/projmac/flutter_rust_bridge/frb_example/integrate_third_party": )
[2.6s] Parse
└── [2.1s] Cargo expand & syn parse
└── [0.3s] Parse HIR
└── [0.2s] Parse MIR
[3.9s] Generate
[1.8s] Polish
└── [0.4s] Run Dart build_runner
└── [1.0s] Run Dart formatter
└── [0.4s] Run Rust formatter Done!
larpoux@Mac-mini:~/projmac/flutter_rust_bridge/frb_example/integrate_third_party$ ls -l lib/src/rust
total 3792
drwxr-xr-x 7 larpoux staff 224 Jun 19 10:51 .
drwxr-xr-x 3 larpoux staff 96 Jun 19 10:47 ..
drwxr-xr-x 5 larpoux staff 160 Jun 19 10:47 api
-rw-r--r-- 1 larpoux staff 1528187 Jun 19 10:58 frb_generated.dart
-rw-r--r-- 1 larpoux staff 226292 Jun 19 10:58 frb_generated.io.dart
-rw-r--r-- 1 larpoux staff 179660 Jun 19 10:58 frb_generated.web.dart
drwxr-xr-x 4 larpoux staff 128 Jun 19 10:51 third_party
larpoux@Mac-mini:~/projmac/flutter_rust_bridge/frb_example/integrate_third_party$ ls -l lib/src/rust/third_party/web_audio_api
total 248
drwxr-xr-x 8 larpoux staff 256 Jun 19 10:51 .
drwxr-xr-x 4 larpoux staff 128 Jun 19 10:51 ..
-rw-r--r-- 1 larpoux staff 32059 Jun 19 10:58 context.dart
-rw-r--r-- 1 larpoux staff 2540 Jun 19 10:58 media_devices.dart
-rw-r--r-- 1 larpoux staff 1756 Jun 19 10:58 media_recorder.dart
-rw-r--r-- 1 larpoux staff 1811 Jun 19 10:58 media_streams.dart
-rw-r--r-- 1 larpoux staff 73785 Jun 19 10:58 node.dart
-rw-r--r-- 1 larpoux staff 3224 Jun 19 10:58 worklet.dart
larpoux@Mac-mini:~/projmac/flutter_rust_bridge/frb_example/integrate_third_party$
Error details: Err(Failed to run build_runner for "/Volumes/mac-J/larpoux/projmac/flutter_rust_bridge/frb_example/integrate_third_party": )
Hmm there is an error!
[2024-06-19T08:58:14.103Z WARN /Volumes/mac-J/larpoux/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.0.0-dev.40/src/library/codegen/polisher/mod.rs:89] Fail to execute_build_runner, but continue to run. Error details: Err(Failed to run build_runner for "/Volumes/mac-J/larpoux/projmac/flutter_rust_bridge/frb_example/integrate_third_party": )
This is perhaps the reason
Yes I think so. Try to run RUST_LOG=debug flutter_rust_bridge_codegen generate
and look at the sections related to build_runner
larpoux@Mac-mini:~/projmac/flutter_rust_bridge/frb_example/integrate_third_party$ RUST_LOG=debug flutter_rust_bridge_codegen generate >/tmp/frb.log
[2.5s] Parse
└── [1.9s] Cargo expand & syn parse
└── [0.4s] Parse HIR
└── [0.2s] Parse MIR
[3.9s] Generate
[1.8s] Polish
└── [0.4s] Run Dart build_runner
└── [1.0s] Run Dart formatter
└── [0.4s] Run Rust formatter larpoux@Mac-mini:~/projmac/flutter_rust_bridge/frb_example/integrate_third_party$
[2024-06-19T09:05:36.947Z WARN /Volumes/mac-J/larpoux/.cargo/registry/src/index.crates.io-6f17d22bba15001f/flutter_rust_bridge_codegen-2.0.0-dev.40/src/library/commands/command_runner.rs:153] command=cd "/Volumes/mac-J/larpoux/projmac/flutter_rust_bridge/frb_example/integrate_third_party" && FRB_SIMPLE_BUILD_SKIP="1" "sh" "-c" "\"flutter\" \"pub\" \"run\" \"build_runner\" \"build\" \"--delete-conflicting-outputs\" \"--enable-experiment=class-modifiers\"" stdout= stderr=Cannot open file, path = '.dart_tool/package_config.json' (OS Error: No such file or directory, errno = 2)
Looks like you need a dart pub get
or flutter pub get
(Hmm it was also on the last log, I should have seen it...)
YEAH! It's much better. Now I am going to try to compile the dart stuff and I will let you know how everything is going. Thank you.
You are welcome!
Enclosed files
What do I do wrongly ?
Hi, could you please provide a minimal reproducible sample (probably as a github repo)? Then I can download and have a check.
This repo : this is just a fork from your own repo, and I replaced simple.rs
by mine. (frb_example/integrate_third_party).
Get it, will check later!
@fzyzcjy : forget this issue : it was my fault. I forgot to add some dependencies in Cargo.toml. Everything OK now. I am going to let you know how things are going ...
I have a dart compilation error :
Launching lib/main.dart on iPhone 15 in debug mode...
Running Xcode build...
Xcode build done. 13.7s
Failed to build iOS app
Error (Xcode): ../lib/src/rust/third_party/web_audio_api/media_recorder.dart:41:54: Error: Type 'MediaStream' not found.
Could not build the application for the simulator.
Error launching application on iPhone 15.
Just for your info : I just add the missing import
by hand, myself.
No worries, happy to see it is solved!
I just add the missing import by hand, myself.
Hmm that looks like a bug. Do you mean everything is correctly generated, except that one import is missing?
could someone (@fzyzcjy ?) tell me briefly where is the code building the .dylib
for iOS ?
Update : I thing I found : rust_builder/cargokit
where is the code building the .dylib for iOS ?
It is using Cargokit under the hood (rust_builder folder indeed), so I guess just check their docs.
However, if you are going to publish it as a package instead of an app, https://cjycode.com/flutter_rust_bridge/manual/integrate/cargokit (e.g. example package https://github.com/fzyzcjy/flutter_rust_bridge/tree/master/frb_example/flutter_package) will be helpful.
Thank you for the links
You are welcome!
Y E H ! ! !
I am able to play a resource asset (RAW PCM) with rust-audio-api-rs called directly by a dart function, using FRB.
I am happy. This is a great day.
This is for me an important milestone. Now I am going to add a gain node
and a panner node
.
I will let you know the result.
BTW: I had many various problems. One of those problems was with the .dart_tool
directory.
I have never been very interested by this directory. I don't save it in git
and I very often delete this directory when I get problems during compilation.
But FRB seems to really need this directory.
Describe the bug
when I code this :
FRB enters an infinite internal loop (never finishes).
toto.log
Steps to reproduce
-
Logs
Expected behavior
No response
Generated binding code
OS
No response
Version of
flutter_rust_bridge_codegen
flutter_rust_bridge_codegen 2.0.0-dev.40
Flutter info
No response
Version of
clang++
No response
Additional context
No response