From 343b205a72df80d1d8db295b24aaf706b07c086b Mon Sep 17 00:00:00 2001 From: squid233 <60126026+squid233@users.noreply.github.com> Date: Wed, 23 Aug 2023 14:02:17 +0800 Subject: [PATCH] [STB] Prepare generator --- build.gradle.kts | 6 +++ modules/overrungl.opengl/build.gradle.kts | 10 +++- modules/overrungl.stb/build.gradle.kts | 18 +++++++ .../kotlin/overrungl/stb/STBGenerator.kt | 49 +++++++++++++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 modules/overrungl.stb/src/generator/kotlin/overrungl/stb/STBGenerator.kt diff --git a/build.gradle.kts b/build.gradle.kts index 0e6decf0..763eadde 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,5 @@ import org.gradle.plugins.ide.idea.model.IdeaModel +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import java.nio.file.Files import kotlin.io.path.Path @@ -7,6 +8,7 @@ plugins { `maven-publish` signing id("me.champeau.jmh") version "0.7.1" apply false + embeddedKotlin("jvm") apply false } val projGroupId: String by project @@ -22,6 +24,7 @@ val developers: String by project val jdkEABuildDoc: String? = "jdk21" val targetJavaVersion = 21 val enablePreview = true +rootProject.ext["enablePreview"] = enablePreview group = projGroupId version = projVersion @@ -118,6 +121,7 @@ enum class Artifact( } subprojects { + apply(plugin = "org.jetbrains.kotlin.jvm") apply(plugin = "java-library") apply(plugin = "idea") apply(plugin = "me.champeau.jmh") @@ -198,6 +202,8 @@ subprojects { } the().module.inheritOutputDirs = true + + the().jvmToolchain(20) } tasks.register("assembleJavadocArgs") { diff --git a/modules/overrungl.opengl/build.gradle.kts b/modules/overrungl.opengl/build.gradle.kts index 63e2c606..e8af8b79 100644 --- a/modules/overrungl.opengl/build.gradle.kts +++ b/modules/overrungl.opengl/build.gradle.kts @@ -1,10 +1,18 @@ +val enablePreview: Boolean by rootProject.ext + sourceSets { create("generator") } +tasks.named("compileGeneratorJava") { + javaCompiler.set(javaToolchains.compilerFor { + languageVersion.set(JavaLanguageVersion.of(20)) + }) +} + tasks.register("generate") { classpath(sourceSets["generator"].runtimeClasspath) - jvmArgs("--enable-preview") + if (enablePreview) jvmArgs("--enable-preview") mainClass.set("overrungl.opengl.OpenGLGenerator") workingDir = File("src/main/java/overrungl/opengl") } diff --git a/modules/overrungl.stb/build.gradle.kts b/modules/overrungl.stb/build.gradle.kts index e69de29b..53f2e952 100644 --- a/modules/overrungl.stb/build.gradle.kts +++ b/modules/overrungl.stb/build.gradle.kts @@ -0,0 +1,18 @@ +val enablePreview: Boolean by rootProject.ext + +sourceSets { + create("generator") +} + +tasks.named("compileGeneratorJava") { + javaCompiler.set(javaToolchains.compilerFor { + targetCompatibility = "20" + }) +} + +tasks.register("generate") { + classpath(sourceSets["generator"].runtimeClasspath) + if (enablePreview) jvmArgs("--enable-preview") + mainClass.set("overrungl.stb.STBGeneratorKt") + workingDir = File("src/main/java/overrungl/stb") +} diff --git a/modules/overrungl.stb/src/generator/kotlin/overrungl/stb/STBGenerator.kt b/modules/overrungl.stb/src/generator/kotlin/overrungl/stb/STBGenerator.kt new file mode 100644 index 00000000..9220e645 --- /dev/null +++ b/modules/overrungl.stb/src/generator/kotlin/overrungl/stb/STBGenerator.kt @@ -0,0 +1,49 @@ +/* + * MIT License + * + * Copyright (c) 2023 Overrun Organization + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + */ + +package overrungl.stb + +class Function { +} + +class STBClass { + private val functions = ArrayList() + + operator fun String.invoke(name: String) { + } + + fun generate() { + TODO() + } +} + +operator fun String.invoke(block: STBClass.() -> Unit) { + STBClass().also(block).generate() +} + +fun vorbis() { + "STBVorbis" { + "stb_vorbis_get_info"("getInfo") + } +} + +/** + * @author squid233 + * @since 0.1.0 + */ +fun main() { + vorbis() +}