Closed
Conversation
3e2d69e to
d97799b
Compare
Contributor
Author
|
I'm validating the interface here using For a language like Go, where Go routines can be moved across OS threads without the user knowing, it can lead to issues with the Graal C interfaces like: We don't want to expose the inner workings to users, so we need to be defensive to this case. |
bc9793b to
09cf391
Compare
Contributor
Author
|
Rebased against |
This introduces native C bindings for Pkl.
Dynamic Library
---------------
Using `org.graalvm.nativeimage` and the `native-image` binary we
produce a dynamic library (for each OS/Arch variant) that provides a
way to initialise itself with a `graal_isolatethread_t`.
Methods are annotated with `@CEntryPoint` and exported.
This change results in an architecture and OS-specific directory being
created which now produces the headers for our shared library
functions:
```
❯ ll libpkl/build/libs/macos-aarch64/
graal_isolate_dynamic.h
graal_isolate.h
libpkl-internal_dynamic.h
libpkl-internal-macos-aarch64_dynamic.h
libpkl-internal-macos-aarch64.dylib
libpkl-internal-macos-aarch64.h
libpkl-internal.dylib
libpkl-internal.h
```
`libpkl`
--------
The produced `libpkl` dynamic 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[1].
```
❯ ll libpkl/build/libs/macos-aarch64/
graal_isolate_dynamic.h
graal_isolate.h
libpkl-internal_dynamic.h
libpkl-internal-macos-aarch64_dynamic.h
libpkl-internal-macos-aarch64.dylib
libpkl-internal-macos-aarch64.h
libpkl-internal.dylib
libpkl-internal.h
libpkl.dylib <--- this is new
libpkl.h <--- this is new
```
JNA
---
Testing of the produced `libpkl` dynamic library is done using Java
Native Access[2] for ease. We provide an `interface` in Kotlin which
JNA transposes against the `libpkl` dynamic library discoverable at
the path that is discoverable with `jna.library.path`.
Load in `projects.pklCommonsCli` to deal with `UnsupportedFeatureException`
---------------------------------------------------------------------------
This is to deal with the following error:
```
Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Detected a started Thread in the image heap. Thread name: main. Threads running in the image generator are no longer running at image runtime. If these objects should not be stored in the image heap, you can use
'--trace-object-instantiation=java.lang.Thread'
```
[1] apple/pkl-evolution#16
Member
|
Closing this; work is continuing on #1238 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces native C bindings for Pkl. See: #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