Skip to content

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

Merged
luhenry merged 12 commits intoluhenry:masterfrom
philwalk:fix/windows-native-build
Mar 31, 2026
Merged

Add Windows native BLAS support (UCRT64 JNI DLL + CI)#39
luhenry merged 12 commits intoluhenry:masterfrom
philwalk:fix/windows-native-build

Conversation

@philwalk
Copy link
Copy Markdown
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
Copy Markdown
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.

Copy link
Copy Markdown
Owner

@luhenry luhenry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I wrote that review some day ago and forgot to submit it...

Copy link
Copy Markdown
Owner

@luhenry luhenry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great progress, one last change related to how the jni.c files are generated.

@luhenry
Copy link
Copy Markdown
Owner

luhenry commented Mar 31, 2026

Once these last comments are addressed, it's good to merge!

@luhenry luhenry merged commit d8a77ab into luhenry:master Mar 31, 2026
28 checks passed
@luhenry
Copy link
Copy Markdown
Owner

luhenry commented Mar 31, 2026

Thank you for your contribution!

@philwalk
Copy link
Copy Markdown
Contributor Author

philwalk commented Apr 1, 2026

Is there a scheduled release anytime soon?

@luhenry
Copy link
Copy Markdown
Owner

luhenry commented Apr 1, 2026

@philwalk yes, I ran into an issue when doing it last night, will fix and release this week.

@philwalk
Copy link
Copy Markdown
Contributor Author

philwalk commented Apr 1, 2026

@luhenry with these changes my numpy-inspired jvm-based library is able to match or exceed the performance of equivalent NumPy code: uni.MatD

@luhenry
Copy link
Copy Markdown
Owner

luhenry commented Apr 1, 2026

@luhenry with these changes my numpy-inspired jvm-based library is able to match or exceed the performance of equivalent NumPy code: uni.MatD

motivating!

@luhenry
Copy link
Copy Markdown
Owner

luhenry commented Apr 2, 2026

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.

2 participants