-
Notifications
You must be signed in to change notification settings - Fork 214
RFC30: add Serde Decorator to RustClientCodegenPlugin #2650
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
base: main
Are you sure you want to change the base?
Changes from 26 commits
2c262f9
3645285
fbcbf04
263eb86
2b1ee72
0b01612
aa9982c
06a3cba
6e38a83
495ad68
a3e8546
c49b208
1c24991
5b5f201
81f7efd
e6dbd97
9e997b6
bbb321e
fa8c04b
918f2cd
8802e83
5211559
88c14cb
c4a41c2
dd4a511
982a95d
954b7e9
de2cdd4
a67a879
cbe908a
7251962
44e5fc4
8a6ff7d
40840ae
dc09315
db679e0
d1b369e
0b8ba89
077d868
348db68
476df23
58c4c53
68a60df
abdf723
1c5fd9a
366a43e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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.smithy.RustCrate | ||
|
||
/** | ||
* Decorator that adds the `serde-serialize` and `serde-deserialize` features. | ||
*/ | ||
class SerdeDecorator : ClientCodegenDecorator { | ||
override val name: String = "SerdeDecorator" | ||
override val order: Byte = -1 | ||
|
||
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")) | ||
} | ||
|
||
// I initially tried to implement with LibRsCustomization but it didn't work some how. | ||
companion object { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the text that is going to be included on the lib.rs docs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What did it look like when it was overriding libRsCustomization? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to find the commit that didn't work, but it's lost somewhere in the commit history. |
||
const val SerdeInfoText = """## 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. | ||
Furthermore, implementation of serde 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. | ||
|
||
""" | ||
} | ||
} |
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
Uh oh!
There was an error while loading. Please reload this page.
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?