Files
mirror/build.rs
CNWei e3cb065b35 fix(shim): 优化配置解析、跨平台编码与 UAC 提权逻辑
- 使用 `OsString`/`PathBuf` 替代 `String`,实现跨平台无损编码与命令行参数透传
- 完善 `FromLua` 转换与边界校验,拦截空洞 (`nil`) 及非整数键
- 修复环境变量拼接时由于内置分隔符导致的 `join_paths` 报错
- 优化 Windows 下 UAC 提权执行逻辑,改用宽字符 API (`ShellExecuteExW`)
2026-08-18 11:15:30 +08:00

47 lines
1.6 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use std::env;
use std::fs;
use std::path::PathBuf;
fn main() {
// CARGO_MANIFEST_DIR -> 项目根目录路径
// CARGO_TARGET_DIR -> 用户自定义了 target 目录,使用该变量
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let target_dir = env::var("CARGO_TARGET_DIR")
.ok()
.map(PathBuf::from)
.unwrap_or_else(|| PathBuf::from(&manifest_dir).join("target"));
// PROFILE -> 获取当前构建配置文件debug/release
let profile = env::var("PROFILE").unwrap();
// let output_dir = target_dir.join(&profile);
// 在 target/debug/ 或 target/release/ 下创建 bin2 目录
let output_dir = target_dir.join(&profile).join("bin2");
// cargo:rerun-if-changed -> 当指定文件变化时,重新运行 xxx
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=rshim.lua");
println!("cargo:rustc-env=OUTPUT_DIR={}", output_dir.display());
// 创建目录
let subdirs = ["bin", "tools"];
for subdir in &subdirs {
let path = output_dir.join(subdir);
if !path.exists() {
fs::create_dir_all(&path).expect(&format!("Failed to create {} directory", subdir));
println!("Created: {:?}", path);
}
}
// 复制文件
let source = PathBuf::from(&manifest_dir).join("shims.lua");
let destination = output_dir.join("rshim.lua");
if source.exists() {
fs::copy(&source, &destination).expect("Failed to copy shims.lua");
println!("Copied shims.lua to: {:?}", destination);
} else {
panic!("shims.lua not found at: {:?}", source);
}
}