isomorphic-git / lightning-fs

A lean and fast 'fs' for the browser
MIT License
493 stars 49 forks source link

Integration with Emscripten #117

Open VariantXYZ opened 1 year ago

VariantXYZ commented 1 year ago

I've been using isomorphic-git with lightning-fs and it's working great so far, but the next stage of my project is calling an emscripten-built assembler. Unfortunately, lightning-fs doesn't seem to implement the mount functionality emscripten expects for integration like BrowserFS.

Is it already possible to utilize lightning-fs within emscripten? If not, I think it would be really useful for lightning-fs to work with emscripten out of the box similar to BrowserFS. The full integration from Git to executing build tools all within the same file system is really appealing.

jcubic commented 1 year ago

Do you want to contribute and implement this? I'm afraid if you will not do this yourself or find someone that will do this, this will never be implemented. This project is the same as isomorphic-git and it doesn't have the main author that writes all the code for free. It's community-driven, I'm a maintainer but I rarely write code myself.

VariantXYZ commented 1 year ago

Gotcha.

Part of me was hoping it was possible and I wouldn't need to do anything, but I'll try to give it a shot. I'll close this issue for now regardless unless someone else wants to take it over.

VariantXYZ commented 1 year ago

Actually, might make more sense to leave this open as I work on it... Kinda closed it in a rush.

So one thing I've been trying instead is seeing if I can save time by bridging lightning-fs in with the Emscripten PROXYFS layer.

Though, for some reason now I'm hitting an issue with none of the synchronous fs APIs working in Chrome...

@jcubic , do you have any idea?

My repro case is fairly straightfoward, reference this: https://github.com/VariantXYZ/LatorGit/blob/c164a5b067e0157723ea27f1d3eb7eda84f90465/index.html#L48

(Changing this line to an await pfs.lstat('/'); will work fine)

The resulting page can be seen here, I tested in Chrome 110.0.5481.178 (Official Build) (64-bit) with the disable security flag. github-pages(1).zip

It seems to be failing here, with the callback 'cb' being null...

jcubic commented 1 year ago

Sorry I have no idea.

VariantXYZ commented 1 year ago

Ah, actually, sorry, I fundamentally misunderstood. That fs API provided needs a callback, and the fs.promises API is asynchronous while emscripten expects entirely synchronous fs calls.

I wonder if the only reasonable path is to write up the synchronous functions manually... though I don't think this'll work great with IndexedDB.

jcubic commented 1 year ago

Yes, this is a problem with Emscripten. I've even created an issue after someone asked a question on StackOverflow https://github.com/emscripten-core/emscripten/issues/6115 it seems there is Asyncify now, but I'm not sure how to use it.