Skip to content

[WasmFS] Support file embedding #16105

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

Merged
merged 4 commits into from
Jan 25, 2022
Merged

[WasmFS] Support file embedding #16105

merged 4 commits into from
Jan 25, 2022

Conversation

kripken
Copy link
Member

@kripken kripken commented Jan 25, 2022

This practically worked since #16050, but the JS side needs to support a
missing parent, which is how the file packager emits it.

Fixes #16014

@kripken kripken requested a review from tlively January 25, 2022 01:04
@kripken
Copy link
Member Author

kripken commented Jan 25, 2022

Minor issue, we had code paths that support both passing name,null and null,name to give just a name and not a pair of parent,name. Rather than support two ways of doing it, I standardized on one of them. This should fix the broken wasmfs test in the browser suite here.

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

It seems stranger to provide parent but not name than it would be to provide name but not parent. Would it be feasible to standardize in the other direction?

@kripken
Copy link
Member Author

kripken commented Jan 25, 2022

I think of it as name, null being "one param is passed, not two, so interpret the only one as the full path". We have similar things elsewhere in JS, where the dynamic nature makes it possible to consider arguments as "optional" that way. But I don't feel strongly, if you still disagree?

@tlively
Copy link
Member

tlively commented Jan 25, 2022

If it's consistent and idiomatic, then lgtm, but it definitely feels weird! Sometimes the parent parameter is actually a parent, but other times it's actually the name while the name parameter goes unused.

@kripken
Copy link
Member Author

kripken commented Jan 25, 2022

Hmm, I looked around a little for an example in our codebase, and can't find one atm... maybe it's not as common as I thought. I'll flip it around as you suggest.

@kripken kripken enabled auto-merge (squash) January 25, 2022 19:25
@kripken
Copy link
Member Author

kripken commented Jan 25, 2022

Oh, I missed the example, which was just a few lines above this, in createPreloadedFile (as opposed to createDataFile which is modified here). That has the logic the first way I did it, and in fact tests break if it does not match between the two places. So I'll go back to the previous way...

This reverts commit e25d4e7.
@kripken kripken disabled auto-merge January 25, 2022 20:25
@kripken kripken merged commit 611b14a into main Jan 25, 2022
@kripken kripken deleted the wfembedd branch January 25, 2022 20:25
@@ -649,7 +649,7 @@ def generate_js(data_target, data_files, metadata):
var content = HEAPU32[start32++];
var name = UTF8ToString(name_addr)
// canOwn this data in the filesystem, it is a slice of wasm memory that will never change
Module['FS_createDataFile'](undefined, name, HEAP8.subarray(content, content + len), true, true, true);
Module['FS_createDataFile'](name, null, HEAP8.subarray(content, content + len), true, true, true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems odd to me too. The way I handled this in #16050 I guess made it work both wasy:

-      var path = name ? PATH.join2(typeof parent === 'string' ? parent : FS.getPath(parent), name) : parent;
+      var path = name;
+      if (parent) {
+        parent = typeof parent === 'string' ? parent : FS.getPath(parent);
+        path = name ? PATH.join2(parent, name) : parent;
+      }

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.

WasmFS: embed-file support
3 participants