Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move re-exports into types and re-export AggregatedBytes #1085

Merged
merged 12 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci-sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ jobs:
path: artifact
- name: untar
run: tar -xvf ./artifact/sdk.tar
- name: Remove examples from workspace
run: sed -i '/"examples\//d' Cargo.toml
- name: Check the SDK
run: cargo check
working-directory: ./sdk
56 changes: 56 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,62 @@
# meta = { "breaking" = false, "tada" = false, "bug" = false }
# author = "rcoh"

[[aws-sdk-rust]]
message = """
Moved the following re-exports into a `types` module for all services:
- `aws_sdk_<service>::AggregatedBytes` -> `aws_sdk_<service>::types::AggregatedBytes`
- `aws_sdk_<service>::Blob` -> `aws_sdk_<service>::types::Blob`
- `aws_sdk_<service>::ByteStream` -> `aws_sdk_<service>::types::ByteStream`
- `aws_sdk_<service>::DateTime` -> `aws_sdk_<service>::types::DateTime`
- `aws_sdk_<service>::SdkError` -> `aws_sdk_<service>::types::SdkError`
"""
references = ["smithy-rs#1085"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "jdisanti"

[[aws-sdk-rust]]
message = """
`AggregatedBytes` and `ByteStream` are now only re-exported if the service has streaming operations,
and `Blob`/`DateTime` are only re-exported if the service uses them.
"""
references = ["smithy-rs#1085"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "jdisanti"

[[aws-sdk-rust]]
message = "The `Client` and `Config` re-exports now have their documentation inlined in the service docs"
references = ["smithy-rs#1085"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "jdisanti"

[[smithy-rs]]
message = """
Moved the following re-exports into a `types` module for all services:
- `<service>::AggregatedBytes` -> `<service>::types::AggregatedBytes`
- `<service>::Blob` -> `<service>::types::Blob`
- `<service>::ByteStream` -> `<service>::types::ByteStream`
- `<service>::DateTime` -> `<service>::types::DateTime`
- `<service>::SdkError` -> `<service>::types::SdkError`
"""
references = ["smithy-rs#1085"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "jdisanti"

[[smithy-rs]]
message = """
`AggregatedBytes` and `ByteStream` are now only re-exported if the service has streaming operations,
and `Blob`/`DateTime` are only re-exported if the service uses them.
"""
references = ["smithy-rs#1085"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "jdisanti"

[[smithy-rs]]
message = "The `Client` and `Config` re-exports now have their documentation inlined in the service docs"
references = ["smithy-rs#1085"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "jdisanti"

[[aws-sdk-rust]]
message = "MSRV increased from `1.54` to `1.56.1` per our 2-behind MSRV policy."
references = ["smithy-rs#1130"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package software.amazon.smithy.rustsdk

import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.traits.TitleTrait
import software.amazon.smithy.rust.codegen.rustlang.Attribute
import software.amazon.smithy.rust.codegen.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.rustlang.DependencyScope
import software.amazon.smithy.rust.codegen.rustlang.Feature
Expand Down Expand Up @@ -78,6 +79,7 @@ class AwsFluentClientDecorator : RustCodegenDecorator {
return baseCustomizations + object : LibRsCustomization() {
override fun section(section: LibRsSection) = when (section) {
is LibRsSection.Body -> writable {
Attribute.DocInline.render(this)
rust("pub use client::Client;")
}
else -> emptySection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class IntegrationTestDependencies(
private val hasBenches: Boolean,
) : LibRsCustomization() {
override fun section(section: LibRsSection) = when (section) {
LibRsSection.Body -> writable {
is LibRsSection.Body -> writable {
if (hasTests) {
val smithyClient = CargoDependency.SmithyClient(runtimeConfig)
.copy(features = setOf("test-util"), scope = DependencyScope.Dev)
Expand Down
3 changes: 2 additions & 1 deletion aws/sdk/integration-tests/glacier/tests/custom-headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* SPDX-License-Identifier: Apache-2.0.
*/

use aws_sdk_glacier::{ByteStream, Credentials, Region};
use aws_sdk_glacier::types::ByteStream;
use aws_sdk_glacier::{Credentials, Region};
use aws_smithy_client::test_connection::capture_request;
use aws_smithy_protocol_test::{assert_ok, validate_headers};

Expand Down
4 changes: 2 additions & 2 deletions aws/sdk/integration-tests/kms/tests/sensitive-it.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use bytes::Bytes;
use kms::error::CreateAliasError;
use kms::operation::{CreateAlias, GenerateRandom};
use kms::output::GenerateRandomOutput;
use kms::Blob;
use kms::types::Blob;

#[test]
fn validate_sensitive_trait() {
Expand All @@ -35,7 +35,7 @@ fn assert_debug<T: std::fmt::Debug>() {}
#[tokio::test]
async fn types_are_send_sync() {
assert_send_sync::<kms::Error>();
assert_send_sync::<kms::SdkError<CreateAliasError>>();
assert_send_sync::<kms::types::SdkError<CreateAliasError>>();
assert_send_sync::<kms::error::CreateAliasError>();
assert_send_sync::<kms::output::CreateAliasOutput>();
assert_send_sync::<kms::Client>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

use aws_http::user_agent::AwsUserAgent;
use aws_sdk_s3::middleware::DefaultMiddleware;
use aws_sdk_s3::{operation::PutObject, Credentials, Region};
use aws_sdk_s3::operation::PutObject;
use aws_sdk_s3::types::ByteStream;
use aws_sdk_s3::{Credentials, Region};
use aws_smithy_client::test_connection::capture_request;
use aws_smithy_client::Client as CoreClient;
use http::HeaderValue;
Expand Down Expand Up @@ -68,7 +70,7 @@ async fn test_s3_signer_with_naughty_string_metadata() -> Result<(), aws_sdk_s3:
let mut builder = PutObject::builder()
.bucket("test-bucket")
.key("text.txt")
.body(aws_sdk_s3::ByteStream::from_static(b"some test text"));
.body(ByteStream::from_static(b"some test text"));

for (idx, line) in NAUGHTY_STRINGS.split('\n').enumerate() {
// add lines to metadata unless they're a comment or empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use aws_sdk_transcribestreaming::model::{
AudioEvent, AudioStream, LanguageCode, MediaEncoding, TranscriptResultStream,
};
use aws_sdk_transcribestreaming::output::StartStreamTranscriptionOutput;
use aws_sdk_transcribestreaming::{Blob, Client, Config, Credentials, Region, SdkError};
use aws_sdk_transcribestreaming::types::{Blob, SdkError};
use aws_sdk_transcribestreaming::{Client, Config, Credentials, Region};
use aws_smithy_client::dvr::{Event, ReplayingConnection};
use aws_smithy_eventstream::frame::{DecodedFrame, HeaderValue, Message, MessageFrameDecoder};
use aws_smithy_http::event_stream::BoxError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ sealed class Attribute {
*/
val NonExhaustive = Custom("non_exhaustive")
val AllowUnusedMut = Custom("allow(unused_mut)")
val DocInline = Custom("doc(inline)")
}

data class Derives(val derives: Set<RuntimeType>) : Attribute() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,84 @@

package software.amazon.smithy.rust.codegen.smithy.customizations

import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.rust.codegen.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.rustlang.asType
import software.amazon.smithy.rust.codegen.rustlang.docs
import software.amazon.smithy.rust.codegen.rustlang.rust
import software.amazon.smithy.rust.codegen.rustlang.rustBlock
import software.amazon.smithy.rust.codegen.rustlang.writable
import software.amazon.smithy.rust.codegen.smithy.RuntimeConfig
import software.amazon.smithy.rust.codegen.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.smithy.generators.LibRsCustomization
import software.amazon.smithy.rust.codegen.smithy.generators.LibRsSection
import software.amazon.smithy.rust.codegen.util.hasEventStreamMember
import software.amazon.smithy.rust.codegen.util.hasStreamingMember

fun pubUseTypes(runtimeConfig: RuntimeConfig) = listOf(
RuntimeType.Blob(runtimeConfig),
RuntimeType.DateTime(runtimeConfig),
CargoDependency.SmithyHttp(runtimeConfig).asType().member("result::SdkError"),
CargoDependency.SmithyHttp(runtimeConfig).asType().member("byte_stream::ByteStream"),
private data class PubUseType(
val type: RuntimeType,
val shouldExport: (Model) -> Boolean,
)

/** Returns true if the model has normal streaming operations (excluding event streams) */
private fun hasStreamingOperations(model: Model): Boolean {
return model.operationShapes.any { operation ->
val input = model.expectShape(operation.inputShape, StructureShape::class.java)
val output = model.expectShape(operation.outputShape, StructureShape::class.java)
(input.hasStreamingMember(model) && !input.hasEventStreamMember(model)) ||
(output.hasStreamingMember(model) && !output.hasEventStreamMember(model))
}
}

/** Returns true if the model has any blob shapes or members */
private fun hasBlobs(model: Model): Boolean {
return model.structureShapes.any { structure ->
structure.members().any { member -> model.expectShape(member.target).isBlobShape }
} || model.unionShapes.any { union ->
union.members().any { member -> model.expectShape(member.target).isBlobShape }
}
}

/** Returns true if the model has any timestamp shapes or members */
private fun hasDateTimes(model: Model): Boolean {
return model.structureShapes.any { structure ->
structure.members().any { member -> model.expectShape(member.target).isTimestampShape }
} || model.unionShapes.any { union ->
union.members().any { member -> model.expectShape(member.target).isTimestampShape }
}
}

/** Returns a list of types that should be re-exported for the given model */
internal fun pubUseTypes(runtimeConfig: RuntimeConfig, model: Model): List<RuntimeType> {
return (
listOf(
PubUseType(RuntimeType.Blob(runtimeConfig), ::hasBlobs),
PubUseType(RuntimeType.DateTime(runtimeConfig), ::hasDateTimes),
) + CargoDependency.SmithyHttp(runtimeConfig).asType().let { http ->
listOf(
PubUseType(http.member("result::SdkError")) { true },
PubUseType(http.member("byte_stream::ByteStream"), ::hasStreamingOperations),
PubUseType(http.member("byte_stream::AggregatedBytes"), ::hasStreamingOperations),
)
}
).filter { pubUseType -> pubUseType.shouldExport(model) }.map { it.type }
}

class SmithyTypesPubUseGenerator(private val runtimeConfig: RuntimeConfig) : LibRsCustomization() {
override fun section(section: LibRsSection) = writable {
when (section) {
LibRsSection.Body -> pubUseTypes(runtimeConfig).forEach {
rust("pub use #T;", it)
is LibRsSection.Body -> {
val types = pubUseTypes(runtimeConfig, section.model)
if (types.isNotEmpty()) {
docs("Re-exported types from supporting crates.")
rustBlock("pub mod types") {
types.forEach { type -> rust("pub use #T;", type) }
}
}
}
else -> {
}
else -> { }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import software.amazon.smithy.rust.codegen.util.getTrait
sealed class LibRsSection(name: String) : Section(name) {
object Attributes : LibRsSection("Attributes")
data class ModuleDocumentation(val subsection: String) : LibRsSection("ModuleDocumentation")
object Body : LibRsSection("Body")
data class Body(val model: Model) : LibRsSection("Body")
companion object {
val Examples = "Examples"
val CrateOrganization = "CrateOrganization"
Expand Down Expand Up @@ -67,6 +67,6 @@ class LibRsGenerator(
// TODO(docs): Automated feature documentation
}
modules.forEach { it.render(writer) }
customizations.forEach { it.section(LibRsSection.Body)(writer) }
customizations.forEach { it.section(LibRsSection.Body(model))(writer) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package software.amazon.smithy.rust.codegen.smithy.generators

import software.amazon.smithy.model.knowledge.TopDownIndex
import software.amazon.smithy.rust.codegen.rustlang.Attribute
import software.amazon.smithy.rust.codegen.rustlang.RustModule
import software.amazon.smithy.rust.codegen.smithy.CodegenContext
import software.amazon.smithy.rust.codegen.smithy.RustCrate
Expand Down Expand Up @@ -70,6 +71,7 @@ class ServiceGenerator(
}

rustCrate.lib {
Attribute.DocInline.render(it)
it.write("pub use config::Config;")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fun MemberShape.isOutputEventStream(model: Model): Boolean {
return isEventStream(model) && model.expectShape(container).hasTrait<SyntheticInputTrait>()
}

private fun Shape.hasEventStreamMember(model: Model): Boolean {
fun Shape.hasEventStreamMember(model: Model): Boolean {
return members().any { it.isEventStream(model) }
}

Expand Down
Loading