Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ release = true

[dependencies]
proc-macro2 = "1"
proc-macro-crate = "3"
quote = "1"
# syn 2 rather than 3, which is already in the tree via clap_derive: nothing here
# needs the newer API, and matching what is there avoids a second copy.
syn = { version = "3", features = ["full"] }
# No `proc-macro-crate`: it pulls `toml_edit` (and indexmap/winnow/…) into every
# adopter's compile just to read a Cargo.toml rename. The derive reads the few
# dependency forms usage documents itself — see `crate_name.rs`.

# No dependency on usage-argv, not even for tests. This crate emits tokens and
# links nothing, and dev-depending on the runtime it emits code for creates a cycle
Expand Down
13 changes: 8 additions & 5 deletions derive/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
//! do not collide with anything, and so `cargo expand` shows them together.

use proc_macro2::TokenStream;
use proc_macro_crate::{crate_name, FoundCrate};
use quote::{format_ident, quote};

use crate::crate_name::{crate_name, FoundCrate};
use crate::model::{
rendered_path, Cli, ConditionalDefault, DoubleDash, Field, Kind, Shape, Subcommands, ValueEnum,
};
Expand All @@ -26,16 +26,19 @@ use crate::model::{
/// deliberately enable a different feature set there. Otherwise the `usage-rs` facade provides
/// the runtime as `usage::argv`, keeping derives, tables, and their versions behind one
/// dependency.
///
/// Resolved by reading the adopter's `Cargo.toml` directly rather than via `proc-macro-crate`,
/// so the derive does not drag `toml_edit` into every compile.
fn runtime_path() -> TokenStream {
match crate_name("usage-argv") {
Ok(FoundCrate::Name(name)) => {
let runtime = format_ident!("{}", name.replace('-', "_"));
let runtime = format_ident!("{name}");
quote!(::#runtime)
}
_ => match crate_name("usage-rs") {
Ok(FoundCrate::Itself) => quote!(::usage_rs::argv),
Ok(FoundCrate::Name(name)) => {
let facade = format_ident!("{}", name.replace('-', "_"));
let facade = format_ident!("{name}");
quote!(::#facade::argv)
}
// Preserve the old useful compiler error when neither dependency was declared.
Expand All @@ -52,13 +55,13 @@ fn runtime_path() -> TokenStream {
fn derive_path() -> TokenStream {
match crate_name("usage-derive") {
Ok(FoundCrate::Name(name)) => {
let derive = format_ident!("{}", name.replace('-', "_"));
let derive = format_ident!("{name}");
quote!(::#derive)
}
_ => match crate_name("usage-rs") {
Ok(FoundCrate::Itself) => quote!(::usage_rs),
Ok(FoundCrate::Name(name)) => {
let facade = format_ident!("{}", name.replace('-', "_"));
let facade = format_ident!("{name}");
quote!(::#facade)
}
_ => quote!(::usage_derive),
Expand Down
Loading
Loading