Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C library for Pkl #1026

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft

C library for Pkl #1026

wants to merge 15 commits into from

Conversation

KushalP
Copy link
Contributor

@KushalP KushalP commented Mar 18, 2025

This introduces native C bindings for Pkl.

Follows SPICE-0015

@KushalP KushalP force-pushed the c-library-for-pkl branch 7 times, most recently from 80a0c54 to 3e26bbb Compare March 25, 2025 14:26
KushalP added 15 commits April 4, 2025 14:10
The `assembleNative` target builds out a shared library for each of
the OS/Arch variants we need.
Make sure that `graal_isolate.h` and `graal_isolate_dynamic.h` are
tracked as output files.

Extension adjustment
--------------------

`native-image` will add an extension to the filename provided `-o`. We
need to make sure that we track this correctly for each OS, and remove
the extension when we provide it to `native-image`.
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-macos-aarch64_dynamic.h
libpkl-macos-aarch64.dylib
libpkl-macos-aarch64.h
```
Has a default value with `convention` on `init { ... }`.
`NativeInputStream` lets our encoder/decoder use the correct
implementation within MsgPack.
…ption`

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'
```
As a demonstration of how to build a shared library together with our
`native-image` shared library, use the following locally:

```
❯ gradle :libpkl:assembleNative

❯ clang -v -shared \
    -o libpkl.dylib \
    libpkl/src/main/c/libpkl.c \
    -Ilibpkl/src/main/c \
    -Ilibpkl/build/libs/macos-aarch64 \
    -Llibpkl/build/libs/macos-aarch64 \
    -lpkl-macos-aarch64
```
This is close to a demo of what this could look like.
@KushalP KushalP force-pushed the c-library-for-pkl branch from 56c8534 to 1226e49 Compare April 4, 2025 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant