Minimal JNI bindings for libsodium
This project provides JNI bindings for some libsodium methods.
It's used by Scala CLI to encode repository secrets about to be uploaded to GitHub via the GitHub API. For now, it only exposes libsodium methods that Scala CLI needs.
The motivation for writing libsodiumjni, rather than using any of the existing JNA-based bindings, is mainly using JNI rather than JNA to interface with libsodium, as JNI is supported from GraalVM native images, while JNA is not.
libsodiumjni is built with Mill.
Compile everything with
$ ./mill __.compile
The Mill build automatically compile the C bindings, and generates a .so
/ .dylib
/ .dll
. These files are also built on the CI, and pushed to Maven Central (see below).
libsodiumjni is pushed to Maven Central. Add it in a Mill module with
def ivyDeps = super.ivyDeps() ++ Seq(
ivy"io.github.alexarchambault.tmp.libsodiumjni:libsodiumjni:0.0.2"
)
Both static and dynamic libraries are also pushed as is to Maven Central (see the .so
/ .dylib
/ .dll
and .a
/ .lib
files here for example). From the command line, you can fetch those files with commands such as
$ cs fetch --intransitive io.github.alexarchambault.tmp.libsodiumjni:libsodiumjni:0.0.2,classifier=x86_64-pc-win32,ext=dll,type=dll -A dll
Typical workflow:
- add a
native
method inSodiumApi.java
- run
./mill __.compile
, this should add a corresponding declaration inlibsodiumjni_internal_SodiumApi.h
- add an implementation for that declaration in
libsodiumjni_internal_SodiumApi.c
in the same directory - run
./mill __.compile
to ensure that the new C code compiles fine - use the newly added
native
method inSodium.java
say - optionally, add tests for it in
SodiumTests.java
- ensure those tests pass when running
./mill __.test