Skip to content

Commit 3862ca0

Browse files
crisidev82marbagpose
authored
Initial implementation of Typescript server bindings (#2277)
* A barely working code generation in typescript * Extract shared socket into feature inside aws-smithy-http-server * Building a fully functional application, I think * Add NAPI build.rs * Refactor all names to use typescript instead of js * Add (hopefully) the PR bot for TS * Clippy fixes * Fix documentation Signed-off-by: Daniele Ahmed <ahmeddan@amazon.de> * set_reuse_port in socket not on windows Signed-off-by: Daniele Ahmed <ahmeddan@amazon.de> * Add example implementation * Allow the new application to build * Remove all occurrences of Python * Simplify README * Fix issue with the codegen-diff-revision script * Try to prevent the ci-lint to bother us with TODO at this stage of development * Remove codegen-client from typescript dependencies Signed-off-by: Bigo <1781140+crisidev@users.noreply.github.com> * Add CODEOWNERS and fix some other linting issues * Add license * Prevent from running tests on typescript in Windows Signed-off-by: Bigo <1781140+crisidev@users.noreply.github.com> * Initial work to remove error from this PR * Update to call_async Signed-off-by: Daniele Ahmed <ahmeddan@amazon.de> * types/node in package.json Signed-off-by: Daniele Ahmed <ahmeddan@amazon.de> * Generate app.ts Signed-off-by: Daniele Ahmed <ahmeddan@amazon.de> * Improve makefile * Adapting code to the latest changes and removing runtime dependency (for now). * Removing rust-runtime/aws-smithy-http-server-typescript. * Making CI happy. * Restoring ServerCodegenDecorator to be like main. * Adding back the aws-smithy-http-server-typescript crate back. * Removing index.js file. --------- Signed-off-by: Daniele Ahmed <ahmeddan@amazon.de> Signed-off-by: Bigo <1781140+crisidev@users.noreply.github.com> Co-authored-by: 82marbag <69267416+82marbag@users.noreply.github.com> Co-authored-by: Alberto Pose <albepose@amazon.com>
1 parent 9006fe8 commit 3862ca0

File tree

38 files changed

+1947
-42
lines changed

38 files changed

+1947
-42
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ jobs:
189189
pushd "${runtime_path}" &>/dev/null
190190
# aws-smithy-http-server-python cannot be compiled on Windows since it uses the `signal-hook` crate
191191
# which is not really yet fully supported on the platform.
192-
cargo test --all-features --workspace --exclude aws-smithy-http-server-python
193-
cargo doc --no-deps --document-private-items --all-features --workspace --exclude aws-smithy-http-server-python
192+
# aws-smithy-http-server-typescript cannot be compiled right now on Windows.
193+
cargo test --all-features --workspace --exclude aws-smithy-http-server-python --exclude aws-smithy-http-server-typescript
194+
cargo doc --no-deps --document-private-items --all-features --workspace --exclude aws-smithy-http-server-python --exclude aws-smithy-http-server-typescript
194195
popd &>/dev/null
195196
done
196197
@@ -210,24 +211,24 @@ jobs:
210211
- target: i686-unknown-linux-gnu
211212
build_smithy_rs_features: --all-features
212213
build_aws_exclude: ''
213-
build_smithy_rs_exclude: --exclude aws-smithy-http-server-python
214+
build_smithy_rs_exclude: --exclude aws-smithy-http-server-python --exclude aws-smithy-http-server-typescript
214215
test_smithy_rs_features: --all-features
215216
test_aws_exclude: ''
216-
test_smithy_rs_exclude: --exclude aws-smithy-http-server-python
217+
test_smithy_rs_exclude: --exclude aws-smithy-http-server-python --exclude aws-smithy-http-server-typescript
217218
- target: powerpc-unknown-linux-gnu
218219
build_smithy_rs_features: --features native-tls
219220
build_aws_exclude: --exclude aws-inlineable
220-
build_smithy_rs_exclude: --exclude aws-smithy-http-server-python
221+
build_smithy_rs_exclude: --exclude aws-smithy-http-server-python --exclude aws-smithy-http-server-typescript
221222
test_smithy_rs_features: --features native-tls
222223
test_aws_exclude: --exclude aws-inlineable
223-
test_smithy_rs_exclude: --exclude aws-smithy-http-server-python
224+
test_smithy_rs_exclude: --exclude aws-smithy-http-server-python --exclude aws-smithy-http-server-typescript
224225
- target: powerpc64-unknown-linux-gnu
225226
build_smithy_rs_features: --features native-tls
226227
build_aws_exclude: --exclude aws-inlineable
227-
build_smithy_rs_exclude: --exclude aws-smithy-http-server-python
228+
build_smithy_rs_exclude: --exclude aws-smithy-http-server-python --exclude aws-smithy-http-server-typescript
228229
test_smithy_rs_features: --features native-tls
229230
test_aws_exclude: --exclude aws-inlineable
230-
test_smithy_rs_exclude: --exclude aws-smithy-http-server-python
231+
test_smithy_rs_exclude: --exclude aws-smithy-http-server-python --exclude aws-smithy-http-server-typescript
231232
env:
232233
CROSS_CONFIG: Cross.toml
233234
steps:

.github/workflows/pull-request-bot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,15 @@ jobs:
110110
./gradlew -Paws.services=+sts,+sso,+transcribestreaming,+dynamodb :aws:sdk:assemble
111111
112112
# Copy the Server runtime crate(s) in
113-
cp -r rust-runtime/aws-smithy-http-server rust-runtime/aws-smithy-http-server-python aws/sdk/build/aws-sdk/sdk
113+
cp -r rust-runtime/aws-smithy-http-server rust-runtime/aws-smithy-http-server-python rust-runtime/aws-smithy-http-server-typescript aws/sdk/build/aws-sdk/sdk
114114
115115
pushd aws/sdk/build/aws-sdk
116116
117117
# Remove example crates from workspace
118118
sed -i '/examples/d' Cargo.toml
119119
120120
# Add server runtime crates to the workspace
121-
sed -i 's/"sdk\/sts",/"sdk\/sts","sdk\/aws-smithy-http-server","sdk\/aws-smithy-http-server-python",/' Cargo.toml
121+
sed -i 's/"sdk\/sts",/"sdk\/sts","sdk\/aws-smithy-http-server","sdk\/aws-smithy-http-server-python","sdk\/aws-smithy-http-server-typescript",/' Cargo.toml
122122
123123
cargo doc --no-deps --all-features
124124
popd

CODEOWNERS

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
1-
* @awslabs/rust-sdk-owners
1+
* @awslabs/rust-sdk-owners
22

33
# Server
4-
/codegen-server-test/ @awslabs/smithy-rs-server
5-
/codegen-server/ @awslabs/smithy-rs-server
6-
/rust-runtime/aws-smithy-http-server/ @awslabs/smithy-rs-server
4+
/codegen-server-test/ @awslabs/smithy-rs-server
5+
/codegen-server/ @awslabs/smithy-rs-server
6+
/rust-runtime/aws-smithy-http-server/ @awslabs/smithy-rs-server
77

88
# Python Server
9-
/codegen-server-test/python/ @awslabs/smithy-rs-python-server @awslabs/smithy-rs-server
10-
/codegen-server/python/ @awslabs/smithy-rs-python-server @awslabs/smithy-rs-server
11-
/rust-runtime/aws-smithy-http-server-python/ @awslabs/smithy-rs-python-server @awslabs/smithy-rs-server
9+
/codegen-server-test/python/ @awslabs/smithy-rs-python-server @awslabs/smithy-rs-server
10+
/codegen-server/python/ @awslabs/smithy-rs-python-server @awslabs/smithy-rs-server
11+
/rust-runtime/aws-smithy-http-server-python/ @awslabs/smithy-rs-python-server @awslabs/smithy-rs-server
12+
13+
# Typescript Server
14+
/codegen-server-test/typescript/ @awslabs/smithy-rs-typescript-server @awslabs/smithy-rs-server
15+
/codegen-server/typescript/ @awslabs/smithy-rs-typescript-server @awslabs/smithy-rs-server
16+
/rust-runtime/aws-smithy-http-server-typescript/ @awslabs/smithy-rs-typescript-server @awslabs/smithy-rs-server
1217

1318
# Shared ownership
14-
/.github/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
15-
/CHANGELOG.md @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
16-
/CHANGELOG.next.toml @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
17-
/README.md @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
18-
/build.gradle.kts @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
19-
/buildSrc/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
20-
/codegen-core/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
21-
/design/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
22-
/gradle.properties @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
23-
/tools/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
24-
/rust-runtime/aws-smithy-async/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
25-
/rust-runtime/aws-smithy-eventstream/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
26-
/rust-runtime/aws-smithy-http/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
27-
/rust-runtime/aws-smithy-json/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
28-
/rust-runtime/aws-smithy-protocol-test/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
29-
/rust-runtime/aws-smithy-types/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
30-
/rust-runtime/aws-smithy-types-convert/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
31-
/rust-runtime/aws-smithy-xml/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
32-
/rust-runtime/inlineable/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
33-
/rust-runtime/build.gradle.kts @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
34-
/rust-runtime/Cargo.toml @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
19+
/.github/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
20+
/CHANGELOG.md @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
21+
/CHANGELOG.next.toml @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
22+
/README.md @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
23+
/build.gradle.kts @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
24+
/buildSrc/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
25+
/codegen-core/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
26+
/design/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
27+
/gradle.properties @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
28+
/tools/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
29+
/rust-runtime/aws-smithy-async/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
30+
/rust-runtime/aws-smithy-eventstream/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
31+
/rust-runtime/aws-smithy-http/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
32+
/rust-runtime/aws-smithy-json/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
33+
/rust-runtime/aws-smithy-protocol-test/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
34+
/rust-runtime/aws-smithy-types/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
35+
/rust-runtime/aws-smithy-types-convert/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
36+
/rust-runtime/aws-smithy-xml/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
37+
/rust-runtime/inlineable/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
38+
/rust-runtime/build.gradle.kts @awslabs/rust-sdk-owners @awslabs/smithy-rs-server
39+
/rust-runtime/Cargo.toml @awslabs/rust-sdk-owners @awslabs/smithy-rs-server

buildSrc/src/main/kotlin/CrateSet.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ object CrateSet {
4040
val SERVER_SMITHY_RUNTIME = SMITHY_RUNTIME_COMMON + listOf(
4141
"aws-smithy-http-server",
4242
"aws-smithy-http-server-python",
43+
"aws-smithy-http-server-typescript",
4344
)
4445

4546
val ENTIRE_SMITHY_RUNTIME = (AWS_SDK_SMITHY_RUNTIME + SERVER_SMITHY_RUNTIME).toSortedSet()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import java.nio.file.Path
1616
sealed class DependencyScope {
1717
object Dev : DependencyScope()
1818
object Compile : DependencyScope()
19+
object Build : DependencyScope()
1920
}
2021

2122
sealed class DependencyLocation

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ class RustWriter private constructor(
468468
debugMode = debugMode,
469469
devDependenciesOnly = true,
470470
)
471-
471+
fileName == "package.json" -> rawWriter(fileName, debugMode = debugMode)
472472
else -> RustWriter(fileName, namespace, debugMode = debugMode)
473473
}
474474
}
@@ -514,7 +514,7 @@ class RustWriter private constructor(
514514
init {
515515
expressionStart = '#'
516516
if (filename.endsWith(".rs")) {
517-
require(namespace.startsWith("crate") || filename.startsWith("tests/")) {
517+
require(namespace.startsWith("crate") || filename.startsWith("tests/") || filename == "build.rs") {
518518
"We can only write into files in the crate (got $namespace)"
519519
}
520520
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class CargoTomlGenerator(
7272
).toMap(),
7373
"dependencies" to dependencies.filter { it.scope == DependencyScope.Compile }
7474
.associate { it.name to it.toMap() },
75+
"build-dependencies" to dependencies.filter { it.scope == DependencyScope.Build }
76+
.associate { it.name to it.toMap() },
7577
"dev-dependencies" to dependencies.filter { it.scope == DependencyScope.Dev }
7678
.associate { it.name to it.toMap() },
7779
"features" to cargoFeatures.toMap(),
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
description = "Generates Rust/Typescript code from Smithy models and runs the protocol tests"
7+
extra["displayName"] = "Smithy :: Rust :: Codegen :: Server :: Typescript :: Test"
8+
extra["moduleName"] = "software.amazon.smithy.rust.kotlin.codegen.server.typescript.test"
9+
10+
tasks["jar"].enabled = false
11+
12+
plugins {
13+
id("software.amazon.smithy")
14+
}
15+
16+
val smithyVersion: String by project
17+
val defaultRustDocFlags: String by project
18+
val properties = PropertyRetriever(rootProject, project)
19+
20+
val pluginName = "rust-server-codegen-typescript"
21+
val workingDirUnderBuildDir = "smithyprojections/codegen-server-test-typescript/"
22+
23+
configure<software.amazon.smithy.gradle.SmithyExtension> {
24+
outputDirectory = file("$buildDir/$workingDirUnderBuildDir")
25+
}
26+
27+
buildscript {
28+
val smithyVersion: String by project
29+
dependencies {
30+
classpath("software.amazon.smithy:smithy-cli:$smithyVersion")
31+
}
32+
}
33+
34+
dependencies {
35+
implementation(project(":codegen-server:typescript"))
36+
implementation("software.amazon.smithy:smithy-aws-protocol-tests:$smithyVersion")
37+
implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
38+
implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
39+
}
40+
41+
val allCodegenTests = "../../codegen-core/common-test-models".let { commonModels ->
42+
listOf(
43+
CodegenTest("com.amazonaws.simple#SimpleService", "simple", imports = listOf("$commonModels/simple.smithy")),
44+
CodegenTest("com.aws.example.ts#PokemonService", "pokemon-service-server-sdk"),
45+
)
46+
}
47+
48+
project.registerGenerateSmithyBuildTask(rootProject, pluginName, allCodegenTests)
49+
project.registerGenerateCargoWorkspaceTask(rootProject, pluginName, allCodegenTests, workingDirUnderBuildDir)
50+
project.registerGenerateCargoConfigTomlTask(buildDir.resolve(workingDirUnderBuildDir))
51+
52+
tasks["smithyBuildJar"].dependsOn("generateSmithyBuild")
53+
tasks["assemble"].finalizedBy("generateCargoWorkspace")
54+
55+
project.registerModifyMtimeTask()
56+
project.registerCargoCommandsTasks(buildDir.resolve(workingDirUnderBuildDir), defaultRustDocFlags)
57+
58+
tasks["test"].finalizedBy(cargoCommands(properties).map { it.toString })
59+
60+
tasks["clean"].doFirst { delete("smithy-build.json") }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../codegen-core/common-test-models/pokemon-common.smithy
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/// TODO(https://github.com/awslabs/smithy-rs/issues/1508)
2+
/// reconcile this model with the main one living inside codegen-server-test/model/pokemon.smithy
3+
/// once the Typescript implementation supports Streaming and Union shapes.
4+
$version: "1.0"
5+
6+
namespace com.aws.example.ts
7+
8+
use aws.protocols#restJson1
9+
use com.aws.example#PokemonSpecies
10+
use com.aws.example#GetServerStatistics
11+
use com.aws.example#DoNothing
12+
use com.aws.example#CheckHealth
13+
14+
/// The Pokémon Service allows you to retrieve information about Pokémon species.
15+
@title("Pokémon Service")
16+
@restJson1
17+
service PokemonService {
18+
version: "2021-12-01",
19+
resources: [PokemonSpecies],
20+
operations: [
21+
GetServerStatistics,
22+
DoNothing,
23+
CheckHealth,
24+
],
25+
}

0 commit comments

Comments
 (0)