diff options
| author | 1992414357@qq.com <1992414357@qq.com> | 2025-05-27 07:21:37 +0800 |
|---|---|---|
| committer | 1992414357@qq.com <1992414357@qq.com> | 2025-05-27 07:21:37 +0800 |
| commit | f8336ed832fa8e1ddd2f1783bdfc23d3279d5e6a (patch) | |
| tree | 42097cd72e46736ac3a544bd3d6dc50e2327a677 /.cargo/scripts | |
First commit
Diffstat (limited to '.cargo/scripts')
| -rw-r--r-- | .cargo/scripts/generate_documents.bat | 59 | ||||
| -rw-r--r-- | .cargo/scripts/release_console/generate_console_release_file.bat | 63 | ||||
| -rw-r--r-- | .cargo/scripts/release_files_win | 6 | ||||
| -rw-r--r-- | .cargo/scripts/release_project.bat | 37 |
4 files changed, 165 insertions, 0 deletions
diff --git a/.cargo/scripts/generate_documents.bat b/.cargo/scripts/generate_documents.bat new file mode 100644 index 0000000..edde8ea --- /dev/null +++ b/.cargo/scripts/generate_documents.bat @@ -0,0 +1,59 @@ +@echo off +setlocal enabledelayedexpansion + +:: ================= 路径 ================= +set "CARGO_TARGET_DIR=.\.cargo\shared\target" +set "DOC_SOURCE_DIR=%CARGO_TARGET_DIR%\doc" +set "DOC_DEST_DIR=.\documents\cargo_doc" + +:: ============== Crate 列表 ============== +set "CRATE_PATHS=core console" + +:: =============== 文档路径 =============== +set "DOC_LINK_PATHS=nogamepads_core nogpadc nogpads" + +:: =============== 生成文档 =============== +if not exist "%DOC_DEST_DIR%" mkdir "%DOC_DEST_DIR%" +:: cargo clean --target-dir "%CARGO_TARGET_DIR%" +for %%c in (%CRATE_PATHS%) do ( + echo [INFO] Generating documentation for crate: %%c + cargo doc --no-deps --manifest-path "./%%c/Cargo.toml" + if !errorlevel! neq 0 ( + echo [ERROR] Failed to generate docs for crate: %%c + exit /b !errorlevel! + ) +) + +:: ============== 清理旧文件 ============== +if exist "%DOC_DEST_DIR%" ( + echo [INFO] Removing old documents... + rmdir /s /q "%DOC_DEST_DIR%" +) + +:: ============== 复制新文件 ============== +echo [INFO] Copying new documents to %DOC_DEST_DIR%... +xcopy /E /I /Q /Y "%DOC_SOURCE_DIR%" "%DOC_DEST_DIR%" +if !errorlevel! neq 0 ( + echo [ERROR] Failed to copy documents + exit /b !errorlevel! +) + +:: ================= 清理 ================= +:: Uncomment to clean generated docs from target directory +:: rmdir /s /q "%DOC_SOURCE_DIR%" + +:: =============== 生成链接 =============== +echo. +echo [DOCUMENTATION LINKS] + +:: 获取当前目录绝对路径(转换为URL格式) +set "CURRENT_DIR=%CD:\=/%" + +:: 遍历自定义路径列表 +for %%p in (%DOC_LINK_PATHS%) do ( + set "HTML_PATH=file:///%CURRENT_DIR%/documents/cargo_doc/%%p/index.html" + echo !HTML_PATH! +) + +echo [SUCCESS] Documentation generated at: %DOC_DEST_DIR% +endlocal
\ No newline at end of file diff --git a/.cargo/scripts/release_console/generate_console_release_file.bat b/.cargo/scripts/release_console/generate_console_release_file.bat new file mode 100644 index 0000000..601391b --- /dev/null +++ b/.cargo/scripts/release_console/generate_console_release_file.bat @@ -0,0 +1,63 @@ +@echo off +setlocal enabledelayedexpansion + +:: ================= 路径 ================= +:: 源文件目录 +set "CONSOLE_DIR=.cargo\shared\target\release\deps" +:: 待复制文件列表 +set "FILE_LIST=.cargo\scripts\release_files_win" +:: 控制台文件目标目录(基础路径) +set "BASE_DEST_DIR=release\dev\" +:: 证书文件 +set "LICENSE_FILE=LICENSE-LGPL-2" +set "LICENSE_TP_FILE=LICENSE-THIRD-PARTY" + +:: ============= 创建基础目录 ============= +if not exist "%BASE_DEST_DIR%" mkdir "%BASE_DEST_DIR%" + +:: =========== 清空目标目录内容 =========== +if exist "%BASE_DEST_DIR%" ( + echo [INFO] Cleaning target directory "%BASE_DEST_DIR%" + :: 删除所有文件(包括隐藏/只读文件) + del /f /s /q "%BASE_DEST_DIR%\*.*" >nul 2>&1 + :: 递归删除所有子目录 + for /d %%D in ("%BASE_DEST_DIR%\*") do rd /s /q "%%D" >nul 2>&1 +) + +:: ======== 读取文件列表并复制文件 ======== +for /f "delims=" %%F in ('findstr /v /r "^// ^$" "%FILE_LIST%"') do ( + set "line=%%F" + :: 分割行内容为 filename 和相对路径 + for /f "tokens=1,* delims=:" %%A in ("!line!") do ( + set "filename=%%A" + set "rel_path=%%B" + ) + :: 去除两端的空格 + for /f "tokens=* delims= " %%L in ("!filename!") do set "filename=%%L" + for /f "tokens=* delims= " %%P in ("!rel_path!") do set "rel_path=%%P" + :: 构造完整目标路径 + set "dest_path=%BASE_DEST_DIR%!rel_path:.\=!" + :: 提取目标目录并创建 + for %%I in ("!dest_path!") do set "dest_dir=%%~dpI" + if not exist "!dest_dir!" mkdir "!dest_dir!" + :: 复制文件 + set "source_file=%CONSOLE_DIR%\!filename!" + if exist "!source_file!" ( + echo [INFO] Copying "!filename!" to "!dest_path!" + copy /Y "!source_file!" "!dest_path!" >nul + if errorlevel 1 ( + echo [ERROR] Failed to copy "!filename!" + ) else ( + echo [SUCCESS] Copied "!filename!" + ) + ) else ( + echo [ERROR] Source file "!source_file!" not found + ) +) + +:: ============= 复制证书文件 ============= +copy /Y "%LICENSE_FILE%" "%BASE_DEST_DIR%\" >nul +copy /Y "%LICENSE_TP_FILE%" "%BASE_DEST_DIR%\" >nul + +endlocal +exit /b 0
\ No newline at end of file diff --git a/.cargo/scripts/release_files_win b/.cargo/scripts/release_files_win new file mode 100644 index 0000000..bfc7841 --- /dev/null +++ b/.cargo/scripts/release_files_win @@ -0,0 +1,6 @@ +// 控制台部分 +nogpadc.exe : .\bin\nogpadc.exe +nogpads.exe : .\bin\nogpads.exe + +// Dll部分 +nogamepads_c.dll : .\bridge\libs\nogamepads_c.dll
\ No newline at end of file diff --git a/.cargo/scripts/release_project.bat b/.cargo/scripts/release_project.bat new file mode 100644 index 0000000..3979e9d --- /dev/null +++ b/.cargo/scripts/release_project.bat @@ -0,0 +1,37 @@ +@echo off +setlocal enabledelayedexpansion + +:: ================= 路径 ================= +:: 控制台程序的 CRATE +set "CONSOLE_CRATE_DIR=console" + +:: C动态链接库的 CRATE +set "DLL_CRATE_DIR=core_c" + +:: 打包地址 +set "RELEASE_DIR=release\dev" + +:: ================= 构建 ================= +:: 控制台程序 +echo [INFO] Building console ... +pushd ".\%CONSOLE_CRATE_DIR%\" +cargo build --release +popd +echo +:: C动态链接库 +echo [INFO] Building dll ... +pushd ".\%DLL_CRATE_DIR%\" +cargo build --release +popd + +echo Done. +echo + +:: =============== 发布文件 =============== +echo +echo [INFO] Generating release files +call .\.cargo\scripts\release_console\generate_console_release_file.bat + +explorer.exe ".\%RELEASE_DIR%\" + +echo Done.
\ No newline at end of file |
