Skip to content

Commit

Permalink
Update build scripts and Marshal
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Feb 2, 2024
1 parent d9e2876 commit 53f5c4e
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 53 deletions.
48 changes: 11 additions & 37 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import org.gradle.plugins.ide.idea.model.IdeaModel
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.nio.file.Files
import kotlin.io.path.Path

Expand All @@ -8,7 +7,6 @@ plugins {
`maven-publish`
signing
id("me.champeau.jmh") version "0.7.2" apply false
embeddedKotlin("jvm") apply false
}

val projGroupId: String by project
Expand All @@ -29,8 +27,6 @@ val kotlinTargetJdkVersion: String by rootProject

val targetJavaVersion = jdkVersion.toInt()

val overrunMarshalVersion: String by rootProject

group = projGroupId
version = projVersion

Expand Down Expand Up @@ -122,23 +118,19 @@ enum class Artifact(
}
}

Artifact.values().forEach { project(it.subprojectName).ext["subName"] = "-${it.subprojectName.substring(1)}" }
project(Artifact.CORE.subprojectName).ext["subName"] = ""
project(":samples").ext["subName"] = "-samples"
val artifactNameMap = buildMap {
Artifact.values().forEach { put(it.subprojectName, it.artifactName) }
put(":samples", "overrungl-samples")
}

buildList {
addAll(Artifact.values().map { it.subprojectName })
add(":samples")
}.forEach {
project(it) {
apply(plugin = "org.jetbrains.kotlin.jvm")
artifactNameMap.forEach { (subprojectName, artifactName) ->
project(subprojectName) {
apply(plugin = "java-library")
apply(plugin = "idea")
apply(plugin = "me.champeau.jmh")

group = projGroupId
version = projVersion
val artifactName = "$projArtifactId${ext["subName"]}"

repositories {
mavenCentral()
Expand All @@ -148,15 +140,12 @@ buildList {
maven { url = uri("https://maven.aliyun.com/repository/central") }
}

val annotationProcessor by configurations
val api by configurations
val compileOnly by configurations
val implementation by configurations
dependencies {
compileOnly("org.jetbrains:annotations:24.1.0")
api("io.github.over-run:marshal:$overrunMarshalVersion")
if (project.name != "core") {
implementation(project(Artifact.CORE.subprojectName))
compileOnly(project(Artifact.CORE.subprojectName))
constraints { api("io.github.over-run:overrungl:$projVersion") }
}
}

Expand All @@ -166,10 +155,6 @@ buildList {
options.release.set(targetJavaVersion)
}

tasks.withType<KotlinCompile> {
kotlinOptions { jvmTarget = kotlinTargetJdkVersion }
}

tasks.withType<Test> {
if (jdkEnablePreview.toBoolean()) jvmArgs("--enable-preview")
}
Expand Down Expand Up @@ -329,16 +314,14 @@ publishing.publications {
version = projVersion
description = module.projectDescription
project(module.subprojectName) {
artifact(tasks["jar"])
artifact(tasks["sourcesJar"]) { classifier = "sources" }
artifact(tasks["javadocJar"]) { classifier = "javadoc" }
from(components["java"])
}
module.nativeBinding?.platforms?.forEach {
val nativeName = module.nativeFileName(it)!!
val file = File("${rootProject.projectDir}/natives/$nativeName")
if (file.exists()) {
val nativeParent = File(nativeName).parent
artifact(tasks.create<Jar>("nativeJar${module.mavenName}${it.taskSuffix}") {
artifact(tasks.register<Jar>("nativeJar${module.mavenName}${it.taskSuffix}") {
archiveBaseName.set(module.artifactName)
archiveClassifier.set(it.classifier)
from(file) { into(nativeParent) }
Expand All @@ -347,16 +330,6 @@ publishing.publications {
}
pom {
setupPom(module.projectName, module.projectDescription, "jar")
if (module != Artifact.CORE) {
withXml {
asNode().appendNode("dependencies").appendNode("dependency").apply {
appendNode("groupId", "io.github.over-run")
appendNode("artifactId", "overrungl")
appendNode("version", projVersion)
appendNode("scope", "compile")
}
}
}
}
}
}
Expand Down Expand Up @@ -421,6 +394,7 @@ publishing.repositories {
else "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
)
}
mavenLocal()
}

signing {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ jdkEnablePreview=true
jdkEarlyAccessDoc=jdk22
kotlinTargetJdkVersion=21

overrunMarshalVersion=0.1.0-alpha.15-jdk22
overrunMarshalVersion=0.1.0-alpha.17-jdk22
overrunPlatformVersion=1.0.0
2 changes: 2 additions & 0 deletions modules/overrungl.core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
val overrunMarshalVersion: String by rootProject
val overrunPlatformVersion: String by rootProject

dependencies {
api("io.github.over-run:marshal:$overrunMarshalVersion")
api("io.github.over-run:platform:$overrunPlatformVersion")
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandles;

import static java.lang.foreign.ValueLayout.*;
import static overrungl.glfw.Handles.*;
Expand All @@ -43,7 +44,7 @@ public interface GLFW {
/**
* The instance of GLFW.
*/
GLFW INSTANCE = Downcall.load(lookup);
GLFW INSTANCE = Downcall.load(MethodHandles.lookup(), lookup);

/**
* The major version number of the GLFW header.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import overrun.marshal.gen.Type;

import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandles;

/**
* This is the header file of the native access functions.
Expand All @@ -39,7 +40,7 @@ public interface GLFWNative {
/**
* The instance of GLFWNative.
*/
GLFWNative INSTANCE = Downcall.load(Handles.lookup);
GLFWNative INSTANCE = Downcall.load(MethodHandles.lookup(), Handles.lookup);

/**
* Returns the adapter device name of the specified monitor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import overrun.marshal.gen.Type;

import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandles;

/**
* The GLFW Vulkan binding.
Expand All @@ -34,7 +35,7 @@ public interface GLFWVulkan {
/**
* The instance of GLFWVulkan.
*/
GLFWVulkan INSTANCE = Downcall.load(Handles.lookup);
GLFWVulkan INSTANCE = Downcall.load(MethodHandles.lookup(), Handles.lookup);

/**
* Returns the address of the specified Vulkan instance function.
Expand Down
3 changes: 2 additions & 1 deletion modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.util.Map;

import static java.lang.foreign.ValueLayout.*;
Expand Down Expand Up @@ -131,7 +132,7 @@ public interface NFD {
/**
* The instance of NFD.
*/
NFD INSTANCE = Downcall.load(NFDInternal.LOOKUP, Map.of(
NFD INSTANCE = Downcall.load(MethodHandles.lookup(), NFDInternal.LOOKUP, Map.of(
"NFD_PathSet_GetPathN", FunctionDescriptor.of(JAVA_INT, ADDRESS, PATH_SET_SIZE, ADDRESS),
"NFD_PathSet_FreePathN", FunctionDescriptor.ofVoid(ADDRESS),
"NFD_FreePathU8", FunctionDescriptor.ofVoid(ADDRESS),
Expand Down
10 changes: 10 additions & 0 deletions modules/overrungl.opengl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
embeddedKotlin("jvm") apply false
}

val jdkVersion: String by rootProject
val jdkEnablePreview: String by rootProject
val kotlinTargetJdkVersion: String by rootProject
Expand All @@ -6,6 +12,10 @@ sourceSets {
create("generator")
}

tasks.withType<KotlinCompile> {
kotlinOptions { jvmTarget = kotlinTargetJdkVersion }
}

tasks.named<JavaCompile>("compileGeneratorJava") {
javaCompiler.set(javaToolchains.compilerFor {
targetCompatibility = kotlinTargetJdkVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.MethodHandles;
import java.util.Map;

/**
Expand Down Expand Up @@ -49,6 +50,7 @@ public final class GLLoader {
"glMapNamedBuffer", FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT),
"glMapNamedBufferRange", FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_LONG, ValueLayout.JAVA_LONG, ValueLayout.JAVA_INT)
);
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();

/**
* Loads OpenGL flags.
Expand All @@ -68,7 +70,7 @@ public static GLFlags loadFlags(GLLoadFunc load) {
*/
@Nullable
public static GL load(GLFlags flags) {
return flags.GL10 ? Downcall.load(GL.class, flags.load.lookup(), DESCRIPTOR_MAP) : null;
return flags.GL10 ? Downcall.load(LOOKUP, GL.class, flags.load.lookup(), DESCRIPTOR_MAP) : null;
}

/**
Expand All @@ -79,7 +81,7 @@ public static GL load(GLFlags flags) {
*/
@Nullable
public static GLLegacy loadLegacy(GLFlags flags) {
return flags.GL10 ? Downcall.load(GLLegacy.class, flags.load.lookup(), DESCRIPTOR_MAP) : null;
return flags.GL10 ? Downcall.load(LOOKUP, GLLegacy.class, flags.load.lookup(), DESCRIPTOR_MAP) : null;
}

/**
Expand All @@ -90,6 +92,6 @@ public static GLLegacy loadLegacy(GLFlags flags) {
*/
@Nullable
public static GLExtension loadExtension(GLFlags flags) {
return flags.foundExtension ? Downcall.load(GLExtension.class, flags.load.lookup(), DESCRIPTOR_MAP) : null;
return flags.foundExtension ? Downcall.load(LOOKUP, GLExtension.class, flags.load.lookup(), DESCRIPTOR_MAP) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import overrun.marshal.gen.Sized;

import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandles;

/**
* Easy-to-deploy,
Expand Down Expand Up @@ -58,7 +59,7 @@ interface STBEasyFont {
/**
* The instance of STBEasyFont.
*/
STBEasyFont INSTANCE = Downcall.load(Handles.lookup);
STBEasyFont INSTANCE = Downcall.load(MethodHandles.lookup(), Handles.lookup);

/**
* {@return spacing}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.lang.foreign.MemorySegment;
import java.lang.foreign.SegmentAllocator;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.MethodHandles;

/**
* The STB image reader.
Expand All @@ -36,7 +37,7 @@ public interface STBImage {
/**
* The instance of STBImage.
*/
STBImage INSTANCE = Downcall.load(Handles.lookup);
STBImage INSTANCE = Downcall.load(MethodHandles.lookup(), Handles.lookup);
// only used for desiredChannels
/**
* Image channels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import overrungl.NativeType;

import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandles;

/**
* The STB image resizer.
Expand All @@ -32,7 +33,7 @@ public interface STBImageResize2 {
/**
* The instance of STBImageResize2.
*/
STBImageResize2 INSTANCE = Downcall.load(Handles.lookup);
STBImageResize2 INSTANCE = Downcall.load(MethodHandles.lookup(), Handles.lookup);

//===============================================================
// Simple-complexity API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.SegmentAllocator;
import java.lang.invoke.MethodHandles;

/**
* The STB image writer.
Expand All @@ -36,7 +37,7 @@ public interface STBImageWrite {
/**
* The instance of STBImageWrite.
*/
STBImageWrite INSTANCE = Downcall.load(Handles.lookup);
STBImageWrite INSTANCE = Downcall.load(MethodHandles.lookup(), Handles.lookup);

@Convert(Type.INT)
@Entrypoint("stbi_get_write_tga_with_rle")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import overrun.marshal.Downcall;
import overrun.marshal.gen.Entrypoint;

import java.lang.invoke.MethodHandles;

/**
* The STB perlin noise generator.
*
Expand All @@ -29,7 +31,7 @@ public interface STBPerlin {
/**
* The instance of STBPerlin.
*/
STBPerlin INSTANCE = Downcall.load(Handles.lookup);
STBPerlin INSTANCE = Downcall.load(MethodHandles.lookup(), Handles.lookup);

/**
* This function computes a random value at the coordinate (x,y,z).<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import overrun.marshal.Downcall;
import overrun.marshal.gen.Entrypoint;

import java.lang.invoke.MethodHandles;

/**
* Useful for e.g. packing rectangular textures into an atlas.
* Does not do rotation.
Expand All @@ -32,7 +34,7 @@ public interface STBRectPack {
/**
* The instance of STBRectPack.
*/
STBRectPack INSTANCE = Downcall.load(Handles.lookup);
STBRectPack INSTANCE = Downcall.load(MethodHandles.lookup(), Handles.lookup);
/**
* Mostly for internal use, but this is the maximum supported coordinate value.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import overrungl.NativeType;

import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandles;

/**
* =======================================================================
Expand Down Expand Up @@ -312,7 +313,7 @@ public interface STBTrueType {
/**
* The instance of STBTrueType.
*/
STBTrueType INSTANCE = Downcall.load(Handles.lookup);
STBTrueType INSTANCE = Downcall.load(MethodHandles.lookup(), Handles.lookup);
/**
* STBTT_vmove
*/
Expand Down
Loading

0 comments on commit 53f5c4e

Please sign in to comment.