fn main() { tauri_build::build(); // 从 tauri.conf.json 读取 identifier,注入编译时常量 MCP_APP_IDENTIFIER。 // CLI 模式(mcp-server)无 tauri app handle,无法通过 app.path().app_data_dir() 获取 // 真实路径;此常量让 default_db_path 自动拼出 Tauri 实际使用的 APPDATA/{identifier}/ 路径, // 保证 MCP server 与 GUI 应用读写同一数据库,无需手动传 --db。 let conf_path = std::path::Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()) .join("tauri.conf.json"); if let Ok(content) = std::fs::read_to_string(&conf_path) { if let Some(identifier) = content .lines() .find(|l| l.contains("\"identifier\"")) .and_then(|l| l.split(':').nth(1)) .map(|s| s.trim().trim_matches(',').trim_matches('"')) { println!("cargo:rustc-env=MCP_APP_IDENTIFIER={}", identifier); } } // 测试二进制(lib test)没有 tauri 给 bin 内嵌的窗口清单,而 GUI 依赖(tao/muda/tray_icon) // 会静态导入 comctl32 的 TaskDialogIndirect 等导出(仅存在于 SxS v6 程序集),无清单时 // 加载器绑定 System32 的 5.82 版(缺这些导出),进程启动即 STATUS_ENTRYPOINT_NOT_FOUND, // cargo test 全部无法运行。用延迟加载把 comctl32 绑定推迟到首次调用,测试进程从不触碰 // GUI 入口即永不解析;app 端 bin 自带清单选到 v6,行为不变。不用 /MANIFEST:EMBED 方案是 // 因为它会与 tauri 内嵌的资源清单产生重复 RT_MANIFEST,链接失败。 println!("cargo:rustc-link-arg=/DELAYLOAD:comctl32.dll"); println!("cargo:rustc-link-lib=delayimp"); }