From 89bf57f33a9f0f5a96fc50e272c83d926fa35c4a Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 17 Aug 2026 19:21:52 +0800 Subject: refactor!: replace build.rs with compile-time macro build steps BREAKING CHANGE: Replace the `build`/`builds` feature system with compile-time macro-driven generation. `gen_program!()` now automatically invokes `build_comp!()` and `build_pathf!()` when the `comp`/`pathf` features are enabled, eliminating the need for `build.rs` and `[build-dependencies]` blocks. This removes the `build` feature, the `mingling::build` module, and all related build-time API functions. Completion scripts are now written to `{target_directory}/mingling/` instead of `target/release/`. The `mingling_cli` uses `build_comp!("mling")` for its custom binary name. --- mingling_cli/Cargo.lock | 31 ++++++++++++++++--------------- mingling_cli/Cargo.toml | 9 --------- mingling_cli/build.rs | 8 -------- mingling_cli/src/lib.rs | 4 ++++ mingling_cli/src/pkg_mgr/cmd_install.rs | 21 ++++++++++++++++----- 5 files changed, 36 insertions(+), 37 deletions(-) (limited to 'mingling_cli') diff --git a/mingling_cli/Cargo.lock b/mingling_cli/Cargo.lock index c738a0e..aab6b82 100644 --- a/mingling_cli/Cargo.lock +++ b/mingling_cli/Cargo.lock @@ -95,9 +95,9 @@ checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" [[package]] name = "camino" -version = "1.2.4" +version = "1.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f2d30e4173c4026932d51d31d6b0613b1fd3014bf3f9f8943d4ba139c437ba0" +checksum = "bb1307f12aa967b5a58416e87b3653360e0fd614a016b6e970db08fecbb1b80d" dependencies = [ "serde_core", ] @@ -746,15 +746,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.187" +version = "0.2.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7743783ea728ef5c31194c6590797eed286449b4a4e87d626d8a51f0a94e732" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" [[package]] name = "libredox" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2026a5056764a10b2bf5d56488cba40da507f5493a6a429340e2004d9ed085fa" +checksum = "28d0a00925a9f930d679b6789b721e3a7f9ed110f41b86d2497caa780c3a070a" dependencies = [ "libc", ] @@ -849,9 +849,7 @@ name = "mingling_core" version = "0.5.0" dependencies = [ "just_fmt 0.2.0", - "just_template", "might_be_async", - "mingling_pathf", ] [[package]] @@ -859,6 +857,8 @@ name = "mingling_macros" version = "0.5.0" dependencies = [ "just_fmt 0.2.0", + "just_template", + "mingling_pathf", "proc-macro2", "quote", "syn 2.0.119", @@ -868,6 +868,7 @@ dependencies = [ name = "mingling_pathf" version = "0.5.0" dependencies = [ + "cargo_metadata", "just_fmt 0.2.0", "proc-macro2", "syn 2.0.119", @@ -1402,18 +1403,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.19" +version = "2.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a43598840e33d5b0331f38c5e30d13bb11c11210a4b58f0d9b18a5a5eefcd9" +checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "2.0.19" +version = "2.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43cbfe0cf76104d42a574802844187e84a305e531ed54455f11fbde0f10541cd" +checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af" dependencies = [ "proc-macro2", "quote", @@ -1464,13 +1465,13 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6328af13490e73a9b4694030fafd93f8c8c6a9dede33e821c3fc63eddf8042ba" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.119", + "syn 3.0.2", ] [[package]] diff --git a/mingling_cli/Cargo.toml b/mingling_cli/Cargo.toml index dfc686d..19b4c1b 100644 --- a/mingling_cli/Cargo.toml +++ b/mingling_cli/Cargo.toml @@ -30,15 +30,6 @@ features = [ "comp", ] -[build-dependencies.mingling] -path = "../mingling" -features = [ - "build", - "pathf", - "dispatch_tree", - "comp" -] - [dependencies] # Project analyze diff --git a/mingling_cli/build.rs b/mingling_cli/build.rs index 0dc0b28..4df33d0 100644 --- a/mingling_cli/build.rs +++ b/mingling_cli/build.rs @@ -1,14 +1,6 @@ -use mingling::build::{analyze_and_build_type_mapping, build_comp_scripts}; - pub mod pre; fn main() { - // Perform path analysis and build type mapping table - analyze_and_build_type_mapping().ok(); - - // Generate Mingling CLI Completion Scripts - build_comp_scripts("mling").unwrap(); - // Generate lint registry pre::gen_mod_file().unwrap(); pre::gen_lint_registry().unwrap(); diff --git a/mingling_cli/src/lib.rs b/mingling_cli/src/lib.rs index d5a5b22..0b93f08 100644 --- a/mingling_cli/src/lib.rs +++ b/mingling_cli/src/lib.rs @@ -24,6 +24,10 @@ pub mod proj_mgr; pub mod updater; pub mod utils; +// The `comp` feature makes `gen_program!()` generate completion scripts named after +// the crate (`mingling-cli_comp.*`). Generate an additional set for the `mling` binary. +mingling::macros::build_comp!("mling"); + #[help] pub fn help_global(_: EntryFallback) -> String { format!("{}\n", include_str!("../help/help.txt").parse_color_code()) diff --git a/mingling_cli/src/pkg_mgr/cmd_install.rs b/mingling_cli/src/pkg_mgr/cmd_install.rs index c7dcaef..0b552a6 100644 --- a/mingling_cli/src/pkg_mgr/cmd_install.rs +++ b/mingling_cli/src/pkg_mgr/cmd_install.rs @@ -34,6 +34,9 @@ pub struct StateInstallBuild { pub workspace_root: PathBuf, pub install_dir: PathBuf, pub release_dir: PathBuf, + /// Directory holding Mingling's compile-time build outputs + /// (`{target_directory}/mingling/`), e.g. the completion scripts. + pub mingling_dir: PathBuf, pub exe_suffix: &'static str, pub enable: bool, } @@ -43,6 +46,9 @@ pub struct StateInstallBuild { pub struct StateInstallCopy { pub install_dir: PathBuf, pub release_dir: PathBuf, + /// Directory holding Mingling's compile-time build outputs + /// (`{target_directory}/mingling/`), e.g. the completion scripts. + pub mingling_dir: PathBuf, pub exe_suffix: &'static str, pub installed: Vec, pub enable: bool, @@ -95,6 +101,10 @@ pub fn install( .target_directory .join("release") .into_std_path_buf(), + mingling_dir: metadata + .target_directory + .join("mingling") + .into_std_path_buf(), exe_suffix: env::consts::EXE_SUFFIX, enable: enable.bool(), } @@ -117,6 +127,7 @@ pub fn handle_state_install_build(state: StateInstallBuild) -> Next { StateInstallCopy { install_dir: state.install_dir, release_dir: state.release_dir, + mingling_dir: state.mingling_dir, exe_suffix: state.exe_suffix, installed: vec![], enable: state.enable, @@ -159,13 +170,13 @@ pub fn handle_state_install_copy( } } - // Completion scripts are generated into the build profile directory - // (OUT_DIR/../../../), copy every one whose name contains `_comp`, - // regardless of its suffix - for entry in fs::read_dir(&state.release_dir).map_err(|e| { + // Completion scripts are generated into `{target_directory}/mingling/` at + // compile time (via `build_comp!()`); copy every one whose name contains + // `_comp`, regardless of its suffix. + for entry in fs::read_dir(&state.mingling_dir).map_err(|e| { io::Error::new( e.kind(), - format!("failed to read {}: {e}", state.release_dir.display()), + format!("failed to read {}: {e}", state.mingling_dir.display()), ) })? { let entry = entry.map_err(|e| { -- cgit