From 2c262f9e5fb1532b202d45d9b2cecdb2699ad7b6 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 27 Apr 2023 04:13:28 +0000 Subject: [PATCH 01/32] serde decorator --- .../client/smithy/RustClientCodegenPlugin.kt | 200 +++++++++--------- .../client/smithy/customize/SerdeDecorator.kt | 28 +++ 2 files changed, 129 insertions(+), 99 deletions(-) create mode 100644 codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt index faa3a01c5d..322e81a94c 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt @@ -3,103 +3,105 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy + package software.amazon.smithy.rust.codegen.client.smithy -import software.amazon.smithy.build.PluginContext -import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider -import software.amazon.smithy.model.Model -import software.amazon.smithy.model.shapes.ServiceShape -import software.amazon.smithy.rust.codegen.client.smithy.customizations.ApiKeyAuthDecorator -import software.amazon.smithy.rust.codegen.client.smithy.customizations.ClientCustomizations -import software.amazon.smithy.rust.codegen.client.smithy.customizations.HttpAuthDecorator -import software.amazon.smithy.rust.codegen.client.smithy.customizations.HttpConnectorConfigDecorator -import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedClientCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.customize.NoOpEventStreamSigningDecorator -import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCustomizations -import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointParamsDecorator -import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointsDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientDecorator -import software.amazon.smithy.rust.codegen.client.testutil.ClientDecoratableBuildPlugin -import software.amazon.smithy.rust.codegen.core.rustlang.Attribute.Companion.NonExhaustive -import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolProvider -import software.amazon.smithy.rust.codegen.core.smithy.BaseSymbolMetadataProvider -import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget -import software.amazon.smithy.rust.codegen.core.smithy.EventStreamSymbolProvider -import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig -import software.amazon.smithy.rust.codegen.core.smithy.StreamingShapeMetadataProvider -import software.amazon.smithy.rust.codegen.core.smithy.StreamingShapeSymbolProvider -import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor -import java.util.logging.Level -import java.util.logging.Logger - -/** - * Rust Client Codegen Plugin - * - * This is the entrypoint for code generation, triggered by the smithy-build plugin. - * `resources/META-INF.services/software.amazon.smithy.build.SmithyBuildPlugin` refers to this class by name which - * enables the smithy-build plugin to invoke `execute` with all Smithy plugin context + models. - */ -class RustClientCodegenPlugin : ClientDecoratableBuildPlugin() { - override fun getName(): String = "rust-client-codegen" - - override fun executeWithDecorator( - context: PluginContext, - vararg decorator: ClientCodegenDecorator, - ) { - // Suppress extremely noisy logs about reserved words - Logger.getLogger(ReservedWordSymbolProvider::class.java.name).level = Level.OFF - // Discover `RustCodegenDecorators` on the classpath. `RustCodegenDecorator` returns different types of - // customizations. A customization is a function of: - // - location (e.g. the mutate section of an operation) - // - context (e.g. the of the operation) - // - writer: The active RustWriter at the given location - val codegenDecorator = - CombinedClientCodegenDecorator.fromClasspath( - context, - ClientCustomizations(), - RequiredCustomizations(), - FluentClientDecorator(), - EndpointsDecorator(), - EndpointParamsDecorator(), - NoOpEventStreamSigningDecorator(), - ApiKeyAuthDecorator(), - HttpAuthDecorator(), - HttpConnectorConfigDecorator(), - *decorator, - ) - - // ClientCodegenVisitor is the main driver of code generation that traverses the model and generates code - ClientCodegenVisitor(context, codegenDecorator).execute() - } - - companion object { - /** - * When generating code, smithy types need to be converted into Rust types—that is the core role of the symbol provider - * - * The Symbol provider is composed of a base [SymbolVisitor] which handles the core functionality, then is layered - * with other symbol providers, documented inline, to handle the full scope of Smithy types. - */ - fun baseSymbolProvider( - settings: ClientRustSettings, - model: Model, - serviceShape: ServiceShape, - rustSymbolProviderConfig: RustSymbolProviderConfig, - codegenDecorator: ClientCodegenDecorator, - ) = - SymbolVisitor(settings, model, serviceShape = serviceShape, config = rustSymbolProviderConfig) - // Generate different types for EventStream shapes (e.g. transcribe streaming) - .let { EventStreamSymbolProvider(rustSymbolProviderConfig.runtimeConfig, it, CodegenTarget.CLIENT) } - // Generate `ByteStream` instead of `Blob` for streaming binary shapes (e.g. S3 GetObject) - .let { StreamingShapeSymbolProvider(it) } - // Add Rust attributes (like `#[derive(PartialEq)]`) to generated shapes - .let { BaseSymbolMetadataProvider(it, additionalAttributes = listOf(NonExhaustive)) } - // Streaming shapes need different derives (e.g. they cannot derive `PartialEq`) - .let { StreamingShapeMetadataProvider(it) } - // Rename shapes that clash with Rust reserved words & and other SDK specific features e.g. `send()` cannot - // be the name of an operation input - .let { RustReservedWordSymbolProvider(it, ClientReservedWords) } - // Allows decorators to inject a custom symbol provider - .let { codegenDecorator.symbolProvider(it) } - } -} + import software.amazon.smithy.build.PluginContext + import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider + import software.amazon.smithy.model.Model + import software.amazon.smithy.model.shapes.ServiceShape + import software.amazon.smithy.rust.codegen.client.smithy.customizations.ApiKeyAuthDecorator + import software.amazon.smithy.rust.codegen.client.smithy.customizations.ClientCustomizations + import software.amazon.smithy.rust.codegen.client.smithy.customizations.HttpAuthDecorator + import software.amazon.smithy.rust.codegen.client.smithy.customizations.HttpConnectorConfigDecorator + import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator + import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedClientCodegenDecorator + import software.amazon.smithy.rust.codegen.client.smithy.customize.NoOpEventStreamSigningDecorator + import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCustomizations + import software.amazon.smithy.rust.codegen.client.smithy.customize.SerdeDecorator + import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointParamsDecorator + import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointsDecorator + import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientDecorator + import software.amazon.smithy.rust.codegen.client.testutil.ClientDecoratableBuildPlugin + import software.amazon.smithy.rust.codegen.core.rustlang.Attribute.Companion.NonExhaustive + import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolProvider + import software.amazon.smithy.rust.codegen.core.smithy.BaseSymbolMetadataProvider + import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget + import software.amazon.smithy.rust.codegen.core.smithy.EventStreamSymbolProvider + import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig + import software.amazon.smithy.rust.codegen.core.smithy.StreamingShapeMetadataProvider + import software.amazon.smithy.rust.codegen.core.smithy.StreamingShapeSymbolProvider + import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor + import java.util.logging.Level + import java.util.logging.Logger + + /** + * Rust Client Codegen Plugin + * + * This is the entrypoint for code generation, triggered by the smithy-build plugin. + * `resources/META-INF.services/software.amazon.smithy.build.SmithyBuildPlugin` refers to this class by name which + * enables the smithy-build plugin to invoke `execute` with all Smithy plugin context + models. + */ + class RustClientCodegenPlugin : ClientDecoratableBuildPlugin() { + override fun getName(): String = "rust-client-codegen" + + override fun executeWithDecorator( + context: PluginContext, + vararg decorator: ClientCodegenDecorator, + ) { + // Suppress extremely noisy logs about reserved words + Logger.getLogger(ReservedWordSymbolProvider::class.java.name).level = Level.OFF + // Discover `RustCodegenDecorators` on the classpath. `RustCodegenDecorator` returns different types of + // customizations. A customization is a function of: + // - location (e.g. the mutate section of an operation) + // - context (e.g. the of the operation) + // - writer: The active RustWriter at the given location + val codegenDecorator = + CombinedClientCodegenDecorator.fromClasspath( + context, + SerdeDecorator(), + ClientCustomizations(), + RequiredCustomizations(), + FluentClientDecorator(), + EndpointsDecorator(), + EndpointParamsDecorator(), + NoOpEventStreamSigningDecorator(), + ApiKeyAuthDecorator(), + HttpAuthDecorator(), + HttpConnectorConfigDecorator(), + *decorator, + ) + + // ClientCodegenVisitor is the main driver of code generation that traverses the model and generates code + ClientCodegenVisitor(context, codegenDecorator).execute() + } + + companion object { + /** + * When generating code, smithy types need to be converted into Rust types—that is the core role of the symbol provider + * + * The Symbol provider is composed of a base [SymbolVisitor] which handles the core functionality, then is layered + * with other symbol providers, documented inline, to handle the full scope of Smithy types. + */ + fun baseSymbolProvider( + settings: ClientRustSettings, + model: Model, + serviceShape: ServiceShape, + rustSymbolProviderConfig: RustSymbolProviderConfig, + codegenDecorator: ClientCodegenDecorator, + ) = + SymbolVisitor(settings, model, serviceShape = serviceShape, config = rustSymbolProviderConfig) + // Generate different types for EventStream shapes (e.g. transcribe streaming) + .let { EventStreamSymbolProvider(rustSymbolProviderConfig.runtimeConfig, it, CodegenTarget.CLIENT) } + // Generate `ByteStream` instead of `Blob` for streaming binary shapes (e.g. S3 GetObject) + .let { StreamingShapeSymbolProvider(it) } + // Add Rust attributes (like `#[derive(PartialEq)]`) to generated shapes + .let { BaseSymbolMetadataProvider(it, additionalAttributes = listOf(NonExhaustive)) } + // Streaming shapes need different derives (e.g. they cannot derive `PartialEq`) + .let { StreamingShapeMetadataProvider(it) } + // Rename shapes that clash with Rust reserved words & and other SDK specific features e.g. `send()` cannot + // be the name of an operation input + .let { RustReservedWordSymbolProvider(it, ClientReservedWords) } + // Allows decorators to inject a custom symbol provider + .let { codegenDecorator.symbolProvider(it) } + } + } \ No newline at end of file diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt new file mode 100644 index 0000000000..7471d405ef --- /dev/null +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -0,0 +1,28 @@ +/* +* 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 + +/** + * This class, + * - Adds serde as a dependency + * + */ +class SerdeDecorator : ClientCodegenDecorator { + override val name: String = "SerdeDecorator" + override val order: Byte = -1 + + override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { + fun _feature(feature_name: String, crate_name: String): Feature { + return Feature(feature_name, false, listOf(crate_name + "/" + feature_name)) + } + rustCrate.mergeFeature(_feature("serde-serialize", "aws-smithy-types")) + rustCrate.mergeFeature(_feature("serde-deserialize", "aws-smithy-types")) + } +} \ No newline at end of file From 3645285aa5101e8c3aaf1ba1392d92c9bff730f7 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 27 Apr 2023 04:15:57 +0000 Subject: [PATCH 02/32] update --- .../client/smithy/RustClientCodegenPlugin.kt | 208 +++++++++--------- 1 file changed, 104 insertions(+), 104 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt index 322e81a94c..d8a333b205 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt @@ -1,107 +1,107 @@ /* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ +* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +* SPDX-License-Identifier: Apache-2.0 +*/ - package software.amazon.smithy.rust.codegen.client.smithy +package software.amazon.smithy.rust.codegen.client.smithy - import software.amazon.smithy.build.PluginContext - import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider - import software.amazon.smithy.model.Model - import software.amazon.smithy.model.shapes.ServiceShape - import software.amazon.smithy.rust.codegen.client.smithy.customizations.ApiKeyAuthDecorator - import software.amazon.smithy.rust.codegen.client.smithy.customizations.ClientCustomizations - import software.amazon.smithy.rust.codegen.client.smithy.customizations.HttpAuthDecorator - import software.amazon.smithy.rust.codegen.client.smithy.customizations.HttpConnectorConfigDecorator - import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator - import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedClientCodegenDecorator - import software.amazon.smithy.rust.codegen.client.smithy.customize.NoOpEventStreamSigningDecorator - import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCustomizations - import software.amazon.smithy.rust.codegen.client.smithy.customize.SerdeDecorator - import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointParamsDecorator - import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointsDecorator - import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientDecorator - import software.amazon.smithy.rust.codegen.client.testutil.ClientDecoratableBuildPlugin - import software.amazon.smithy.rust.codegen.core.rustlang.Attribute.Companion.NonExhaustive - import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolProvider - import software.amazon.smithy.rust.codegen.core.smithy.BaseSymbolMetadataProvider - import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget - import software.amazon.smithy.rust.codegen.core.smithy.EventStreamSymbolProvider - import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig - import software.amazon.smithy.rust.codegen.core.smithy.StreamingShapeMetadataProvider - import software.amazon.smithy.rust.codegen.core.smithy.StreamingShapeSymbolProvider - import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor - import java.util.logging.Level - import java.util.logging.Logger - - /** - * Rust Client Codegen Plugin - * - * This is the entrypoint for code generation, triggered by the smithy-build plugin. - * `resources/META-INF.services/software.amazon.smithy.build.SmithyBuildPlugin` refers to this class by name which - * enables the smithy-build plugin to invoke `execute` with all Smithy plugin context + models. - */ - class RustClientCodegenPlugin : ClientDecoratableBuildPlugin() { - override fun getName(): String = "rust-client-codegen" - - override fun executeWithDecorator( - context: PluginContext, - vararg decorator: ClientCodegenDecorator, - ) { - // Suppress extremely noisy logs about reserved words - Logger.getLogger(ReservedWordSymbolProvider::class.java.name).level = Level.OFF - // Discover `RustCodegenDecorators` on the classpath. `RustCodegenDecorator` returns different types of - // customizations. A customization is a function of: - // - location (e.g. the mutate section of an operation) - // - context (e.g. the of the operation) - // - writer: The active RustWriter at the given location - val codegenDecorator = - CombinedClientCodegenDecorator.fromClasspath( - context, - SerdeDecorator(), - ClientCustomizations(), - RequiredCustomizations(), - FluentClientDecorator(), - EndpointsDecorator(), - EndpointParamsDecorator(), - NoOpEventStreamSigningDecorator(), - ApiKeyAuthDecorator(), - HttpAuthDecorator(), - HttpConnectorConfigDecorator(), - *decorator, - ) - - // ClientCodegenVisitor is the main driver of code generation that traverses the model and generates code - ClientCodegenVisitor(context, codegenDecorator).execute() - } - - companion object { - /** - * When generating code, smithy types need to be converted into Rust types—that is the core role of the symbol provider - * - * The Symbol provider is composed of a base [SymbolVisitor] which handles the core functionality, then is layered - * with other symbol providers, documented inline, to handle the full scope of Smithy types. - */ - fun baseSymbolProvider( - settings: ClientRustSettings, - model: Model, - serviceShape: ServiceShape, - rustSymbolProviderConfig: RustSymbolProviderConfig, - codegenDecorator: ClientCodegenDecorator, - ) = - SymbolVisitor(settings, model, serviceShape = serviceShape, config = rustSymbolProviderConfig) - // Generate different types for EventStream shapes (e.g. transcribe streaming) - .let { EventStreamSymbolProvider(rustSymbolProviderConfig.runtimeConfig, it, CodegenTarget.CLIENT) } - // Generate `ByteStream` instead of `Blob` for streaming binary shapes (e.g. S3 GetObject) - .let { StreamingShapeSymbolProvider(it) } - // Add Rust attributes (like `#[derive(PartialEq)]`) to generated shapes - .let { BaseSymbolMetadataProvider(it, additionalAttributes = listOf(NonExhaustive)) } - // Streaming shapes need different derives (e.g. they cannot derive `PartialEq`) - .let { StreamingShapeMetadataProvider(it) } - // Rename shapes that clash with Rust reserved words & and other SDK specific features e.g. `send()` cannot - // be the name of an operation input - .let { RustReservedWordSymbolProvider(it, ClientReservedWords) } - // Allows decorators to inject a custom symbol provider - .let { codegenDecorator.symbolProvider(it) } - } - } \ No newline at end of file +import software.amazon.smithy.build.PluginContext +import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider +import software.amazon.smithy.model.Model +import software.amazon.smithy.model.shapes.ServiceShape +import software.amazon.smithy.rust.codegen.client.smithy.customizations.ApiKeyAuthDecorator +import software.amazon.smithy.rust.codegen.client.smithy.customizations.ClientCustomizations +import software.amazon.smithy.rust.codegen.client.smithy.customizations.HttpAuthDecorator +import software.amazon.smithy.rust.codegen.client.smithy.customizations.HttpConnectorConfigDecorator +import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedClientCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.customize.NoOpEventStreamSigningDecorator +import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCustomizations +import software.amazon.smithy.rust.codegen.client.smithy.customize.SerdeDecorator +import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointParamsDecorator +import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointsDecorator +import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientDecorator +import software.amazon.smithy.rust.codegen.client.testutil.ClientDecoratableBuildPlugin +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute.Companion.NonExhaustive +import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.BaseSymbolMetadataProvider +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.EventStreamSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig +import software.amazon.smithy.rust.codegen.core.smithy.StreamingShapeMetadataProvider +import software.amazon.smithy.rust.codegen.core.smithy.StreamingShapeSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor +import java.util.logging.Level +import java.util.logging.Logger + +/** + * Rust Client Codegen Plugin +* +* This is the entrypoint for code generation, triggered by the smithy-build plugin. +* `resources/META-INF.services/software.amazon.smithy.build.SmithyBuildPlugin` refers to this class by name which +* enables the smithy-build plugin to invoke `execute` with all Smithy plugin context + models. +*/ +class RustClientCodegenPlugin : ClientDecoratableBuildPlugin() { + override fun getName(): String = "rust-client-codegen" + + override fun executeWithDecorator( + context: PluginContext, + vararg decorator: ClientCodegenDecorator, + ) { + // Suppress extremely noisy logs about reserved words + Logger.getLogger(ReservedWordSymbolProvider::class.java.name).level = Level.OFF + // Discover `RustCodegenDecorators` on the classpath. `RustCodegenDecorator` returns different types of + // customizations. A customization is a function of: + // - location (e.g. the mutate section of an operation) + // - context (e.g. the of the operation) + // - writer: The active RustWriter at the given location + val codegenDecorator = + CombinedClientCodegenDecorator.fromClasspath( + context, + SerdeDecorator(), + ClientCustomizations(), + RequiredCustomizations(), + FluentClientDecorator(), + EndpointsDecorator(), + EndpointParamsDecorator(), + NoOpEventStreamSigningDecorator(), + ApiKeyAuthDecorator(), + HttpAuthDecorator(), + HttpConnectorConfigDecorator(), + *decorator, + ) + + // ClientCodegenVisitor is the main driver of code generation that traverses the model and generates code + ClientCodegenVisitor(context, codegenDecorator).execute() + } + + companion object { + /** + * When generating code, smithy types need to be converted into Rust types—that is the core role of the symbol provider + * + * The Symbol provider is composed of a base [SymbolVisitor] which handles the core functionality, then is layered + * with other symbol providers, documented inline, to handle the full scope of Smithy types. + */ + fun baseSymbolProvider( + settings: ClientRustSettings, + model: Model, + serviceShape: ServiceShape, + rustSymbolProviderConfig: RustSymbolProviderConfig, + codegenDecorator: ClientCodegenDecorator, + ) = + SymbolVisitor(settings, model, serviceShape = serviceShape, config = rustSymbolProviderConfig) + // Generate different types for EventStream shapes (e.g. transcribe streaming) + .let { EventStreamSymbolProvider(rustSymbolProviderConfig.runtimeConfig, it, CodegenTarget.CLIENT) } + // Generate `ByteStream` instead of `Blob` for streaming binary shapes (e.g. S3 GetObject) + .let { StreamingShapeSymbolProvider(it) } + // Add Rust attributes (like `#[derive(PartialEq)]`) to generated shapes + .let { BaseSymbolMetadataProvider(it, additionalAttributes = listOf(NonExhaustive)) } + // Streaming shapes need different derives (e.g. they cannot derive `PartialEq`) + .let { StreamingShapeMetadataProvider(it) } + // Rename shapes that clash with Rust reserved words & and other SDK specific features e.g. `send()` cannot + // be the name of an operation input + .let { RustReservedWordSymbolProvider(it, ClientReservedWords) } + // Allows decorators to inject a custom symbol provider + .let { codegenDecorator.symbolProvider(it) } + } +} \ No newline at end of file From fbcbf04dcf25dcbdb9329834ce7cb883df4aa0e1 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 27 Apr 2023 04:16:15 +0000 Subject: [PATCH 03/32] update --- .../client/smithy/RustClientCodegenPlugin.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt index d8a333b205..fea222cec0 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt @@ -36,11 +36,11 @@ import java.util.logging.Logger /** * Rust Client Codegen Plugin -* -* This is the entrypoint for code generation, triggered by the smithy-build plugin. -* `resources/META-INF.services/software.amazon.smithy.build.SmithyBuildPlugin` refers to this class by name which -* enables the smithy-build plugin to invoke `execute` with all Smithy plugin context + models. -*/ + * + * This is the entrypoint for code generation, triggered by the smithy-build plugin. + * `resources/META-INF.services/software.amazon.smithy.build.SmithyBuildPlugin` refers to this class by name which + * enables the smithy-build plugin to invoke `execute` with all Smithy plugin context + models. + */ class RustClientCodegenPlugin : ClientDecoratableBuildPlugin() { override fun getName(): String = "rust-client-codegen" @@ -78,10 +78,10 @@ class RustClientCodegenPlugin : ClientDecoratableBuildPlugin() { companion object { /** * When generating code, smithy types need to be converted into Rust types—that is the core role of the symbol provider - * - * The Symbol provider is composed of a base [SymbolVisitor] which handles the core functionality, then is layered - * with other symbol providers, documented inline, to handle the full scope of Smithy types. - */ + * + * The Symbol provider is composed of a base [SymbolVisitor] which handles the core functionality, then is layered + * with other symbol providers, documented inline, to handle the full scope of Smithy types. + */ fun baseSymbolProvider( settings: ClientRustSettings, model: Model, From 263eb867d240bcdf994dac2a4d5da3fb80854e7c Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 27 Apr 2023 04:17:15 +0000 Subject: [PATCH 04/32] update --- .../rust/codegen/client/smithy/RustClientCodegenPlugin.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt index fea222cec0..2b7e94b5cc 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt @@ -1,7 +1,7 @@ /* -* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -* SPDX-License-Identifier: Apache-2.0 -*/ + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ package software.amazon.smithy.rust.codegen.client.smithy From 2b1ee72f56353f5fde17b47f9ffa8fcd68b3a39d Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 27 Apr 2023 04:19:06 +0000 Subject: [PATCH 05/32] update --- .../rust/codegen/client/smithy/RustClientCodegenPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt index 2b7e94b5cc..3f21fa2272 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt @@ -104,4 +104,4 @@ class RustClientCodegenPlugin : ClientDecoratableBuildPlugin() { // Allows decorators to inject a custom symbol provider .let { codegenDecorator.symbolProvider(it) } } -} \ No newline at end of file +} From 0b01612108f784324d16e5ac766a19d192532be7 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 27 Apr 2023 04:21:11 +0000 Subject: [PATCH 06/32] update --- .../rust/codegen/client/smithy/customize/SerdeDecorator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 7471d405ef..56a777b470 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -25,4 +25,4 @@ class SerdeDecorator : ClientCodegenDecorator { rustCrate.mergeFeature(_feature("serde-serialize", "aws-smithy-types")) rustCrate.mergeFeature(_feature("serde-deserialize", "aws-smithy-types")) } -} \ No newline at end of file +} From a3e8546d0762878cdea84fe9322d39d6264e3038 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Thu, 29 Jun 2023 17:25:38 +0900 Subject: [PATCH 07/32] Update codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt Co-authored-by: John DiSanti --- .../rust/codegen/client/smithy/customize/SerdeDecorator.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 56a777b470..5800704d7a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -10,9 +10,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.Feature import software.amazon.smithy.rust.codegen.core.smithy.RustCrate /** - * This class, - * - Adds serde as a dependency - * + * Decorator that adds the `serde-serialize` and `serde-deserialize` features. */ class SerdeDecorator : ClientCodegenDecorator { override val name: String = "SerdeDecorator" From c49b208514c07f6d24c2696eb15ed5c9c106db63 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Tue, 4 Jul 2023 01:25:02 +0000 Subject: [PATCH 08/32] update --- .../client/smithy/customize/SerdeDecorator.kt | 48 +++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 5800704d7a..85b52f739a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -7,20 +7,62 @@ 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.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. + * This class, + * - Adds serde as a dependency + * */ class SerdeDecorator : ClientCodegenDecorator { override val name: String = "SerdeDecorator" override val order: Byte = -1 override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { - fun _feature(feature_name: String, crate_name: String): Feature { - return Feature(feature_name, false, listOf(crate_name + "/" + feature_name)) + fun _feature(featureName: String, crateName: String): Feature { + return Feature(featureName, false, listOf("$crateName/$featureName")) } rustCrate.mergeFeature(_feature("serde-serialize", "aws-smithy-types")) rustCrate.mergeFeature(_feature("serde-deserialize", "aws-smithy-types")) } + + override fun libRsCustomizations( + codegenContext: ClientCodegenContext, + baseCustomizations: List, + ): List = baseCustomizations + SerdeDocGenerator(codegenContext) +} + +class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibRsCustomization() { + override fun section(section: LibRsSection): Writable { + if (section is LibRsSection.ModuleDoc && section.subsection is ModuleDocSection.ServiceDocs) { + return writable { + """ + # 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 + 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() + } + } else { + return emptySection + } + } } From 1c249918e1f8dedde4ccfc6cb34495dba86f7a1b Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Tue, 4 Jul 2023 02:37:38 +0000 Subject: [PATCH 09/32] update --- .../client/smithy/customize/SerdeDecorator.kt | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 85b52f739a..23a63538f4 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -24,11 +24,11 @@ class SerdeDecorator : ClientCodegenDecorator { override val order: Byte = -1 override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { - fun _feature(featureName: String, crateName: String): Feature { - return Feature(featureName, false, listOf("$crateName/$featureName")) + fun feature(featureName: String): Feature { + return Feature(featureName, false, listOf("aws-smithy-types/$featureName")) } - rustCrate.mergeFeature(_feature("serde-serialize", "aws-smithy-types")) - rustCrate.mergeFeature(_feature("serde-deserialize", "aws-smithy-types")) + rustCrate.mergeFeature(feature("serde-serialize")) + rustCrate.mergeFeature(feature("serde-deserialize")) } override fun libRsCustomizations( @@ -39,26 +39,14 @@ class SerdeDecorator : ClientCodegenDecorator { class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibRsCustomization() { override fun section(section: LibRsSection): Writable { - if (section is LibRsSection.ModuleDoc && section.subsection is ModuleDocSection.ServiceDocs) { + if (section is LibRsSection.ModuleDoc) { return writable { """ - # How to enable `Serialize` and `Deserialize` + ### 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 - 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() } } else { From 5b5f201309f07b45c9f0d079c632e532505ab1bd Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Tue, 4 Jul 2023 02:37:59 +0000 Subject: [PATCH 10/32] update --- .../core/smithy/generators/LibRsGenerator.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt index 1da954f086..5c80b3267c 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt @@ -22,6 +22,7 @@ sealed class ModuleDocSection { data class ServiceDocs(val documentationTraitValue: String?) : ModuleDocSection() object CrateOrganization : ModuleDocSection() object Examples : ModuleDocSection() + object UnstableFeature : ModuleDocSection() } sealed class LibRsSection(name: String) : Section(name) { @@ -62,6 +63,27 @@ class LibRsGenerator( containerDocs(escape(defaultServiceDocs ?: settings.moduleName)) } + // Unstable Feature + docSection(ModuleDocSection.UnstableFeature).also { docs -> + if (docs.isNotEmpty()) { + containerDocs("\n## Unstable Features") + val awsSdkUnstable = """ + Some highly experimental features requires passing `aws_sdk_unstable` to RUSTFLAGS. + e.g. + ```bash + export RUSTFLAGS="--cfg aws_sdk_unstable" + cargo build --features serde-serialize + ``` + + If you enable unstable features without enabling `RUSTFLAGS="--cfg aws_sdk_unstable"`, compilation will fail with a message detailing the reason. + """.trimIndent() + containerDocs(awsSdkUnstable) + docs.forEach { writeTo -> + writeTo(this) + } + } + } + // Crate Organization docSection(ModuleDocSection.CrateOrganization).also { docs -> if (docs.isNotEmpty()) { From 81f7efd7ac4a88d631457cafa1361a70d8865d2c Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Tue, 4 Jul 2023 03:10:28 +0000 Subject: [PATCH 11/32] update --- .../client/smithy/customize/SerdeDecorator.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 23a63538f4..9714eef0d5 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -39,18 +39,18 @@ class SerdeDecorator : ClientCodegenDecorator { class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibRsCustomization() { override fun section(section: LibRsSection): Writable { - if (section is LibRsSection.ModuleDoc) { - return writable { + return if (section is LibRsSection.ModuleDoc && section.subsection is ModuleDocSection.UnstableFeature) { + writable { """ - ### 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. - """.trimIndent() + ## 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. + """.trimIndent() } } else { - return emptySection + emptySection } } } From e6dbd9724977f55ca25201660fbc7a29c77a4224 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Tue, 4 Jul 2023 03:12:18 +0000 Subject: [PATCH 12/32] update --- .../rust/codegen/core/smithy/generators/LibRsGenerator.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt index 5c80b3267c..725b3ea250 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt @@ -66,8 +66,8 @@ class LibRsGenerator( // Unstable Feature docSection(ModuleDocSection.UnstableFeature).also { docs -> if (docs.isNotEmpty()) { - containerDocs("\n## Unstable Features") val awsSdkUnstable = """ + # Unstable Features Some highly experimental features requires passing `aws_sdk_unstable` to RUSTFLAGS. e.g. ```bash @@ -75,7 +75,7 @@ class LibRsGenerator( cargo build --features serde-serialize ``` - If you enable unstable features without enabling `RUSTFLAGS="--cfg aws_sdk_unstable"`, compilation will fail with a message detailing the reason. + If you enable unstable features without enabling `RUSTFLAGS="--cfg aws_sdk_unstable"`, compilation will fail with a message describing the reason. """.trimIndent() containerDocs(awsSdkUnstable) docs.forEach { writeTo -> From 9e997b6c8dab2233b980e186702a0f3243b44ac9 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Tue, 4 Jul 2023 03:28:10 +0000 Subject: [PATCH 13/32] update --- .../client/smithy/customize/SerdeDecorator.kt | 12 ++++++------ .../core/smithy/generators/LibRsGenerator.kt | 18 +++++++++--------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 9714eef0d5..fba326f85c 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -42,12 +42,12 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR return if (section is LibRsSection.ModuleDoc && section.subsection is ModuleDocSection.UnstableFeature) { writable { """ - ## 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. - """.trimIndent() + ## 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. + """.trimIndent() } } else { emptySection diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt index 725b3ea250..90cd82e4e9 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt @@ -67,15 +67,15 @@ class LibRsGenerator( docSection(ModuleDocSection.UnstableFeature).also { docs -> if (docs.isNotEmpty()) { val awsSdkUnstable = """ - # Unstable Features - Some highly experimental features requires passing `aws_sdk_unstable` to RUSTFLAGS. - e.g. - ```bash - export RUSTFLAGS="--cfg aws_sdk_unstable" - cargo build --features serde-serialize - ``` - - If you enable unstable features without enabling `RUSTFLAGS="--cfg aws_sdk_unstable"`, compilation will fail with a message describing the reason. + # Unstable Features + Some highly experimental features requires passing `aws_sdk_unstable` to RUSTFLAGS. + e.g. + ```bash + export RUSTFLAGS="--cfg aws_sdk_unstable" + cargo build --features serde-serialize + ``` + + If you enable unstable features without enabling `RUSTFLAGS="--cfg aws_sdk_unstable"`, compilation will fail with a message describing the reason. """.trimIndent() containerDocs(awsSdkUnstable) docs.forEach { writeTo -> From bbb321e6ed56a5292f997ec7c8d97d851b624f3d Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Sun, 16 Jul 2023 11:55:06 +0000 Subject: [PATCH 14/32] asdf --- .../client/smithy/customize/SerdeDecorator.kt | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index fba326f85c..aaa33f1817 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -15,9 +15,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection import software.amazon.smithy.rust.codegen.core.smithy.generators.ModuleDocSection /** - * This class, - * - Adds serde as a dependency - * + * Decorator that adds the `serde-serialize` and `serde-deserialize` features. */ class SerdeDecorator : ClientCodegenDecorator { override val name: String = "SerdeDecorator" @@ -38,17 +36,31 @@ class SerdeDecorator : ClientCodegenDecorator { } class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibRsCustomization() { + companion object { + 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. + + """ + } override fun section(section: LibRsSection): Writable { return if (section is LibRsSection.ModuleDoc && section.subsection is ModuleDocSection.UnstableFeature) { - writable { - """ - ## 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. - """.trimIndent() - } + writable { SerdeInfoText.trimIndent() } } else { emptySection } From fa8c04b6dc5a52ae632effb0aef2fc776044c93e Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Sun, 16 Jul 2023 12:00:53 +0000 Subject: [PATCH 15/32] asdf --- .../core/smithy/generators/LibRsGenerator.kt | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt index 90cd82e4e9..ebb2da7ea0 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt @@ -63,27 +63,6 @@ class LibRsGenerator( containerDocs(escape(defaultServiceDocs ?: settings.moduleName)) } - // Unstable Feature - docSection(ModuleDocSection.UnstableFeature).also { docs -> - if (docs.isNotEmpty()) { - val awsSdkUnstable = """ - # Unstable Features - Some highly experimental features requires passing `aws_sdk_unstable` to RUSTFLAGS. - e.g. - ```bash - export RUSTFLAGS="--cfg aws_sdk_unstable" - cargo build --features serde-serialize - ``` - - If you enable unstable features without enabling `RUSTFLAGS="--cfg aws_sdk_unstable"`, compilation will fail with a message describing the reason. - """.trimIndent() - containerDocs(awsSdkUnstable) - docs.forEach { writeTo -> - writeTo(this) - } - } - } - // Crate Organization docSection(ModuleDocSection.CrateOrganization).also { docs -> if (docs.isNotEmpty()) { From 918f2cdbdf6a0ada2fcf0003ee5047c447bd716a Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Sun, 16 Jul 2023 21:04:20 +0900 Subject: [PATCH 16/32] Update LibRsGenerator.kt --- .../smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt index ebb2da7ea0..1da954f086 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt @@ -22,7 +22,6 @@ sealed class ModuleDocSection { data class ServiceDocs(val documentationTraitValue: String?) : ModuleDocSection() object CrateOrganization : ModuleDocSection() object Examples : ModuleDocSection() - object UnstableFeature : ModuleDocSection() } sealed class LibRsSection(name: String) : Section(name) { From 8802e835125e9bb61f20502eb2dc2a040be73901 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Sun, 16 Jul 2023 21:05:11 +0900 Subject: [PATCH 17/32] Update SerdeDecorator.kt --- .../rust/codegen/client/smithy/customize/SerdeDecorator.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index aaa33f1817..6602cbd0d9 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -58,6 +58,8 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR """ } + /* + I initially tried to implement with LibRsCustomization but it didn't work some how. override fun section(section: LibRsSection): Writable { return if (section is LibRsSection.ModuleDoc && section.subsection is ModuleDocSection.UnstableFeature) { writable { SerdeInfoText.trimIndent() } @@ -65,4 +67,5 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR emptySection } } + */ } From 5211559902a61f65c26d6a915407247b94bd9b4a Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Sun, 16 Jul 2023 12:15:54 +0000 Subject: [PATCH 18/32] asdf --- .../client/smithy/customize/SerdeDecorator.kt | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 6602cbd0d9..7c887e456e 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -29,13 +29,7 @@ class SerdeDecorator : ClientCodegenDecorator { rustCrate.mergeFeature(feature("serde-deserialize")) } - override fun libRsCustomizations( - codegenContext: ClientCodegenContext, - baseCustomizations: List, - ): List = baseCustomizations + SerdeDocGenerator(codegenContext) -} - -class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibRsCustomization() { + // I initially tried to implement with LibRsCustomization but it didn't work some how. companion object { const val SerdeInfoText = """## How to enable `Serialize` and `Deserialize` @@ -58,14 +52,4 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR """ } - /* - I initially tried to implement with LibRsCustomization but it didn't work some how. - override fun section(section: LibRsSection): Writable { - return if (section is LibRsSection.ModuleDoc && section.subsection is ModuleDocSection.UnstableFeature) { - writable { SerdeInfoText.trimIndent() } - } else { - emptySection - } - } - */ } From c4a41c26eca2d7209c8a5c7b1d4246b849d1ef0c Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Sun, 16 Jul 2023 12:30:41 +0000 Subject: [PATCH 19/32] update --- .../rust/codegen/client/smithy/customize/SerdeDecorator.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 7c887e456e..84266f6134 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -7,12 +7,7 @@ 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.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. From dd4a511f2b02885eacdd352d91b18326e8ea712a Mon Sep 17 00:00:00 2001 From: Thomas Cameron <68596478+thomas-k-cameron@users.noreply.github.com> Date: Mon, 17 Jul 2023 05:36:35 +0000 Subject: [PATCH 20/32] asdf --- .devcontainer/devcontainer.json | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100755 index 0000000000..b332f39d78 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,22 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu +{ + "name": "Ubuntu", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/base:jammy" + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "uname -a", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} From 982a95ddb30139f34f79713d0418f496a29ce8f4 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Tue, 18 Jul 2023 09:13:29 +0900 Subject: [PATCH 21/32] Delete devcontainer.json --- .devcontainer/devcontainer.json | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100755 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100755 index b332f39d78..0000000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,22 +0,0 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the -// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu -{ - "name": "Ubuntu", - // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/base:jammy" - - // Features to add to the dev container. More info: https://containers.dev/features. - // "features": {}, - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "uname -a", - - // Configure tool-specific properties. - // "customizations": {}, - - // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" -} From 8a6ff7d67986124c07a9676bfc9dc0d05995a9fc Mon Sep 17 00:00:00 2001 From: Thomas K Cameron Date: Mon, 11 Dec 2023 17:46:26 +0900 Subject: [PATCH 22/32] update --- .../client/smithy/customize/SerdeDecorator.kt | 90 +++++++++++++++++-- 1 file changed, 82 insertions(+), 8 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 56a777b470..47c1aa75ba 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -7,22 +7,96 @@ 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.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 /** - * This class, - * - Adds serde as a dependency - * + * Decorator that adds the `serde-serialize` and `serde-deserialize` features. */ class SerdeDecorator : ClientCodegenDecorator { override val name: String = "SerdeDecorator" - override val order: Byte = -1 + override val order: Byte = 5 override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { - fun _feature(feature_name: String, crate_name: String): Feature { - return Feature(feature_name, false, listOf(crate_name + "/" + feature_name)) + fun feature(featureName: String): Feature { + return Feature(featureName, false, listOf("aws-smithy-types/$featureName")) } - rustCrate.mergeFeature(_feature("serde-serialize", "aws-smithy-types")) - rustCrate.mergeFeature(_feature("serde-deserialize", "aws-smithy-types")) + rustCrate.mergeFeature(feature("serde-serialize")) + rustCrate.mergeFeature(feature("serde-deserialize")) + + } + + override fun libRsCustomizations( + codegenContext: ClientCodegenContext, + baseCustomizations: List + ): List { + return baseCustomizations + SerdeDocGenerator(codegenContext) + } + + // I initially tried to implement with LibRsCustomization but it didn't work some how. + companion object { + const val SerdeInfoText = """## How to enable `Serialize` and `Deserialize` + + Some 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. + + """ } + } + +class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibRsCustomization() { + override fun section(section: LibRsSection): Writable { + return when (section) { + is LibRsSection.ModuleDoc -> writable(SerdeInfoText) + else -> emptySection + } + } + companion object { + const val SerdeInfoText = """## How to enable `Serialize` and `Deserialize` + + Some 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. + + """ + } +} +/* +I initially tried to implement with LibRsCustomization but it didn't work some how. +override fun section(section: LibRsSection): Writable { + return if (section is LibRsSection.ModuleDoc && section.subsection is ModuleDocSection.UnstableFeature) { + writable { SerdeInfoText.trimIndent() } + } else { + emptySection + } +} +*/ From dc093156b2229a678cca55ec2df32819e5af734f Mon Sep 17 00:00:00 2001 From: Thomas K Cameron Date: Mon, 11 Dec 2023 18:03:36 +0900 Subject: [PATCH 23/32] update --- .../rust/codegen/client/smithy/customize/SerdeDecorator.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 3240603fed..dc729c7ff0 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -45,7 +45,8 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR } } companion object { - const val SerdeInfoText = """## How to enable `Serialize` and `Deserialize` + 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. @@ -62,7 +63,7 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR If you enable `serde-serialize` and/or `serde-deserialize` without `RUSTFLAGS="--cfg aws_sdk_unstable"`, compilation will fail with warning. - - """ + + """.trimIndent() } } From db679e01f7dcd886c441174b68ea39997e44a73c Mon Sep 17 00:00:00 2001 From: Thomas K Cameron Date: Mon, 11 Dec 2023 18:16:01 +0900 Subject: [PATCH 24/32] update --- .../codegen/client/smithy/customize/SerdeDecorator.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index dc729c7ff0..1e67d02421 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -12,6 +12,7 @@ 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. @@ -40,7 +41,13 @@ class SerdeDecorator : ClientCodegenDecorator { class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibRsCustomization() { override fun section(section: LibRsSection): Writable { return when (section) { - is LibRsSection.ModuleDoc -> writable(SerdeInfoText) + is LibRsSection.ModuleDoc-> { + if (section.subsection is ModuleDocSection.CrateOrganization) { + return writable(SerdeInfoText) + } else { + return emptySection + } + } else -> emptySection } } From d1b369ebb080ed002c6c8db8f8796f17af0eedbb Mon Sep 17 00:00:00 2001 From: Thomas K Cameron Date: Mon, 11 Dec 2023 18:21:08 +0900 Subject: [PATCH 25/32] update --- .../codegen/client/smithy/customize/SerdeDecorator.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 1e67d02421..efc3b68d70 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -6,6 +6,7 @@ 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.containerDocs 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.writable @@ -43,7 +44,9 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR return when (section) { is LibRsSection.ModuleDoc-> { if (section.subsection is ModuleDocSection.CrateOrganization) { - return writable(SerdeInfoText) + return writable { + SerdeInfoText + } } else { return emptySection } @@ -52,7 +55,7 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR } } companion object { - val SerdeInfoText = """ + val SerdeInfoText = 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. @@ -71,6 +74,6 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR If you enable `serde-serialize` and/or `serde-deserialize` without `RUSTFLAGS="--cfg aws_sdk_unstable"`, compilation will fail with warning. - """.trimIndent() + """.trimIndent()) } } From 0b8ba89e85ecd55e0a6ffc94159740ec14f67e85 Mon Sep 17 00:00:00 2001 From: Thomas K Cameron Date: Mon, 11 Dec 2023 18:30:26 +0900 Subject: [PATCH 26/32] update --- .../codegen/client/smithy/customize/SerdeDecorator.kt | 9 +++++---- .../codegen/core/smithy/generators/LibRsGenerator.kt | 11 +++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index efc3b68d70..d1492ea67a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -43,7 +43,7 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR override fun section(section: LibRsSection): Writable { return when (section) { is LibRsSection.ModuleDoc-> { - if (section.subsection is ModuleDocSection.CrateOrganization) { + if (section.subsection is ModuleDocSection.AWSSdkUnstable) { return writable { SerdeInfoText } @@ -55,9 +55,10 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR } } companion object { - val SerdeInfoText = containerDocs(""" - ## How to enable `Serialize` and `Deserialize` + 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. @@ -74,6 +75,6 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR If you enable `serde-serialize` and/or `serde-deserialize` without `RUSTFLAGS="--cfg aws_sdk_unstable"`, compilation will fail with warning. - """.trimIndent()) + """.trimIndent() } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt index ab87afa1b8..93d01ea1ab 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt @@ -23,6 +23,7 @@ sealed class ModuleDocSection { data class ServiceDocs(val documentationTraitValue: String?) : ModuleDocSection() object CrateOrganization : ModuleDocSection() object Examples : ModuleDocSection() + object AWSSdkUnstable : ModuleDocSection() } sealed class LibRsSection(name: String) : Section(name) { @@ -74,6 +75,16 @@ class LibRsGenerator( } } + docSection(ModuleDocSection.AWSSdkUnstable).also { docs -> + if (docs.isNotEmpty()) { + containerDocs("\n## Enabling Unstable Features") + docs.forEach { writeTo -> + writeTo(this) + } + } + } + + // Examples docSection(ModuleDocSection.Examples).also { docs -> if (docs.isNotEmpty() || settings.examplesUri != null) { From 077d868c46d453000603073a7c5c4076ec0f5074 Mon Sep 17 00:00:00 2001 From: Thomas K Cameron Date: Mon, 11 Dec 2023 18:46:09 +0900 Subject: [PATCH 27/32] asdf --- .../client/smithy/customize/SerdeDecorator.kt | 57 ++++++++++--------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index d1492ea67a..64b654b98f 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -8,6 +8,7 @@ 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.containerDocs import software.amazon.smithy.rust.codegen.core.rustlang.Feature +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.RustCrate @@ -42,39 +43,41 @@ class SerdeDecorator : ClientCodegenDecorator { class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibRsCustomization() { override fun section(section: LibRsSection): Writable { return when (section) { - is LibRsSection.ModuleDoc-> { + is LibRsSection.ModuleDoc-> if (section.subsection is ModuleDocSection.AWSSdkUnstable) { - return writable { - SerdeInfoText - } + serdeInfoText() } else { - return emptySection + emptySection } - } + else -> emptySection } } - companion object { - - 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. - 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() + 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() + ) + } } } From 348db6871782d5860adc426f6b67587e29dd1074 Mon Sep 17 00:00:00 2001 From: Thomas K Cameron Date: Mon, 11 Dec 2023 18:56:24 +0900 Subject: [PATCH 28/32] modified: codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt --- .../rust/codegen/client/smithy/customize/SerdeDecorator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 64b654b98f..42d13831a3 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -58,7 +58,7 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR return writable { containerDocs( """ - ## How to enable `Serialize` and `Deserialize` + ### 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. From 476df23e631918126167a88da60232820eeaae6f Mon Sep 17 00:00:00 2001 From: Thomas K Cameron Date: Mon, 11 Dec 2023 19:20:38 +0900 Subject: [PATCH 29/32] update --- .../rust/codegen/client/smithy/customize/SerdeDecorator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 42d13831a3..460e94c40d 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -58,7 +58,7 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR return writable { containerDocs( """ - ### How to enable `Serialize` and `Deserialize` + \## 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. From 58c4c538d745c11435d584af4b2f15a6bff33511 Mon Sep 17 00:00:00 2001 From: Thomas K Cameron Date: Mon, 11 Dec 2023 19:25:27 +0900 Subject: [PATCH 30/32] update --- .../rust/codegen/client/smithy/customize/SerdeDecorator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 460e94c40d..37ccd11b93 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -58,7 +58,7 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR return writable { containerDocs( """ - \## How to enable `Serialize` and `Deserialize` + #\## 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. From 68a60dfc747612a47d8ee2bb1150aa055876dbe4 Mon Sep 17 00:00:00 2001 From: Thomas K Cameron Date: Mon, 11 Dec 2023 19:27:45 +0900 Subject: [PATCH 31/32] update --- .../rust/codegen/client/smithy/customize/SerdeDecorator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 37ccd11b93..64b654b98f 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -58,7 +58,7 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR return writable { containerDocs( """ - #\## How to enable `Serialize` and `Deserialize` + ## 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. From abdf723a8da9aa66cb3bfc59962280c3e1dc6c50 Mon Sep 17 00:00:00 2001 From: Thomas Cameron Date: Mon, 11 Dec 2023 10:41:04 +0000 Subject: [PATCH 32/32] modified: codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt modified: codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt --- .../client/smithy/customize/SerdeDecorator.kt | 22 +++++++++---------- .../core/smithy/generators/LibRsGenerator.kt | 1 - 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt index 64b654b98f..1a14fb7049 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/SerdeDecorator.kt @@ -6,10 +6,9 @@ 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.containerDocs import software.amazon.smithy.rust.codegen.core.rustlang.Feature -import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter 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 @@ -29,12 +28,11 @@ class SerdeDecorator : ClientCodegenDecorator { } rustCrate.mergeFeature(feature("serde-serialize")) rustCrate.mergeFeature(feature("serde-deserialize")) - } override fun libRsCustomizations( codegenContext: ClientCodegenContext, - baseCustomizations: List + baseCustomizations: List, ): List { return baseCustomizations + SerdeDocGenerator(codegenContext) } @@ -43,7 +41,7 @@ class SerdeDecorator : ClientCodegenDecorator { class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibRsCustomization() { override fun section(section: LibRsSection): Writable { return when (section) { - is LibRsSection.ModuleDoc-> + is LibRsSection.ModuleDoc -> if (section.subsection is ModuleDocSection.AWSSdkUnstable) { serdeInfoText() } else { @@ -59,24 +57,24 @@ class SerdeDocGenerator(private val codegenContext: ClientCodegenContext) : LibR 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() + + """.trimIndent(), ) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt index 93d01ea1ab..b6d2fbd7d2 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt @@ -84,7 +84,6 @@ class LibRsGenerator( } } - // Examples docSection(ModuleDocSection.Examples).also { docs -> if (docs.isNotEmpty() || settings.examplesUri != null) {