Skip to content

Commit 55ab7f4

Browse files
committed
Add guide section about platform-dependent nature of jextract
Reviewed-by: mcimadamore
1 parent 1cc982b commit 55ab7f4

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Jextract
22

3-
`jextract` is a tool which mechanically generates Java bindings from a native library headers. This tools leverages the [clang C API](https://clang.llvm.org/doxygen/group__CINDEX.html) in order to parse the headers associated with a given native library, and the generated Java bindings build upon the [Foreign Function & Memory API](https://openjdk.java.net/jeps/454). The `jextract` tool was originally developed in the context of [Project Panama](https://openjdk.java.net/projects/panama/) (and then made available in the Project Panama [Early Access binaries](https://jdk.java.net/panama/)).
3+
`jextract` is a tool which mechanically generates Java bindings from native library headers. This tools leverages the [clang C API](https://clang.llvm.org/doxygen/group__CINDEX.html) in order to parse the headers associated with a given native library, and the generated Java bindings build upon the [Foreign Function & Memory API](https://openjdk.java.net/jeps/454). The `jextract` tool was originally developed in the context of [Project Panama](https://openjdk.java.net/projects/panama/) (and then made available in the Project Panama [Early Access binaries](https://jdk.java.net/panama/)).
44

55
:bulb: For instruction on how to use the jextract tool, please refer to the guide [here](doc/GUIDE.md).
66

doc/GUIDE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,29 @@ function pointer types, and typedefs of struct or union types result in addition
8585
being generated. (All of these are discussed in more detail in the
8686
[Using The Code Generated By Jextract section](#using-the-code-generated-by-jextract)).
8787

88+
Generally speaking, the bindings generated by jextract depend on the platform on which
89+
jextract is running. For example, when a C header file is processed by the C pre-processor,
90+
it is possible for code in the header file to detect the current platform using
91+
pre-processor directives, and expand to a different result based on that platform (see
92+
also the section on [pre-processor definitions](#preprocessor-definitions)). Additionally,
93+
different built in C types can have different formats depending on the platform (for
94+
example, the `long` type has different formats on Linux and Windows). Both of these are
95+
examples of things that can lead jextract to generate different outputs depending on the
96+
platform on which it is run. Care should be taken when generating bindings with jextract
97+
on one platform, and using those bindings on another platform, as the header files may
98+
contain platform-dependent code that can cause the generated code to misbehave when used
99+
on another platform.
100+
101+
However, it is also possible for a C library to be written in such a way that it is not
102+
platform dependent: a so-called _portable_ library. These libraries, for instance, use
103+
data types that have the same format on all supported platforms (such as `long long`
104+
instead of `long`, or an explicitly-sized integer type such as `int64_t`). Sharing the
105+
bindings generated for a portable library across different platforms should work without
106+
issues. It is typically advisable to generate different sets of bindings, one on each
107+
platform on which the bindings are intended to be used, and then comparing the generated
108+
code to make sure that there are no differences between platforms, before sharing a single
109+
set of bindings between different platforms.
110+
88111
Jextract assumes that the version of a native library that a project uses is relatively stable.
89112
Therefore, jextract is intended to be run once, and then for the generated sources to be added to the project.
90113
Jextract only needs to be run again when the native library, or jextract itself are updated.

0 commit comments

Comments
 (0)