-
Notifications
You must be signed in to change notification settings - Fork 195
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
RFC30: add Serde Decorator to RustClientCodegenPlugin #2650
Open
thomas-k-cameron
wants to merge
46
commits into
smithy-lang:main
Choose a base branch
from
thomas-k-cameron:RFC30/serde-decorator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
2c262f9
serde decorator
thomas-k-cameron 3645285
update
thomas-k-cameron fbcbf04
update
thomas-k-cameron 263eb86
update
thomas-k-cameron 2b1ee72
update
thomas-k-cameron 0b01612
update
thomas-k-cameron aa9982c
Merge branch 'main' into RFC30/serde-decorator
thomas-k-cameron 06a3cba
Merge branch 'main' into RFC30/serde-decorator
thomas-k-cameron 6e38a83
Merge branch 'main' into RFC30/serde-decorator
thomas-k-cameron 495ad68
Merge branch 'main' into RFC30/serde-decorator
thomas-k-cameron a3e8546
Update codegen-client/src/main/kotlin/software/amazon/smithy/rust/cod…
thomas-k-cameron c49b208
update
thomas-k-cameron 1c24991
update
thomas-k-cameron 5b5f201
update
thomas-k-cameron 81f7efd
update
thomas-k-cameron e6dbd97
update
thomas-k-cameron 9e997b6
update
thomas-k-cameron bbb321e
asdf
thomas-k-cameron fa8c04b
asdf
thomas-k-cameron 918f2cd
Update LibRsGenerator.kt
thomas-k-cameron 8802e83
Update SerdeDecorator.kt
thomas-k-cameron 5211559
asdf
thomas-k-cameron 88c14cb
Merge branch 'main' into RFC30/serde-decorator
thomas-k-cameron c4a41c2
update
thomas-k-cameron dd4a511
asdf
thomas-k-cameron 982a95d
Delete devcontainer.json
thomas-k-cameron 954b7e9
Merge branch 'main' into RFC30/serde-decorator
thomas-k-cameron de2cdd4
Merge branch 'main' into RFC30/serde-decorator
thomas-k-cameron a67a879
Merge branch 'main' into RFC30/serde-decorator
thomas-k-cameron cbe908a
Merge branch 'main' into RFC30/serde-decorator
thomas-k-cameron 7251962
Merge branch 'main' into RFC30/serde-decorator
thomas-k-cameron 44e5fc4
Merge branch 'main' into RFC30/serde-decorator
thomas-k-cameron 8a6ff7d
update
thomas-k-cameron 40840ae
Merge branch 'RFC30/serde-decorator' of https://github.com/thomas-k-c…
thomas-k-cameron dc09315
update
thomas-k-cameron db679e0
update
thomas-k-cameron d1b369e
update
thomas-k-cameron 0b8ba89
update
thomas-k-cameron 077d868
asdf
thomas-k-cameron 348db68
modified: codegen-client/src/main/kotlin/software/amazon/smithy/rus…
thomas-k-cameron 476df23
update
thomas-k-cameron 58c4c53
update
thomas-k-cameron 68a60df
update
thomas-k-cameron abdf723
modified: codegen-client/src/main/kotlin/software/amazon/smithy/rus…
thomas-k-cameron 1c5fd9a
Merge branch 'main' into RFC30/serde-decorator
thomas-k-cameron 366a43e
Merge branch 'main' into RFC30/serde-decorator
thomas-k-cameron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.rust.codegen.client.smithy.customize | ||
|
||
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext | ||
import software.amazon.smithy.rust.codegen.core.rustlang.Feature | ||
import software.amazon.smithy.rust.codegen.core.rustlang.Writable | ||
import software.amazon.smithy.rust.codegen.core.rustlang.containerDocs | ||
import software.amazon.smithy.rust.codegen.core.rustlang.writable | ||
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate | ||
import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization | ||
import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection | ||
import software.amazon.smithy.rust.codegen.core.smithy.generators.ModuleDocSection | ||
|
||
/** | ||
* Decorator that adds the `serde-serialize` and `serde-deserialize` features. | ||
*/ | ||
class SerdeDecorator : ClientCodegenDecorator { | ||
override val name: String = "SerdeDecorator" | ||
override val order: Byte = 5 | ||
|
||
override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { | ||
fun feature(featureName: String): Feature { | ||
return Feature(featureName, false, listOf("aws-smithy-types/$featureName")) | ||
} | ||
rustCrate.mergeFeature(feature("serde-serialize")) | ||
rustCrate.mergeFeature(feature("serde-deserialize")) | ||
} | ||
|
||
override fun libRsCustomizations( | ||
codegenContext: ClientCodegenContext, | ||
baseCustomizations: List<LibRsCustomization>, | ||
): List<LibRsCustomization> { | ||
return baseCustomizations + SerdeDocGenerator(codegenContext) | ||
} | ||
} | ||
|
||
class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibRsCustomization() { | ||
override fun section(section: LibRsSection): Writable { | ||
return when (section) { | ||
is LibRsSection.ModuleDoc -> | ||
if (section.subsection is ModuleDocSection.AWSSdkUnstable) { | ||
serdeInfoText() | ||
} else { | ||
emptySection | ||
} | ||
|
||
else -> emptySection | ||
} | ||
} | ||
|
||
private fun serdeInfoText(): Writable { | ||
return writable { | ||
containerDocs( | ||
""" | ||
## How to enable `Serialize` and `Deserialize` | ||
|
||
This data type implements `Serialize` and `Deserialize` traits from the popular serde crate, but those traits are behind feature gate. | ||
|
||
As they increase it's compile time dramatically, you should not turn them on unless it's necessary. | ||
Implementation of `serde` traits in AWS SDK for Rust is still unstable, and implementation may change anytime in future. | ||
|
||
To enable traits, you must pass `aws_sdk_unstable` to RUSTFLAGS and enable `serde-serialize` or `serde-deserialize` feature. | ||
|
||
e.g. | ||
```bash,no_run | ||
export RUSTFLAGS="--cfg aws_sdk_unstable" | ||
cargo build --features serde-serialize serde-deserialize | ||
``` | ||
|
||
If you enable `serde-serialize` and/or `serde-deserialize` without `RUSTFLAGS="--cfg aws_sdk_unstable"`, | ||
compilation will fail with warning. | ||
|
||
""".trimIndent(), | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would be good to also hook into the
ModuleDocSection.ServiceDocs
, or even add a newModuleDocSection.Features
, so that these features can be described in the docs. That way, the documentation can inform on the--cfg aws_sdk_unstable
requirement. This would require registering aLibRsCustomization
, sooverride fun libRsCustomizations(...)
.There's an example here that adds information to the "Crate Organization" documentation section: https://github.com/awslabs/smithy-rs/blob/2f60a5e0904037ec5237c080c61817617b9d8c06/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientCustomizations.kt#L19
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 added this function but it seems like there are no changes to the generated code.
Is there anything else that I'm supposed to add?