Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge master branch #4

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 48 additions & 28 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#
version: 2.1


executors:
jvm:
docker:
Expand All @@ -17,6 +16,32 @@ executors:
docker:
- image: circleci/node:lts

native:
docker:
- image: cimg/base:2020.01

commands:

conformance_test:
parameters:
target:
description: Target platform for which to run conformance tests
type: string

steps:
- attach_workspace:
at: ~/project

- restore_cache:
name: Restore protobuf cache
keys:
- v3-protobuf-3.10.1

- run:
name: Run << parameters.target >> conformance tests
command: |
export CONF_TEST_PATH=~/protobuf/conformance/conformance-test-runner
./conformance/test-conformance.sh << parameters.target >>

jobs:

Expand All @@ -27,6 +52,10 @@ jobs:
steps:
- checkout

- run:
name: Install Kotlin/Native compiler dependencies
command: sudo apt update && sudo apt install libncurses5

- run:
name: Collect files for dependencies cache key
command: |
Expand Down Expand Up @@ -105,7 +134,7 @@ jobs:

- run:
name: Build conformance test suite
command: ./gradlew :conformance:lib:assemble :conformance:jvm:installDist
command: ./gradlew :conformance:lib:assemble :conformance:jvm:installDist :conformance:native:build

# persist files necessary to run conformance tests
- persist_to_workspace:
Expand All @@ -119,11 +148,15 @@ jobs:
- build/js
- conformance/js/failing_tests.txt
- conformance/js/run.sh
# native
- conformance/native/build/bin/linux/conformanceReleaseExecutable/conformance.kexe
- conformance/native/failing_tests.txt

- save_cache:
name: Save dependencies cache
paths:
- ~/.gradle
- ~/.konan
key: v2-dependencies-{{ checksum "/tmp/circleci_cache_key" }}
when: always

Expand All @@ -133,40 +166,24 @@ jobs:
name: jvm

steps:
- attach_workspace:
at: ~/project

- restore_cache:
name: Restore protobuf cache
keys:
- v3-protobuf-3.10.1

- run:
name: Run JVM conformance tests
command: |
export CONF_TEST_PATH=~/protobuf/conformance/conformance-test-runner
./conformance/test-conformance.sh jvm

- conformance_test:
target: jvm

conformance_js:
executor:
name: nodejs

steps:
- attach_workspace:
at: ~/project

- restore_cache:
name: Restore protobuf cache
keys:
- v3-protobuf-3.10.1
- conformance_test:
target: js

- run:
name: Run JS conformance tests
command: |
export CONF_TEST_PATH=~/protobuf/conformance/conformance-test-runner
./conformance/test-conformance.sh js
conformance_native:
executor:
name: native

steps:
- conformance_test:
target: linux

build_examples:
executor:
Expand Down Expand Up @@ -228,6 +245,9 @@ workflows:
- conformance_js:
requires:
- build
- conformance_native:
requires:
- build
- build_examples:
requires:
- build
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ It is built to work across multiple Kotlin platforms.
**Features**

* Clean data class generation
* Works for JVM and JS
* Works for JVM, JS and Native
* Support for proto2 and proto3 syntaxes
* Oneof's are properly handled as sealed classes
* Specialized support to handle wrappers from the well-known types (e.g. `StringValue`, `BoolValue`) as nullable primitives (`String?`, `Boolean?`, etc.)
Expand All @@ -21,8 +21,6 @@ It is built to work across multiple Kotlin platforms.

**Not Yet Implemented**

* Kotlin Native runtime support
* Protobuf code generator in Kotlin Native for easier importing
* Specialized support for more of the well known types (e.g. `Any`)
* Support for protobuf annotations
* Access to the protobuf descriptor from generated code
Expand Down Expand Up @@ -234,7 +232,15 @@ Then the dependency can be added for JVM libraries:

```
dependencies {
implementation 'com.github.streem.pbandk:pbandk-runtime-jvm:0.8.1'
implementation 'com.github.streem.pbandk:pbandk-runtime-jvm:0.9.0-SNAPSHOT'
}
```

or for the Native libraries:

```
dependencies {
implementation "com.github.streem.pbandk:pbandk-runtime-native:0.9.0-SNAPSHOT
}
```

Expand All @@ -253,7 +259,7 @@ runtime:

```
dependencies {
compileOnly 'com.github.streem.pbandk:protoc-gen-kotlin-lib-jvm:0.8.1'
compileOnly 'com.github.streem.pbandk:protoc-gen-kotlin-jvm:0.9.0-SNAPSHOT'
}
```

Expand Down Expand Up @@ -433,12 +439,10 @@ Set the `CONF_TEST_PATH` environment variable (used to run the tests below) with
export CONF_TEST_PATH="$(pwd)/conformance-test-runner"
```

Now, back in `pbandk`, build both the JS and JVM projects via:
Now, back in `pbandk`, build all JS. JVM and native projects via:

```
./gradlew \
:conformance:lib:assemble
:conformance:jvm:installDist
./gradlew :conformance:lib:assemble :conformance:jvm:installDist :conformance:native:build
```

You are now ready to run the conformance tests. Make sure `CONF_TEST_PATH` environment variable is set to `path/to/protobuf/conformance/conformance-test-runner` (see above).
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {

allprojects {
group = "com.github.streem.pbandk"
version = "0.8.2-SNAPSHOT"
version = "0.9.0-SNAPSHOT"

repositories {
jcenter()
Expand Down
45 changes: 45 additions & 0 deletions buildSrc/src/main/kotlin/KotlinProtocTask.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Console
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.Sync
import org.gradle.internal.os.OperatingSystem
import org.gradle.kotlin.dsl.property

@Suppress("UnstableApiUsage")
open class KotlinProtocTask : ProtocTask() {
@Input
@Optional
val kotlinPackage: Property<String> = project.objects.property()

@Input
@Optional
val jsonSupport: Property<Boolean> = project.objects.property<Boolean>().apply {
convention(true)
}

@Input
@Optional
val jsonUseProtoNames: Property<Boolean> = project.objects.property<Boolean>().apply {
convention(true)
}

@Console
val logLevel: Property<String> = project.objects.property()

private val protocGenKotlinInstallDir = project.project(":protoc-gen-kotlin:jvm").tasks
.named("installDist", Sync::class.java)
.map { it.destinationDir }

init {
inputs.dir(protocGenKotlinInstallDir)
plugin.set("kotlin")
pluginPath.set(project.layout.file(protocGenKotlinInstallDir.map {
it.resolve("bin/protoc-gen-kotlin" + ".bat".takeIf { OperatingSystem.current().isWindows }.orEmpty())
}))
pluginOptions.add(kotlinPackage.map { "kotlin_package" to it })
pluginOptions.add(logLevel.map { "log" to it })
pluginOptions.add(jsonSupport.map { "json_support" to it })
pluginOptions.add(jsonUseProtoNames.map { "json_use_proto_names" to it })
}
}
47 changes: 24 additions & 23 deletions buildSrc/src/main/kotlin/ProtocTask.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileCollection
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.*
import org.gradle.internal.os.OperatingSystem
import org.gradle.kotlin.dsl.listProperty
import org.gradle.kotlin.dsl.property

@Suppress("UnstableApiUsage")
Expand All @@ -15,15 +17,24 @@ open class ProtocTask : AbstractExecTask<ProtocTask>(ProtocTask::class.java) {

@Input
val protoc: Property<String> = project.objects.property<String>().apply {
convention("protoc")
convention(
project.providers.systemProperty("protoc.path")
.map { project.layout.projectDirectory.dir(it).file("bin/protoc") }
.map { it.asFile.absolutePath }
.orElse("protoc")
)
}

@Input
val plugin: Property<String> = project.objects.property()

@Input
@Optional
val kotlinPackage: Property<String> = project.objects.property()
val pluginOptions: ListProperty<Pair<Any, Any>> = project.objects.listProperty()

@Console
val logLevel: Property<String> = project.objects.property()
@InputFile
@Optional
val pluginPath: RegularFileProperty = project.objects.fileProperty()

private val protoFileDir: DirectoryProperty = project.objects.directoryProperty().apply {
convention(includeDir)
Expand All @@ -39,30 +50,20 @@ open class ProtocTask : AbstractExecTask<ProtocTask>(ProtocTask::class.java) {
this.include("*.proto")
}

private val protocGenKotlinInstallDir = project.project(":protoc-gen-kotlin:jvm").tasks
.named("installDist", Sync::class.java)
.map { it.destinationDir }

init {
inputs.dir(protocGenKotlinInstallDir)
}

override fun exec() {
executable = protoc.get()

// Build CLI args
val kotlinOut = listOfNotNull(
kotlinPackage.orNull.let { "kotlin_package=$it" },
logLevel.orNull.let { "log=$it" },
"json_use_proto_names=true",
"empty_arg:${outputDir.get()}"
args(
pluginOptions.orNull
?.takeUnless { it.isEmpty() }
?.joinToString(separator = ",", postfix = ":") { (k, v) -> "$k=$v" }
.let { "--${plugin.get()}_out=${it.orEmpty()}${outputDir.get()}" }
)
args(kotlinOut.joinToString(separator = ",", prefix = "--kotlin_out="))

val protocGenKotlinPath = protocGenKotlinInstallDir.get().resolve(
"bin/protoc-gen-kotlin" + ".bat".takeIf { OperatingSystem.current().isWindows }.orEmpty()
)
args("--plugin=protoc-gen-kotlin=$protocGenKotlinPath")
pluginPath.orNull?.let {
args("--plugin=protoc-gen-${plugin.get()}=${it.asFile.absolutePath}")
}

args("-I", includeDir.get())

Expand Down
30 changes: 19 additions & 11 deletions conformance/lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
Expand All @@ -18,11 +20,22 @@ kotlin {
nodejs {}
}

// For ARM, should be changed to iosArm32 or iosArm64
// For Linux, should be changed to e.g. linuxX64
// For MacOS, should be changed to e.g. macosX64
// For Windows, should be changed to e.g. mingwX64
// macosX64("macos")
macosX64("macos")
linuxX64("linux")
// Uncomment to enable Windows
// mingwX64("windows")

targets.withType<KotlinNativeTarget> {
val main by compilations.getting {
defaultSourceSet {
kotlin.srcDir("src/nativeMain/kotlin")
}
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:${Versions.kotlinSerialization}")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-native:${Versions.kotlinCoroutines}")
}
}
}

sourceSets {
val commonMain by getting {
Expand Down Expand Up @@ -70,16 +83,11 @@ kotlin {
implementation(kotlin("test-js"))
}
}

// sourceSets["macosMain"].dependencies {
// }
// sourceSets["macosTest"].dependencies {
// }
}
}

tasks {
val generateProto by registering(ProtocTask::class) {
val generateProto by registering(KotlinProtocTask::class) {
includeDir.set(project.file("src/commonMain/proto"))
outputDir.set(project.file("src/commonMain/kotlin"))
kotlinPackage.set("pbandk.conformance.pb")
Expand Down
Loading