Skip to content

Build Plugin #58

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

Merged
merged 10 commits into from
Dec 22, 2022
Merged

Build Plugin #58

merged 10 commits into from
Dec 22, 2022

Conversation

adam-fowler
Copy link
Member

@adam-fowler adam-fowler commented Nov 5, 2022

At this point this is a little experimental. I can't use it in the current release of Soto as it requires Swift 5.6 or later.

This PR adds a build plugin that will generate AWS service swift files from a Smithy model file and the endpoints.json file from AWS. In theory someone doesn't need to download the whole of Soto anymore. There is one gotcha here, without Soto you don't get the extension code. In some cases this will just be missing functionality but for services that require middleware (S3, Glacier, ApiGateway) they will not compile.

Changes include

  • Adding a couple of new options to SotoCodeGenerator to deal with single service files. Previously it assumed we were working on a folder of service files.
  • Combined some of the generated source files so there is always the same number of files output. The plugin needs to know what files will be generated.
  • Create build plugin

For a project to use this it needs to add the following dependencies to their Package.swift

        .package(url: "https://github.com/soto-project/soto-codegenerator", branch: "feature/plugin"),
        .package(url: "https://github.com/soto-project/soto-core.git", from: "6.0.0")

Create a target with an empty dummy.swift file and the Smithy model file for the service you want code for. You can find the service files here. In the Package.swift add the target as follows

        .target(
            name: "MyService",
            dependencies: [.product(name: "SotoCore", package: "soto-core")],
            plugins: [.plugin(name: "SotoCodeGeneratorPlugin", package: "soto-codegenerator")]
        ),

Copy the endpoints.json to the root of your package

Now when you build it will generate the swift service files in .build/plugins/outputs/soto-codegenerator-plugin/MyService/SotoCodeGeneratorPlugin/GeneratedSources.

You can find an example project here https://github.com/adam-fowler/soto-codegenerator-plugin-test

@adam-fowler adam-fowler marked this pull request as draft November 5, 2022 11:30
@adam-fowler
Copy link
Member Author

@ktoso @0xTim

@adam-fowler
Copy link
Member Author

adam-fowler commented Nov 5, 2022

Eventually I should be able to use this with Soto, and people wouldn't be downloading Swift files for every service. They would just be downloading the service model files and generating the code for services they need.

Instead of outputting optional error, paginator and waiter files, combine them with the api or shapes file to always generate a consistent number of files.
Copy link
Member

@0xTim 0xTim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Looking forward to seeing this get used

@adam-fowler adam-fowler merged commit 0434566 into main Dec 22, 2022
@adam-fowler adam-fowler deleted the feature/plugin branch December 22, 2022 22:16
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.

2 participants