From ceb76789ce1fc08c0a7b2c2b903297d47431f6c3 Mon Sep 17 00:00:00 2001 From: Kinflou Date: Tue, 1 Sep 2026 21:39:06 +0800 Subject: [PATCH] feat: feature-gate the generator crates (rollout step 6) comline-codegen-rust / -typescript become optional deps behind gen-rust / gen-typescript features (both default). generator_registry() guards each register() with #[cfg(feature = ...)]. A build with --no-default-features --features gen-rust drops the typescript crate and its dep tree entirely. Default build + 36 + 2 tests pass; rust-only build compiles; fmt clean. --- Cargo.toml | 12 ++++++++++-- src/commands/generate.rs | 7 ++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0cd2634..7c9f4b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,8 +27,16 @@ toml = "0.8" # `comline-core` in the tree. Local dev: see .cargo/config. comline-core = { git = "https://github.com/ComlineProject/core", rev = "aa84d970d3295df59cc3e620bdb71bf96382f97b" } comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "4f29f4fce4e2e0b3775e4d687a7188112eaf58e3" } -comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "070c77759b77f3f9a51ae217734277c95414f71f" } -comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "97d8b2ea3db8b0489eaa8a1ad1fa2e89cfb391e6" } +comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "070c77759b77f3f9a51ae217734277c95414f71f", optional = true } +comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "97d8b2ea3db8b0489eaa8a1ad1fa2e89cfb391e6", optional = true } + +[features] +# Which language generators are compiled in. Drop one to shed its whole +# dependency tree from the build. A build with neither can compile but +# `comline generate` will find no generator. +default = ["gen-rust", "gen-typescript"] +gen-rust = ["dep:comline-codegen-rust"] +gen-typescript = ["dep:comline-codegen-typescript"] [target.'cfg(unix)'.dependencies] libc = "0.2" diff --git a/src/commands/generate.rs b/src/commands/generate.rs index bb74a72..92af12f 100644 --- a/src/commands/generate.rs +++ b/src/commands/generate.rs @@ -24,10 +24,15 @@ use crate::gen_config::{self, ComlineToml, DeclaredLang, Overrides, VersionSpec} use crate::{history, ui, watch}; /// The generator registry, composed from the per-language `comline-codegen-*` -/// crates this CLI was built with. (Feature-gating the set is rollout step 6.) +/// crates this CLI was built with — one `register()` per crate, each behind its +/// `gen-` cargo feature (both on by default). A build without a feature +/// never compiles that generator crate or its dependency tree. pub(crate) fn generator_registry() -> Registry { + #[allow(unused_mut)] let mut registry = Registry::new(); + #[cfg(feature = "gen-rust")] comline_codegen_rust::register(&mut registry); + #[cfg(feature = "gen-typescript")] comline_codegen_typescript::register(&mut registry); registry }