Skip to content
Merged
80 changes: 79 additions & 1 deletion .github/workflows/build-and-test.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,47 @@ jobs:
*/target/native/macos-*/
if-no-files-found: error

build-windows-natives:
name: "Build: Windows Natives"
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Cache M2 local repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: m2
- name: Set up JDK 25
uses: actions/setup-java@v4
with:
java-version: 25
distribution: temurin
- name: Set up MSYS2 (UCRT64)
uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
update: false
install: >-
mingw-w64-ucrt-x86_64-gcc
mingw-w64-ucrt-x86_64-dlfcn
make
- name: Add MSYS2 UCRT64 to PATH
shell: msys2 {0}
run: echo "$(cygpath -w /ucrt64/bin)" >> $GITHUB_PATH
- name: Build
run: mvn --batch-mode --no-transfer-progress compile
- name: Upload Windows natives
uses: actions/upload-artifact@v4
with:
name: windows-natives
path: |
*/target/native/windows-*/
if-no-files-found: error

build-jar:
name: "Build: Packaging JARs"
runs-on: ubuntu-latest
needs: [build-macos-natives]
needs: [build-macos-natives, build-windows-natives]
steps:
- uses: actions/checkout@v4
- name: Cache M2 local repository
Expand All @@ -60,6 +97,11 @@ jobs:
with:
name: macos-natives
path: .
- name: Download Windows natives
uses: actions/download-artifact@v4
with:
name: windows-natives
path: .
- name: Build
run: mvn --batch-mode --no-transfer-progress package -DskipTests
- name: Log content of jar files
Expand Down Expand Up @@ -137,3 +179,39 @@ jobs:
distribution: temurin
- name: Test
run: mvn --batch-mode --no-transfer-progress --projects test-utils,blas,lapack,arpack test --fail-at-end -Dmaven.main.skip=true -Dmaven.antrun.skip=true

test-windows:
name: "Test: runs-on: windows-latest, jdk: ${{ matrix.jdk }}"
runs-on: windows-latest
needs: [build-jar]
strategy:
matrix:
jdk: [11, 17, 21, 25]
steps:
- uses: actions/checkout@v4
- name: Cache M2 local repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: m2
- name: Set up MSYS2 (UCRT64) with OpenBLAS
uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
update: false
install: mingw-w64-ucrt-x86_64-openblas
- name: Add MSYS2 ucrt64 bin to PATH
shell: msys2 {0}
run: echo "$(cygpath -w /ucrt64/bin)" >> $GITHUB_PATH
- name: Download target folder
uses: actions/download-artifact@v4
with:
name: target-dir
path: .
- name: Set up JDK ${{ matrix.jdk }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.jdk }}
distribution: temurin
- name: Test
run: mvn --batch-mode --no-transfer-progress --projects test-utils,blas test --fail-at-end "-Dmaven.main.skip=true" "-Dmaven.antrun.skip=true" "-Ddev.ludovic.netlib.blas.nativeLib=libopenblas.dll"
Comment thread
philwalk marked this conversation as resolved.
Outdated
Comment thread
philwalk marked this conversation as resolved.
Outdated
Comment thread
philwalk marked this conversation as resolved.
Outdated
82 changes: 80 additions & 2 deletions .github/workflows/release.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,47 @@ jobs:
*/target/native/macos-*/
if-no-files-found: error

build-windows-natives:
name: "Build: Windows Natives"
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Cache M2 local repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: m2
- name: Set up JDK 25
uses: actions/setup-java@v4
with:
java-version: 25
distribution: temurin
- name: Set up MSYS2 (UCRT64)
uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
update: false
install: >-
mingw-w64-ucrt-x86_64-gcc
mingw-w64-ucrt-x86_64-dlfcn
make
- name: Add MSYS2 UCRT64 to PATH
shell: msys2 {0}
run: echo "$(cygpath -w /ucrt64/bin)" >> $GITHUB_PATH
- name: Build
run: mvn --batch-mode --no-transfer-progress compile
- name: Upload Windows natives
uses: actions/upload-artifact@v4
with:
name: windows-natives
path: |
*/target/native/windows-*/
if-no-files-found: error

build-jar:
name: "Build: Packaging JARs"
runs-on: ubuntu-latest
needs: [build-macos-natives]
needs: [build-macos-natives, build-windows-natives]
steps:
- uses: actions/checkout@v4
- name: Cache M2 local repository
Expand All @@ -60,6 +97,11 @@ jobs:
with:
name: macos-natives
path: .
- name: Download Windows natives
uses: actions/download-artifact@v4
with:
name: windows-natives
path: .
- name: Build
run: mvn --batch-mode --no-transfer-progress package -DskipTests
- name: Log content of jar files
Expand Down Expand Up @@ -138,10 +180,46 @@ jobs:
- name: Test
run: mvn --batch-mode --no-transfer-progress --projects test-utils,blas,lapack,arpack test --fail-at-end -Dmaven.main.skip=true -Dmaven.antrun.skip=true

test-windows:
name: "Test: runs-on: windows-latest, jdk: ${{ matrix.jdk }}"
runs-on: windows-latest
needs: [build-jar]
strategy:
matrix:
jdk: [11, 17, 21, 25]
steps:
- uses: actions/checkout@v4
- name: Cache M2 local repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: m2
- name: Set up MSYS2 (UCRT64) with OpenBLAS
uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
update: false
install: mingw-w64-ucrt-x86_64-openblas
- name: Add MSYS2 ucrt64 bin to PATH
shell: msys2 {0}
run: echo "$(cygpath -w /ucrt64/bin)" >> $GITHUB_PATH
- name: Download target folder
uses: actions/download-artifact@v4
with:
name: target-dir
path: .
- name: Set up JDK ${{ matrix.jdk }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.jdk }}
distribution: temurin
- name: Test
run: mvn --batch-mode --no-transfer-progress --projects test-utils,blas test --fail-at-end "-Dmaven.main.skip=true" "-Dmaven.antrun.skip=true" "-Ddev.ludovic.netlib.blas.nativeLib=libopenblas.dll"
Comment thread
philwalk marked this conversation as resolved.
Outdated

release:
name: Release
runs-on: ubuntu-latest
needs: [build-jar, test-linux, test-macos]
needs: [build-jar, test-linux, test-macos, test-windows]
# Map step output to job output
outputs:
release_upload_url: ${{ steps.create_release.outputs.upload_url }}
Expand Down
15 changes: 12 additions & 3 deletions arpack/src/main/java/dev/ludovic/netlib/arpack/JNIARPACK.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermissions;

final class JNIARPACK extends AbstractARPACK implements NativeARPACK {
Expand All @@ -42,24 +44,31 @@ protected JNIARPACK() {
if (osName == null || osName.isEmpty()) {
throw new RuntimeException("Unable to load native implementation");
}
boolean isWindows = osName.startsWith("Windows");
if (osName.equals("Mac OS X")) {
osName = "macos";
} else if (isWindows) {
osName = "windows";
}
String osArch = System.getProperty("os.arch");
if (osArch == null || osArch.isEmpty()) {
throw new RuntimeException("Unable to load native implementation");
}

String libPrefix = "libnetlibarpackjni";
String libExtension = osName.equals("macos") ? ".dylib" : ".so";
String libExtension = osName.equals("macos") ? ".dylib" : isWindows ? ".dll" : ".so";
String libName = libPrefix + libExtension;

FileAttribute<?>[] attrs = FileSystems.getDefault()
.supportedFileAttributeViews().contains("posix")
? new FileAttribute<?>[]{ PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxr-x---")) }
: new FileAttribute<?>[0];

Path temp;
try (InputStream resource = this.getClass().getClassLoader().getResourceAsStream(
String.format("resources/native/%s-%s/%s", osName, osArch, libName))) {
assert resource != null;
Files.copy(resource, temp = Files.createTempFile(libPrefix, libExtension,
PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxr-x---"))),
Files.copy(resource, temp = Files.createTempFile(libPrefix, libExtension, attrs),
StandardCopyOption.REPLACE_EXISTING);
temp.toFile().deleteOnExit();
} catch (IOException e) {
Expand Down
12 changes: 11 additions & 1 deletion arpack/src/main/native/jni.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#ifdef _WIN32
Comment thread
philwalk marked this conversation as resolved.
# include <windows.h>
# define dlopen(name, flags) ((void*)LoadLibraryA(name))
# define dlsym(h, name) ((void*)GetProcAddress((HMODULE)(h), name))
# define dlclose(h) FreeLibrary((HMODULE)(h))
# define dlerror() "LoadLibrary failed"
# define RTLD_LAZY 0
# define RTLD_LOCAL 0
#else
# include <dlfcn.h>
#endif

#include "dev_ludovic_netlib_arpack_JNIARPACK.h"

Expand Down
15 changes: 11 additions & 4 deletions blas/src/main/java/dev/ludovic/netlib/blas/JNIBLAS.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.logging.Logger;

Expand All @@ -45,27 +47,32 @@ protected JNIBLAS() {
if (osName == null || osName.isEmpty()) {
throw new RuntimeException("Unable to load native implementation");
}
boolean isWindows = osName.startsWith("Windows");
if (osName.equals("Mac OS X")) {
osName = "macos";
} else if (isWindows) {
osName = "windows";
}
String osArch = System.getProperty("os.arch");
if (osArch == null || osArch.isEmpty()) {
throw new RuntimeException("Unable to load native implementation");
}

String libPrefix = "libnetlibblasjni";
String libExtension = osName.equals("macos") ? ".dylib" : ".so";
String libExtension = osName.equals("macos") ? ".dylib" : isWindows ? ".dll" : ".so";
String libName = libPrefix + libExtension;

log.fine(String.format("Trying to load native implementation from resource: resources/native/%s-%s/%s", osName, osArch, libName));
FileAttribute<?>[] attrs = FileSystems.getDefault()
.supportedFileAttributeViews().contains("posix")
? new FileAttribute<?>[]{ PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxr-x---")) }
: new FileAttribute<?>[0];

Path temp;
try (InputStream resource = this.getClass().getClassLoader().getResourceAsStream(
String.format("resources/native/%s-%s/%s", osName, osArch, libName))) {
assert resource != null;
Files.copy(resource, temp = Files.createTempFile(libPrefix, libExtension,
PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxr-x---"))),
StandardCopyOption.REPLACE_EXISTING);
Files.copy(resource, temp = Files.createTempFile(libPrefix, libExtension, attrs), StandardCopyOption.REPLACE_EXISTING);
temp.toFile().deleteOnExit();
} catch (IOException e) {
throw new UncheckedIOException("Unable to load native implementation", e);
Expand Down
12 changes: 11 additions & 1 deletion blas/src/main/native/jni.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#ifdef _WIN32
# include <windows.h>
# define dlopen(name, flags) ((void*)LoadLibraryA(name))
# define dlsym(h, name) ((void*)GetProcAddress((HMODULE)(h), name))
# define dlclose(h) FreeLibrary((HMODULE)(h))
# define dlerror() "LoadLibrary failed"
# define RTLD_LAZY 0
# define RTLD_LOCAL 0
#else
# include <dlfcn.h>
#endif

#include "dev_ludovic_netlib_blas_JNIBLAS.h"

Expand Down
15 changes: 12 additions & 3 deletions lapack/src/main/java/dev/ludovic/netlib/lapack/JNILAPACK.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermissions;

final class JNILAPACK extends AbstractLAPACK implements NativeLAPACK {
Expand All @@ -42,24 +44,31 @@ protected JNILAPACK() {
if (osName == null || osName.isEmpty()) {
throw new RuntimeException("Unable to load native implementation");
}
boolean isWindows = osName.startsWith("Windows");
if (osName.equals("Mac OS X")) {
osName = "macos";
} else if (isWindows) {
osName = "windows";
}
String osArch = System.getProperty("os.arch");
if (osArch == null || osArch.isEmpty()) {
throw new RuntimeException("Unable to load native implementation");
}

String libPrefix = "libnetliblapackjni";
String libExtension = osName.equals("macos") ? ".dylib" : ".so";
String libExtension = osName.equals("macos") ? ".dylib" : isWindows ? ".dll" : ".so";
String libName = libPrefix + libExtension;

FileAttribute<?>[] attrs = FileSystems.getDefault()
.supportedFileAttributeViews().contains("posix")
? new FileAttribute<?>[]{ PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxr-x---")) }
: new FileAttribute<?>[0];

Path temp;
try (InputStream resource = this.getClass().getClassLoader().getResourceAsStream(
String.format("resources/native/%s-%s/%s", osName, osArch, libName))) {
assert resource != null;
Files.copy(resource, temp = Files.createTempFile(libPrefix, libExtension,
PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxr-x---"))),
Files.copy(resource, temp = Files.createTempFile(libPrefix, libExtension, attrs),
StandardCopyOption.REPLACE_EXISTING);
temp.toFile().deleteOnExit();
} catch (IOException e) {
Expand Down
Loading
Loading