Unverified Commit efdca448 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Add uuidv4 implementation & rust-runtime as JAR (#55)

* Add uuidv4 implementation & rust-runtime as JAR

* Add inlineable crate

* Flesh out dependency test
parent 5af7fc0b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ dependencies {
    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")
    runtimeOnly(project(":rust-runtime"))
    testImplementation("org.junit.jupiter:junit-jupiter:5.6.1")
    testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion")
}
+13 −0
Original line number Diff line number Diff line
@@ -54,6 +54,19 @@ class InlineDependency(name: String, val module: String, val renderer: (RustWrit
    }

    fun key() = "$module::$name"

    companion object {
        fun forRustFile(name: String, module: String, filename: String): InlineDependency {
            // The inline crate is loaded as a dependency on the runtime classpath
            val rustFile = this::class.java.getResource("/inlineable/src/$filename")
            check(rustFile != null)
            return InlineDependency(name, module) { writer ->
                writer.write(rustFile.readText())
            }
        }

        fun uuid() = forRustFile("v4", "uuid", "uuid.rs")
    }
}

/**
+26 −4
Original line number Diff line number Diff line
package software.amazon.smithy.rust.codegen.lang

import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import org.junit.jupiter.api.Test
import software.amazon.smithy.rust.testutil.compileAndTest

internal class InlineDependencyTest {
    fun makeDep() = InlineDependency("func", "module") {
    fun makeDep(name: String) = InlineDependency(name, "module") {
        it.rustBlock("fn foo()") {}
    }

    @Test
    fun `dependency equality`() {
        val depa = makeDep()
        val depb = makeDep()
    fun `equal dependencies should be equal`() {
        val depa = makeDep("func")
        val depb = makeDep("func")
        depa.renderer shouldBe depb.renderer
        depa.key() shouldBe depb.key()

        depa.key() shouldNotBe makeDep("func2").key()
    }

    @Test
    fun `locate dependencies from the inlineable module`() {
        val dep = InlineDependency.uuid()
        val testWriter = RustWriter.forModule(null)
        testWriter.withModule("uuid") {
            dep.renderer(this)
        }
        testWriter.compileAndTest(
            """
            use crate::uuid;
            let res = uuid::v4(0);
            assert_eq!(res, "00000000-0000-4000-8000-000000000000");
        """
        )
    }
}
+15 −0
Original line number Diff line number Diff line
description = "Rust Runtime"
plugins {
    kotlin("jvm")
}

group = "software.amazon.rustruntime"

version = "1.0"

tasks.jar {
    from("./") {
        include("inlineable/src/*.rs")
        include("inlineable/Cargo.toml")
    }
}
+11 −0
Original line number Diff line number Diff line
[package]
name = "inlineable"
version = "0.1.0"
authors = ["Russell Cohen <rcoh@amazon.com>"]
edition = "2018"
description = """
The modules of this crate are intended to be inlined directly into the SDK as needed.
"""

[dev-dependencies]
proptest = "0.10.1"
Loading