Skip to content

Commit

Permalink
Setup compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
erwin-kok committed Dec 19, 2024
1 parent 934154d commit 116f12a
Show file tree
Hide file tree
Showing 18 changed files with 338 additions and 66 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: ci
on: [ push, pull_request ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
cache: 'gradle'

- name: Gradle build
run: ./gradlew build --no-daemon
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# KIK

[![ci](https://github.com/erwin-kok/kik/actions/workflows/ci.yaml/badge.svg)](https://github.com/erwin-kok/kik/actions/workflows/ci.yaml)
[![Kotlin](https://img.shields.io/badge/kotlin-2.1.0-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![License](https://img.shields.io/github/license/erwin-kok/kik.svg)](https://github.com/erwin-kok/kik/blob/master/LICENSE)

Experimental
11 changes: 10 additions & 1 deletion build-logic/src/main/kotlin/kik.common.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
idea
kotlin("jvm")
}

group = "org.erwinkok.kik"
version = "0.0.1"
version = "0.1.0"

tasks.test {
useJUnitPlatform()
}

tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}

tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_17.toString()
targetCompatibility = JavaVersion.VERSION_17.toString()
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask

plugins {
alias(libs.plugins.build.versions)
alias(libs.plugins.versions)
}

fun isNonStable(version: String): Boolean {
Expand Down
59 changes: 0 additions & 59 deletions gradle.txt

This file was deleted.

19 changes: 17 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
[versions]
kotlin = "2.0.21"
auto-service = "1.1.1"
auto-service-ksp = "1.2.0"
kotlin = "2.1.0"
kotlin-compile-testing = "0.7.0"

# Plugins
compatibility-plugin = "0.16.3"
ksp-plugin = "2.1.0-1.0.29"
versions-plugin = "0.51.0"

[libraries]
kotlin-compiler-embeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable", version.ref = "kotlin" }
kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }

auto-service = { module = "com.google.auto.service:auto-service", version.ref = "auto-service" }
auto-service-annotations = { module = "com.google.auto.service:auto-service-annotations", version.ref = "auto-service" }
auto-service-ksp = { module = "dev.zacsweers.autoservice:auto-service-ksp", version.ref = "auto-service-ksp" }
kotlin-compile-testing = { module = "dev.zacsweers.kctfork:core", version.ref = "kotlin-compile-testing" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }

[plugins]
build-versions = { id = "com.github.ben-manes.versions", version.ref = "versions-plugin" }
compatibility = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "compatibility-plugin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp-plugin" }
versions = { id = "com.github.ben-manes.versions", version.ref = "versions-plugin" }

39 changes: 39 additions & 0 deletions kik-compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
idea
kotlin("jvm") version "2.1.0"
alias(libs.plugins.ksp)
alias(libs.plugins.compatibility)
}

group = "org.erwinkok.kik"
version = "0.1.0"

repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("stdlib"))
implementation(gradleApi())
implementation(libs.kotlin.compiler.embeddable)
implementation(libs.auto.service)
implementation(libs.auto.service.annotations)
ksp(libs.auto.service.ksp)

testImplementation(libs.kotlin.compile.testing)
testImplementation(libs.kotlin.test)
}

tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}

tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_17.toString()
targetCompatibility = JavaVersion.VERSION_17.toString()
}
27 changes: 27 additions & 0 deletions kik-compiler-plugin/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@file:Suppress("UnstableApiUsage")

pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
mavenLocal()
}
}

dependencyResolutionManagement {
repositories {
gradlePluginPortal()
mavenCentral()
mavenLocal()
}

versionCatalogs {
create("libs") {
if (file("../gradle/libs.versions.toml").exists()) {
from(files("../gradle/libs.versions.toml"))
}
}
}
}

rootProject.name = "kik-compiler-plugin"
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@file:OptIn(ExperimentalCompilerApi::class)

package org.erwinkok.kik.compiler

import com.google.auto.service.AutoService
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
import org.jetbrains.kotlin.compiler.plugin.CliOption
import org.jetbrains.kotlin.compiler.plugin.CliOptionProcessingException
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.CompilerConfigurationKey
import kotlin.text.toBoolean

@AutoService(CommandLineProcessor::class)
class KikCommandLineProcessor : CommandLineProcessor {
companion object {
internal val KEY_ENABLED = CompilerConfigurationKey<Boolean>("Enable/disable the kik compiler plugin on the given compilation")
internal val KEY_DEBUG = CompilerConfigurationKey<Boolean>("Enable/disable debug logging on the given compilation")

val ENABLED_OPTION =
CliOption(
optionName = "enabled",
valueDescription = "<true | false>",
description = KEY_ENABLED.toString(),
required = true,
allowMultipleOccurrences = false,
)
val DEBUG_OPTION =
CliOption(
optionName = "debug",
valueDescription = "<true | false>",
description = KEY_DEBUG.toString(),
required = false,
allowMultipleOccurrences = false,
)
}

override val pluginId = "org.erwinkok.kik.kik-compiler-plugin"
override val pluginOptions = listOf(ENABLED_OPTION, DEBUG_OPTION)

override fun processOption(option: AbstractCliOption, value: String, configuration: CompilerConfiguration) = when (option) {
ENABLED_OPTION -> configuration.put(KEY_ENABLED, value.toBoolean())
DEBUG_OPTION -> configuration.put(KEY_DEBUG, value.toBoolean())
else -> throw CliOptionProcessingException("Unknown option: ${option.optionName}")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@file:OptIn(ExperimentalCompilerApi::class)

package org.erwinkok.kik.compiler

import com.google.auto.service.AutoService
import org.erwinkok.kik.compiler.KikCommandLineProcessor.Companion.KEY_ENABLED
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar.ExtensionStorage
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.CompilerConfiguration

@AutoService(CompilerPluginRegistrar::class)
class SerializationComponentRegistrar : CompilerPluginRegistrar() {
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
if (configuration[KEY_ENABLED] == false) {
return
}
}

override val supportsK2: Boolean
get() = true
}
29 changes: 29 additions & 0 deletions kik-gradle-plugin/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@file:Suppress("UnstableApiUsage")

pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
mavenLocal()
}
}

dependencyResolutionManagement {
repositories {
gradlePluginPortal()
mavenCentral()
mavenLocal()
}

versionCatalogs {
create("libs") {
if (file("../gradle/libs.versions.toml").exists()) {
from(files("../gradle/libs.versions.toml"))
}
}
}
}

rootProject.name = "kik-gradle-plugin"

include(":typesystem")
47 changes: 47 additions & 0 deletions kik-gradle-plugin/typesystem/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@file:Suppress("UnstableApiUsage")

import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
idea
kotlin("jvm") version "2.1.0"
id("java-gradle-plugin")
}

group = "org.erwinkok.kik.gradleplugin"
version = "0.1.0"

gradlePlugin {
website.set("https://github.com/erwin-kok/kik")
vcsUrl.set("https://github.com/erwin-kok/kik")
plugins {
create("kikCompilerPlugin") {
id = "org.erwinkok.kik.compiler-plugin"
implementationClass = "org.erwinkok.kik.compiler.gradleplugin.KikCompilerGradlePlugin"
displayName = "kik-compiler Gradle Plugin"
description = displayName
tags.set(listOf("http", "kotlin", "kotlin-mpp", "k8s"))
}
}
}

dependencies {
implementation(kotlin("stdlib"))
implementation(gradleApi())
}

dependencies {
add("compileOnly", kotlin("gradle-plugin"))
}

tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}

tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_17.toString()
targetCompatibility = JavaVersion.VERSION_17.toString()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.erwinkok.kik.compiler.gradleplugin

enum class ErrorCheckingMode {
NONE,
WARNING,
ERROR,
}

open class KikCompilerGradleConfiguration {
var generateQualifiedTypeName: Boolean = false
var errorCheckingMode: ErrorCheckingMode = ErrorCheckingMode.ERROR
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2024. Erwin Kok. Apache License. See LICENSE file for more details.
package org.erwinkok.kik.compiler.gradleplugin

import org.gradle.api.Plugin
import org.gradle.api.Project
import kotlin.jvm.java

class KikCompilerGradlePlugin : Plugin<Project> {
override fun apply(project: Project) {
with(project) {
extensions.create("kikCompiler", KikCompilerGradleConfiguration::class.java)
pluginManager.apply(KikCompilerSubPlugin::class.java)
}
}
}
Loading

0 comments on commit 116f12a

Please sign in to comment.