Skip to content

Commit

Permalink
Version 1.16.1:
Browse files Browse the repository at this point in the history
- Remove dependency on Java-GI functionality. Add base interop functionality in new package io.github.jwharm.cairobindings.
- Rename base class from ProxyInstance to Proxy
- Fix handling of empty String parameters
- Cleanup build structure and gradle build files
- Add toolchain resolver convention plugin
- Change FTSynthesize to a record class
- Change tests of PDF, PS and SVG Surfaces to use null instead of empty String
- Upgrade gradle wrapper to 8.3
  • Loading branch information
jwharm committed Sep 2, 2023
1 parent 3f98099 commit c7d6dc2
Show file tree
Hide file tree
Showing 124 changed files with 641 additions and 269 deletions.
70 changes: 70 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
plugins {
id 'java-library'
id 'maven-publish'
}

group = "io.github.jwharm.cairo-java-bindings"
version = "1.16.1"

repositories {
mavenCentral()
}

dependencies {
testImplementation "org.junit.jupiter:junit-jupiter:5.9.2"
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(20)
}
withSourcesJar()
withJavadocJar()
}

tasks.named('compileJava') {
options.compilerArgs += "--enable-preview"
}

tasks.named('javadoc') {
options.addBooleanOption("-enable-preview", true)
options.addStringOption("-release", "20")
}

tasks.named('compileTestJava') {
options.compilerArgs += '--enable-preview'
}

tasks.named('test') {
useJUnitPlatform()
jvmArgs += "--enable-preview"
jvmArgs += "--enable-native-access=ALL-UNNAMED"
systemProperty 'java.library.path','/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib:/lib/x86_64-linux-gnu'
}

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
pom {
groupId = 'io.github.jwharm.cairobindings'
description = 'Java language bindings for cairo'
url = 'https://github.com/jwharm/cairo-java-bindings/'
licenses {
license {
name = 'GNU Lesser General Public License, version 2.1'
url = 'https://www.gnu.org/licenses/lgpl-2.1.txt'
}
}
developers {
developer {
id = 'jwharm'
name = 'Jan-Willem Harmannij'
url = 'https://github.com/jwharm'
}
}
}
}
}
}
49 changes: 0 additions & 49 deletions cairo/build.gradle

This file was deleted.

13 changes: 0 additions & 13 deletions cairo/src/main/java/module-info.java

This file was deleted.

Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 8 additions & 4 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum

Expand Down Expand Up @@ -133,10 +130,13 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
Expand Down Expand Up @@ -197,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
2 changes: 0 additions & 2 deletions jitpack.yml

This file was deleted.

7 changes: 5 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
rootProject.name="cairo"
include("cairo")
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.6.0'
}

rootProject.name = 'cairo'
46 changes: 46 additions & 0 deletions src/main/java/io/github/jwharm/cairobindings/Interop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.github.jwharm.cairobindings;

import java.lang.foreign.*;
import java.lang.invoke.*;

/**
* The Interop class contains functionality for interoperability with native code.
*/
public final class Interop {

private final static SymbolLookup symbolLookup;
private final static Linker linker = Linker.nativeLinker();

static {
SymbolLookup loaderLookup = SymbolLookup.loaderLookup();
symbolLookup = name -> loaderLookup.find(name).or(() -> linker.defaultLookup().find(name));
}

// Prevent instantiation
private Interop() {}

/**
* Creates a method handle that is used to call the native function with
* the provided name and function descriptor. The method handle is cached
* and reused in subsequent lookups.
* @param name Name of the native function
* @param fdesc Function descriptor of the native function
* @return the MethodHandle
*/
public static MethodHandle downcallHandle(String name, FunctionDescriptor fdesc) {
return symbolLookup
.find(name)
.map(addr -> linker.downcallHandle(addr, fdesc))
.orElse(null);
}

/**
* Allocate a native string using SegmentAllocator.allocateUtf8String(String).
* @param string the string to allocate as a native string (utf8 char*)
* @param allocator the segment allocator to use
* @return the allocated MemorySegment
*/
public static MemorySegment allocateNativeString(String string, SegmentAllocator allocator) {
return string == null ? MemorySegment.NULL : allocator.allocateUtf8String(string);
}
}
72 changes: 72 additions & 0 deletions src/main/java/io/github/jwharm/cairobindings/LibLoad.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package io.github.jwharm.cairobindings;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;

/**
* The LibLoad class is used internally to load native libraries by name
*/
public final class LibLoad {

static {
String javagiPath = System.getProperty("javagi.path");
String javaPath = System.getProperty("java.library.path");
if (javagiPath != null) {
if (javaPath == null) {
System.setProperty("java.library.path", javagiPath);
} else {
System.setProperty("java.library.path", javaPath + File.pathSeparator + javagiPath);
}
}
}

// Prevent instantiation
private LibLoad() {}

/**
* Load the native library with the provided name
* @param name the name of the library
*/
public static void loadLibrary(String name) {
RuntimeException fail = new RuntimeException("Could not load library " + name);
try {
System.loadLibrary(name);
return;
} catch (Throwable t) {
fail.addSuppressed(t);
}
for (String s : System.getProperty("java.library.path").split(File.pathSeparator)) {
if (s.isBlank()) {
continue;
}

Path pk = Path.of(s).toAbsolutePath().normalize();
if (!Files.isDirectory(pk)) {
continue;
}

Path[] paths;
try (Stream<Path> p = Files.list(pk)) {
paths = p.toArray(Path[]::new);
} catch (Throwable t) {
fail.addSuppressed(t);
continue;
}

for (Path path : paths) {
try {
String fn = path.getFileName().toString();
if (fn.equals(name)) {
System.load(path.toString());
return;
}
} catch (Throwable t) {
fail.addSuppressed(t);
}
}
}
throw fail;
}
}
Loading

0 comments on commit c7d6dc2

Please sign in to comment.