Skip to content

Commit d465bb4

Browse files
update
1 parent 7707662 commit d465bb4

File tree

14 files changed

+118
-29
lines changed

14 files changed

+118
-29
lines changed

buildSrc/src/main/kotlin/CodegenTestCommon.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,25 +245,29 @@ fun Project.registerCargoCommandsTasks(
245245
this.tasks.register<Exec>(Cargo.CHECK.toString) {
246246
dependsOn(dependentTasks)
247247
workingDir(outputDir)
248+
environment("RUSTFLAGS", "--cfg aws_sdk_unstable")
248249
commandLine("cargo", "check", "--lib", "--tests", "--benches", "--all-features")
249250
}
250251

251252
this.tasks.register<Exec>(Cargo.TEST.toString) {
252253
dependsOn(dependentTasks)
253254
workingDir(outputDir)
255+
environment("RUSTFLAGS", "--cfg aws_sdk_unstable")
254256
commandLine("cargo", "test", "--all-features")
255257
}
256258

257259
this.tasks.register<Exec>(Cargo.DOCS.toString) {
258260
dependsOn(dependentTasks)
259261
workingDir(outputDir)
260262
environment("RUSTDOCFLAGS", defaultRustDocFlags)
261-
commandLine("cargo", "doc", "--no-deps", "--document-private-items")
263+
environment("RUSTFLAGS", "--cfg aws_sdk_unstable")
264+
commandLine("cargo", "doc", "--no-deps", "--document-private-items", "--all-features")
262265
}
263266

264267
this.tasks.register<Exec>(Cargo.CLIPPY.toString) {
265268
dependsOn(dependentTasks)
266269
workingDir(outputDir)
267-
commandLine("cargo", "clippy")
270+
environment("RUSTFLAGS", "--cfg aws_sdk_unstable")
271+
commandLine("cargo", "clippy", "--all-features")
268272
}
269273
}

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientEnumGenerator.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator
2121
import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGeneratorContext
2222
import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumMemberModel
2323
import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumType
24+
import software.amazon.smithy.rust.codegen.core.smithy.generators.RenderSerdeAttribute
2425
import software.amazon.smithy.rust.codegen.core.util.dq
2526

2627
/** Infallible enums have an `Unknown` variant and can't fail to parse */
@@ -97,6 +98,8 @@ data class InfallibleEnumType(
9798
part of the enums that are public interface.
9899
""".trimIndent(),
99100
)
101+
102+
RenderSerdeAttribute.writeAttributes(this)
100103
context.enumMeta.render(this)
101104
rust("struct $UnknownVariantValue(pub(crate) String);")
102105
rustBlock("impl $UnknownVariantValue") {

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class FluentClientGenerator(
357357
self.inner = data;
358358
self
359359
}
360-
""",
360+
""",
361361
"AwsSdkUnstableAttribute" to Attribute.AwsSdkUnstableAttribute.inner,
362362
)
363363
}

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,13 @@ class Attribute(val inner: Writable) {
467467
public fun SerdeDeserialize(): Attribute {
468468
return Attribute(cfgAttr(all(writable("aws_sdk_unstable"), feature("serde-deserialize")), derive(RuntimeType.SerdeDeserialize)))
469469
}
470+
public fun SerdeSkip(): Attribute {
471+
return Attribute(cfgAttr(all(writable("aws_sdk_unstable"), any(feature("serde-serialize"), feature("serde-deserialize"))), serde("skip")))
472+
}
473+
474+
public fun SerdeSerializeOrDeserialize(): Attribute {
475+
return Attribute(cfg(all(writable("aws_sdk_unstable"), any(feature("serde-serialize"), feature("serde-deserialize")))))
476+
}
470477

471478
companion object {
472479
val AllowClippyBoxedLocal = Attribute(allow("clippy::boxed_local"))
@@ -530,6 +537,7 @@ class Attribute(val inner: Writable) {
530537
fun allow(lints: Collection<String>): Writable = macroWithArgs("allow", *lints.toTypedArray())
531538
fun allow(vararg lints: String): Writable = macroWithArgs("allow", *lints)
532539
fun deny(vararg lints: String): Writable = macroWithArgs("deny", *lints)
540+
fun serde(vararg lints: String): Writable = macroWithArgs("serde", *lints)
533541
fun any(vararg attrMacros: Writable): Writable = macroWithArgs("any", *attrMacros)
534542
fun cfg(vararg attrMacros: Writable): Writable = macroWithArgs("cfg", *attrMacros)
535543
fun cfg(vararg attrMacros: String): Writable = macroWithArgs("cfg", *attrMacros)

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class BuilderGenerator(
216216
writer.docs("A builder for #D.", structureSymbol)
217217
metadata.additionalAttributes.render(writer)
218218
Attribute(derive(builderDerives)).render(writer)
219-
RenderSerdeAttribute.forStructureShape(writer, shape, model)
219+
RenderSerdeAttribute.forBuilders(writer, shape, model)
220220
SensitiveWarning.addDoc(writer, shape)
221221
writer.rustBlock("pub struct $builderName") {
222222
// add serde
@@ -225,6 +225,7 @@ class BuilderGenerator(
225225
// All fields in the builder are optional.
226226
val memberSymbol = symbolProvider.toSymbol(member).makeOptional()
227227
SensitiveWarning.addDoc(writer, member)
228+
RenderSerdeAttribute.skipIfStream(writer, member, model)
228229
renderBuilderMember(this, memberName, memberSymbol)
229230
}
230231
writeCustomizations(customizations, BuilderSection.AdditionalFields(shape))

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ class CargoTomlGenerator(
8181
"features" to cargoFeatures.toMap(),
8282
).deepMergeWith(manifestCustomizations)
8383

84-
writer.writeWithNoFormatting(TomlWriter().write(cargoToml))
84+
// NOTE: without this it will produce ["target.'cfg(aws_sdk_unstable)'.dependencies"]
85+
// In JSON, this is an equivalent of: {"target.'cfg(aws_sdk_unstable)'.dependencies" : ...}
86+
// To make it work, it has to be: {"target": {'cfg(aws_sdk_unstable)': {"dependencies": ...}}}
87+
// This piece of code fixes it.
88+
var tomlString = TomlWriter().write(cargoToml).replace("\"target.'cfg(aws_sdk_unstable)'.dependencies\"", "target.'cfg(aws_sdk_unstable)'.dependencies")
89+
writer.writeWithNoFormatting(tomlString)
8590
}
8691
}

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/RenderSerdeAttribute.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
package software.amazon.smithy.rust.codegen.core.smithy.generators
77

88
import software.amazon.smithy.model.Model
9+
import software.amazon.smithy.model.shapes.MemberShape
910
import software.amazon.smithy.model.shapes.StructureShape
1011
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
1112
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter
13+
import software.amazon.smithy.rust.codegen.core.rustlang.raw
1214
import software.amazon.smithy.rust.codegen.core.util.isEventStream
15+
import software.amazon.smithy.rust.codegen.core.util.isStreaming
1316

1417
// Part of RFC30
1518
public object RenderSerdeAttribute {
@@ -19,6 +22,28 @@ public object RenderSerdeAttribute {
1922
}
2023
}
2124

25+
public fun forBuilders(writer: RustWriter, shape: StructureShape, model: Model) {
26+
if (shape.members().none { it.isEventStream(model) }) {
27+
writeAttributes(writer)
28+
}
29+
}
30+
31+
public fun skipIfStream(writer: RustWriter, member: MemberShape, model: Model) {
32+
if (member.isEventStream(model)) {
33+
return
34+
}
35+
if (member.isStreaming(model)) {
36+
Attribute("").SerdeSkip().render(writer)
37+
}
38+
}
39+
40+
public fun importSerde(writer: RustWriter) {
41+
// we need this for skip serde to work
42+
Attribute.AllowUnusedImports.render(writer)
43+
Attribute("").SerdeSerializeOrDeserialize().render(writer)
44+
writer.raw("use serde;")
45+
}
46+
2247
public fun writeAttributes(writer: RustWriter) {
2348
Attribute("").SerdeSerialize().render(writer)
2449
Attribute("").SerdeDeserialize().render(writer)

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ open class StructureGenerator(
154154

155155
open fun renderStructureMember(writer: RustWriter, member: MemberShape, memberName: String, memberSymbol: Symbol) {
156156
writer.renderMemberDoc(member, memberSymbol)
157-
SensitiveWarning.addDoc(writer, shape)
158157
writer.deprecatedShape(member)
159158
memberSymbol.expectRustMetadata().render(writer)
160159
writer.write("$memberName: #T,", memberSymbol)
161160
}
162161

163162
open fun renderStructure() {
163+
RenderSerdeAttribute.importSerde(writer)
164164
val symbol = symbolProvider.toSymbol(shape)
165165
val containerMeta = symbol.expectRustMetadata()
166166
writer.documentShape(shape, model)
@@ -172,6 +172,7 @@ open class StructureGenerator(
172172
writer.rustBlock("struct $name ${lifetimeDeclaration()}") {
173173
writer.forEachMember(members) { member, memberName, memberSymbol ->
174174
SensitiveWarning.addDoc(writer, shape)
175+
RenderSerdeAttribute.skipIfStream(writer, member, model)
175176
renderStructureMember(writer, member, memberName, memberSymbol)
176177
}
177178
writeCustomizations(customizations, StructureSection.AdditionalFields(shape))

rust-runtime/aws-smithy-types/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ base64-simd = "0.8"
1919
version = "1"
2020
features = ["derive"]
2121

22-
[target."cfg(aws_sdk_unstable)".dependencies.base64]
23-
version = "0.21.0"
24-
2522
[dev-dependencies]
2623
base64 = "0.13.0"
2724
lazy_static = "1.4"

rust-runtime/aws-smithy-types/src/blob.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
#[cfg(all(
7+
aws_sdk_unstable,
8+
any(feature = "serde-deserialize", feature = "serde-serialize")
9+
))]
10+
use crate::base64;
611
#[cfg(all(aws_sdk_unstable, feature = "serde-serialize"))]
712
use serde::Serialize;
813
#[cfg(all(aws_sdk_unstable, feature = "serde-deserialize"))]
914
use serde::{de::Visitor, Deserialize};
10-
1115
/// Binary Blob Type
1216
///
1317
/// Blobs represent protocol-agnostic binary content.
@@ -104,11 +108,15 @@ impl<'de> Deserialize<'de> for Blob {
104108
}
105109

106110
#[cfg(test)]
107-
#[cfg(all(aws_sdk_unstable, feature = "serde-serialize", feature = "serde-deserialize"))]
111+
#[cfg(all(
112+
aws_sdk_unstable,
113+
feature = "serde-serialize",
114+
feature = "serde-deserialize"
115+
))]
108116
mod test {
109117
use crate::Blob;
110-
use std::collections::HashMap;
111118
use serde::{Deserialize, Serialize};
119+
use std::collections::HashMap;
112120

113121
#[derive(Deserialize, Serialize, Debug, PartialEq)]
114122
struct ForTest {

0 commit comments

Comments
 (0)