lightning-fs icon indicating copy to clipboard operation
lightning-fs copied to clipboard

Integration with Emscripten

Open VariantXYZ opened this issue 2 years ago • 6 comments

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.

VariantXYZ avatar Feb 26 '23 09:02 VariantXYZ

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.

jcubic avatar Feb 26 '23 11:02 jcubic

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 avatar Feb 26 '23 17:02 VariantXYZ

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...

VariantXYZ avatar Feb 26 '23 19:02 VariantXYZ

Sorry I have no idea.

jcubic avatar Feb 26 '23 19:02 jcubic

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.

VariantXYZ avatar Feb 26 '23 20:02 VariantXYZ

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.

jcubic avatar Feb 26 '23 21:02 jcubic