diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index adf537b2a0..71ff23dfe0 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -12,14 +12,13 @@ jobs: name: Build natives libraries strategy: matrix: - # os: [ ubuntu-latest, windows-latest ] - os: [ windows-latest ] + os: [ ubuntu-latest, windows-latest ] target: [ native ] - # include: - # - os: ubuntu-latest - # target: mac64-signed - # - os: ubuntu-latest - # target: mac-arm64-signed + include: + - os: ubuntu-latest + target: mac64-signed + - os: ubuntu-latest + target: mac-arm64-signed runs-on: ${{ matrix.os }} steps: - name: Make space @@ -51,22 +50,19 @@ jobs: perl Configure VC-WIN64A --prefix=C:\openssl1.1.1 nmake nmake install - cp C:\openssl1.1.1\bin\libcrypto-1_1-x64.dll C:\openssl1.1.1\bin\libcrypto.dll - cp C:\openssl1.1.1\bin\libssl-1_1-x64.dll C:\openssl1.1.1\bin\libssl.dll - - name: Zip OpenSSL build - run: Compress-Archive -Destination openssl1.1.1w.zip -Path C:\openssl1.1.1 - - uses: actions/upload-artifact@v3 - with: - name: OpenSSL build - path: | - ./openssl1.1.1w.zip - - - name: Build binaries and package + - name: Build binaries env: OCI_EXE: docker run: make ${{ matrix.target }} package + - name: Copy OpenSSL library + if: runner.os == 'Windows' + run: cp C:\openssl1.1.1\bin\libcrypto-1_1-x64.dll src/main/resources/org/sqlite/native/Windows/x86_64/libcrypto-1_1-x64.dll + + - name: Package + run: make package + - name: Set platform classifier shell: bash run: | diff --git a/Makefile b/Makefile index 81a787cd0a..c68fa164bf 100644 --- a/Makefile +++ b/Makefile @@ -158,7 +158,6 @@ win32: $(SQLITE_UNPACKED) jni-header ./docker/dockcross-windows-x86 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=i686-w64-mingw32.static- OS_NAME=Windows OS_ARCH=x86' win64: $(SQLITE_UNPACKED) jni-header - cp C:/openssl1.1.1/bin/libcrypto.dll $(NATIVE_DIR) ./docker/dockcross-windows-x64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=x86_64-w64-mingw32.static- OS_NAME=Windows OS_ARCH=x86_64' win-armv7: $(SQLITE_UNPACKED) jni-header diff --git a/Makefile.common b/Makefile.common index 0979d6dbc7..4c177ff76d 100644 --- a/Makefile.common +++ b/Makefile.common @@ -68,7 +68,7 @@ CROSS_PREFIX := Default_CC := $(CROSS_PREFIX)gcc Default_STRIP := $(CROSS_PREFIX)strip Default_CCFLAGS := -I$(JAVA_HOME)/include -Ilib/inc_linux -Os -fPIC -fvisibility=hidden -std=gnu11 -march=native -Default_LINKFLAGS := -shared -static-libgcc -pthread -lm -lcrypto +Default_LINKFLAGS := -shared -static-libgcc -pthread -lm Default_LIBNAME := libsqlitejdbc.so Default_SQLITE_FLAGS := @@ -82,7 +82,7 @@ Linux-x86_SQLITE_FLAGS := Linux-x86_64_CC := $(CROSS_PREFIX)gcc Linux-x86_64_STRIP := $(CROSS_PREFIX)strip Linux-x86_64_CCFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -Os -fPIC -m64 -fvisibility=hidden -msse4.2 -maes -Linux-x86_64_LINKFLAGS := $(Default_LINKFLAGS) +Linux-x86_64_LINKFLAGS := $(Default_LINKFLAGS) -lcrypto Linux-x86_64_LIBNAME := libsqlitejdbc.so Linux-x86_64_SQLITE_FLAGS := diff --git a/src/main/java/org/sqlite/SQLiteJDBCLoader.java b/src/main/java/org/sqlite/SQLiteJDBCLoader.java index 133762fdd9..5cc52e50d3 100644 --- a/src/main/java/org/sqlite/SQLiteJDBCLoader.java +++ b/src/main/java/org/sqlite/SQLiteJDBCLoader.java @@ -69,10 +69,6 @@ public static synchronized boolean initialize() throws Exception { if (!extracted) { cleanup(); } - if ("Windows".equalsIgnoreCase(OSInfo.getOSName())) { - loadSQLiteOpenSslLibrary(); - } - extracted = false; loadSQLiteNativeLibrary(); return extracted; } @@ -196,10 +192,11 @@ private static boolean contentsEquals(InputStream in1, InputStream in2) throws I * @param libFolderForCurrentOS Library path. * @param libraryFileName Library name. * @param targetFolder Target folder. + * @param otherLibraryFileNames Other libraries to extract. * @return */ private static boolean extractAndLoadLibraryFile( - String libFolderForCurrentOS, String libraryFileName, String targetFolder) { + String libFolderForCurrentOS, String libraryFileName, String targetFolder, String...otherLibraryFileNames) { String nativeLibraryFilePath = libFolderForCurrentOS + "/" + libraryFileName; // Include architecture name in temporary filename in order to avoid conflicts // when multiple JVMs with different architectures running at the same time @@ -212,6 +209,20 @@ private static boolean extractAndLoadLibraryFile( Path extractedLckFile = Paths.get(targetFolder, extractedLckFileName); try { + // Extract the other library files into the target directory + for (String otherLibraryFileName : otherLibraryFileNames) { + String otherLibraryFilePath = libFolderForCurrentOS + "/" + otherLibraryFileName; + System.out.println("OTHERLIB.Path: " + otherLibraryFilePath); + + Path extractedOtherLibFile = Paths.get(targetFolder, otherLibraryFileNames); + try (InputStream reader = getResourceAsStream(otherLibraryFilePath)) { + Files.copy(reader, extractedOtherLibFile, StandardCopyOption.REPLACE_EXISTING); + } finally { + extractedOtherLibFile.toFile().deleteOnExit(); + } + loadNativeLibrary(targetFolder, otherLibraryFileName); + } + // Extract a native library file into the target directory try (InputStream reader = getResourceAsStream(nativeLibraryFilePath)) { if (Files.notExists(extractedLckFile)) { @@ -317,8 +328,10 @@ private static void loadSQLiteNativeLibrary() throws Exception { // Try loading library from org.sqlite.lib.path library path */ String sqliteNativeLibraryPath = System.getProperty("org.sqlite.lib.path"); String sqliteNativeLibraryName = System.getProperty("org.sqlite.lib.name"); + String sqliteOpenSslLibraryName = System.getProperty("org.sqlite.openssl.lib.name"); if (sqliteNativeLibraryName == null) { sqliteNativeLibraryName = LibraryLoaderUtil.getNativeLibName(); + sqliteOpenSslLibraryName = LibraryLoaderUtil.getNativeLibName("libcrypto-1_1-x64"); } if (sqliteNativeLibraryPath != null) { @@ -336,75 +349,18 @@ private static void loadSQLiteNativeLibrary() throws Exception { LibraryLoaderUtil.hasNativeLib(sqliteNativeLibraryPath, sqliteNativeLibraryName); if (hasNativeLib) { - // temporary library folder - String tempFolder = getTempDir().getAbsolutePath(); - // Try extracting the library from jar - if (extractAndLoadLibraryFile( - sqliteNativeLibraryPath, sqliteNativeLibraryName, tempFolder)) { - extracted = true; - return; - } else { - triedPaths.add(sqliteNativeLibraryPath); - } - } - - // As a last resort try from java.library.path - String javaLibraryPath = System.getProperty("java.library.path", ""); - for (String ldPath : javaLibraryPath.split(File.pathSeparator)) { - if (ldPath.isEmpty()) { - continue; - } - if (loadNativeLibrary(ldPath, sqliteNativeLibraryName)) { - extracted = true; - return; - } else { - triedPaths.add(ldPath); - } - } - - extracted = false; - throw new Exception( - String.format( - "No native library found for os.name=%s, os.arch=%s, paths=[%s]", - OSInfo.getOSName(), - OSInfo.getArchName(), - StringUtils.join(triedPaths, File.pathSeparator))); - } - - private static void loadSQLiteOpenSslLibrary() throws Exception { - if (extracted) { - return; - } - - List triedPaths = new LinkedList<>(); - - // Try loading library from org.sqlite.lib.path library path */ - String sqliteNativeLibraryPath = System.getProperty("org.sqlite.lib.path"); - String sqliteOpenSslLibraryName = System.getProperty("org.sqlite.openssl.lib.name"); - if (sqliteOpenSslLibraryName == null) { - sqliteOpenSslLibraryName = LibraryLoaderUtil.getNativeLibName("crypto"); - } - - if (sqliteNativeLibraryPath != null) { - if (loadNativeLibrary(sqliteNativeLibraryPath, sqliteOpenSslLibraryName)) { - extracted = true; - return; - } else { - triedPaths.add(sqliteNativeLibraryPath); + String[] extraLibNames = new String[] {}; + if ("Windows".equalsIgnoreCase(OSInfo.getOSName())) { + extraLibNames = new String[] { + sqliteOpenSslLibraryName + }; } - } - - // Load the os-dependent library from the jar file - sqliteNativeLibraryPath = LibraryLoaderUtil.getNativeLibResourcePath(); - boolean hasNativeLib = - LibraryLoaderUtil.hasNativeLib(sqliteNativeLibraryPath, sqliteOpenSslLibraryName); - if (hasNativeLib) { // temporary library folder String tempFolder = getTempDir().getAbsolutePath(); // Try extracting the library from jar if (extractAndLoadLibraryFile( - sqliteNativeLibraryPath, sqliteOpenSslLibraryName, tempFolder)) { + sqliteNativeLibraryPath, sqliteNativeLibraryName, tempFolder, extraLibNames)) { extracted = true; return; } else { @@ -418,7 +374,7 @@ private static void loadSQLiteOpenSslLibrary() throws Exception { if (ldPath.isEmpty()) { continue; } - if (loadNativeLibrary(ldPath, sqliteOpenSslLibraryName)) { + if (loadNativeLibrary(ldPath, sqliteNativeLibraryName)) { extracted = true; return; } else { @@ -429,7 +385,7 @@ private static void loadSQLiteOpenSslLibrary() throws Exception { extracted = false; throw new Exception( String.format( - "No openssl library found for os.name=%s, os.arch=%s, paths=[%s]", + "No native library found for os.name=%s, os.arch=%s, paths=[%s]", OSInfo.getOSName(), OSInfo.getArchName(), StringUtils.join(triedPaths, File.pathSeparator)));