-
Notifications
You must be signed in to change notification settings - Fork 196
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
Refactor runtimeType usage in codegen #1933
Conversation
add: AwsCustomization NamedSectionGenerator add: AwsSection for `From<SdkConfig> for service::config::Builder` codegen rename: AwsCodegenDecorator to AwsCombinedCodegenDecorator add: new interface AwsCodegenDecorator that respects AwsCustomizations
fix: tests broken by moves
format: unify casing of runtime type function names format: unify casing of CargoDependency function names rename: args of FluentClientGenerics.sendBounds method to be more explicit update: make orderedDecorators field of CombinedCodegenDecorator accessible to inheritors fix: spelling issues highlighted by IntelliJ update: make protected fields private where possible
|
A new generated diff is ready to view.
A new doc preview is ready to view. |
add: missing copyright headers fix: endpoints test by differentiating between usages of aws-endpoints
A new generated diff is ready to view.
A new doc preview is ready to view. |
update: rename servicecustomizations to servicedecorators remove: decorator name field add: CHANGELOG.next.toml entries
A new generated diff is ready to view.
A new doc preview is ready to view. |
Info for smithy contribs: - `awsRuntimeDependency` has been renamed to `awsRuntimeCrate` in order to match `smithyRuntimeCrate`. Additionally, declaration of the runtime crates has been centralized in `software.amazon.smithy.rustsdk.AwsRuntimeDependency` for AWS types and `software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency` for smithy types. - The `RuntimeConfig` runtime crate functions now return `RuntimeTypes` instead of `CargoDependencies`. This better matches their usage in codegen. If you want to access the cargo dependency, use the `awsRuntimeCrate`/`smithyRuntimeCrate` functions directly. before: `rust("#T", CargoDependency.SmithyClient(runtimeConfig).asType())` after: `rust("#T", runtimeConfig.smithyClient())` - Service-specific decorators in SDK codegen have been moved into `software.amazon.smithy.rustsdk.servicedecorators`. All other decorators have been moved to `software.amazon.smithy.rustsdk.decorators`. -`RustCodegenDecorator`'s name field has been removed. If you need to log the name of a decorator, use Kotlin's builtin `class` field: ```kotlin val someDecorator = SomeDecorator() print(someDecorator::class) // prints "class SomeDecorator" ``` - The class `AwsCodegenDecorator.kt` has been renamed to `AwsCombinedCodegenDecorator.kt`. A new class, now named `AwsCodegenDecorator` is an AWS-specific subclass of `RustCodegenDecorator`. `AwsCodegenDecorator` supports the customization of the `FromSdkConfigForBuilder` section. For example, adding this customization to codegen as part of a decorator: ```kotlin class SleepImplFromSdkConfig : AwsCustomization() { override fun section(section: AwsSection): Writable = writable { when (section) { is AwsSection.FromSdkConfigForBuilder -> rust("builder.set_sleep_impl(input.sleep_impl());") } } } ``` would result in this Rust code being generated: ```rust // In aws-sdk-<service>/src/config.rs impl From<&SdkConfig> for Builder { fn from(input: &#{SdkConfig}) -> Self { let mut builder = Builder::default(); builder.set_sleep_impl(input.sleep_impl()); builder } } ``` - `CombinedCodegenDecorator`'s `orderedDecorators` field is now protected instead of private so that the new `AwsCodegenDecorator` subclass can use it. - `runtimeCrate` has been renamed to `smithyRuntimeCrate` and now requires users to pass the "smithy-" prefix as part of the crate name: before: `val smithyHttp = runtimeCrate("http").asType()` after: `val smithyHttp = smithyRuntimeCrate("smithy-http").asType()`
[this comment was moved into the PR description] |
A new generated diff is ready to view.
A new doc preview is ready to view. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! Lots of nice changes in here, and I love the push for more consistency on the runtime types.
} | ||
} | ||
|
||
fun generateImplFromRefSdkConfigForConfigBuilder( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be in SdkConfigDecorator
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think no because I feel that all the section writing code should be defined in one place. The combined decorator is also the place where we have access to the full list of decorators that modify an AwsSection
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Organizationally, this isn't going to work out well since people will think to look in SdkConfigDecorator
for this code rather than in AwsCombinedCodegenDecorator
. The full list of decorators can be passed into the customizations if it's required (and I think we do that in codegen-core
/codegen-client
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Russell is adding the ability to do this as part of #1953, I can take the change from that or wait for the merge.
...gen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/AwsCombinedCodegenDecorator.kt
Show resolved
Hide resolved
...en/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/HttpRequestChecksumDecorator.kt
Show resolved
Hide resolved
...odegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/IntegrationTestDecorator.kt
Outdated
Show resolved
Hide resolved
aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/decorators/UserAgentDecorator.kt
Show resolved
Hide resolved
...n/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt
Show resolved
Hide resolved
...en-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt
Show resolved
Hide resolved
remove: need to specify `CargoDependency` refactor: get runtime types from `RuntimeType` instead of `RuntimeConfig`
A new generated diff is ready to view.
A new doc preview is ready to view. |
update: RuntimeType usage
format: run `pre-commit run --all-files`
A new generated diff is ready to view.
A new doc preview is ready to view. |
…n with other conversion methods
A new generated diff is ready to view.
A new doc preview is ready to view. |
@@ -11,8 +11,8 @@ import software.amazon.smithy.model.traits.AnnotationTrait | |||
|
|||
/** Synthetic trait that indicates an operation is presignable. */ | |||
// TODO(https://github.com/awslabs/smithy/pull/897) this can be replaced when the trait is added to Smithy. | |||
class PresignableTrait(val syntheticOperationId: ShapeId) : AnnotationTrait(ID, Node.objectNode()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this was never used?
"HeaderMap" to RuntimeType.http.member("HeaderMap"), | ||
"JsonError" to CargoDependency.smithyJson(runtimeConfig).asType().member("deserialize::Error"), | ||
"Response" to RuntimeType.http.member("Response"), | ||
"Bytes" to Bytes.toType().resolve("Bytes"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personally, I do actually appreciate the prefix so I know this is a rust library but not a super strong preference
"HeaderMap" to RuntimeType.http.member("HeaderMap"), | ||
"Response" to RuntimeType.http.member("Response"), | ||
"XmlError" to CargoDependency.smithyXml(runtimeConfig).asType().member("decode::XmlError"), | ||
"Bytes" to Bytes.toType().resolve("Bytes"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if replacing the single-source-of-truth Bytes
with a resolved package everywhere is useful? Maybe a CommonTypes
module?
can you move the "changelog" comment into the PR description so it's easier to find? |
A new generated diff is ready to view.
A new doc preview is ready to view. |
I'm going to close this and re-open separate PRs, each with a subset of the changes. |
Description
This primarily does three things:
Info for smithy contribs:
awsRuntimeDependency
has been renamed toawsRuntimeCrate
in order to matchsmithyRuntimeCrate
. Additionally, declaration of the runtime crates has been centralized insoftware.amazon.smithy.rustsdk.AwsRuntimeDependency
for AWS types andsoftware.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
for smithy types.The
RuntimeConfig
runtime crate functions now returnRuntimeTypes
instead ofCargoDependencies
. This better matches their usage in codegen. If you want to access the cargo dependency, use theawsRuntimeCrate
/smithyRuntimeCrate
functions directly.before:
rust("#T", CargoDependency.SmithyClient(runtimeConfig).asType())
after:
rust("#T", runtimeConfig.smithyClient())
Service-specific decorators in SDK codegen have been moved into
software.amazon.smithy.rustsdk.servicedecorators
. All other decorators have been moved tosoftware.amazon.smithy.rustsdk.decorators
.-
RustCodegenDecorator
's name field has been removed. If you need to log the name of a decorator, use Kotlin's builtinclass
field:The class
AwsCodegenDecorator.kt
has been renamed toAwsCombinedCodegenDecorator.kt
. A new class, now namedAwsCodegenDecorator
is an AWS-specific subclass ofRustCodegenDecorator
.AwsCodegenDecorator
supports the customization of theFromSdkConfigForBuilder
section.For example, adding this customization to codegen as part of a decorator:
would result in this Rust code being generated:
CombinedCodegenDecorator
'sorderedDecorators
field is now protected instead of private so that the newAwsCodegenDecorator
subclass can use it.runtimeCrate
has been renamed tosmithyRuntimeCrate
and now requires users to pass the "smithy-" prefix as part of the crate name:before:
val smithyHttp = runtimeCrate("http").asType()
after:
val smithyHttp = smithyRuntimeCrate("smithy-http").asType()
Testing
ran existing tests
Checklist
CHANGELOG.next.toml
if I made changes to the smithy-rs codegen or runtime cratesCHANGELOG.next.toml
if I made changes to the AWS SDK, generated SDK code, or SDK runtime cratesBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.