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

implement hash concat for wasm pkg #2387

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

Slixe
Copy link

@Slixe Slixe commented Nov 2, 2024

Changes

Closes #2384

Checklist

  • An issue to be fixed by this PR is listed above.
  • New tests are added to ensure new features are working. Please refer to this page to see how to add a test.
  • ./frb_internal precommit --mode slow (or fast) is run (it internal runs code generator, does auto formatting, etc).
  • If this PR adds/changes features, documentations (in the ./website folder) are updated.
  • CI is passing. Please refer to this page to see how to solve a failed CI.

Remark for PR creator

  • ./frb_internal --help shows utilities for development.
  • If fzyzcjy does not reply for a few days, maybe he just did not see it, so please ping him.

Copy link

welcome bot commented Nov 2, 2024

Hi! Thanks for opening this pull request! 😄

@Slixe Slixe marked this pull request as draft November 2, 2024 17:47
@@ -149,8 +153,12 @@ Future<String> _getRustCreateName({required String rustCrateDir}) async {
return rustCrateName;
}

Future<int> _getRustContentHash({required String rustCrateDir}) async {
throw UnimplementedError();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fzyzcjy how would you fetch the rust content hash from the build-web command?

Copy link
Owner

@fzyzcjy fzyzcjy Nov 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way may be parsing the generated code and find it.

But I am thinking about something more general: How does normal wasm-pack + js users (i.e. not wasm + dart users) handle this? I guess there may be some ways to add content hashing within wasm-pack ecosystem, and maybe we can utilize it.

EDIT: https://rustwasm.github.io/docs/wasm-pack/tutorials/hybrid-applications-with-webpack/using-your-library.html Hmm I guess maybe js users will just import it as a npm package or something like that, and rely on webpack to add hashing. But we do surely do not want to introduce webpack. Thus our current way seems reasonable.

Another question: Rust content hash only hashes about the bindings. But if the user changes other codes (e.g. some rust code), the hash will not change. Maybe we can find a better hash. Sorry for pointing for this hash yesterday - too tired then :(

Maybe we can create an issue at wasm-pack to discuss this. They officially support the no-module deployment, i.e. deploy without the need of webpack. So maybe we can ask what is the suggested way to handle such cache-invalidtion issues in this case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can just build it like it was, and then at the final packing we hash the wasm file, append it to the filename and put it in the loader config too?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable! More brainstorms based on that:

  • Instead of rust_lib-abcdef.js, we do rust_lib.js?dummy_query=abcdef (where abcdef is the content hash). Then we do not need to rename anything to keep it simple.
  • Then, after build-web, if this feature is enabled, we just compute hash(read_file(rust_lib.js) + read_file(rust_lib.wasm)), and write it to a field in frb_generated.dart.

I am still wondering whether there are more "native" solutions instead of hand crafting it...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right, we could do that. Unfortunately the generated js file split the filename.js and add _bg.wasm as suffix. We would need to do a find and replace to add _bg.wasm?dummy=abcdef

so maybe having it in the directly would be better / easier.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, show we ask wasm-pack if they want to handle the hash on their side, or should I continue to work on a implementation here?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can create an issue there to have a discussion with them (feel free to cc me if you like). Because if this feature is done there, then not only frb but also every other package that depend on wasm-pack will benefit from this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Web target with hash included in wasm pkg files to solve cache issues
2 participants