mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 14:20:35 +01:00
[PR #1136] [CLOSED] C library for Pkl #908
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/apple/pkl/pull/1136
Author: @KushalP
Created: 7/22/2025
Status: ❌ Closed
Base:
main← Head:c-library📝 Commits (2)
bbe00d7C library for Pklbbb5a3dDocument howmessageis de/serialized📊 Changes
35 files changed (+2202 additions, -301 deletions)
View changed files
📝
.circleci/config.pkl(+5 -2)📝
.circleci/config.yml(+878 -60)📝
.circleci/jobs/BuildNativeJob.pkl(+13 -1)📝
buildSrc/src/main/kotlin/BuildInfo.kt(+26 -16)📝
buildSrc/src/main/kotlin/NativeImageBuild.kt(+61 -17)➕
buildSrc/src/main/kotlin/Target.kt(+82 -0)📝
buildSrc/src/main/kotlin/pklNativeExecutable.gradle.kts(+67 -136)📝
buildSrc/src/main/kotlin/pklNativeLifecycle.gradle.kts(+19 -50)📝
gradle/libs.versions.toml(+4 -0)➕
libpkl/gradle.lockfile(+73 -0)➕
libpkl/libpkl.gradle.kts(+258 -0)➕
libpkl/src/main/c/pkl.c(+141 -0)➕
libpkl/src/main/c/pkl.h(+85 -0)➕
libpkl/src/main/java/org/pkl/libpkl/LibPkl.java(+93 -0)➕
libpkl/src/main/java/org/pkl/libpkl/LibPklLogger.java(+29 -0)➕
libpkl/src/main/java/org/pkl/libpkl/NativeInputStream.java(+46 -0)➕
libpkl/src/main/java/org/pkl/libpkl/NativeTransport.java(+70 -0)➕
libpkl/src/main/java/org/pkl/libpkl/package-info.java(+4 -0)➕
libpkl/src/nativeTest/kotlin/org/pkl/libpkl/LibPklJNA.kt(+40 -0)➕
libpkl/src/nativeTest/kotlin/org/pkl/libpkl/LibPklMessageTransport.kt(+62 -0)...and 15 more files
📄 Description
This PR introduces native C bindings for Pkl. See: https://github.com/apple/pkl/issues/993
Dynamic Library
Using
org.graalvm.nativeimageand thenative-imagebinary we produce a dynamic-sharedlibrary (for each OS/Arch variant) that provides a way to initialise itself with agraal_isolatethread_t.Methods are annotated with
@CEntryPointand exported.This change results in an architecture and OS-specific directory being
created which now produces the headers for our shared library
functions:
Gradle Tasks
NativeImageBuildhas been extended to allow creating a shared library. Alongside this, a:libpkl:nativeTesttask has been creating which uses JNA to drive the dynamic library from Java.JNA
Testing of the produced
libpkldynamic library is done using Java Native Access for ease. We provide aninterfacein Kotlin which JNA transposes against thelibpkldynamic library discoverable at the path that is discoverable withjna.library.path.libpklThe produced
libpkldynamic library wraps the GraalVM C interface into something that is future-friendly for the needs of a Pkl integrator. It exports an interface which aligns with SPICE-0015.Note the last three items called out in the Dynamic Library section.
Outstanding tasks
There's work remaining before this can be merged.
graal_attach_threadbehaviourgraal_attach_thread(and related C methods) before eachpkl_send_message,pkl_version, andpkl_close-library_nameflag tonative-imageto not require a fully-qualified path for library inclusionlibpkl_internal.dylibandlibpkl.dylibinto a single artefact that is easier for users to consume aslibpkl.dylibpkl_version()much simpler, and get it to return a hard-coded string value that is automatically string replaced with the version on build🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.