Skip to content
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

Implement smithy-dafny-codegen library that supports dafny-client-codegen smithy-build.json plugin for AWS SDK generation #151

Closed
robin-aws opened this issue Mar 1, 2023 · 5 comments
Assignees
Labels
general-dafny-use New functionality or clean up for broader use of this repo

Comments

@robin-aws
Copy link
Contributor

robin-aws commented Mar 1, 2023

This will support the standard workflow for generating a client for a given Smithy model, as described here: https://smithy.io/2.0/guides/using-code-generation/generating-a-client.html. Ours will only support AWS service models at first, since the implementation will emit Dafny and target language code to wrap up existing AWS SDKs.

This should be mostly wrapping up existing functionality in this tool. There are some minor open design questions about how to configure things, since in our case we will be emitting a project that will handle one or more Dafny-supported target languages.

The workflow for users should be perfectly parallel to how it works for other smithy-<language> tools:

  1. Add the common software.amazon.smithy Gradle plugin
  2. Add this new smithy-dafny-codegen library as an implementation dependency
  3. Configure the dafny-codegen Smithy build plugin in a smithy-build.json file.

A typical smithy-build.json file might look something like this:

{
    "version": "1.0",
    "plugins": {
        "dafny-codegen": {
            "service": "com.amazonaws.kms#TrentService",
            "targetLanguages": ["cs", "java"],
        }
    }
}

(The configuration for a given SmithyBuildPlugin seems to be an arbitrary JSON object, and we'll likely need more properties)

Given this configuration, the plugin should output a "complete Dafny project" just as other codegen plugins do - e.g. see this documentation about the typescript-codegen plugin: https://smithy.io/2.0/guides/using-code-generation/generating-a-client.html#add-the-codegen-plugin. The definition of a "Dafny project" is fuzzy at the time of writing this, however. I would suggest generating a Makefile to build the result for the configured target languages, which will involve invoking dafny as well as target language tooling. In the future there should be more Dafny-native support for project management, such as dafny-lang/dafny#3169 and/or dafny-lang/dafny#2907, at which point we can offer a more standard output style option.

@robin-aws robin-aws changed the title Add dafny-codgen Gradle plugin that supports AWS SDK generation Add dafny-codgen SmithyBuildPlugin plugin that supports AWS SDK generation Mar 1, 2023
@robin-aws
Copy link
Contributor Author

Corrected my understanding: there's one big "Smithy Gradle plugin" (https://github.com/awslabs/smithy-gradle-plugin/). Smithy has its own plugin mechanism that we need to implement: https://github.com/awslabs/smithy/blob/main/smithy-build/src/main/java/software/amazon/smithy/build/SmithyBuildPlugin.java

@robin-aws robin-aws added the general-dafny-use New functionality or clean up for broader use of this repo label Mar 1, 2023
@robin-aws robin-aws changed the title Add dafny-codgen SmithyBuildPlugin plugin that supports AWS SDK generation Publish smithy-dafny-codgen library that supports dafny-codegen smithy-build.json plugin for AWS SDK generation Mar 1, 2023
@alex-chew
Copy link
Contributor

Note to self - check on the current best practice for configuring client region.

@alex-chew alex-chew changed the title Publish smithy-dafny-codgen library that supports dafny-codegen smithy-build.json plugin for AWS SDK generation Publish smithy-dafny-codegen library that supports dafny-codegen smithy-build.json plugin for AWS SDK generation Mar 3, 2023
@robin-aws robin-aws changed the title Publish smithy-dafny-codegen library that supports dafny-codegen smithy-build.json plugin for AWS SDK generation Implement smithy-dafny-codegen library that supports dafny-codegen smithy-build.json plugin for AWS SDK generation Mar 3, 2023
@robin-aws robin-aws changed the title Implement smithy-dafny-codegen library that supports dafny-codegen smithy-build.json plugin for AWS SDK generation Implement smithy-dafny-codegen library that supports dafny-client-codegen smithy-build.json plugin for AWS SDK generation Mar 3, 2023
@robin-aws
Copy link
Contributor Author

Note I'm going to cut a PR to add a new TestModel to show a complete example project for generating a Dafny client for a given AWS service. TTD FTW! :)

@robin-aws
Copy link
Contributor Author

I have to do a bit more to hook it up to the CI, but this should help clarify the requirements beyond the issue description: https://github.com/awslabs/polymorph/tree/smithy-client-codegen-test-model/TestModels/aws-sdks/sqs

@robin-aws
Copy link
Contributor Author

Another wrinkle: Smithy codegen has a notion of "edition": https://smithy.io/2.0/guides/building-codegen/configuring-the-generator.html#edition

That applies equally well to smithy-dafny, as how we map Smithy shapes to Dafny types will evolve over time just as it does in other languages. But our implementation of wrapping existing SDKs means we have to know the "edition" of those SDKs too. The existing codegen CLI is already modeling this concept with switches like --java-aws-sdk-version. We'll need an equivalent bit of smithy-build.json configuration, unless we can somehow discover this metadata on the target language SDK software artifacts.

This was referenced Mar 29, 2023
robin-aws pushed a commit that referenced this issue Apr 19, 2024
Co-authored-by: Valerie Lambert <[email protected]>
Co-authored-by: Alex Chew <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
general-dafny-use New functionality or clean up for broader use of this repo
Projects
None yet
Development

No branches or pull requests

2 participants