-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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
Showing
124 changed files
with
641 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.