JNA
sokol-zig
Our great sponsors
JNA | sokol-zig | |
---|---|---|
22 | 9 | |
8,247 | 277 | |
0.7% | - | |
7.8 | 9.0 | |
24 days ago | 1 day ago | |
Java | C | |
GNU General Public License v3.0 or later | - |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
JNA
-
FFM (Foreign Function and Memory API) Goes Final
As far as I understand it, with JNA, all calls into C code go through libffi: https://github.com/java-native-access/jna/blob/master/www/Fu...
This means that every call sets up some libffi data structures and libffi uses this information to perform the native call. Likewise in the other direction for return values. With JNI (and Panama), Hotspot can directly emit the argument/return code a the call, not too dissimilar from what a C or C++ compiler would do. There is still some overhead from maintaining JVM invariants. For example, I think a thread blocked in an FFI call can still participate in a safepoint. But that applies to JNI as well.
- Projetos em Java -- Por que vocĂȘ ou sua equipe escolheram a linguagem Java?
-
Are there any Non-Mobile Kotlin Native libraries wrapping C libraries like libhidapi/opengl?
If you were prepared to go to the JVM you might try JNA. https://github.com/java-native-access/jna
-
How to create fundamental libraries for my language?
Other good example, but for Java platform is JNA library. Do not mix it with Java's JNI, which is a bad example of how it could be done.
-
Rust vs Java for simple small GUI apps
In case you haven't used it (assuming that you already know about JNI, for comparison) - https://github.com/java-native-access/jna is about as easy as it gets for native interop. Also, as mentioned in another comment, with the Java FFM (Foreign Function and Memory) API already in preview mode, pretty soon, there will be no external dependencies at all, and Java should be able to interop with any language that can talk to C.
- Kotlin/Native
-
Does Java 18 finally have a better alternative to JNI?
The complexity of JNI has given rise to some community-driven libraries that make it simpler to do FFI in Java. Java Native Access (JNA) is one of them. It's built on top of JNI and at least makes FFI easier to use, especially as it removes the need to write any C binding code manually and reduces the chances of memory safety issues. Still, it has some of the disadvantages of being JNI-based and is slightly slower than JNI in many cases. However, JNA is widely used and battle-tested, so definitely a better option than using JNI directly.
-
JEP 419: Foreign Function and Memory API
This is about calling into any native operating system APIs, as long as they are callable via C or C++ (which these days means "all" operating system APIs).
JNI is somewhat harder to use, because you need custom glue on both sides of the border: Some custom classes in Java and some custom code on the C (and C++) side.
This proposal would remove the need for the glue on the C side and would allow a pure java solution.
Something like this has existed in third-party form for a while as JNA (https://github.com/java-native-access/jna), but now it's going to be built into the JRE itself (if the proposal passes through review)
- How run ToS on MacOSX as a java command?
-
Choosing Java as your language for a Machine Learning project
I use JNA https://github.com/java-native-access/jna , as you can write the entire interface in Java faster as well as easier without the need of messing with the complexities of JNI.
sokol-zig
-
Zig cookbook: collection of simple Zig programs that demonstrate good practices
Zig currently doesn't allow chained designators and also doesn't allow to partially initialize arrays and fill up the rest of the array with default values.
E.g. the closest Zig equivalent to this C99 code:
https://github.com/floooh/sokol-samples/blob/b3bc55c4411fa03...
...is this:
https://github.com/floooh/sokol-zig/blob/a4b3c287fadd153a504...
...note how part of the initialization had to be moved out into "code".
There's a ticket about this here, but it's currently not high-priority:
https://github.com/ziglang/zig/issues/6068
-
Nim v2.0 Released
I maintain auto-generated bindings for my C libraries for Zig and Nim (and Odin and Rust - although the Rust bindings definitely need some love to make them a lot more idiomatic).
I think looking at the examples (which is essentially the same code in different languages) gives you a high level idea, but they only scratch the surface when it comes to language features (things like the Zig code not using comptime features):
Zig: https://github.com/floooh/sokol-zig/tree/master/src/examples
Nim: https://github.com/floooh/sokol-nim/tree/master/examples
Odin: https://github.com/floooh/sokol-odin/tree/main/examples
Rust: https://github.com/floooh/sokol-rust/tree/main/examples
-
Zig Build System
IMHO you really need a programming language to describe a build, even when the result looks very declarative.
E.g. not sure how Meson handles this, but when I have a project with dozens of similar build targets and platform specific compile options, I really want to do the build description in a loop instead of a data tree.
(for example: https://github.com/floooh/sokol-zig/blob/3f978e58712f9eb029b...)
- Zig and WASM
-
Mach v0.1 - cross-platform Zig graphics in ~60 seconds
Is this project comparable to the zig sokol project?https://github.com/floooh/sokol-zig
-
How does zig magically cross compile without target shared libraries
I was rather amazed that I could cross-compile the zig-sokol examples https://github.com/floooh/sokol-zig for a Windows target on a Linux host (WSL Ubuntu). I simply set -target x86_64-windows and copied the executable into Windows and got a nice spinning cube displayed.
-
Mach Engine: The Future of Graphics (With Zig)
(disclaimer: shameless plug) Here's another cross-platform alternative, auto-generated Zig bindings to the Sokol headers:
https://github.com/floooh/sokol-zig
This is quite a bit slimmer than using one of the WebGPU libraries like wgpu-rs or Dawn, because sokol-gfx doesn't need an integrated shader cross-compiler (instead translation from a common shader source to the backend-specific shader formats happens offline).
Eventually I'd also like to support the Android, iOS and WASM backends from Zig (currently this only works from C/C++, for instance here are the WASM demos: https://floooh.github.io/sokol-html5/)
-
Making Win32 APIs More Accessible to More Languages
I'm tackling this issue from two sides:
(1) Change the C-API to make it more "binding-generator-friendly", for instance by adding a range/slice-struct to th C-API which bundles a pointer and associated size, or specially named typedefs that only exist to give the binding generator hints for special case handling.
(2) Make the bindings-generator configurable on a per-language and per-API basis, this can be as simple as a map which overrides type- and function-names, or injects manually written code into the generated bindings.
The goal is to make the generated bindings more idiomatic to the target language.
This mostly works if you have control over the underlying C-API of course, e.g. the language bindings are created by the original C-library project, not as an external project to convert a fixed C-API.
I wrote a blog post about this whole topic:
https://floooh.github.io/2020/08/23/sokol-bindgen.html
...and here's an example of one such semi-auto-generated Zig bindings, note the two "injected" helper functions at the top:
https://github.com/floooh/sokol-zig/tree/master/src/sokol
...for instance note the "injected" helper functions here:
https://github.com/floooh/sokol-zig/blob/1c93f60ad178869b84d...
-
Game Development
As you can see from the comments there are lots of options. Sokol is another one https://github.com/floooh/sokol-zig
What are some alternatives?
JNR - Java Abstracted Foreign Function Layer
zig-bgfx-sdl2 - Minimal zig project to get bgfx running with sdl2
JavaCPP - The missing bridge between Java and native C++
bigger - bigg (bgfx + imgui + glfw + glm) + utils
SWIG - SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages.
sokol-samples - Sample code for https://github.com/floooh/sokol
panama-foreign - https://openjdk.org/projects/panama
go - The Go programming language
rust-bindgen - Automatically generates Rust FFI bindings to C (and some C++) libraries.
ffmpeg - FFmpeg Zig package
Introducing .NET Multi-platform App UI (MAUI) - .NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
liwords - A site that allows people to play a crossword board game against each other