diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-17 19:21:52 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-17 19:21:52 +0800 |
| commit | 89bf57f33a9f0f5a96fc50e272c83d926fa35c4a (patch) | |
| tree | cc5a72e850bdd9215b60dc1655f162e22ee97d12 /mingling_cli/src | |
| parent | 40bb7ffd6954184fac718c8f99c9cdc3e054e4eb (diff) | |
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.
Diffstat (limited to 'mingling_cli/src')
| -rw-r--r-- | mingling_cli/src/lib.rs | 4 | ||||
| -rw-r--r-- | mingling_cli/src/pkg_mgr/cmd_install.rs | 21 |
2 files changed, 20 insertions, 5 deletions
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<PathBuf>, 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| { |
