Skip to content

Commit 40bde51

Browse files
authored
Merge branch 'main' into requestid
2 parents da1ddb7 + 9a4c1f3 commit 40bde51

File tree

108 files changed

+3192
-1012
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+3192
-1012
lines changed

CHANGELOG.next.toml

+9-1
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,14 @@ message = """
242242
243243
* The `length` trait on `string` shapes.
244244
* The `length` trait on `map` shapes.
245+
* The `range` trait on `integer` shapes.
246+
* The `pattern` trait on `string` shapes.
245247
246248
Upon receiving a request that violates the modeled constraints, the server SDK will reject it with a message indicating why.
247249
248250
Unsupported (constraint trait, target shape) combinations will now fail at code generation time, whereas previously they were just ignored. This is a breaking change to raise awareness in service owners of their server SDKs behaving differently than what was modeled. To continue generating a server SDK with unsupported constraint traits, set `codegenConfig.ignoreUnsupportedConstraints` to `true` in your `smithy-build.json`.
249251
"""
250-
references = ["smithy-rs#1199", "smithy-rs#1342", "smithy-rs#1401"]
252+
references = ["smithy-rs#1199", "smithy-rs#1342", "smithy-rs#1401", "smithy-rs#2005", "smithy-rs#1998"]
251253
meta = { "breaking" = true, "tada" = true, "bug" = false, "target" = "server" }
252254
author = "david-perez"
253255

@@ -478,3 +480,9 @@ x-amzn-errortype: com.example.service#InvalidRequestException
478480
references = ["smithy-rs#1982"]
479481
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" }
480482
author = "david-perez"
483+
484+
[[smithy-rs]]
485+
message = "Make generated enum `values()` functions callable in const contexts."
486+
references = ["smithy-rs#2011"]
487+
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "all" }
488+
author = "lsr0"

aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class AwsFluentClientDecorator : RustCodegenDecorator<ClientProtocolGenerator, C
107107
),
108108
retryClassifier = runtimeConfig.awsHttp().toType().member("retry::AwsResponseRetryClassifier"),
109109
).render(rustCrate)
110-
rustCrate.withNonRootModule(CustomizableOperationGenerator.CUSTOMIZE_MODULE) {
110+
rustCrate.withModule(CustomizableOperationGenerator.CustomizeModule) {
111111
renderCustomizableOperationSendMethod(runtimeConfig, generics, this)
112112
}
113113
rustCrate.withModule(FluentClientGenerator.clientModule) {

aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/InlineAwsDependency.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ package software.amazon.smithy.rustsdk
77

88
import software.amazon.smithy.rust.codegen.core.rustlang.InlineDependency
99
import software.amazon.smithy.rust.codegen.core.rustlang.RustDependency
10+
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
1011
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
1112

1213
object InlineAwsDependency {
1314
fun forRustFile(file: String, visibility: Visibility = Visibility.PRIVATE, vararg additionalDependency: RustDependency): InlineDependency =
14-
InlineDependency.Companion.forRustFile(file, "aws-inlineable", visibility, *additionalDependency)
15+
InlineDependency.Companion.forRustFile(RustModule.new(file, visibility), "/aws-inlineable/src/$file.rs", *additionalDependency)
1516
}

aws/sdk/integration-tests/README.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Handwritten Integration Test Root
22

3-
This folder contains hand-written integration tests that are specific to
3+
This folder contains handwritten integration tests that are specific to
44
individual services. In order for your test to be merged into the final artifact:
55

66
- The crate name must match the generated crate name, e.g. `kms`, `dynamodb`
@@ -13,8 +13,8 @@ tests & inserted into the `tests` folder of the final generated service crate.
1313

1414
Some integration test roots have a `benches/` directory. In these, `cargo bench` can be
1515
invoked to run the benchmarks against the current version of smithy-rs. To compare
16-
across smithy-rs versions, you can use git to checkout the version to compare against,
17-
run the benchmark, and then checkout the other version and run it again:
16+
across smithy-rs versions, you can `git checkout` the version to compare against,
17+
run the benchmark, and then `git checkout` the other version and run it again:
1818

1919
```bash
2020
# For example, this was the very first commit that had a benchmark
@@ -42,3 +42,11 @@ cargo bench
4242

4343
# Compare!
4444
```
45+
46+
## Adding dependencies to tests
47+
48+
When adding new dependencies or adding new features to old dependencies, don't forget to update the
49+
[`IntegrationTestDependencies` file][IntegrationTestDependencies]. Otherwise, after your tests have been copied into
50+
their respective SDK crates may fail when run due to a dependency resolution error.
51+
52+
[IntegrationTestDependencies]: ../../sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt

aws/sdk/integration-tests/s3/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ hyper = "0.14.12"
2727
serde_json = "1"
2828
smol = "1.2"
2929
tempfile = "3"
30-
tokio = { version = "1.8.4", features = ["full", "test-util"] }
30+
tokio = { version = "1.8.4", features = ["macros", "test-util", "rt-multi-thread"] }
3131
tracing = "0.1.37"
3232
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }

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

-12
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.Cli
2323
import software.amazon.smithy.rust.codegen.client.smithy.protocols.ClientProtocolLoader
2424
import software.amazon.smithy.rust.codegen.client.smithy.transformers.AddErrorMessage
2525
import software.amazon.smithy.rust.codegen.client.smithy.transformers.RemoveEventStreamOperations
26-
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
27-
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
2826
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
2927
import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider
3028
import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig
@@ -82,19 +80,9 @@ class CodegenVisitor(
8280

8381
codegenContext = ClientCodegenContext(model, symbolProvider, service, protocol, settings, codegenDecorator)
8482

85-
val clientPublicModules = setOf(
86-
RustModule.Error,
87-
RustModule.Model,
88-
RustModule.Input,
89-
RustModule.Output,
90-
RustModule.Config,
91-
RustModule.Types,
92-
RustModule.operation(Visibility.PUBLIC),
93-
).associateBy { it.name }
9483
rustCrate = RustCrate(
9584
context.fileManifest,
9685
symbolProvider,
97-
clientPublicModules,
9886
codegenContext.settings.codegenConfig,
9987
)
10088
protocolGenerator = protocolGeneratorFactory.buildProtocolGenerator(codegenContext)

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators
77

88
import software.amazon.smithy.model.shapes.MemberShape
99
import software.amazon.smithy.model.shapes.StructureShape
10-
import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata
1110
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
1211
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
13-
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
1412
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
1513
import software.amazon.smithy.rust.codegen.core.rustlang.rust
1614
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
@@ -24,7 +22,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.protocols.lensName
2422

2523
/** Generator for accessing nested fields through optional values **/
2624
class NestedAccessorGenerator(private val symbolProvider: RustSymbolProvider) {
27-
private val module = RustModule("lens", RustMetadata(visibility = Visibility.PUBLIC), "Generated accessors for nested fields")
25+
private val module = RustModule.private("lens", "Generated accessors for nested fields")
2826

2927
/**
3028
* Generate an accessor on [root] that consumes [root] and returns an `Option<T>` for the nested item

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ import software.amazon.smithy.model.traits.IdempotencyTokenTrait
1313
import software.amazon.smithy.model.traits.PaginatedTrait
1414
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerics
1515
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
16-
import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata
1716
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
1817
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
19-
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
2018
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
2119
import software.amazon.smithy.rust.codegen.core.rustlang.render
2220
import software.amazon.smithy.rust.codegen.core.rustlang.rust
@@ -78,11 +76,7 @@ class PaginatorGenerator private constructor(
7876
private val idx = PaginatedIndex.of(model)
7977
private val paginationInfo =
8078
idx.getPaginationInfo(service, operation).orNull() ?: PANIC("failed to load pagination info")
81-
private val module = RustModule(
82-
"paginator",
83-
RustMetadata(visibility = Visibility.PUBLIC),
84-
documentation = "Paginators for the service",
85-
)
79+
private val module = RustModule.public("paginator", "Paginators for the service")
8680

8781
private val inputType = symbolProvider.toSymbol(operation.inputShape(model))
8882
private val outputShape = operation.outputShape(model)
@@ -99,7 +93,12 @@ class PaginatorGenerator private constructor(
9993
"generics" to generics.decl,
10094
"bounds" to generics.bounds,
10195
"page_size_setter" to pageSizeSetter(),
102-
"send_bounds" to generics.sendBounds(symbolProvider.toSymbol(operation), outputType, errorType, retryClassifier),
96+
"send_bounds" to generics.sendBounds(
97+
symbolProvider.toSymbol(operation),
98+
outputType,
99+
errorType,
100+
retryClassifier,
101+
),
103102

104103
// Operation Types
105104
"operation" to symbolProvider.toSymbol(operation),
@@ -288,7 +287,8 @@ class PaginatorGenerator private constructor(
288287
private fun pageSizeSetter() = writable {
289288
paginationInfo.pageSizeMember.orNull()?.also {
290289
val memberName = symbolProvider.toMemberName(it)
291-
val pageSizeT = symbolProvider.toSymbol(it).rustType().stripOuter<RustType.Option>().render(true)
290+
val pageSizeT =
291+
symbolProvider.toSymbol(it).rustType().stripOuter<RustType.Option>().render(true)
292292
rust(
293293
"""
294294
/// Set the page size

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

+3-9
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustGenerics
1111
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
1212
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter
1313
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
14-
import software.amazon.smithy.rust.codegen.core.rustlang.docs
15-
import software.amazon.smithy.rust.codegen.core.rustlang.rust
1614
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
1715
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
1816
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
@@ -26,20 +24,16 @@ class CustomizableOperationGenerator(
2624
private val generics: FluentClientGenerics,
2725
private val includeFluentClient: Boolean,
2826
) {
27+
2928
companion object {
30-
const val CUSTOMIZE_MODULE = "crate::operation::customize"
29+
val CustomizeModule = RustModule.public("customize", "Operation customization and supporting types", parent = RustModule.operation(Visibility.PUBLIC))
3130
}
3231

3332
private val smithyHttp = CargoDependency.smithyHttp(runtimeConfig).toType()
3433
private val smithyTypes = CargoDependency.smithyTypes(runtimeConfig).toType()
3534

3635
fun render(crate: RustCrate) {
37-
crate.withModule(RustModule.operation(Visibility.PUBLIC)) {
38-
docs("Operation customization and supporting types")
39-
rust("pub mod customize;")
40-
}
41-
42-
crate.withNonRootModule(CUSTOMIZE_MODULE) {
36+
crate.withModule(CustomizeModule) {
4337
rustTemplate(
4438
"""
4539
pub use #{Operation};

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
2121
import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords
2222
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
2323
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter
24+
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
2425
import software.amazon.smithy.rust.codegen.core.rustlang.asArgumentType
2526
import software.amazon.smithy.rust.codegen.core.rustlang.asOptional
2627
import software.amazon.smithy.rust.codegen.core.rustlang.deprecatedShape
@@ -220,7 +221,7 @@ class FluentClientGenerator(
220221
)
221222
}
222223
}
223-
writer.withModule(RustModule.public("fluent_builders")) {
224+
writer.withInlineModule(RustModule.new("fluent_builders", visibility = Visibility.PUBLIC, inline = true)) {
224225
docs(
225226
"""
226227
Utilities to ergonomically construct a request to the service.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class ProtocolTestGenerator(
100100
Attribute.Custom("allow(unreachable_code, unused_variables)"),
101101
),
102102
)
103-
writer.withModule(RustModule(testModuleName, moduleMeta)) {
103+
writer.withInlineModule(RustModule.LeafModule(testModuleName, moduleMeta, inline = true)) {
104104
renderAllTestCases(allTests)
105105
}
106106
}

codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/SmithyTypesPubUseGeneratorTest.kt

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig
1313
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
1414

1515
class SmithyTypesPubUseGeneratorTest {
16-
private fun emptyModel() = modelWithMember()
1716
private fun modelWithMember(
1817
inputMember: String = "",
1918
outputMember: String = "",

codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitorTest.kt

-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCusto
1515
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientDecorator
1616
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
1717
import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext
18-
import kotlin.io.path.createDirectory
19-
import kotlin.io.path.writeText
2018

2119
class CodegenVisitorTest {
2220
@Test
@@ -48,8 +46,6 @@ class CodegenVisitorTest {
4846
}
4947
""".asSmithyModel(smithyVersion = "2.0")
5048
val (ctx, testDir) = generatePluginContext(model)
51-
testDir.resolve("src").createDirectory()
52-
testDir.resolve("src/main.rs").writeText("fn main() {}")
5349
val codegenDecorator =
5450
CombinedCodegenDecorator.fromClasspath(
5551
ctx,

codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/SymbolVisitorTest.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ import software.amazon.smithy.model.traits.SparseTrait
2929
import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider
3030
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
3131
import software.amazon.smithy.rust.codegen.core.rustlang.render
32-
import software.amazon.smithy.rust.codegen.core.smithy.Errors
33-
import software.amazon.smithy.rust.codegen.core.smithy.Models
34-
import software.amazon.smithy.rust.codegen.core.smithy.Operations
32+
import software.amazon.smithy.rust.codegen.core.smithy.ErrorsModule
33+
import software.amazon.smithy.rust.codegen.core.smithy.ModelsModule
34+
import software.amazon.smithy.rust.codegen.core.smithy.OperationsModule
3535
import software.amazon.smithy.rust.codegen.core.smithy.isOptional
3636
import software.amazon.smithy.rust.codegen.core.smithy.rustType
3737
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
@@ -57,7 +57,7 @@ class SymbolVisitorTest {
5757
val provider: SymbolProvider = testSymbolProvider(model)
5858
val sym = provider.toSymbol(struct)
5959
sym.rustType().render(false) shouldBe "MyStruct"
60-
sym.definitionFile shouldContain Models.filename
60+
sym.definitionFile shouldContain ModelsModule.definitionFile()
6161
sym.namespace shouldBe "crate::model"
6262
}
6363

@@ -77,7 +77,7 @@ class SymbolVisitorTest {
7777
val provider: SymbolProvider = testSymbolProvider(model)
7878
val sym = provider.toSymbol(struct)
7979
sym.rustType().render(false) shouldBe "TerribleError"
80-
sym.definitionFile shouldContain Errors.filename
80+
sym.definitionFile shouldContain ErrorsModule.definitionFile()
8181
}
8282

8383
@Test
@@ -101,7 +101,7 @@ class SymbolVisitorTest {
101101
val provider: SymbolProvider = testSymbolProvider(model)
102102
val sym = provider.toSymbol(shape)
103103
sym.rustType().render(false) shouldBe "StandardUnit"
104-
sym.definitionFile shouldContain Models.filename
104+
sym.definitionFile shouldContain ModelsModule.definitionFile()
105105
sym.namespace shouldBe "crate::model"
106106
}
107107

@@ -260,7 +260,7 @@ class SymbolVisitorTest {
260260
}
261261
""".asSmithyModel()
262262
val symbol = testSymbolProvider(model).toSymbol(model.expectShape(ShapeId.from("smithy.example#PutObject")))
263-
symbol.definitionFile shouldBe("src/${Operations.filename}")
263+
symbol.definitionFile shouldBe(OperationsModule.definitionFile())
264264
symbol.name shouldBe "PutObject"
265265
}
266266
}

codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import software.amazon.smithy.model.traits.EndpointTrait
1212
import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest
1313
import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider
1414
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
15-
import software.amazon.smithy.rust.codegen.core.rustlang.Visibility
1615
import software.amazon.smithy.rust.codegen.core.rustlang.rust
1716
import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock
1817
import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock
@@ -59,7 +58,7 @@ internal class EndpointTraitBindingsTest {
5958
operationShape.expectTrait(EndpointTrait::class.java),
6059
)
6160
val project = TestWorkspace.testProject()
62-
project.withModule(RustModule.default("test", visibility = Visibility.PRIVATE)) {
61+
project.withModule(RustModule.private("test")) {
6362
rust(
6463
"""
6564
struct GetStatusInput {

0 commit comments

Comments
 (0)