iceiix / fs-web Goto Github PK
View Code? Open in Web Editor NEWexperiments in alternative std::fs implementations for use on the web (incomplete)
License: Apache License 2.0
experiments in alternative std::fs implementations for use on the web (incomplete)
License: Apache License 2.0
The libc crate has "Raw FFI bindings to platform libraries like libc", and is used by std::fs's unix backend to access the filesystem. How about a web-based libc replacement?
Emscripten actually has this, since it is meant for compiling C/C++ apps for the web, see https://github.com/emscripten-core/emscripten/blob/master/src/library_fs.js among others. Emscripten's libc implementation is written in JavaScript.
Could we port Emscripten's libc, JavaScript and all, to be usable from Rust? js-sys and wasm-bindgen can access JavaScript from WASM. There is overhead from WASM to JS and it is not all that elegant. Also, library_fs.js appears to be preprocessed as part of Emscripten's build process, would have to somehow use the output as it is in the browser. But this port would give us a state-of-the-art (best in class) libc implementation.
Then it could be dropped into unix_fs.rs, creating an API layering like this: std::fs -> libc -> browser.
Having to deal with raw pointers and C foreign function interfaces is cumbersome, technically necessary for compatibility, but another middle ground alternative could be to write a libc alternative in pure Rust, with safe Rust types and using web-sys and/or js-sys to access the web platform, then call it from unix_fs.rs.
Are there existing Rust libc implementations? https://lib.rs/search?q=libc finds a few:
https://lib.rs/crates/rs-libc "A subset of libc that can be used with Rust in freestanding environments", but its mostly string functions, not I/O like filesystem syscalls
various safe wrappers
https://lib.rs/crates/pwasm-libc https://lib.rs/crates/owasm-libc "Parity WebAssembly standard library libc bindings", only memcpy?
https://lib.rs/crates/rlibc "A bare-metal library supplying certain libc functions like memcpy, memmove, memset and memcmp. This is designed for use in freestanding environments where another libc does not exist, since rustc may implicitly insert calls to such functions.", again only memory functions, and it is obsolete since 2016 since compiler_builtins has these
How about Rust-based operating systems? Redox's libc: https://github.com/redox-os/libc and relibc, written in Rust: https://github.com/redox-os/relibc "
relibc is a portable POSIX C standard library written in Rust. It is under heavy development, and currently supports Redox and Linux." , meant for Redox but supports Linux syscalls using sc. Another possible API layer to implement: Linux syscalls, just beneath the libc layer. Perhaps too low-level.
https://wasi.dev (WebAssembly System Interface) has some solutions, but it not entirely the same problem space
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.