mirror of
https://github.com/aiclientproxy/proxycast.git
synced 2026-10-25 10:04:32 +08:00
284 lines
5.4 KiB
Markdown
284 lines
5.4 KiB
Markdown
---
|
|
title: 构建指南
|
|
description: 本地开发和构建发布
|
|
navigation:
|
|
icon: i-heroicons-wrench-screwdriver
|
|
---
|
|
|
|
# 构建指南
|
|
|
|
本指南介绍如何在本地开发和构建 Lime。
|
|
|
|
## 本地开发
|
|
|
|
::alert{type="warning"}
|
|
Lime 桌面端当前仅支持 macOS 与 Windows,本页不再提供 Linux 打包与发布说明。
|
|
::
|
|
|
|
### 环境准备
|
|
|
|
1. **安装 Node.js**
|
|
|
|
```bash
|
|
# 使用 nvm 安装
|
|
nvm install 22
|
|
nvm use 22
|
|
```
|
|
|
|
Windows 用户请使用 Node.js 官方安装器安装 22.x,并重新打开终端后通过 `node -v` 确认版本。
|
|
|
|
2. **安装 pnpm**
|
|
|
|
```bash
|
|
npm install -g pnpm
|
|
```
|
|
|
|
3. **安装 Rust**
|
|
|
|
```bash
|
|
# macOS
|
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
|
|
|
# Windows
|
|
# 下载并运行 rustup-init.exe
|
|
```
|
|
|
|
4. **安装 Tauri 依赖**
|
|
|
|
**macOS:**
|
|
|
|
```bash
|
|
xcode-select --install
|
|
```
|
|
|
|
**Windows:**
|
|
|
|
- 安装 Visual Studio Build Tools
|
|
- 安装 WebView2(开发模式必需;对外分发时默认推荐在线小包,离线或受限网络环境再提供离线大包)
|
|
|
|
### 启动开发
|
|
|
|
```bash
|
|
# 安装依赖
|
|
pnpm install
|
|
|
|
# 启动开发模式
|
|
pnpm tauri dev
|
|
```
|
|
|
|
开发模式特性:
|
|
|
|
- 前端热重载
|
|
- Rust 代码变更自动重新编译
|
|
- 开发者工具可用
|
|
|
|
### 开发配置
|
|
|
|
#### 前端配置
|
|
|
|
`vite.config.ts`:
|
|
|
|
```typescript
|
|
export default defineConfig({
|
|
plugins: [react()],
|
|
server: {
|
|
port: 1420,
|
|
strictPort: true,
|
|
},
|
|
});
|
|
```
|
|
|
|
#### Tauri 配置
|
|
|
|
`src-tauri/tauri.conf.json`:
|
|
|
|
```json
|
|
{
|
|
"build": {
|
|
"devPath": "http://localhost:1420",
|
|
"distDir": "../dist"
|
|
}
|
|
}
|
|
```
|
|
|
|
## 构建发布
|
|
|
|
### 构建命令
|
|
|
|
```bash
|
|
# 构建当前平台
|
|
pnpm tauri build
|
|
|
|
# 构建 debug 版本
|
|
pnpm tauri build --debug
|
|
```
|
|
|
|
### 自动更新产物与签名
|
|
|
|
Lime 当前的桌面端升级流程分成两步:
|
|
|
|
- 检查更新:客户端直接请求静态清单 `latest.json`
|
|
- 安装更新:客户端使用 Tauri updater 校验签名并安装对应平台包
|
|
|
|
`src-tauri/tauri.conf.json` 与 `src-tauri/tauri.conf.headless.json` 已启用 `createUpdaterArtifacts: true`,构建发布包时会额外生成 updater 需要的签名产物与 `latest.json`。
|
|
|
|
本地或 CI 构建发布版本时,至少需要准备以下环境变量:
|
|
|
|
```bash
|
|
# updater 校验使用的公钥;编译时注入到桌面端
|
|
export LIME_UPDATER_PUBLIC_KEY="..."
|
|
|
|
# Tauri 生成 latest.json 和签名文件时使用的私钥
|
|
export TAURI_SIGNING_PRIVATE_KEY="..."
|
|
export TAURI_SIGNING_PRIVATE_KEY_PASSWORD="..."
|
|
```
|
|
|
|
如果缺少 `LIME_UPDATER_PUBLIC_KEY`,应用仍可读取 `latest.json` 显示新版本信息,但会降级为只能跳转发布页手动下载,无法执行应用内安装。
|
|
|
|
### 构建产物
|
|
|
|
| 平台 | 产物位置 |
|
|
| ------- | --------------------------------------- |
|
|
| macOS | `src-tauri/target/release/bundle/dmg/` |
|
|
| Windows | `src-tauri/target/release/bundle/nsis/` |
|
|
|
|
### 跨平台构建
|
|
|
|
#### macOS 构建
|
|
|
|
```bash
|
|
# 构建 Apple Silicon
|
|
pnpm tauri build --target aarch64-apple-darwin
|
|
|
|
# 构建 Intel
|
|
pnpm tauri build --target x86_64-apple-darwin
|
|
|
|
# 构建 Universal
|
|
pnpm tauri build --target universal-apple-darwin
|
|
```
|
|
|
|
#### Windows 构建
|
|
|
|
```bash
|
|
# 构建 64 位 Windows 在线安装包(推荐,体积更小,安装时按需下载 WebView2)
|
|
pnpm tauri build --target x86_64-pc-windows-msvc --config src-tauri/tauri.windows.online.conf.json
|
|
|
|
# 构建 64 位 Windows 离线安装包(体积更大,内置离线 WebView2 安装器)
|
|
pnpm tauri build --target x86_64-pc-windows-msvc --config src-tauri/tauri.windows.conf.json
|
|
```
|
|
|
|
> 建议默认对外分发在线小包;只有内网、离线或受限网络环境,再提供离线大包。
|
|
|
|
## 版本管理
|
|
|
|
### 更新版本号
|
|
|
|
1. 更新 `package.json`:
|
|
|
|
```json
|
|
{
|
|
"version": "1.0.1"
|
|
}
|
|
```
|
|
|
|
2. 更新 `src-tauri/Cargo.toml`:
|
|
|
|
```toml
|
|
[package]
|
|
version = "1.0.1"
|
|
```
|
|
|
|
3. 更新 `src-tauri/tauri.conf.json`:
|
|
|
|
```json
|
|
{
|
|
"version": "1.0.1"
|
|
}
|
|
```
|
|
|
|
### 创建发布
|
|
|
|
```bash
|
|
# 创建 tag
|
|
git tag v1.0.1
|
|
git push origin v1.0.1
|
|
```
|
|
|
|
## CI/CD
|
|
|
|
### GitHub Actions
|
|
|
|
项目使用 GitHub Actions 自动构建:
|
|
|
|
- Push 到 main 分支触发构建
|
|
- 创建 tag 触发发布
|
|
- Release 工作流会把 `LIME_UPDATER_PUBLIC_KEY`、`TAURI_SIGNING_PRIVATE_KEY`、`TAURI_SIGNING_PRIVATE_KEY_PASSWORD` 注入构建环境,用于生成可校验的 updater 清单与安装包签名
|
|
|
|
### 构建矩阵
|
|
|
|
| 平台 | 架构 | Runner |
|
|
| ------- | ----- | ------------ |
|
|
| macOS | arm64 | macos-latest |
|
|
| macOS | x64 | macos-13 |
|
|
| Windows | x64 | windows-2022 |
|
|
|
|
## 调试
|
|
|
|
### 前端调试
|
|
|
|
开发模式下按 `F12` 打开开发者工具。
|
|
|
|
### 后端调试
|
|
|
|
```bash
|
|
# 启用 Rust 日志
|
|
RUST_LOG=debug pnpm tauri dev
|
|
```
|
|
|
|
### 日志位置
|
|
|
|
| 平台 | 路径 |
|
|
| ------- | ---------------------- |
|
|
| macOS | `~/Library/Logs/Lime/` |
|
|
| Windows | `%APPDATA%\Lime\logs\` |
|
|
|
|
## 常见问题
|
|
|
|
### 构建失败
|
|
|
|
1. 确保所有依赖已安装
|
|
2. 清理构建缓存:
|
|
|
|
```bash
|
|
# 清理前端
|
|
rm -rf node_modules dist
|
|
pnpm install
|
|
|
|
# 清理 Rust
|
|
cd src-tauri
|
|
cargo clean
|
|
```
|
|
|
|
### 签名问题
|
|
|
|
macOS 构建需要代码签名:
|
|
|
|
```bash
|
|
# 设置签名身份
|
|
export APPLE_SIGNING_IDENTITY="Developer ID Application: ..."
|
|
```
|
|
|
|
Windows 构建强烈建议签名:
|
|
|
|
```bash
|
|
# 设置签名证书
|
|
export TAURI_SIGNING_PRIVATE_KEY="..."
|
|
```
|
|
|
|
如果要让桌面端“检查更新后直接安装”可用,还需要同时配置:
|
|
|
|
```bash
|
|
export LIME_UPDATER_PUBLIC_KEY="..."
|
|
export TAURI_SIGNING_PRIVATE_KEY_PASSWORD="..."
|
|
```
|