From 6a5bf30f6459b0cb9cce4ec2fa4dcd9079ff9999 Mon Sep 17 00:00:00 2001 From: Gizmo Date: Wed, 10 Apr 2024 22:47:57 +0800 Subject: [PATCH] refactor: restructure Rust components into workspace - Move Rust code from `installer-src` to `crates/installer` to utilize Cargo workspace for better project organization and build efficiency. - Update Makefile and README to reflect new build instructions and project structure. - Improve project modularity and prepare for future Rust components integration. --- .gitignore | 1 + installer-src/Cargo.lock => Cargo.lock | 24 +++++++++---------- Cargo.toml | 9 +++++++ Makefile | 9 +++---- README.md | 5 ++-- .../installer}/.gitignore | 0 .../installer}/Cargo.toml | 13 ++++------ .../installer}/assets/.gitkeep | 0 .../installer}/src/main.rs | 0 .../installer}/src/utils.rs | 0 .../installer}/src/vcc.rs | 0 11 files changed, 34 insertions(+), 27 deletions(-) rename installer-src/Cargo.lock => Cargo.lock (96%) create mode 100644 Cargo.toml rename {installer-src => crates/installer}/.gitignore (100%) rename {installer-src => crates/installer}/Cargo.toml (75%) rename {installer-src => crates/installer}/assets/.gitkeep (100%) rename {installer-src => crates/installer}/src/main.rs (100%) rename {installer-src => crates/installer}/src/utils.rs (100%) rename {installer-src => crates/installer}/src/vcc.rs (100%) diff --git a/.gitignore b/.gitignore index fe173f8..e63ffb3 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ test-data .env.local .vscode/* !.vscode/extensions.json +target diff --git a/installer-src/Cargo.lock b/Cargo.lock similarity index 96% rename from installer-src/Cargo.lock rename to Cargo.lock index 23e7e11..469cee3 100644 --- a/installer-src/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" [[package]] name = "cfg-if" @@ -23,6 +23,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "installer" +version = "0.1.0" +dependencies = [ + "anyhow", + "regex-automata", + "scopeguard", + "winreg", +] + [[package]] name = "memchr" version = "2.7.2" @@ -52,16 +62,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "vcc-auto-translate-installer" -version = "1.6.0" -dependencies = [ - "anyhow", - "regex-automata", - "scopeguard", - "winreg", -] - [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..6cf63e4 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[workspace] +resolver = "2" +members = ["crates/installer"] + +[profile.release] +lto = true +opt-level = 'z' +panic = 'abort' +strip = true diff --git a/Makefile b/Makefile index 149bb59..68ae42f 100644 --- a/Makefile +++ b/Makefile @@ -13,20 +13,21 @@ build-patch-loader: @rm -rf build/*.css build-installer: build-patch-loader - @cp build/patch-loader.js installer-src/assets/patch-loader.js - @cd installer-src && cargo build --release --locked --target x86_64-pc-windows-gnu - @cp installer-src/target/x86_64-pc-windows-gnu/release/vcc-auto-translate-installer.exe build/vcc-auto-translate-installer.exe + @cp build/patch-loader.js crates/installer/assets/patch-loader.js + @cargo build --release --locked --target x86_64-pc-windows-gnu + @cp target/x86_64-pc-windows-gnu/release/vcc-auto-translate-installer.exe build/ sha256sum: @rm -f build/*.sha256; for file in build/*; do sha256sum $$file > $$file.sha256; done -compress: build-installer +compress: @if [ -n "$(shell command -v upx 2> /dev/null)" ]; then for file in build/*.exe; do upx $$file; done; fi clean: @rm -f cmd/installer/vcc-auto-translate.js @rm -f cmd/installer/localization/*.json @rm -rf build + @cargo clean dev: clean build-patch-loader @rm -f installer-src/assets/patch-loader.js diff --git a/README.md b/README.md index ac4cbbe..289c4d8 100644 --- a/README.md +++ b/README.md @@ -50,12 +50,11 @@ VCC(VRChat Creator Companion) 的翻译脚本, 用于自动翻译 VCC 的界面. ```shell pnpm install pnpm run build:patch-loader -Copy-Item build/patch-loader.js installer-src/assets/patch-loader.js -cd installer-src +Copy-Item build/patch-loader.js crates/installer/assets/patch-loader.js cargo build --release --locked ``` -编译完成后, 你可以在`installer-src/target/release`目录找到编译好的自动安装工具. +编译完成后, 你可以在`target/release`目录找到编译好的自动安装工具. ## Related diff --git a/installer-src/.gitignore b/crates/installer/.gitignore similarity index 100% rename from installer-src/.gitignore rename to crates/installer/.gitignore diff --git a/installer-src/Cargo.toml b/crates/installer/Cargo.toml similarity index 75% rename from installer-src/Cargo.toml rename to crates/installer/Cargo.toml index 5e172d7..d205851 100644 --- a/installer-src/Cargo.toml +++ b/crates/installer/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "vcc-auto-translate-installer" -version = "1.6.0" +name = "installer" +version = "0.1.0" edition = "2021" [dependencies] @@ -11,9 +11,6 @@ scopeguard = { version = "1.2.0", default-features = false } [target.'cfg(windows)'.dependencies] winreg = { version = "0.52.0" } -[profile.release] -lto = true -opt-level = 'z' -strip = true -codegen-units = 1 -panic = "abort" +[[bin]] +name = "vcc-auto-translate-installer" +path = "src/main.rs" diff --git a/installer-src/assets/.gitkeep b/crates/installer/assets/.gitkeep similarity index 100% rename from installer-src/assets/.gitkeep rename to crates/installer/assets/.gitkeep diff --git a/installer-src/src/main.rs b/crates/installer/src/main.rs similarity index 100% rename from installer-src/src/main.rs rename to crates/installer/src/main.rs diff --git a/installer-src/src/utils.rs b/crates/installer/src/utils.rs similarity index 100% rename from installer-src/src/utils.rs rename to crates/installer/src/utils.rs diff --git a/installer-src/src/vcc.rs b/crates/installer/src/vcc.rs similarity index 100% rename from installer-src/src/vcc.rs rename to crates/installer/src/vcc.rs