Skip to content

Instantly share code, notes, and snippets.

@drewstone
Created April 21, 2025 12:16
Show Gist options
  • Select an option

  • Save drewstone/acc8d90f381c185adda9e3f272ca98a2 to your computer and use it in GitHub Desktop.

Select an option

Save drewstone/acc8d90f381c185adda9e3f272ca98a2 to your computer and use it in GitHub Desktop.

To support the full cargo tangle blueprint create --name my_project workflow—including smart contract deployment with Forge/Soldeer and compiling Tangle Blueprint Rust projects—all within a browser-based IDE, you’ll need a hybrid architecture that merges:

  • WASM-based toolchains for Rust and Solidity
  • Filesystem + container abstraction (via WASI, VFS, and maybe container2wasm or web-container)
  • Persistent user workspace and streaming build logs/output

🔧 Recommended Architecture

1. Rust Compilation in the Browser

You can support Blueprint compilation by integrating:

✅ Option A: wasm-cargo or rustc-wasm

  • Compile a restricted subset of Rust to WASM via wasm32-wasi or wasm32-unknown-unknown
  • Use webcontainer (from StackBlitz) to simulate the workspace and run cargo inside the browser with WASI syscalls.
  • Track toolchains with wasmer/wapm or precompile toolchains into your WASM bundle

✅ Option B: Use a backend sandbox (e.g. Docker or Firecracker VM)

  • Run cargo build, forge build, etc. in an ephemeral environment on your infra.
  • Stream logs via WebSocket to your IDE.
  • More reliable for full native builds including networking, Tangle SDK, etc.

🔄 Combine both: WASM for lightweight in-browser validation, backend for heavy builds (configurable per user/project)


2. Forge/Soldeer Compilation in Browser

Forge and Soldeer are written in Rust and can be compiled to WASM.

Forge to WASM

  • Compile foundry (includes forge) to WASM using cargo build --target=wasm32-wasi
  • Package with wasmer-js or webcontainer for browser FS access
  • OR run forge in Docker-in-browser using:

⛔️ Limitations: solc and forge require syscalls and networking. Might be better to use your own WASMified Solc (like used in Remix IDE), or run it remotely.


3. Docker in Browser

You have 3 paths to make this real:

  • Converts Docker containers to WASM modules using WASI
  • Can sandbox the container for web execution
  • Requires a WASM runtime in-browser (e.g., wasmer-js, wasmtime-py, or jco)
  • Run WASM-compiled binaries (like Rust/C/C++/Forge) with WASI support in-browser
  • Supports WASIX: fork/exec, TCP, pipes
  • Entire browser-based Linux+Node environment
  • Could build a Forge+Cargo pre-bundle in this

🧩 IDE Integration

Frontend (UI)

  • Monaco-based editor with split panes
  • Project Explorer: detect *-bin, *-lib, and contracts
  • Tabs: code / build logs / contract ABIs / deployed addresses
  • "Run" button that builds project and deploys test instance locally

Backend or Worker (Sandbox)

  • Workerized sandbox using wasm-cargo or webcontainer runtime
  • API to trigger full cargo tangle blueprint create + cargo build + forge build
  • Save compiled artifacts and contract deployments

🔄 Proposed Workflow Steps

graph TD
    A[User: Clicks "New Blueprint"] --> B[cargo tangle blueprint create]
    B --> C[Creates folders + contracts + lib/bin crates]
    C --> D[User edits code in Monaco IDE]
    D --> E1[Build Rust via cargo WASM / backend]
    D --> E2[Compile & deploy contracts via Forge WASM / backend]
    E1 --> F[Show Rust build output]
    E2 --> G[Show contract address / ABI]
    F --> H[Stream build status + diagnostics to user]
Loading

💡 Bonus Ideas

  • Multi-tenant ephemeral backends: Use something like Railway/Firecracker to execute user jobs securely.
  • Streaming compiler logs: Use @webcontainer/log-streaming or WebSocket log relays.
  • Custom Forge-in-WASM build: Fork foundry and trim non-essential features to compile it more easily to WASM.

Would you like a working prototype scaffold of the IDE code with WebContainer + Monaco + Cargo support + contract deploy UI?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment