Loading .gitignore 0 → 100644 +45 −0 Original line number Diff line number Diff line # attn: Intellij related ignores belong in ~/.gitignore # Java/Kotlin # Compiled class file *.class # Log file *.log # BlueJ files *.ctxt # Mobile Tools for Java (J2ME) .mtj.tmp/ # Package Files # *.jar *.war *.nar *.ear *.zip *.tar.gz *.rar # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* # Gradle .gradle build/ # Ignore Gradle GUI config gradle-app.setting # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) !gradle-wrapper.jar # Cache of project .gradletasknamecache # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 # gradle/wrapper/gradle-wrapper.properties # MacOS .DS_Store README.md +9 −14 Original line number Diff line number Diff line ## My Project # Smithy Rust Smithy code generators for Rust TODO: Fill this README out! ## Setup 1. `./gradlew` will setup gradle for you 2. Running tests requires a working Rust installation. See [Rust docs](https://www.rust-lang.org/learn/get-started) for installation instructions on your platform. Be sure to: * Change the title in this README * Edit your repository description on GitHub ## Security See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information. ## License This project is licensed under the Apache-2.0 License. ## Run tests ```./tesh.sh``` This will run all the unit tests, codegen an example model end-to-end and validates that the generated code compiles. No newline at end of file build.gradle.kts 0 → 100644 +89 −0 Original line number Diff line number Diff line /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ buildscript { repositories { google() jcenter() } val kotlinVersion: String by project dependencies { classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") } } plugins { kotlin("jvm") version "1.3.72" apply false id("org.jetbrains.dokka") version "0.10.0" } allprojects { repositories { mavenLocal() mavenCentral() jcenter() google() } } apply(from = rootProject.file("gradle/maincodecoverage.gradle")) val ktlint by configurations.creating val ktlintVersion: String by project dependencies { ktlint("com.pinterest:ktlint:$ktlintVersion") } val lintPaths = listOf( "codegen/src/**/*.kt" ) tasks.register<JavaExec>("ktlint") { description = "Check Kotlin code style." group = "Verification" classpath = configurations.getByName("ktlint") main = "com.pinterest.ktlint.Main" args = lintPaths } tasks.register<JavaExec>("ktlintFormat") { description = "Auto fix Kotlin code style violations" group = "formatting" classpath = configurations.getByName("ktlint") main = "com.pinterest.ktlint.Main" args = listOf("-F") + lintPaths } @Suppress("UnstableApiUsage") task<JacocoMerge>("jacocoMerge") { group = LifecycleBasePlugin.VERIFICATION_GROUP description = "Merge the JaCoCo data files from all subprojects into one" afterEvaluate { // An empty FileCollection val execFiles = objects.fileCollection() val projectList = subprojects + project projectList.forEach { subProject: Project -> if (subProject.pluginManager.hasPlugin("jacoco")) { val testTasks = subProject.tasks.withType<Test>() // ensure that .exec files are actually present dependsOn(testTasks) testTasks.forEach { task: Test -> // The JacocoTaskExtension is the source of truth for the location of the .exec file. val extension = task.extensions.findByType(JacocoTaskExtension::class.java) extension?.let { execFiles.from(it.destinationFile) } } } } executionData = execFiles } doFirst { // .exec files might be missing if a project has no tests. Filter in execution phase. executionData = executionData.filter { it.canRead() } } } codegen/build.gradle.kts 0 → 100644 +105 −0 Original line number Diff line number Diff line /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ plugins { kotlin("jvm") id("org.jetbrains.dokka") jacoco maven `maven-publish` } description = "Generates Rust code from Smithy models" extra["displayName"] = "Smithy :: Rust :: Codegen" extra["moduleName"] = "software.amazon.software.amazon.smithy.rust.codegen.smithy.rust.codegen" group = "software.amazon.software.amazon.smithy.rust.codegen.smithy" version = "0.1.0" val smithyVersion: String by project val kotestVersion: String by project dependencies { implementation(kotlin("stdlib-jdk8")) api("software.amazon.smithy:smithy-codegen-core:$smithyVersion") implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion") implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion") testImplementation("org.junit.jupiter:junit-jupiter:5.6.1") testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion") } // unlike the client-runtime, software.amazon.smithy.rust.codegen.smithy-kotlin codegen package is not expected to run on Android...we can target 1.8 tasks.compileKotlin { kotlinOptions.jvmTarget = "1.8" } tasks.compileTestKotlin { kotlinOptions.jvmTarget = "1.8" } // Reusable license copySpec val licenseSpec = copySpec { from("${project.rootDir}/LICENSE") from("${project.rootDir}/NOTICE") } // Configure jars to include license related info tasks.jar { metaInf.with(licenseSpec) inputs.property("moduleName", project.name) manifest { attributes["Automatic-Module-Name"] = project.name } } val sourcesJar by tasks.creating(Jar::class) { group = "publishing" description = "Assembles Kotlin sources jar" classifier = "sources" from(sourceSets.getByName("main").allSource) } tasks.test { useJUnitPlatform() testLogging { events("passed", "skipped", "failed") showStandardStreams = true } } tasks.dokka { outputFormat = "html" outputDirectory = "$buildDir/javadoc" } // Always build documentation tasks["build"].finalizedBy(tasks["dokka"]) // Configure jacoco (code coverage) to generate an HTML report tasks.jacocoTestReport { reports { xml.isEnabled = false csv.isEnabled = false html.destination = file("$buildDir/reports/jacoco") } } // Always run the jacoco test report after testing. tasks["test"].finalizedBy(tasks["jacocoTestReport"]) publishing { publications { create<MavenPublication>("default") { from(components["java"]) artifact(sourcesJar) } } repositories { maven { url = uri("$buildDir/repository") } } } codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustDependency.kt 0 → 100644 +52 −0 Original line number Diff line number Diff line /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ package software.amazon.smithy.rust.codegen.lang import software.amazon.smithy.codegen.core.SymbolDependency import software.amazon.smithy.codegen.core.SymbolDependencyContainer import software.amazon.smithy.rust.codegen.smithy.RuntimeConfig sealed class DependencyLocation data class CratesIo(val version: String) : DependencyLocation() data class Local(val path: String? = null) : DependencyLocation() data class RustDependency( val name: String, val location: DependencyLocation ) : SymbolDependencyContainer { override fun getDependencies(): List<SymbolDependency> { return listOf( SymbolDependency.builder().packageName(name).version(this.version()).putProperty(PropKey, this).build() ) } private fun version(): String = when (location) { is CratesIo -> location.version is Local -> "local" } override fun toString(): String { return when (location) { is CratesIo -> """$name = "${location.version}"""" is Local -> """$name = { path = "${location.path}/$name" }""" } } companion object { val Http: RustDependency = RustDependency("http", CratesIo("0.2")) fun SmithyTypes(runtimeConfig: RuntimeConfig) = RustDependency("${runtimeConfig.cratePrefix}-types", Local(runtimeConfig.relativePath)) fun SmithyHttp(runtimeConfig: RuntimeConfig) = RustDependency( "${runtimeConfig.cratePrefix}-http", Local(runtimeConfig.relativePath) ) private val PropKey = "rustdep" fun fromSymbolDependency(symbolDependency: SymbolDependency) = symbolDependency.getProperty(PropKey, RustDependency::class.java).get() } } Loading
.gitignore 0 → 100644 +45 −0 Original line number Diff line number Diff line # attn: Intellij related ignores belong in ~/.gitignore # Java/Kotlin # Compiled class file *.class # Log file *.log # BlueJ files *.ctxt # Mobile Tools for Java (J2ME) .mtj.tmp/ # Package Files # *.jar *.war *.nar *.ear *.zip *.tar.gz *.rar # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* # Gradle .gradle build/ # Ignore Gradle GUI config gradle-app.setting # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) !gradle-wrapper.jar # Cache of project .gradletasknamecache # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 # gradle/wrapper/gradle-wrapper.properties # MacOS .DS_Store
README.md +9 −14 Original line number Diff line number Diff line ## My Project # Smithy Rust Smithy code generators for Rust TODO: Fill this README out! ## Setup 1. `./gradlew` will setup gradle for you 2. Running tests requires a working Rust installation. See [Rust docs](https://www.rust-lang.org/learn/get-started) for installation instructions on your platform. Be sure to: * Change the title in this README * Edit your repository description on GitHub ## Security See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information. ## License This project is licensed under the Apache-2.0 License. ## Run tests ```./tesh.sh``` This will run all the unit tests, codegen an example model end-to-end and validates that the generated code compiles. No newline at end of file
build.gradle.kts 0 → 100644 +89 −0 Original line number Diff line number Diff line /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ buildscript { repositories { google() jcenter() } val kotlinVersion: String by project dependencies { classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") } } plugins { kotlin("jvm") version "1.3.72" apply false id("org.jetbrains.dokka") version "0.10.0" } allprojects { repositories { mavenLocal() mavenCentral() jcenter() google() } } apply(from = rootProject.file("gradle/maincodecoverage.gradle")) val ktlint by configurations.creating val ktlintVersion: String by project dependencies { ktlint("com.pinterest:ktlint:$ktlintVersion") } val lintPaths = listOf( "codegen/src/**/*.kt" ) tasks.register<JavaExec>("ktlint") { description = "Check Kotlin code style." group = "Verification" classpath = configurations.getByName("ktlint") main = "com.pinterest.ktlint.Main" args = lintPaths } tasks.register<JavaExec>("ktlintFormat") { description = "Auto fix Kotlin code style violations" group = "formatting" classpath = configurations.getByName("ktlint") main = "com.pinterest.ktlint.Main" args = listOf("-F") + lintPaths } @Suppress("UnstableApiUsage") task<JacocoMerge>("jacocoMerge") { group = LifecycleBasePlugin.VERIFICATION_GROUP description = "Merge the JaCoCo data files from all subprojects into one" afterEvaluate { // An empty FileCollection val execFiles = objects.fileCollection() val projectList = subprojects + project projectList.forEach { subProject: Project -> if (subProject.pluginManager.hasPlugin("jacoco")) { val testTasks = subProject.tasks.withType<Test>() // ensure that .exec files are actually present dependsOn(testTasks) testTasks.forEach { task: Test -> // The JacocoTaskExtension is the source of truth for the location of the .exec file. val extension = task.extensions.findByType(JacocoTaskExtension::class.java) extension?.let { execFiles.from(it.destinationFile) } } } } executionData = execFiles } doFirst { // .exec files might be missing if a project has no tests. Filter in execution phase. executionData = executionData.filter { it.canRead() } } }
codegen/build.gradle.kts 0 → 100644 +105 −0 Original line number Diff line number Diff line /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ plugins { kotlin("jvm") id("org.jetbrains.dokka") jacoco maven `maven-publish` } description = "Generates Rust code from Smithy models" extra["displayName"] = "Smithy :: Rust :: Codegen" extra["moduleName"] = "software.amazon.software.amazon.smithy.rust.codegen.smithy.rust.codegen" group = "software.amazon.software.amazon.smithy.rust.codegen.smithy" version = "0.1.0" val smithyVersion: String by project val kotestVersion: String by project dependencies { implementation(kotlin("stdlib-jdk8")) api("software.amazon.smithy:smithy-codegen-core:$smithyVersion") implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion") implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion") testImplementation("org.junit.jupiter:junit-jupiter:5.6.1") testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion") } // unlike the client-runtime, software.amazon.smithy.rust.codegen.smithy-kotlin codegen package is not expected to run on Android...we can target 1.8 tasks.compileKotlin { kotlinOptions.jvmTarget = "1.8" } tasks.compileTestKotlin { kotlinOptions.jvmTarget = "1.8" } // Reusable license copySpec val licenseSpec = copySpec { from("${project.rootDir}/LICENSE") from("${project.rootDir}/NOTICE") } // Configure jars to include license related info tasks.jar { metaInf.with(licenseSpec) inputs.property("moduleName", project.name) manifest { attributes["Automatic-Module-Name"] = project.name } } val sourcesJar by tasks.creating(Jar::class) { group = "publishing" description = "Assembles Kotlin sources jar" classifier = "sources" from(sourceSets.getByName("main").allSource) } tasks.test { useJUnitPlatform() testLogging { events("passed", "skipped", "failed") showStandardStreams = true } } tasks.dokka { outputFormat = "html" outputDirectory = "$buildDir/javadoc" } // Always build documentation tasks["build"].finalizedBy(tasks["dokka"]) // Configure jacoco (code coverage) to generate an HTML report tasks.jacocoTestReport { reports { xml.isEnabled = false csv.isEnabled = false html.destination = file("$buildDir/reports/jacoco") } } // Always run the jacoco test report after testing. tasks["test"].finalizedBy(tasks["jacocoTestReport"]) publishing { publications { create<MavenPublication>("default") { from(components["java"]) artifact(sourcesJar) } } repositories { maven { url = uri("$buildDir/repository") } } }
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/lang/RustDependency.kt 0 → 100644 +52 −0 Original line number Diff line number Diff line /* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ package software.amazon.smithy.rust.codegen.lang import software.amazon.smithy.codegen.core.SymbolDependency import software.amazon.smithy.codegen.core.SymbolDependencyContainer import software.amazon.smithy.rust.codegen.smithy.RuntimeConfig sealed class DependencyLocation data class CratesIo(val version: String) : DependencyLocation() data class Local(val path: String? = null) : DependencyLocation() data class RustDependency( val name: String, val location: DependencyLocation ) : SymbolDependencyContainer { override fun getDependencies(): List<SymbolDependency> { return listOf( SymbolDependency.builder().packageName(name).version(this.version()).putProperty(PropKey, this).build() ) } private fun version(): String = when (location) { is CratesIo -> location.version is Local -> "local" } override fun toString(): String { return when (location) { is CratesIo -> """$name = "${location.version}"""" is Local -> """$name = { path = "${location.path}/$name" }""" } } companion object { val Http: RustDependency = RustDependency("http", CratesIo("0.2")) fun SmithyTypes(runtimeConfig: RuntimeConfig) = RustDependency("${runtimeConfig.cratePrefix}-types", Local(runtimeConfig.relativePath)) fun SmithyHttp(runtimeConfig: RuntimeConfig) = RustDependency( "${runtimeConfig.cratePrefix}-http", Local(runtimeConfig.relativePath) ) private val PropKey = "rustdep" fun fromSymbolDependency(symbolDependency: SymbolDependency) = symbolDependency.getProperty(PropKey, RustDependency::class.java).get() } }