forked from smithy-lang/smithy-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServerCargoDependency.kt
58 lines (54 loc) · 3.05 KB
/
ServerCargoDependency.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package software.amazon.smithy.rust.codegen.server.smithy
import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo
import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope
import software.amazon.smithy.rust.codegen.core.rustlang.InlineDependency
import software.amazon.smithy.rust.codegen.core.rustlang.RustModule
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
/**
* Object used *exclusively* in the runtime of the server, for separation concerns.
* Analogous to the companion object in [CargoDependency]; see its documentation for details.
* For a dependency that is used in the client, or in both the client and the server, use [CargoDependency] directly.
*/
object ServerCargoDependency {
val AsyncTrait: CargoDependency = CargoDependency("async-trait", CratesIo("0.1"))
val FormUrlEncoded: CargoDependency = CargoDependency("form_urlencoded", CratesIo("1"))
val FuturesUtil: CargoDependency = CargoDependency("futures-util", CratesIo("0.3"))
val Mime: CargoDependency = CargoDependency("mime", CratesIo("0.3"))
val Nom: CargoDependency = CargoDependency("nom", CratesIo("7"))
val OnceCell: CargoDependency = CargoDependency("once_cell", CratesIo("1.13"))
val PinProjectLite: CargoDependency = CargoDependency("pin-project-lite", CratesIo("0.2"))
val Tower: CargoDependency = CargoDependency("tower", CratesIo("0.4"))
val TokioDev: CargoDependency = CargoDependency("tokio", CratesIo("1.8.4"), scope = DependencyScope.Dev)
val Regex: CargoDependency = CargoDependency("regex", CratesIo("1.5.5"))
fun smithyHttpServer(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-http-server")
fun smithyTypes(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-types")
}
/**
* A dependency on a snippet of code
*
* ServerInlineDependency should not be instantiated directly, rather, it should be constructed with
* [software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.forInlineFun]
*
* ServerInlineDependencies are created as private modules within the main crate. This is useful for any code that
* doesn't need to exist in a shared crate, but must still be generated exactly once during codegen.
*
* CodegenVisitor de-duplicates inline dependencies by (module, name) during code generation.
*/
object ServerInlineDependency {
fun serverOperationHandler(runtimeConfig: RuntimeConfig): InlineDependency =
InlineDependency.forRustFile(
RustModule.private("server_operation_handler_trait"),
"/inlineable/src/server_operation_handler_trait.rs",
ServerCargoDependency.smithyHttpServer(runtimeConfig),
CargoDependency.Http,
ServerCargoDependency.PinProjectLite,
ServerCargoDependency.Tower,
ServerCargoDependency.FuturesUtil,
ServerCargoDependency.AsyncTrait,
)
}