Zig cross-compilation of native libraries by bp-alex · Pull Request #217 · lmdbjava/lmdbjava

@bp-alex

This new approach provides a number of benefits:

1. The LmdbJava Native project can be archived. This project required
coordination with LmdbJava module releases and added extra artifacts
to Maven Central simply to wrap native libraries. The native project
also required a great deal of Maven configuration and it was always
tedious to support additional platforms. Using Zig eliminates the need
to run QEMU emulators in builds to support unusual platforms etc.

2. Zig supports numerous cross-compilation targets straight out of the
box. A full list is available via zig targets | jq -r '.libc[]' and
this presently lists 64 on my machine. This is likely to accommodate
most LmdbJava platform support requests we are likely to receive.

3. Platform naming conventions have now been standardised based on the
Zig target name. Support for individual build chains or specific
processors is now simplified and much more transparent.

4. The GitHub Action has been amended to perform cross-compilation
under Linux and upload the resulting native artifacts for later build
steps. The later build steps run the Verifier on a native VM where
available (eg Windows, Mac OS) and this therefore tests the
cross-compiled libraries.

5. Target name resolution logic has been refactored and externalised
in its own class with corresponding unit tests to ensure corner cases
are duly considered and any bugs more easily reproduced and
permanently rectified.

This change is backwards compatible with users who used (and may
continue to use) the lmdbjava.native.lib system property.

@bp-alex mentioned this pull request

Apr 23, 2023

This was referenced

Apr 24, 2023

bp-alex added a commit that referenced this pull request

Apr 24, 2023

bp-alex added a commit that referenced this pull request

Apr 24, 2023

bp-alex added a commit that referenced this pull request

Oct 30, 2025
Commit 288bb09 introduced Zig cross-compilation of LMDB (#217).
Benchmarking as part of #262 revealed the cross-compiled libraries are
significantly slower than LMDB compiled with native toolchains. Using
the methodology from e634b3f:

Library Source                  Score (ms)   Delta vs Baseline
--------------------------------------------------------------
System Arch Linux (GCC)         45.00        Baseline
Fetched Arch Linux (GCC)        45.03        +0.05%
Zig unoptimized (debug)         59.01        +31.12%
Zig optimized (-O2 stripped)    58.82        +30.70%

This removes Zig cross-compilation and adopts the org.lmdbjava:native
artifact, which packages LMDB libraries compiled with native toolchains
from distribution package managers. This simplifies building as Zig
installation and cross-compile.sh are no longer required.