Skip to content

Add SDK and CLI compilation test #1131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Add SDK and CLI compilation test #1131

wants to merge 3 commits into from

Conversation

augustuswm
Copy link
Contributor

@augustuswm augustuswm commented May 2, 2025

This PR extracts a test I was working on in a separate branch. The goal is to verify that the SDKs and CLIs that are generated via tests actually compile.

This is done via a small macro that takes a schema file and outputs the generate SDK and CLI tokens. These tokens are contained within a test function which will fail to compile if the SDK or CLI fail to compile. If they do successfully compile then the test trivially passes.

Notably the currently checked in buildomat and nexus files currently fail this test during CLI compilation. I have not tracked it down yet, but it looks to likely be related to the handling of Vec arguments to the CLI.

buildomat.json
ValueEnum is not implemented for types::GetThingOrThingsId

pub fn cli_get_thing_or_things() -> ::clap::Command {
    ::clap::Command::new("").arg(
        ::clap::Arg::new("id")
            .long("id")
            .value_parser(::clap::value_parser!(types::GetThingOrThingsId))
            .required(false),
    )
}

This tracks as there is no derive or manual implementation for GetThingOrThingsId

#[serde(untagged)]
pub enum GetThingOrThingsId {
   Variant0(::std::string::String),
   Variant1(::std::vec::Vec<::std::string::String>),
}

The other error here (which is also the case with nexus.json), I am a little less clear on:

error[E0277]: the trait bound `clap::builder::Str: From<std::string::String>` is not satisfied
    --> progenitor-impl/tests/test_compilation.rs:12:5
     |
12   |     cli_tokens!("buildomat.json");
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<std::string::String>` is not implemented for `clap::builder::Str`
     |
     = help: the following other types implement trait `From<T>`:
               `clap::builder::Str` implements `From<&&str>`
               `clap::builder::Str` implements `From<&clap::builder::Str>`
               `clap::builder::Str` implements `From<&str>`
               `clap::builder::Str` implements `From<Id>`
     = note: required for `std::string::String` to implement `Into<clap::builder::Str>`
     = note: required for `PossibleValue` to implement `From<std::string::String>`
     = note: 3 redundant requirements hidden
     = note: required for `[std::string::String; 2]` to implement `Into<PossibleValuesParser>`
note: required by a bound in `PossibleValuesParser::new`
    --> /home/awm/.cargo/registry/src/index.crates.io-6f17d22bba15001f/clap_builder-4.5.37/src/builder/value_parser.rs:1200:29
     |
1200 |     pub fn new(values: impl Into<PossibleValuesParser>) -> Self {
     |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `PossibleValuesParser::new`
     = note: this error originates in the macro `cli_tokens` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `progenitor-impl` (test "test_compilation") due to 1 previous error
error: command `/home/awm/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo test --no-run --message-format json-render-diagnostics` exited with code 101

But presumably is related to the generated TypedValueParser construction here:

pub fn cli_header_arg() -> ::clap::Command {
    ::clap::Command::new("").arg(
        ::clap::Arg::new("accept-language")
            .long("accept-language")
            .value_parser(::clap::builder::TypedValueParser::map(
                ::clap::builder::PossibleValuesParser::new([
                    types::HeaderArgAcceptLanguage::De.to_string(),
                    types::HeaderArgAcceptLanguage::En.to_string(),
                ]),
                |s| types::HeaderArgAcceptLanguage::try_from(s).unwrap(),
            ))
            .required(false),
    )
}

@augustuswm
Copy link
Contributor Author

augustuswm commented May 2, 2025

Secondary issue (clap::builder::Str: From<std::string::String>) was due to a missing feature flag in clap. The string features was required to be able to construct PossibleValuesParsers from Strings as opposed to &'static str.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant