Code Monkey home page Code Monkey logo

fs-web's People

Watchers

 avatar  avatar  avatar

fs-web's Issues

Idea: libc implementation for the web

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.