aboutsummaryrefslogtreecommitdiff
path: root/examples/example-completion
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-17 19:21:52 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-17 19:21:52 +0800
commit89bf57f33a9f0f5a96fc50e272c83d926fa35c4a (patch)
treecc5a72e850bdd9215b60dc1655f162e22ee97d12 /examples/example-completion
parent40bb7ffd6954184fac718c8f99c9cdc3e054e4eb (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 'examples/example-completion')
-rw-r--r--examples/example-completion/Cargo.lock102
-rw-r--r--examples/example-completion/Cargo.toml12
-rw-r--r--examples/example-completion/build.rs14
-rw-r--r--examples/example-completion/page.toml2
-rw-r--r--examples/example-completion/src/main.rs27
5 files changed, 108 insertions, 49 deletions
diff --git a/examples/example-completion/Cargo.lock b/examples/example-completion/Cargo.lock
index d4b2f33..d98661c 100644
--- a/examples/example-completion/Cargo.lock
+++ b/examples/example-completion/Cargo.lock
@@ -20,6 +20,39 @@ dependencies = [
]
[[package]]
+name = "camino"
+version = "1.2.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bb1307f12aa967b5a58416e87b3653360e0fd614a016b6e970db08fecbb1b80d"
+dependencies = [
+ "serde_core",
+]
+
+[[package]]
+name = "cargo-platform"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dd0061da739915fae12ea00e16397555ed4371a6bb285431aab930f61b0aa4ba"
+dependencies = [
+ "serde",
+ "serde_core",
+]
+
+[[package]]
+name = "cargo_metadata"
+version = "0.23.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ef987d17b0a113becdd19d3d0022d04d7ef41f9efe4f3fb63ac44ba61df3ade9"
+dependencies = [
+ "camino",
+ "cargo-platform",
+ "semver",
+ "serde",
+ "serde_json",
+ "thiserror",
+]
+
+[[package]]
name = "equivalent"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -49,6 +82,12 @@ dependencies = [
]
[[package]]
+name = "itoa"
+version = "1.0.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
+
+[[package]]
name = "just_fmt"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -113,7 +152,6 @@ name = "mingling_core"
version = "0.5.0"
dependencies = [
"just_fmt 0.2.0",
- "just_template",
"might_be_async",
]
@@ -122,12 +160,24 @@ name = "mingling_macros"
version = "0.5.0"
dependencies = [
"just_fmt 0.2.0",
+ "just_template",
+ "mingling_pathf",
"proc-macro2",
"quote",
"syn 2.0.118",
]
[[package]]
+name = "mingling_pathf"
+version = "0.5.0"
+dependencies = [
+ "cargo_metadata",
+ "just_fmt 0.2.0",
+ "proc-macro2",
+ "syn 2.0.118",
+]
+
+[[package]]
name = "proc-macro2"
version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -146,12 +196,23 @@ dependencies = [
]
[[package]]
+name = "semver"
+version = "1.0.28"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
+dependencies = [
+ "serde",
+ "serde_core",
+]
+
+[[package]]
name = "serde"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
dependencies = [
"serde_core",
+ "serde_derive",
]
[[package]]
@@ -175,6 +236,19 @@ dependencies = [
]
[[package]]
+name = "serde_json"
+version = "1.0.151"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14"
+dependencies = [
+ "itoa",
+ "memchr",
+ "serde",
+ "serde_core",
+ "zmij",
+]
+
+[[package]]
name = "serde_spanned"
version = "0.6.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -206,6 +280,26 @@ dependencies = [
]
[[package]]
+name = "thiserror"
+version = "2.0.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ec86235f5fcc2a73650310756d2ac5b138a5780bbbdfae3eeccec992c435ba4f"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "2.0.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bc04cd3e1236dd4a98afca4569f2deb3f120e5422a4023be2cb683f8486292af"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 3.0.3",
+]
+
+[[package]]
name = "toml"
version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -260,3 +354,9 @@ checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"
dependencies = [
"memchr",
]
+
+[[package]]
+name = "zmij"
+version = "1.0.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
diff --git a/examples/example-completion/Cargo.toml b/examples/example-completion/Cargo.toml
index 9884f4e..59b6902 100644
--- a/examples/example-completion/Cargo.toml
+++ b/examples/example-completion/Cargo.toml
@@ -12,16 +12,4 @@ features = [
"picker",
]
-[build-dependencies.mingling]
-path = "../../mingling"
-
-features = [
- # Enable `comp` features
- "comp",
-
- # If you want to build completion scripts,
- # enable `build` features
- "build",
-]
-
[workspace]
diff --git a/examples/example-completion/build.rs b/examples/example-completion/build.rs
deleted file mode 100644
index e1ffba1..0000000
--- a/examples/example-completion/build.rs
+++ /dev/null
@@ -1,14 +0,0 @@
-fn main() {
- build_scripts();
-}
-
-/// Generate completion scripts
-fn build_scripts() {
- // `env!("CARGO_PKG_NAME")` equals the crate name, which matches the binary name.
- // If your binary name differs from the crate name, specify it explicitly.
- mingling::build::build_comp_scripts(
- // Your binary name:
- env!("CARGO_PKG_NAME"),
- )
- .unwrap();
-}
diff --git a/examples/example-completion/page.toml b/examples/example-completion/page.toml
index adccd86..4336513 100644
--- a/examples/example-completion/page.toml
+++ b/examples/example-completion/page.toml
@@ -7,4 +7,4 @@ desc = """
Demonstrates how to implement dynamic shell completion with `#[completion]` and generate scripts for bash, zsh, fish, and pwsh.
"""
tags = ["comp"]
-files = ["src/main.rs", "build.rs", "Cargo.toml"]
+files = ["src/main.rs", "Cargo.toml"]
diff --git a/examples/example-completion/src/main.rs b/examples/example-completion/src/main.rs
index 389cf74..385387b 100644
--- a/examples/example-completion/src/main.rs
+++ b/examples/example-completion/src/main.rs
@@ -7,30 +7,15 @@
//! To make your completions work, you need to generate a completion script using Mingling's tools
//!
//! 1. Enable features
-//! You need to enable the `build` and `comp` features for `mingling` in `[build-dependencies]`
+//! Enable the `comp` feature for `mingling` in `[dependencies]`
//!
-//! 2. Write `build.rs`
-//! Write the following in `build.rs`
-//!
-//! ```rust,ignore
-//! fn main() {
-//! build_scripts();
-//! }
-//!
-//! /// Generate completion scripts
-//! fn build_scripts() {
-//! // `env!("CARGO_PKG_NAME")` equals the crate name, which matches the binary name.
-//! // If your binary name differs from the crate name, specify it explicitly.
-//! mingling::build::build_comp_scripts(
-//! // Your binary name:
-//! env!("CARGO_PKG_NAME"),
-//! )
-//! .unwrap();
-//! }
-//! ```
+//! 2. Generate completion scripts
+//! When the `comp` feature is enabled, `gen_program!()` automatically invokes
+//! `build_comp!()` at compile time, which generates the completion scripts
+//! (named after `CARGO_PKG_NAME`) into `target/mingling/`.
//!
//! 3. Verify
-//! Build your project with `cargo build --release`. The completion scripts will be generated in `target/release/`
+//! Build your project with `cargo build`. The completion scripts will be generated in `target/mingling/`
//!
//! Execute the script or have it be automatically sourced by your Shell
//!