# Windows 版本构建指南 由于交叉编译需要特定的系统依赖,建议在 Windows 原生环境或使用 Windows CI/CD 服务构建。 ## 方法一:Windows 原生构建(推荐) ### 1. 环境准备 在 Windows 机器上安装以下工具: 1. **Rust** (https://rustup.rs/) ```powershell winget install Rustlang.Rustup # 或下载 rustup-init.exe 运行 ``` 2. **Node.js 18+** (https://nodejs.org/) ```powershell winget install OpenJS.NodeJS.LTS ``` 3. **Visual Studio Build Tools 2022** ```powershell winget install Microsoft.VisualStudio.2022.BuildTools ``` 安装时勾选 "使用 C++ 的桌面开发" ### 2. 构建步骤 ```powershell # 克隆仓库 git clone https://github.com/your-username/impress_asr_input_rust.git cd impress_asr_input_rust # 安装前端依赖 cd web npm install npm run build cd .. # 构建 Windows GUI 版本 cargo build --release --features gui # 构建产物位置 # target/release/impress_asr_gui.exe # target/release/impress_asr.exe ``` ## 方法二:使用 cargo-xwin(需要 Linux/macOS) 如果你没有 Windows 机器,可以使用 `cargo-xwin` 在 Linux/macOS 上交叉编译: ### 1. 安装 cargo-xwin ```bash # 首先安装 zig (用于交叉编译) curl -L https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz | tar -xJ sudo mv zig-linux-x86_64-0.11.0 /opt/zig sudo ln -s /opt/zig/zig /usr/local/bin/zig # 安装 cargo-xwin cargo install cargo-xwin ``` ### 2. 构建 ```bash # 构建 Windows x64 GUI 版本 cargo xwin build --release --features gui --target x86_64-pc-windows-msvc # 构建产物位置 # target/x86_64-pc-windows-msvc/release/impress_asr_gui.exe ``` ## 方法三:GitHub Actions CI/CD 项目已配置 GitHub Actions 工作流,可以自动构建 Windows 版本。 ### 创建工作流文件 `.github/workflows/build-windows.yml`: ```yaml name: Build Windows on: push: tags: ['v*'] workflow_dispatch: env: CARGO_TERM_COLOR: always RUSTFLAGS: "-C target-feature=+crt-static" jobs: build-windows: runs-on: windows-latest steps: - uses: actions/checkout@v4 - name: Install Rust uses: dtolnay/rust-action@stable with: targets: x86_64-pc-windows-msvc - name: Install Node.js uses: actions/setup-node@v4 with: node-version: '18' - name: Build Frontend run: | cd web npm install npm run build - name: Build GUI run: cargo build --release --features gui - name: Upload Artifact uses: actions/upload-artifact@v4 with: name: impress-asr-gui-windows path: target/release/impress_asr_gui.exe - name: Create Release Package run: | mkdir release cp target/release/impress_asr_gui.exe release/ cp target/release/impress_asr.exe release/ cp README.md release/ cp LICENSE release/ mkdir release/models echo "将模型文件放入此目录" > release/models/README.txt - name: Upload Release uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/') with: files: release/* ``` ## 方法四:使用 Docker ```dockerfile # Dockerfile.windows FROM messense/rust-crossbuild:windows-x86_64 RUN apt-get update && apt-get install -y \ nodejs \ npm \ && rm -rf /var/lib/apt/lists/* WORKDIR /app COPY . . RUN cd web && npm install && npm run build RUN cargo build --release --features gui CMD ["cargo", "build", "--release", "--features", "gui"] ``` 构建并提取: ```bash docker build -f Dockerfile.windows -t impress-asr-windows . docker run --rm -v $(pwd)/output:/output impress-asr-windows \ cp target/release/impress_asr_gui.exe /output/ ``` ## Windows 安装包制作(可选) 使用 Inno Setup 创建安装程序: ### 1. 安装 Inno Setup ```powershell winget install JRSoftware.InnoSetup ``` ### 2. 创建安装脚本 `installer.iss` ```iss #define MyAppName "impress ASR Input" #define MyAppVersion "0.1.0" #define MyAppPublisher "Your Name" [Setup] AppId={{YOUR-APP-ID} AppName={#MyAppName} AppVersion={#MyAppVersion} AppPublisher={#MyAppPublisher} DefaultDirName={autopf}\{#MyAppName} DefaultGroupName={#MyAppName} OutputDir=installer OutputBaseFilename={#MyAppName}-setup-{#MyAppVersion} SetupIconFile=resources\icons\icon.ico Compression=lzma2 SolidCompression=yes WizardStyle=modern [Languages] Name: "chinesesimp"; MessagesFile: "compiler:Default.isl" [Files] Source: "target\release\impress_asr_gui.exe"; DestDir: "{app}"; Flags: ignoreversion Source: "target\release\impress_asr.exe"; DestDir: "{app}"; Flags: ignoreversion Source: "README.md"; DestDir: "{app}"; Flags: ignoreversion Source: "models\*"; DestDir: "{app}\models"; Flags: recursesubdirs [Icons] Name: "{group}\{#MyAppName}"; Filename: "{app}\impress_asr_gui.exe" Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\impress_asr_gui.exe" [Run] Filename: "{app}\impress_asr_gui.exe"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent ``` ### 3. 编译安装程序 ```powershell & "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" installer.iss ``` ## 构建产物 成功构建后,你将得到: - `impress_asr_gui.exe` - GUI 应用程序 - `impress_asr.exe` - 命令行工具 ### 分发 将以下文件打包分发给用户: ``` impress_asr_input_rust-v0.1.0-windows-x64/ ├── impress_asr_gui.exe ├── impress_asr.exe ├── models/ │ └── sensevoice-small.onnx (需要单独下载) ├── README.md └── LICENSE ``` ## 常见问题 ### Q: 构建时提示找不到 Windows SDK? A: 确保安装了 Visual Studio Build Tools,并在安装时选择了 "使用 C++ 的桌面开发"。 ### Q: 链接错误 LNK1181? A: 确保以管理员身份运行 Developer Command Prompt for VS 2022,或正确配置了环境变量。 ### Q: 程序启动后闪退? A: 检查是否缺少 Microsoft Visual C++ Redistributable,下载安装: https://aka.ms/vs/17/release/vc_redist.x64.exe ### Q: 如何静默安装? A: 使用 Inno Setup 安装程序时添加参数: ``` /impress-asr-setup-0.1.0.exe /VERYSILENT /NORESTART ```