Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hashes are the same but there is a hash mismatch shown #1960

Closed
Xoroxa opened this issue May 19, 2024 · 12 comments
Closed

Hashes are the same but there is a hash mismatch shown #1960

Xoroxa opened this issue May 19, 2024 · 12 comments
Labels
bug Something isn't working

Comments

@Xoroxa
Copy link

Xoroxa commented May 19, 2024

Describe the bug

Encountered the hash mismatch even when the hashes were the same. Made a new project and just added the cargo.toml dependencies and my single rust file, and the bug reappears.

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: Content hash on Dart side (496887197) is different from Rust side (-1918914929), indicating out-of-sync code. This may happen when, for example, the Dart code is hot-restarted/hot-reloaded without recompiling Rust code. (Note: This is just a sanity check. Even if content hash does not change, the code may still change and needs to be recompiled)

Steps to reproduce

  1. create new flutter_rust_bridge project
  2. Add dependencies to cargo.toml to this: https://paaster.io/4EaNSzPdHXlO2WmC2Bdbi#qKfbjNKeUYLlcUuUJuKOcnhDwSOZZm-oh1GDycjQJc4
  3. Rust file: https://paaster.io/7uAfWZOxQH6ybuZMXdL4A#ET2ay2na9Y__u4i2tAzWxUtVSDDpiuS2akU4BrdZnQU
  4. Simply add these 2 to a new project and that is all it took for me to get the error.

Logs

https://paaster.io/1MJXUeidwwgpgmPARCEYv#6gzb9ckJCC0tNfj4fDASNmbBpreGDErcRpsB4pFviAE

Expected behavior

No response

Generated binding code

No response

OS

Windows

Version of flutter_rust_bridge_codegen

2.0.0-dev.34 & 2.0.0-dev.33

Flutter info

All checks

Version of clang++

Android (11695104, based on r522817) clang version 18.0.1

Additional context

No response

@Xoroxa Xoroxa added the bug Something isn't working label May 19, 2024
Copy link

welcome bot commented May 19, 2024

Hi! Thanks for opening your first issue here! 😄

@fzyzcjy
Copy link
Owner

fzyzcjy commented May 20, 2024

Hi, could you please show a self-contained minimal reproducible sample? (possibly a github repo). especially I am interested in seeing frb_generated.rs and frb_generated.dart to see whether the numbers match.

In addition, maybe related: #1932, i.e. maybe the old compiled Rust binary is somehow used by the compilation toolchain. Thus, maybe try to

trying to delete the whole target directory in rust, which contains all compiled Rust files

and also feel free to provide more details about your compilation toolchain (how it is compiled), maybe we can report/fix if it is a bug of it.

@fzyzcjy fzyzcjy added the awaiting Waiting for responses, PR, further discussions, upstream release, etc label May 20, 2024
@Xoroxa
Copy link
Author

Xoroxa commented May 20, 2024

Here is a git repo with a minimal reproduction. I am curious to see if it works on your system and not just localized to me. I did check the hashes using this command: cat rust/src/frb_generated.rs | grep HASH && cat lib/src/rust/frb_generated.dart | grep ContentHash. I also already found that other issue and attempted the slated fix. I also made a new project and just imported the two files mentioned in my initial report, and still encountered the issue. When it comes to my compiler, I believe I am compiling using the android ndk at least when it comes to clang. Not sure if there is anything else you require. I appreciate your help on this.

https://github.com/Xoroxa/testflutterbridge

@fzyzcjy
Copy link
Owner

fzyzcjy commented May 20, 2024

https://github.com/Xoroxa/testflutterbridge/blob/1bce6822525fddab5640b92648fa8e3d37b446e0/lib/src/rust/frb_generated.dart#L59

https://github.com/Xoroxa/testflutterbridge/blob/1bce6822525fddab5640b92648fa8e3d37b446e0/rust/src/frb_generated.rs#L35

I agree, the hash is the same.

Content hash on Dart side (496887197) is different from Rust side (-1918914929), indicating out-of-sync code.

Weirdly, both numbers are not the ones in your repo (977052611)!

One way is to add a few prints here and there to see whether the numbers are really wrong or correct. I may check this later if still not fixed, probably within several days or a week, but I guess it may be caused by some environment issues...

@Xoroxa
Copy link
Author

Xoroxa commented May 20, 2024

Actually the reason for the number being different from the one I reported is due to me remaking the project in a new project in order to minify it. If I were to build that project I would get the first of the two hashes for both. I can try to add the print statements tomorrow. I agree that it may be an environment related issues, though I need someone else to run it to make sure. I'll try to get someone to try it out tomorrow as well.

@fzyzcjy
Copy link
Owner

fzyzcjy commented May 20, 2024

I see, then it looks like Rust compilation problem.

I also made a new project and just imported the two files mentioned in my initial report, and still encountered the issue.

Maybe, after the files are modified, try to delete the whole rust/target folder, and in addition to flutter clean, and cd rust && cargo clean, and rebuild it

@Xoroxa
Copy link
Author

Xoroxa commented May 20, 2024

I already attempted those steps under the new and old project. I believe the only thing it could be is either a bug or something to do with my environment. I will try and check today if it is my environment and update accordingly.

@fzyzcjy
Copy link
Owner

fzyzcjy commented May 20, 2024

I tried to run it locally, but it yields the following compilation error. It looks fixable, but since it is unrelated to flutter_rust_bridge, I guess if there is a minimal reproducible sample that can directly compile, I will try to run it locally and see whether it works.

SEVERE:   exit status: 0
SEVERE:   running: "/Users/tom/Library/Android/sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ar" "s" "/Volumes/MyExternal/ExternalRefCode/testflutterbridge/build/rust_lib_testflutterbridge/build/aarch64-linux-android/debug/build/crfsuite-sys-eaf8ad7d36c1227a/out/libcrfsuite.a"
SEVERE:   exit status: 0
SEVERE:   cargo:rustc-link-lib=static=crfsuite
SEVERE:   cargo:rustc-link-search=native=/Volumes/MyExternal/ExternalRefCode/testflutterbridge/build/rust_lib_testflutterbridge/build/aarch64-linux-android/debug/build/crfsuite-sys-eaf8ad7d36c1227a/out
SEVERE:   cargo:warning=No Sysroot detected, assuming the target is baremetal. If you have a sysroot, you must either define a TARGET_SYSROOT or use Dinghy to build your project.
SEVERE:   OPT_LEVEL = Some("0")
SEVERE:   TARGET = Some("aarch64-linux-android")
SEVERE:   HOST = Some("x86_64-apple-darwin")
SEVERE:   cargo:rerun-if-env-changed=CC_aarch64-linux-android
SEVERE:   CC_aarch64-linux-android = Some("/Users/tom/Library/Android/sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang")
SEVERE:   cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
SEVERE:   CRATE_CC_NO_DEFAULTS = None
SEVERE:   DEBUG = Some("true")
SEVERE:   cargo:rerun-if-env-changed=CFLAGS_aarch64-linux-android
SEVERE:   CFLAGS_aarch64-linux-android = Some("--target=aarch64-linux-android21")
SEVERE: 
SEVERE:   --- stderr
SEVERE:   Apple clang version 14.0.0 (clang-1400.0.29.202)
SEVERE:   Target: aarch64-unknown-linux-android
SEVERE:   Thread model: posix
SEVERE:   InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
SEVERE:   ignoring nonexistent directory "/include"
SEVERE:   ignoring nonexistent directory "/usr/include"
SEVERE:   #include "..." search starts here:
SEVERE:   #include <...> search starts here:
SEVERE:    /Users/tom/Library/Android/sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/darwin-x86_64/lib64/clang/12.0.8/include
SEVERE:    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.0/include
SEVERE:    /usr/local/include
SEVERE:   End of search list.
SEVERE:   c/include/crfsuite.h:40:10: fatal error: 'stdio.h' file not found
SEVERE:   thread 'main' panicked at /Users/tom/.cargo/git/checkouts/crfsuite-rs-a6a77ee2c83ba718/2701cdc/crfsuite-sys/build.rs:60:10:
SEVERE:   called `Result::unwrap()` on an `Err` value: ClangDiagnostic("c/include/crfsuite.h:40:10: fatal error: 'stdio.h' file not found\n")
SEVERE:   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
SEVERE: warning: build failed, waiting for other jobs to finish...
SEVERE: --------------------------------------------------------------------------------
SEVERE: #0      runCommand (package:build_tool/src/util.dart:121:5)
SEVERE: #1      RustBuilder.build (package:build_tool/src/builder.dart:142:5)
SEVERE: <asynchronous suspension>
SEVERE: #2      ArtifactProvider.getArtifacts (package:build_tool/src/artifacts_provider.dart:71:25)
SEVERE: <asynchronous suspension>
SEVERE: #3      BuildGradle.build (package:build_tool/src/build_gradle.dart:35:23)
SEVERE: <asynchronous suspension>
SEVERE: #4      BuildGradleCommand.runBuildCommand (package:build_tool/src/build_tool.dart:65:5)
SEVERE: <asynchronous suspension>
SEVERE: #5      BuildCommand.run (package:build_tool/src/build_tool.dart:37:5)
SEVERE: <asynchronous suspension>
SEVERE: #6      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
SEVERE: <asynchronous suspension>
SEVERE: #7      runMain (package:build_tool/src/build_tool.dart:251:5)
SEVERE: <asynchronous suspension>
SEVERE: --------------------------------------------------------------------------------
SEVERE: BuildTool arguments: [build-gradle]
SEVERE: ================================================================================

FAILURE: Build failed with an exception.

* Where:
Script '/Volumes/MyExternal/ExternalRefCode/testflutterbridge/rust_builder/cargokit/gradle/plugin.gradle' line: 68

* What went wrong:
Execution failed for task ':rust_lib_testflutterbridge:cargokitCargoBuildRust_lib_testflutterbridgeDebug'.
> Process 'command '/Volumes/MyExternal/ExternalRefCode/testflutterbridge/rust_builder/cargokit/gradle/../run_build_tool.sh'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2m 53s
Running Gradle task 'assembleDebug'...                            174.7s
Error: Gradle task assembleDebug failed with exit code 1

@Xoroxa
Copy link
Author

Xoroxa commented May 20, 2024

I had encountered this issue before as well c/include/crfsuite.h:40:10: fatal error: 'stdio.h' file not found. It is due to stdio.h not being available when building. If I recall correctly I upgraded my android ndk version to the latest release and it was fixed.

@Xoroxa
Copy link
Author

Xoroxa commented May 22, 2024

I figured out the issue and it had nothing to do with flutter_rust_bridge hence the closing of this issue.

@Xoroxa Xoroxa closed this as completed May 22, 2024
@fzyzcjy
Copy link
Owner

fzyzcjy commented May 23, 2024

Happy to see it is solved!

@fzyzcjy fzyzcjy removed the awaiting Waiting for responses, PR, further discussions, upstream release, etc label May 23, 2024
Copy link
Contributor

github-actions bot commented Jun 6, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants