-
Notifications
You must be signed in to change notification settings - Fork 306
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
Slixe
wants to merge
1
commit into
fzyzcjy:master
Choose a base branch
from
Slixe:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
rust_lib-abcdef.js
, we dorust_lib.js?dummy_query=abcdef
(whereabcdef
is the content hash). Then we do not need to rename anything to keep it simple.build-web
, if this feature is enabled, we just computehash(read_file(rust_lib.js) + read_file(rust_lib.wasm))
, and write it to a field infrb_generated.dart
.I am still wondering whether there are more "native" solutions instead of hand crafting it...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!