Unverified Commit 336c1a29 authored by david-perez's avatar david-perez Committed by GitHub
Browse files

Add the ability to generate `pub(crate)` values (#1444)

A small commit adding the ability to generate `pub(crate)` values.
Currently we don't need to, but this is used in #1342. It's also nicer
to use an enum instead of passing around a boolean.
parent 8cefacff
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ package software.amazon.smithy.rustsdk

import software.amazon.smithy.codegen.core.CodegenException
import software.amazon.smithy.rust.codegen.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.rustlang.Visibility
import software.amazon.smithy.rust.codegen.smithy.RuntimeConfig
import software.amazon.smithy.rust.codegen.smithy.RuntimeCrateLocation
import software.amazon.smithy.rust.codegen.smithy.RuntimeType
@@ -43,12 +44,12 @@ fun RuntimeConfig.awsRoot(): RuntimeCrateLocation {
object AwsRuntimeType {
    val S3Errors by lazy { RuntimeType.forInlineDependency(InlineAwsDependency.forRustFile("s3_errors")) }
    val Presigning by lazy {
        RuntimeType.forInlineDependency(InlineAwsDependency.forRustFile("presigning", public = true))
        RuntimeType.forInlineDependency(InlineAwsDependency.forRustFile("presigning", visibility = Visibility.PUBLIC))
    }

    fun RuntimeConfig.defaultMiddleware() = RuntimeType.forInlineDependency(
        InlineAwsDependency.forRustFile(
            "middleware", public = true,
            "middleware", visibility = Visibility.PUBLIC,
            CargoDependency.SmithyHttp(this),
            CargoDependency.SmithyHttpTower(this),
            CargoDependency.SmithyClient(this),
+3 −2
Original line number Diff line number Diff line
@@ -7,8 +7,9 @@ package software.amazon.smithy.rustsdk

import software.amazon.smithy.rust.codegen.rustlang.InlineDependency
import software.amazon.smithy.rust.codegen.rustlang.RustDependency
import software.amazon.smithy.rust.codegen.rustlang.Visibility

object InlineAwsDependency {
    fun forRustFile(file: String, public: Boolean = false, vararg additionalDependency: RustDependency): InlineDependency =
        InlineDependency.Companion.forRustFile(file, "aws-inlineable", public, *additionalDependency)
    fun forRustFile(file: String, visibility: Visibility = Visibility.PRIVATE, vararg additionalDependency: RustDependency): InlineDependency =
        InlineDependency.Companion.forRustFile(file, "aws-inlineable", visibility, *additionalDependency)
}
+2 −1
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.rust.codegen.rustlang.Attribute
import software.amazon.smithy.rust.codegen.rustlang.RustMetadata
import software.amazon.smithy.rust.codegen.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.rustlang.Visibility
import software.amazon.smithy.rust.codegen.rustlang.Writable
import software.amazon.smithy.rust.codegen.rustlang.documentShape
import software.amazon.smithy.rust.codegen.rustlang.rust
@@ -37,7 +38,7 @@ class ServerCombinedErrorGenerator(
        val symbol = operation.errorSymbol(symbolProvider)
        val meta = RustMetadata(
            derives = Attribute.Derives(setOf(RuntimeType.Debug)),
            public = true
            visibility = Visibility.PUBLIC
        )

        writer.rust("/// Error type for the `${operationSymbol.name}` operation.")
+3 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import software.amazon.smithy.rust.codegen.rustlang.Attribute
import software.amazon.smithy.rust.codegen.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.rustlang.RustMetadata
import software.amazon.smithy.rust.codegen.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.rustlang.Visibility
import software.amazon.smithy.rust.codegen.rustlang.asType
import software.amazon.smithy.rust.codegen.rustlang.escape
import software.amazon.smithy.rust.codegen.rustlang.rust
@@ -132,11 +133,11 @@ class ServerProtocolTestGenerator(
            val operationName = operationSymbol.name
            val testModuleName = "server_${operationName.toSnakeCase()}_test"
            val moduleMeta = RustMetadata(
                public = false,
                additionalAttributes = listOf(
                    Attribute.Cfg("test"),
                    Attribute.Custom("allow(unreachable_code, unused_variables)")
                )
                ),
                visibility = Visibility.PRIVATE
            )
            writer.withModule(testModuleName, moduleMeta) {
                renderAllTestCases(allTests)
+3 −3
Original line number Diff line number Diff line
@@ -74,15 +74,15 @@ class InlineDependency(
            name: String,
            baseDir: String,
            vararg additionalDependencies: RustDependency
        ): InlineDependency = forRustFile(name, baseDir, public = false, *additionalDependencies)
        ): InlineDependency = forRustFile(name, baseDir, visibility = Visibility.PRIVATE, *additionalDependencies)

        fun forRustFile(
            name: String,
            baseDir: String,
            public: Boolean,
            visibility: Visibility,
            vararg additionalDependencies: RustDependency
        ): InlineDependency {
            val module = RustModule.default(name, public)
            val module = RustModule.default(name, visibility)
            val filename = "$name.rs"
            // The inline crate is loaded as a dependency on the runtime classpath
            val rustFile = this::class.java.getResource("/$baseDir/src/$filename")
Loading