Skip to content

Add Windows native BLAS support (UCRT64 JNI DLL + CI)#39

Open
philwalk wants to merge 5 commits intoluhenry:masterfrom
philwalk:fix/windows-native-build
Open

Add Windows native BLAS support (UCRT64 JNI DLL + CI)#39
philwalk wants to merge 5 commits intoluhenry:masterfrom
philwalk:fix/windows-native-build

Conversation

@philwalk
Copy link
Contributor

Summary

Enables JNIBLAS to load and function on Windows by making three changes:

blas/src/main/native/jni.c — Windows dlfcn shim

Replaces the unconditional #include <dlfcn.h> with a #ifdef _WIN32 block
that maps dlopen/dlsym/dlclose/dlerror to LoadLibraryA/GetProcAddress/
FreeLibrary. This allows jni.c to compile on Windows without a POSIX libdl
dependency. The DLL is linked with -Wl,-Bstatic,-ldl,-Bdynamic so libdl.a is
folded in statically — the resulting .dll imports only KERNEL32.dll and standard
CRT forwarders.

pom.xmlwindows-native Maven profile

Adds a profile activated automatically on Windows (<os><family>windows</family></os>)
that invokes make with ucrt64 gcc to build libnetlibblasjni.dll into
target/native/windows-amd64/, matching the layout expected by the resource-copy plugin.

CI workflows — Windows build and test jobs

Both build-and-test.yml and release.yml gain:

  • build-windows-natives: runs on windows-latest, sets up MSYS2 UCRT64
    (msys2/setup-msys2@v2), generates the JNI header via Maven, then compiles
    and links the DLL with ucrt64 gcc.
  • build-jar: updated needs to include build-windows-natives; downloads
    the windows-natives artifact alongside macos-natives so the DLL is packaged
    into the JAR.
  • test-windows: runs on windows-latest across JDK 11/17/21/25, installs
    OpenBLAS via MSYS2 (mingw-w64-ucrt-x86_64-openblas), and runs the BLAS test
    suite with -Ddev.ludovic.netlib.blas.nativeLib=libopenblas.dll.

Testing

Built and verified locally on Windows (MSYS2 UCRT64). objdump confirms the DLL
has no libdl.dll dependency. The full uni test suite (which uses JNIBLAS via
netlib) passes with native OpenBLAS acceleration confirmed.

On Windows (NTFS), Files.createTempFile with POSIX file attributes throws:
  UnsupportedOperationException: 'posix:permissions' not supported as initial attribute

This crash prevents JNIBLAS, JNILAPACK, and JNIARPACK from loading on any
Windows JVM, silently falling back to the pure-Java implementation.

Fix: guard the POSIX attribute with a FileSystems.getDefault() check, which
returns an empty attribute array on non-POSIX filesystems (Windows/NTFS).
Also add Windows os.name normalisation ("windows") and .dll extension to
match the existing macOS pattern.

Affected files: JNIBLAS.java, JNILAPACK.java, JNIARPACK.java
@philwalk
Copy link
Contributor Author

If the next release will not include this PR, can we publish it as a SNAPSHOT or nightly? I have some MacOS tests I'd like to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant