Skip to content

Repository files navigation

Byte

Web Syntax. Rust Bones. Zero Runtime.

Byte 是一个编译期 UI 框架。前端用 HTML/CSS 编写,后端用 Rust。两者完全分离——byte build 将前端编译为纯 Rust 代码,然后 cargo build 产出原生二进制。无 WebView,无 JS 引擎。

ui/index.html + ui/style.css  →  [byte build]  →  src/generated/ui.rs  →  [rustc]  →  原生二进制
     (前端)                     (显式编译步骤)     (生成代码)            (编译)      (无运行时开销)

核心哲学

Electron Tauri Byte
渲染 Chromium System WebView GPUI (GPU 原生)
JS 引擎 V8 WebView's JS 无(编译期)
内存占用 ~100MB+ ~50MB+ <10MB
启动速度 中等 即时
UI 执行 JS VM IPC → Rust 直接 Rust 调用

快速开始

# 安装 CLI
cargo install byte_cli

# 创建新项目
byte new my-app
cd my-app

# 编译前端 + 运行
byte run

项目结构

my-byte-app/
├── ui/                  ← 前端(纯 HTML/CSS,与 Rust 无关)
│   ├── index.html       ← UI 结构
│   └── style.css        ← 样式
├── src/                 ← 后端(纯 Rust)
│   ├── main.rs          ← 应用入口
│   └── generated/
│       └── ui.rs        ← byte build 生成的胶水代码
└── Cargo.toml           ← 只依赖 gpui,无 build-dependencies

没有 build.rs 前端编译是 byte build 这个独立 CLI 命令,不是 Cargo 的构建钩子。前端就是前端,后端就是后端。

工作原理

┌─────────────────────┐  ← 前端(开发者编写)
│  ui/index.html      │     <div><h1>Hello</h1><button>Click</button></div>
│  ui/style.css       │     button { background: #585b70; }
└──────────┬──────────┘
           ↓  byte build(独立编译步骤)
┌──────────┴──────────┐  ← The Bridge (byte_compiler)
│  HTML Parser        │     DOM 树
│  CSS Parser         │     样式表
│  Code Generator     │     DOM → Rust TokenStream
└──────────┬──────────┘
           ↓  输出到 src/generated/ui.rs
┌──────────┴──────────┐  ← 后端(纯 Rust,编译进二进制)
│  GPUI               │     GPU 原生窗口渲染
│  Taffy              │     Flexbox/Grid 布局
└─────────────────────┘

示例

输入ui/index.html(前端开发者写这个):

<div>
    <h1>Hello, Byte!</h1>
    <p>Web Syntax. Rust Bones. Zero Runtime.</p>
    <button>Get Started</button>
</div>

输出src/generated/ui.rsbyte build 生成,后端引入):

pub fn byte_ui() -> impl gpui::IntoElement {
    gpui::div()
        .flex().flex_col()
        .p(px(8.0))
        .bg(gpui::rgb(0xf5f5f5))
        .child(
            gpui::div()
                .text_2xl()
                .font_weight(gpui::FontWeight::BOLD)
                .child("Hello, Byte!")
        )
        .child(
            gpui::div()
                .text_sm()
                .child("Web Syntax. Rust Bones. Zero Runtime.")
        )
        .child(
            gpui::div()
                .bg(gpui::rgb(0x585b70))
                .rounded(px(6.0))
                .cursor_pointer()
                .child("Get Started")
        )
}

路线图

Milestone 版本 代号 状态
M0 v0.1.0 First Light ✅ 前端分离编译 + HTML/CSS → Rust
M1 v0.2.0 The Bridge 🔲 ByteJS DSL → Rust 符号映射
M2 v0.3.0 DevX 🔲 热重载 / 类型感知 / 错误映射
M3 v0.4.0 Ecosystem 🔲 组件模型 / 样式系统 / 跨平台

开发

git clone https://github.com/Ink-dark/Byte.git
cd Byte
cargo run -p hello_byte     # 运行端到端示例
cargo run -p byte_cli -- new my-test-app

许可

Apache License 2.0 — Copyright 2026 Ink-dark


Write Web. Compile Native. Run Rust.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages