JMLX42 opened a new pull request, #7005:
URL: https://github.com/apache/opendal/pull/7005

   ## Summary
   
   Adds a new `wasi-fs` backend that implements filesystem access via the 
`wasi:filesystem` interface for WebAssembly components running in WASI Preview 
2 runtimes (wasmtime, wasmer).
   
   Closes #7004
   
   ## AI Assistance Disclosure
   
   This implementation was developed with assistance from Claude (Anthropic). 
The AI helped with:
   - Researching OpenDAL service patterns and WASI Preview 2 APIs
   - Designing the implementation architecture
   - Writing the initial implementation code
   - Code review and iteration
   
   ## Design Decisions
   
   ### 1. Crate Architecture
   **Decision:** Split crate under `core/services/wasi-fs/` (not inline in core)
   
   **Rationale:** Follows OpenDAL's modern service pattern (RFC 6828). Services 
are being migrated to separate crates for minimal compile-time impact and 
independent versioning.
   
   ### 2. WASI Bindings Approach
   **Decision:** Use the `wasi` crate (v0.14.7) with pre-generated bindings
   
   **Rationale:** 
   - Pre-generated bindings avoid build complexity of running `wit-bindgen` 
during compilation
   - Well-maintained by Bytecode Alliance, stays in sync with WASI spec
   - Simpler dependency management than checking in WIT files
   
   ### 3. Async Model
   **Decision:** Wrap synchronous WASI calls directly in async methods
   
   **Rationale:**
   - WASI Preview 2 filesystem operations are fundamentally synchronous from 
the component's perspective
   - The WASI runtime handles actual I/O scheduling, so blocking in the 
component doesn't block the host thread
   - No `spawn_blocking` needed since there's no separate thread pool in WASM
   
   ### 4. Preopened Directory Handling
   **Decision:** Match root path to preopened directories from host runtime
   
   **Rationale:**
   - Most flexible for users - they specify the desired root path
   - Builder iterates preopened directories and finds the best match
   - Falls back to first preopened directory if root is `/` or not specified
   - Provides clear error messages if no matching preopened directory exists
   
   ### 5. Platform Restriction
   **Decision:** Entire crate guarded by `#![cfg(all(target_arch = "wasm32", 
target_os = "wasi"))]`
   
   **Rationale:**
   - Crate only makes sense on `wasm32-wasip2` target
   - Compiles to nothing on native targets (intentional)
   - Feature flag can be safely enabled without conditional compilation issues
   
   ## Implementation
   
   ### Files Created
   ```
   core/services/wasi-fs/
   ├── Cargo.toml          # Crate manifest with wasi 0.14.7 dependency
   └── src/
       ├── lib.rs          # Module exports + auto-registration via 
#[ctor::ctor]
       ├── config.rs       # WasiFsConfig (root path option)
       ├── backend.rs      # WasiFsBuilder + WasiFsBackend (Access impl)
       ├── core.rs         # Core WASI filesystem operations
       ├── reader.rs       # oio::Read implementation
       ├── writer.rs       # oio::Write implementation
       ├── lister.rs       # oio::List implementation
       ├── deleter.rs      # oio::OneShotDelete implementation
       ├── error.rs        # WASI ErrorCode → OpenDAL ErrorKind mapping
       └── docs.md         # Service documentation
   ```
   
   ### Capabilities
   | Capability | Supported |
   |------------|-----------|
   | stat | ✅ |
   | read | ✅ |
   | write | ✅ |
   | create_dir | ✅ |
   | delete | ✅ |
   | list | ✅ |
   | copy | ✅ (via read+write) |
   | rename | ✅ |
   | append | ✅ |
   | atomic_write | ❌ |
   
   ### Limitations
   - **No atomic writes**: `abort()` returns error since WASI doesn't provide 
atomic file operations
   - **No file locking**: Not supported by WASI filesystem interface
   - **Platform-specific**: Only compiles for `wasm32-wasip2` target
   
   ## Test Plan
   
   - [x] `cargo check` passes on native target
   - [x] `cargo check --features services-wasi-fs` passes
   - [x] `cargo fmt --all` passes
   - [ ] Manual testing with wasmtime (requires WASM component build)
   
   ## Usage Example
   
   ```rust
   use opendal::services::WasiFs;
   use opendal::Operator;
   
   let builder = WasiFs::default().root("/data");
   let op = Operator::new(builder)?.finish();
   
   let content = op.read("hello.txt").await?;
   op.write("output.txt", "Hello, WASI!").await?;
   ```
   
   ```bash
   # Runtime invocation
   wasmtime run --dir /host/path::/guest/path component.wasm
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to