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

Mounting filesystems #3

Open
mstade opened this issue Feb 26, 2020 · 28 comments
Open

Mounting filesystems #3

mstade opened this issue Feb 26, 2020 · 28 comments

Comments

@mstade
Copy link

mstade commented Feb 26, 2020

It seems there's only an in-memory filesystem included with wasm-git (totally makes sense) but if I'm not completely mistaken it also looks like this can quite easily be replaced simply by mounting a filesystem at a given path? Digging through the FS object I see this:

Screenshot 2020-02-26 at 19 13 49

Is there any documentation you can point to on how to implement this interface, and is this all that's needed to plug in a different kind of filesystem?

What I'd like to do is actually write to disk, not memory, when my application is running on a local machine (in Electron, hence #2, but I can do this in Node just as well) but when it's running in a browser I obviously would use an in-memory filesystem. I don't want to just dump one big blob, I'd actually like to write proper files that could be used with a regular git client outside of my app as well.

@petersalomonsen
Copy link
Owner

If you build it yourself you should be able to include support for the file-systems that come with emscripten:

https://emscripten.org/docs/api_reference/Filesystem-API.html#file-systems

In your case you probably want NODEFS

I haven't tested this, but will try as soon as I get time. Thanks for feedback :-)

@mstade
Copy link
Author

mstade commented Feb 26, 2020

Brilliant, I'll see if I can create a build for this, thanks for the tips!

@samdenty
Copy link

samdenty commented Mar 2, 2020

Doesn't work with NodeFS, breaks creating .git/config.lock files.

Works better with emscripten NODERAWFS=1, but still has some issues.

emscripten-core/emscripten#10162 fixes the first issue

@petersalomonsen
Copy link
Owner

Does it work with emscripten-core/emscripten#10162 ?

I did some testing myself and found the reason for the lock failing to be that after renaming a file, the file still exist with the old name:

emscripten-core/emscripten#10628

@samdenty
Copy link

samdenty commented Mar 2, 2020

@petersalomonsen Lock file renaming doesn't fail with NODERAWFS. But it fails with readdir 'Invalid Arguments', which #10162 fixes.

Then failed in libgit2/src/unix/map.c#58, with failed to mmap. Could not write data: No such device

@petersalomonsen
Copy link
Owner

So this should fix the locking issue for NODEFS:

emscripten-core/emscripten#10631

Now I get the same mmap error as you get. Will look into this soon, unless someone is quicker than me :-)

@petersalomonsen
Copy link
Owner

this fixes the mmap error:

emscripten-core/emscripten#10669

after that you'll get permission errors on library_fs.js open method and library_nodefs.js setattr. A dirty workaround to this is to make sure that the mknod call in the open method always have write permission ( node = FS.mknod(path, mode | 0o200, 0); ), and before the truncateSync in setattr also give write permission. I was able to clone in NODEFS this way, but for a PR to emscripten I'll need something better than changing permissions.

@petersalomonsen
Copy link
Owner

I've successfully cloned using NODEFS with the changes committed here: f9ed551

@nachoab
Copy link

nachoab commented Jan 1, 2023

Would it be possible to use the new WasmFS and mount the OPFS fs?

I'm including this flags in the build command, but it's creating a lg.js file that doesn't contain the opfs implementation

-s WASMFS -s FORCE_FILESYSTEM

@petersalomonsen
Copy link
Owner

Thanks, I wasn't aware of this, but it would be interesting to check if it works out of the box. Otherwise I would assume there are minor adjustments needed to support it. I'll have a look in the near future.

@petersalomonsen
Copy link
Owner

Now compiling with the latest emscripten here: #58

Had to increase the stack size to make it work.

Not sure if it actually use WASMFS. Do I have to add the -s WASMFS switch?

@nachoab
Copy link

nachoab commented Jan 4, 2023

Now compiling with the latest emscripten here: #58

Had to increase the stack size to make it work.

Not sure if it actually use WASMFS. Do I have to add the -s WASMFS switch?

Including -s WASMFS is supposed to include the WASMFS JS libraries, but I'm not seeing any of the methods of the opfs js library being included in the exported js unless explicitly added on EXPORTED_RUNTIME_METHODS. But even then, is not useful since FS doesn't include a way to load the OPFS backend, so I guess FS it's just running on memory (with different API so maybe that's making git calls fail)

I asked how to test this here and was suggested to take a look at the tests. But those are tests for the C implementation and don't show how to mount a FS

@petersalomonsen
Copy link
Owner

Maybe it is too early? According to the tracking page here, many of the essential parts are still in status TODO: https://github.com/orgs/emscripten-core/projects/1/views/1?filterQuery=

@nachoab
Copy link

nachoab commented Jan 8, 2023

Yeah your right, I'll give a try in the future

@MeydanOzeri
Copy link

any update on this topic ? im also trying to create a custom file system

@petersalomonsen
Copy link
Owner

Yeah I see that there is progress here: https://github.com/orgs/emscripten-core/projects/1/views/1?filterQuery=

So maybe it's worth a try to integrate this with wasm-git in the near future.

@zavx0z
Copy link

zavx0z commented Nov 11, 2023

Any progress?

@petersalomonsen
Copy link
Owner

Just tried to compile with WASMFS enabled, but seems like it doesn't work quite yet. From the progress tracking pages in the emscripten project ( see previous message ), there are several needed features still missing. So I don't expect this to work yet.

@matbee-eth
Copy link

Just tried to compile with WASMFS enabled, but seems like it doesn't work quite yet. From the progress tracking pages in the emscripten project ( see previous message ), there are several needed features still missing. So I don't expect this to work yet.

Which browser did you test with btw?

@petersalomonsen
Copy link
Owner

Just tried to compile with WASMFS enabled, but seems like it doesn't work quite yet. From the progress tracking pages in the emscripten project ( see previous message ), there are several needed features still missing. So I don't expect this to work yet.

Which browser did you test with btw?

I just enabled the WASMFS flag, and tried running the tests ( using chrome browser ). Might be that I have not configured it correctly, but I've started some work on this now and also a Wasi build.. You can follow my progress in this PR here: #88

Currently been focusing on the Wasi build which is also a quite interesting use case.

@matbee-eth
Copy link

Just tried to compile with WASMFS enabled, but seems like it doesn't work quite yet. From the progress tracking pages in the emscripten project ( see previous message ), there are several needed features still missing. So I don't expect this to work yet.

Which browser did you test with btw?

I just enabled the WASMFS flag, and tried running the tests ( using chrome browser ). Might be that I have not configured it correctly, but I've started some work on this now and also a Wasi build.. You can follow my progress in this PR here: #88

Currently been focusing on the Wasi build which is also a quite interesting use case.

Do you think you could scaffold out some WASMFS tests that I could run against? Understanding you're currently focusing on WASI, I'm not terribly familiar with wasm-git codebase, but I would like to see how far I can get with my minor requirement of filesystem features.

@petersalomonsen
Copy link
Owner

Just tried to compile with WASMFS enabled, but seems like it doesn't work quite yet. From the progress tracking pages in the emscripten project ( see previous message ), there are several needed features still missing. So I don't expect this to work yet.

Which browser did you test with btw?

I just enabled the WASMFS flag, and tried running the tests ( using chrome browser ). Might be that I have not configured it correctly, but I've started some work on this now and also a Wasi build.. You can follow my progress in this PR here: #88
Currently been focusing on the Wasi build which is also a quite interesting use case.

Do you think you could scaffold out some WASMFS tests that I could run against? Understanding you're currently focusing on WASI, I'm not terribly familiar with wasm-git codebase, but I would like to see how far I can get with my minor requirement of filesystem features.

Here's a simple WASMFS test that passes: 844fa31

So it seems to handle simple operations as commit and log, so looks promising.

@petersalomonsen
Copy link
Owner

So I run into problems when mounting WasmFS backends. This is the error I see: emscripten-core/emscripten#18112 which is currently a blocker that needs to be fixed.

@fredericrous
Copy link

fredericrous commented Feb 28, 2024

let's all add thumbs up 👍 to issue emscripten-core/emscripten#18112 then, to try to make it visible

@petersalomonsen
Copy link
Owner

Some updates on what I think are the next steps here: #88 (comment)

@petersalomonsen
Copy link
Owner

So before I start with a new attempt on WASMFS/OPFS, I would like to change to ES6 modules and I also need to replace the Karma test runner ( which is not maintained anymore ).

I have done this in the following PR: #97

Note that changing to ES6 might break client implementations, but still I think it's better to also encourage these to start using ES6. I would like to not support CommonJS moving forward, but let me know if there are any strong opinions on this.

@fredericrous
Copy link

I've been using vite and vitest for a year now, on several projects. I'm super happy with these. especially with the fact that configuration is minimal and the tools are fast.

No need for commonjs support. git wasm is bleeding edge technology, I expect it to only support es6

@ngocdaothanh
Copy link

I hope that wasm-git will be able to use ZenFS:
https://github.com/zen-fs/core

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

No branches or pull requests

9 participants