Skip to content

Commit e5b510c

Browse files
committed
Replace Zig cross-compilation with native library artifact
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.
1 parent e634b3f commit e5b510c

File tree

7 files changed

+16
-103
lines changed

7 files changed

+16
-103
lines changed

.github/workflows/maven.yml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,9 @@ jobs:
2222
java-version: 25
2323
cache: maven
2424

25-
- name: Install Zig
26-
uses: mlugg/setup-zig@v2
27-
28-
- name: Cross compile using Zig
29-
run: ./cross-compile.sh
30-
3125
- name: Build with Maven
3226
run: mvn -B verify -DgcRecordWrites=1000
3327

34-
- name: Store built native libraries for later jobs
35-
uses: actions/upload-artifact@v4
36-
with:
37-
name: native-libraries
38-
path: |
39-
src/main/resources/org/lmdbjava/*.so
40-
src/main/resources/org/lmdbjava/*.dll
41-
4228
- name: Upload code coverage to Codecov
4329
uses: codecov/codecov-action@v5
4430
env:
@@ -65,12 +51,6 @@ jobs:
6551
java-version: ${{ matrix.java }}
6652
cache: maven
6753

68-
- name: Fetch built native libraries
69-
uses: actions/download-artifact@v4
70-
with:
71-
name: native-libraries
72-
path: src/main/resources/org/lmdbjava
73-
7454
- name: Execute verifier
7555
run: mvn -B test -Dtest=VerifierTest -DverificationSeconds=10
7656

@@ -104,12 +84,6 @@ jobs:
10484
gpg-private-key: ${{ secrets.gpg_private_key }}
10585
gpg-passphrase: MAVEN_GPG_PASSPHRASE
10686

107-
- name: Install Zig
108-
uses: mlugg/setup-zig@v2
109-
110-
- name: Cross compile using Zig
111-
run: ./cross-compile.sh
112-
11387
- name: Publish Maven package
11488
run: mvn -B -Pcentral-deploy deploy -DskipTests
11589
env:

README.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,10 @@ any questions.
5757

5858
### Building
5959

60-
This project uses [Zig](https://ziglang.org/) to cross-compile the LMDB native
61-
library for all supported architectures. To locally build LmdbJava you must
62-
firstly install a recent version of Zig and then execute the project's
63-
[cross-compile.sh](https://github.com/lmdbjava/lmdbjava/tree/master/cross-compile.sh)
64-
script. This only needs to be repeated when the `cross-compile.sh` script is
65-
updated (eg following a new official release of the upstream LMDB library).
66-
67-
If you do not wish to install Zig and/or use an operating system which cannot
68-
easily execute the `cross-compile.sh` script, you can download the compiled
69-
LMDB native library for your platform from a location of your choice and set the
70-
`lmdbjava.native.lib` system property to the resulting file system
71-
location. Possible sources of a compiled LMDB native library include operating
72-
system package managers, running `cross-compile.sh` on a supported system, or
73-
copying it from the `org/lmdbjava` directory of any recent, officially released
74-
LmdbJava JAR.
60+
LmdbJava uses a standard Maven build. Its native libraries are provided by the
61+
[`org.lmdbjava:native`](https://github.com/lmdbjava/native) dependency.
62+
63+
To use a different LMDB library, set `lmdbjava.native.lib` system property to the file path.
7564

7665
### Contributing
7766

cross-compile.sh

Lines changed: 0 additions & 43 deletions
This file was deleted.

pom.xml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<jnr-ffi.version>2.2.18</jnr-ffi.version>
4040
<junit.version>5.14.0</junit.version>
4141
<license-maven-plugin.version>4.6</license-maven-plugin.version>
42+
<lmdbjava-native.version>0.9.33-2</lmdbjava-native.version>
4243
<maven-clean-plugin.version>3.5.0</maven-clean-plugin.version>
4344
<maven-compiler-plugin.version>3.14.1</maven-compiler-plugin.version>
4445
<maven-dependency-plugin.version>3.9.0</maven-dependency-plugin.version>
@@ -120,6 +121,11 @@
120121
<version>${junit.version}</version>
121122
<scope>test</scope>
122123
</dependency>
124+
<dependency>
125+
<groupId>org.lmdbjava</groupId>
126+
<artifactId>native</artifactId>
127+
<version>${lmdbjava-native.version}</version>
128+
</dependency>
123129
<dependency>
124130
<groupId>org.mockito</groupId>
125131
<artifactId>mockito-inline</artifactId>
@@ -407,20 +413,9 @@
407413
</licenses>
408414
<developers>
409415
<developer>
410-
<id>krisskross</id>
411-
<name>Kristoffer Sjogren</name>
412-
<email>stoffe -at- gmail.com</email>
413-
<url>http://stoffe.deephacks.org/</url>
414-
<organization/>
415-
<timezone>+1</timezone>
416-
</developer>
417-
<developer>
418-
<id>benalexau</id>
419-
<name>Ben Alex</name>
420-
<email>[email protected]</email>
421-
<url>https://github.com/benalexau/</url>
422-
<organization>Acegi Technology Pty Limited</organization>
423-
<timezone>+10</timezone>
416+
<id>lmdbjava</id>
417+
<name>The LmdbJava Open Source Project</name>
418+
<url>https://github.com/lmdbjava</url>
424419
</developer>
425420
</developers>
426421
<scm>

src/main/java/org/lmdbjava/TargetName.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public final class TargetName {
4343
* Java system property name that can be set to override the embedded library that will be used.
4444
* This is likely to be required if automatic resolution fails but the user still prefers to use
4545
* an LmdbJava-bundled library. This path must include the classpath prefix (usually <code>
46-
* org/lmdbjava</code>).
46+
* org/lmdbjava/native</code>).
4747
*/
4848
public static final String LMDB_EMBEDDED_LIB_PROP = "lmdbjava.embedded.lib";
4949

@@ -94,7 +94,7 @@ static String resolveFilename(
9494

9595
final String pkg = TargetName.class.getPackage().getName().replace('.', '/');
9696
return pkg
97-
+ "/"
97+
+ "/native/"
9898
+ resolveArch(arch)
9999
+ "-"
100100
+ resolveOs(os)

src/main/resources/org/lmdbjava/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/test/java/org/lmdbjava/TargetNameTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void externalTakesPriority() {
6161
}
6262

6363
private void embed(final String lib, final String arch, final String os) {
64-
assertThat(resolveFilename(NONE, NONE, arch, os)).isEqualTo("org/lmdbjava/" + lib);
64+
assertThat(resolveFilename(NONE, NONE, arch, os)).isEqualTo("org/lmdbjava/native/" + lib);
6565
assertThat(isExternal(NONE)).isFalse();
6666
}
6767
}

0 commit comments

Comments
 (0)