Zig cross-compilation of native libraries (#217) · lmdbjava/lmdbjava@288bb09
@@ -21,11 +21,8 @@
2121package org.lmdbjava;
22222323import static java.io.File.createTempFile;
24-import static java.lang.Boolean.getBoolean;
2524import static java.lang.System.getProperty;
2625import static java.lang.Thread.currentThread;
27-import static java.util.Locale.ENGLISH;
28-import static java.util.Objects.nonNull;
2926import static java.util.Objects.requireNonNull;
3027import static jnr.ffi.LibraryLoader.create;
3128import static jnr.ffi.Runtime.getRuntime;
5552 */
5653final class Library {
575458-/**
59- * Java system property name that can be set to disable automatic extraction
60- * of the LMDB system library from the LmdbJava JAR. This may be desirable if
61- * an operating system-provided LMDB system library is preferred (eg operating
62- * system package management, vendor support, special compiler flags, security
63- * auditing, profile guided optimization builds, faster startup time by
64- * avoiding the library copy etc).
65- */
66-public static final String DISABLE_EXTRACT_PROP = "lmdbjava.disable.extract";
6755/**
6856 * Java system property name that can be set to the path of an existing
6957 * directory into which the LMDB system library will be extracted from the
7058 * LmdbJava JAR. If unspecified the LMDB system library is extracted to the
7159 * <code>java.io.tmpdir</code>. Ignored if the LMDB system library is not
7260 * being extracted from the LmdbJava JAR (as would be the case if other
73- * system properties defined in <code>Library</code> have been set).
61+ * system properties defined in <code>TargetName</code> have been set).
7462 */
7563public static final String LMDB_EXTRACT_DIR_PROP = "lmdbjava.extract.dir";
76-/**
77- * Java system property name that can be set to provide a custom path to a
78- * external LMDB system library. If set, the system property
79- * DISABLE_EXTRACT_PROP will be overridden.
80- */
81-public static final String LMDB_NATIVE_LIB_PROP = "lmdbjava.native.lib";
82-/**
83- * Indicates whether automatic extraction of the LMDB system library is
84- * permitted.
85- */
86-public static final boolean SHOULD_EXTRACT = !getBoolean(DISABLE_EXTRACT_PROP);
8764/**
8865 * Indicates the directory where the LMDB system library will be extracted.
8966 */
9067static final String EXTRACT_DIR = getProperty(LMDB_EXTRACT_DIR_PROP,
9168getProperty("java.io.tmpdir"));
9269static final Lmdb LIB;
9370static final jnr.ffi.Runtime RUNTIME;
94-/**
95- * Indicates whether external LMDB system library is provided.
96- */
97-static final boolean SHOULD_USE_LIB = nonNull(
98-getProperty(LMDB_NATIVE_LIB_PROP));
99-private static final String LIB_NAME = "lmdb";
1007110172static {
10273final String libToLoad;
10374104-final String arch = getProperty("os.arch");
105-final boolean arch64 = "x64".equals(arch) || "amd64".equals(arch)
106- || "x86_64".equals(arch);
107-108-final String os = getProperty("os.name");
109-final boolean linux = os.toLowerCase(ENGLISH).startsWith("linux");
110-final boolean osx = os.startsWith("Mac OS X");
111-final boolean windows = os.startsWith("Windows");
112-113-if (SHOULD_USE_LIB) {
114-libToLoad = getProperty(LMDB_NATIVE_LIB_PROP);
115- } else if (SHOULD_EXTRACT && arch64 && linux) {
116-libToLoad = extract("org/lmdbjava/lmdbjava-native-linux-x86_64.so");
117- } else if (SHOULD_EXTRACT && arch64 && osx) {
118-libToLoad = extract("org/lmdbjava/lmdbjava-native-osx-x86_64.dylib");
119- } else if (SHOULD_EXTRACT && arch64 && windows) {
120-libToLoad = extract("org/lmdbjava/lmdbjava-native-windows-x86_64.dll");
75+if (TargetName.IS_EXTERNAL) {
76+libToLoad = TargetName.RESOLVED_FILENAME;
12177 } else {
122-libToLoad = LIB_NAME;
78+libToLoad = extract(TargetName.RESOLVED_FILENAME);
12379 }
1248012581LIB = create(Lmdb.class).load(libToLoad);