fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.14k stars 285 forks source link

[Bug] Crates with their own build process don't work #1374

Closed Unbreathable closed 12 months ago

Unbreathable commented 12 months ago

Describe the bug

Whenever I try to build my voice library using the "audiopus_sys" crate it doesn't build. When I run "cargo build" in the project like normal it builds perfectly fine, but when I do the same through "flutter run" it doesn't work. I pasted the error into the field below. I'm running Windows 11 with the latest flutter (3.13.2) with the latest cargo/rust (1.70.0).

Codegen logs with RUST_LOG=debug environment variable

CUSTOMBUILD : error : failed to run custom build command for `audiopus_sys v0.2.2` [C:\Users\thisi\OneDrive\Desktop\temp\bridge-test\hello\build\windows\_cargo-build_voice_lib.vcxproj]

To Reproduce

It's pretty basic to reproduce it and I would suggest doing that.

  1. Do "cargo add audiopus_sys" to add the crate
  2. Re-generate the code using "flutter_rust_bridge_codegen [...]"
  3. Run the app using "flutter run"
  4. There should be the error I pasted above (this thing hit my file path limit of 260, so I had to disable it in the registry, you might have to do that as well)

Expected behavior

No response

Generated binding code

No response

OS

Windows

Version of flutter_rust_bridge_codegen

No response

Flutter info

No response

Version of clang++

No response

Version of ffigen

No response

Additional context

No response

welcome[bot] commented 12 months ago

Hi! Thanks for opening your first issue here! :smile:

fzyzcjy commented 12 months ago

Hi, could you please provide a bit more error logs? From what is shown, it may be because that crate does not compile, which may not be related to FRB but may need to create an issue at that crate

Unbreathable commented 12 months ago

Well, I'm not at home right now, so I can't get the full logs. I will when I'm home, but I was wondering if this you could maybe just be a corrosion issue since corrosion is the thing that actually builds the library. And since it works with a normal "cargo build" corrosion probably does something preventing libopus from building correctly. Could this be the case?

fzyzcjy commented 12 months ago

Surely possible! (Indeed it is hard to say anything is impossible without strong evidence ;) )

Unbreathable commented 12 months ago

Well here is the full log anyway (I've translated some things cause my PC is set to German):

Connected devices:
Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22621.2283]
Chrome (web)      • chrome  • web-javascript • Google Chrome 116.0.5845.188
Edge (web)        • edge    • web-javascript • Microsoft Edge 116.0.1938.69
[1]: Windows (windows)
[2]: Chrome (chrome)
[3]: Edge (edge)
Please choose one (or "q" to quit): 1
Launching lib\main.dart on Windows in debug mode...
CUSTOMBUILD : error : failed to run custom build command for `audiopus_sys v0.2.2` [C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\_cargo-build_space-lib.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(248,5): error MSB8066: The custom build for "C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\CMakeFiles\9eebda6e74c82e1656313f697ff5d0e3\_cargo-build_space-lib.rule" ended with code 101. [C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\_cargo-build_space-lib.vcxproj]
Building Windows application...                                     8,8s
Exception: Build process failed.

I hope this helps cause there really isn't much more, the weird thing is when I try just building the rust crate it's pulling I don't get any errors:

grafik

Also, when I remove the dependency on the crate "audiopus_sys" it's fine.

fzyzcjy commented 12 months ago

Maybe try to let

error : failed to run custom build command for audiopus_sys v0.2.2

output more verbose logs. You may need to inject the verbose flag into where the cargo build is called during that flutter build.

p.s. I have personally seen opencv not buildable because of environment variables different in flutter build environment and directly call from command line

Unbreathable commented 12 months ago

Alright here are the verbose logs, I didn't realize I could get that much out of it sorry.

[ +204 ms]      Compiling rodio v0.17.1
[        ]        Running `C:/Users/thisi/.rustup/toolchains/stable-x86_64-pc-windows-msvc/bin/rustc.exe --crate-name rodio --edition=2021
C:\Users\thisi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\rodio-0.17.1\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib   
--emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no --cfg "feature=\"claxon\"" --cfg "feature=\"default\"" --cfg "feature=\"flac\"" --cfg "feature=\"hound\"" --cfg
"feature=\"lewton\"" --cfg "feature=\"mp3\"" --cfg "feature=\"symphonia\"" --cfg "feature=\"symphonia-mp3\"" --cfg "feature=\"vorbis\"" --cfg "feature=\"wav\"" -C metadata=b5cab7d943de9e68 
-C extra-filename=-b5cab7d943de9e68 --out-dir "C:/Users/thisi/OneDrive/Dokumente/We(e)b
Stuff/FJ/chat/chat_interface/interface/build/windows/x64/Release/cargo/build\x86_64-pc-windows-msvc\release\deps" --target x86_64-pc-windows-msvc -L
"dependency=C:/Users/thisi/OneDrive/Dokumente/We(e)b Stuff/FJ/chat/chat_interface/interface/build/windows/x64/Release/cargo/build\x86_64-pc-windows-msvc\release\deps" -L
"dependency=C:/Users/thisi/OneDrive/Dokumente/We(e)b Stuff/FJ/chat/chat_interface/interface/build/windows/x64/Release/cargo/build\release\deps" --extern
"claxon=C:/Users/thisi/OneDrive/Dokumente/We(e)b
Stuff/FJ/chat/chat_interface/interface/build/windows/x64/Release/cargo/build\x86_64-pc-windows-msvc\release\deps\libclaxon-8d533a1adb6d1ca6.rmeta" --extern
"cpal=C:/Users/thisi/OneDrive/Dokumente/We(e)b
Stuff/FJ/chat/chat_interface/interface/build/windows/x64/Release/cargo/build\x86_64-pc-windows-msvc\release\deps\libcpal-2f4a4e90c36dc233.rmeta" --extern
"hound=C:/Users/thisi/OneDrive/Dokumente/We(e)b
Stuff/FJ/chat/chat_interface/interface/build/windows/x64/Release/cargo/build\x86_64-pc-windows-msvc\release\deps\libhound-cf66365ef1d08fb6.rmeta" --extern
"lewton=C:/Users/thisi/OneDrive/Dokumente/We(e)b
Stuff/FJ/chat/chat_interface/interface/build/windows/x64/Release/cargo/build\x86_64-pc-windows-msvc\release\deps\liblewton-3bf72bc7d7127917.rmeta" --extern
"symphonia=C:/Users/thisi/OneDrive/Dokumente/We(e)b
Stuff/FJ/chat/chat_interface/interface/build/windows/x64/Release/cargo/build\x86_64-pc-windows-msvc\release\deps\libsymphonia-cc55475799924cb8.rmeta" --cap-lints allow -L
native=C:\Users\thisi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_x86_64_msvc-0.48.5\lib -L
native=C:\Users\thisi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_x86_64_msvc-0.42.2\lib`
[+1142 ms] CUSTOMBUILD : error : failed to run custom build command for `audiopus_sys v0.2.2` [C:\Users\thisi\OneDrive\Dokumente\We(e)b
Stuff\FJ\chat\chat_interface\interface\build\windows\_cargo-build_space-lib.vcxproj]
[   +1 ms]   Caused by:
[        ]     process didn't exit successfully: `C:/Users/thisi/OneDrive/Dokumente/We(e)b
Stuff/FJ/chat/chat_interface/interface/build/windows/x64/Release/cargo/build\release\build\audiopus_sys-f578f4ffcf5b84d5\build-script-build` (exit code: 101)
-Brepro" "-DCMAKE_C_FLAGS_RELEASE= -nologo -MD -Brepro" "-DCMAKE_CXX_FLAGS= -nologo -MD -Brepro" "-DCMAKE_CXX_FLAGS_RELEASE= -nologo -MD -Brepro" "-DCMAKE_ASM_FLAGS= -nologo -MD -Brepro"
"-DCMAKE_ASM_FLAGS_RELEASE= -nologo -MD -Brepro" "-DCMAKE_BUILD_TYPE=Release"
[        ]     -- Opus project version: 0
[        ]     -- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22621.
[        ]     -- The C compiler identification is unknown
[        ]     -- Configuring incomplete, errors occurred!
[        ]     --- stderr
[        ]     CMake Warning at cmake/OpusPackageVersion.cmake:61 (message):
[        ]       Could not get package version.
[        ]     Call Stack (most recent call first):
[        ]       CMakeLists.txt:5 (get_package_version)
[        ]     CMake Error at CMakeLists.txt:7 (project):
[        ]       No CMAKE_C_COMPILER could be found.
[        ]     thread 'main' panicked at '
[        ]     command did not execute successfully, got: exit code: 1
[        ]     build script failed, must exit now', C:\Users\thisi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\cmake-0.1.50\src\lib.rs:1098:5
[        ]     note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[        ] CUSTOMBUILD : warning : build failed, waiting for other jobs to finish... [C:\Users\thisi\OneDrive\Dokumente\We(e)b
Stuff\FJ\chat\chat_interface\interface\build\windows\_cargo-build_space-lib.vcxproj]
[ +834 ms] C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(248,5): error MSB8066: Der benutzerdefinierte Build f�r
"C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\CMakeFiles\9eebda6e74c82e1656313f697ff5d0e3\_cargo-build_space-lib.rule" wurde mit dem Code 101
beendet. [C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\_cargo-build_space-lib.vcxproj]
[   +3 ms] Die Erstellung des Projekts "C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\_cargo-build_space-lib.vcxproj" ist abgeschlossen
(Standardziele) -- FEHLER.
[        ] Die Erstellung des Projekts "C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\cargo-build_space-lib.vcxproj" ist abgeschlossen (Standardziele)
-- FEHLER.
[        ] Die Erstellung des Projekts "C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\ALL_BUILD.vcxproj" ist abgeschlossen (Standardziele) -- FEHLER.
[        ] Die Erstellung des Projekts "C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\INSTALL.vcxproj" ist abgeschlossen (Standardziele) -- FEHLER.
[   +2 ms] Fehler beim Buildvorgang.
[        ] "C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\INSTALL.vcxproj" (Standardziel) (1) ->
[        ] "C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\ALL_BUILD.vcxproj" (Standardziel) (3) ->
[        ] "C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\cargo-build_space-lib.vcxproj" (Standardziel) (4) ->
[        ] "C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\_cargo-build_space-lib.vcxproj" (Standardziel) (5) ->
[        ] (CustomBuild Ziel) -> 
[        ]   CUSTOMBUILD : warning : build failed, waiting for other jobs to finish... [C:\Users\thisi\OneDrive\Dokumente\We(e)b
Stuff\FJ\chat\chat_interface\interface\build\windows\_cargo-build_space-lib.vcxproj]
[        ] "C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\INSTALL.vcxproj" (Standardziel) (1) ->
[        ] "C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\ALL_BUILD.vcxproj" (Standardziel) (3) ->
[        ] "C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\cargo-build_space-lib.vcxproj" (Standardziel) (4) ->
[        ] "C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\_cargo-build_space-lib.vcxproj" (Standardziel) (5) ->
[        ] (CustomBuild Ziel) -> 
[        ]   CUSTOMBUILD : error : failed to run custom build command for `audiopus_sys v0.2.2` [C:\Users\thisi\OneDrive\Dokumente\We(e)b
Stuff\FJ\chat\chat_interface\interface\build\windows\_cargo-build_space-lib.vcxproj]
[        ]   C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(248,5): error MSB8066: Der benutzerdefinierte Build f�r
"C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\CMakeFiles\9eebda6e74c82e1656313f697ff5d0e3\_cargo-build_space-lib.rule" wurde mit dem Code 101        
beendet. [C:\Users\thisi\OneDrive\Dokumente\We(e)b Stuff\FJ\chat\chat_interface\interface\build\windows\_cargo-build_space-lib.vcxproj]
[        ]     1 Warnung(en)
[        ]     2 Fehler
[        ] Verstrichene Zeit 00:00:02.82
[  +14 ms] Building Windows application... (completed in 6,1s)
[   +1 ms] "flutter windows" took 6.567ms.
[   +2 ms] Build process failed.
[        ]
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      _runBuild (package:flutter_tools/src/windows/build_windows.dart:220:5)
           <asynchronous suspension>
           #2      buildWindows (package:flutter_tools/src/windows/build_windows.dart:96:5)
           <asynchronous suspension>
           #3      BuildWindowsCommand.runCommand (package:flutter_tools/src/commands/build_windows.dart:56:5)
           <asynchronous suspension>
           #4      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1297:27)
           <asynchronous suspension>
           #5      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #6      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
           <asynchronous suspension>
           #7      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:339:9)
           <asynchronous suspension>
           #8      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #9      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:285:5)
           <asynchronous suspension>
           #10     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:115:9)
           <asynchronous suspension>
           #11     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #12     main (package:flutter_tools/executable.dart:90:3)
           <asynchronous suspension>

[   +4 ms] Running 0 shutdown hooks
[        ] Shutdown hooks complete
[        ] exiting with code 1

For comparison here is what it looks like when it builds it using "cargo build --verbose" without using "flutter run". It's on the longer side so I uploaded it to hastebin instead: https://hastebin.com/share/banawecaye.r

fzyzcjy commented 12 months ago

Then it looks like a environmental issue related to the crate you are using. I guess maybe we can create an issue at that crate's issue tracker.

Unbreathable commented 12 months ago

My guess is that it's an issue with my CMake file because their build process works just fine with "cargo build". I think I'm doing something wrong with corrosion so we should probably make an issue there first and see what they say cause the crate is only broken in a niche edge case when being built with corrosion through CMake.

Edit: I've already tried looking in the corrosion documentation but they don't seem to have anything related to my issue.

Unbreathable commented 12 months ago

Well I'm guessing this isn't the best solution, but I've just now found another crate that actually compiles with corrosion. I feel like it was just an issue with the crate I was using as you speculated. Sorry for bothering you and I hope you have a nice day. I'm closing this issue now as my stuff is resolved.

fzyzcjy commented 12 months ago

Happy to the the issue is resolved (workarounded)!

github-actions[bot] commented 11 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.