Skip to content

Commit 1c20f46

Browse files
authored
ci : enable bindings java job (ggml-org#3070)
* ci : re-enable bindings-java (java) job This commit re-enables the job previously name `java` which was disabled in the build.yml file. The motivation for this is that we recently fixed a few issue in the java bindings and it should be possible to build them on windows. Refs: ggml-org#2949 Resolves: ggml-org#2781
1 parent adaea08 commit 1c20f46

File tree

4 files changed

+162
-51
lines changed

4 files changed

+162
-51
lines changed

.github/workflows/build.yml

Lines changed: 121 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ jobs:
561561
run: >
562562
cmake -S . -B ./build -A ${{ matrix.arch }}
563563
-DCMAKE_BUILD_TYPE=${{ matrix.build }}
564+
-DBUILD_SHARED_LIBS=ON
564565
-DWHISPER_SDL2=${{ matrix.sdl2 }}
565566
566567
- name: Build
@@ -572,12 +573,37 @@ jobs:
572573
if: matrix.sdl2 == 'ON'
573574
run: copy "$env:SDL2_DIR/../lib/${{ matrix.s2arc }}/SDL2.dll" build/bin/${{ matrix.build }}
574575

575-
- name: Upload dll
576+
- name: Upload SDL2.dll
577+
if: matrix.sdl2 == 'ON'
576578
uses: actions/upload-artifact@v4
577579
with:
578-
name: ${{ matrix.jnaPath }}_whisper.dll
580+
name: ${{ matrix.s2arc }}_SDL2.dll
581+
path: build/bin/${{ matrix.build }}/SDL2.dll
582+
583+
- name: Upload whisper dll
584+
uses: actions/upload-artifact@v4
585+
with:
586+
name: whisper_${{ matrix.arch }}.dll
579587
path: build/bin/${{ matrix.build }}/whisper.dll
580588

589+
- name: Upload ggml dll
590+
uses: actions/upload-artifact@v4
591+
with:
592+
name: ggml_${{ matrix.arch }}.dll
593+
path: build/bin/${{ matrix.build }}/ggml.dll
594+
595+
- name: Upload ggml base dll
596+
uses: actions/upload-artifact@v4
597+
with:
598+
name: ggml_base_${{ matrix.arch }}.dll
599+
path: build/bin/${{ matrix.build }}/ggml-base.dll
600+
601+
- name: Upload ggml cpu dll
602+
uses: actions/upload-artifact@v4
603+
with:
604+
name: ggml_cpu_${{ matrix.arch }}.dll
605+
path: build/bin/${{ matrix.build }}/ggml-cpu.dll
606+
581607
- name: Upload binaries
582608
if: matrix.sdl2 == 'ON'
583609
uses: actions/upload-artifact@v4
@@ -996,49 +1022,99 @@ jobs:
9961022
chmod +x ./gradlew
9971023
./gradlew assembleRelease
9981024
999-
# TODO: disabled because of following fail: https://github.com/ggerganov/whisper.cpp/actions/runs/9686220096/job/26735899598
1000-
# java:
1001-
# needs: [ 'windows' ]
1002-
# runs-on: windows-latest
1003-
# steps:
1004-
# - uses: actions/checkout@v4
1005-
#
1006-
# - name: Install Java
1007-
# uses: actions/setup-java@v4
1008-
# with:
1009-
# distribution: zulu
1010-
# java-version: 20
1011-
#
1012-
# - name: Download Windows lib
1013-
# uses: actions/download-artifact@v4
1014-
# with:
1015-
# name: win32-x86-64_whisper.dll
1016-
# path: bindings/java/build/generated/resources/main/win32-x86-64
1017-
#
1018-
# - name: Build
1019-
# run: |
1020-
# models\download-ggml-model.cmd tiny.en
1021-
# cd bindings/java
1022-
# chmod +x ./gradlew
1023-
# ./gradlew build
1024-
#
1025-
# - name: Upload jar
1026-
# uses: actions/upload-artifact@v4
1027-
# with:
1028-
# name: whispercpp.jar
1029-
# path: bindings/java/build/libs/whispercpp-*.jar
1030-
#
1031-
# - name: Publish package
1032-
# if: ${{ github.ref == 'refs/heads/master' }}
1033-
# uses: gradle/gradle-build-action@v2.4.2
1034-
# with:
1035-
# arguments: publish
1036-
# build-root-directory: bindings/java
1037-
# env:
1038-
# MAVEN_USERNAME: ${{ secrets.JIRA_USER }}
1039-
# MAVEN_PASSWORD: ${{ secrets.JIRA_PASS }}
1040-
# PGP_SECRET: ${{ secrets.GPG_PRIVATE_KEY }}
1041-
# PGP_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
1025+
bindings-java:
1026+
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' ||
1027+
github.event.inputs.run_type == 'full-ci' }}
1028+
needs: ['windows']
1029+
runs-on: windows-latest
1030+
steps:
1031+
- uses: actions/checkout@v4
1032+
1033+
- name: Install Java
1034+
uses: actions/setup-java@v4
1035+
with:
1036+
distribution: zulu
1037+
java-version: 20
1038+
1039+
- name: Download Whisper Windows lib
1040+
uses: actions/download-artifact@v4
1041+
with:
1042+
name: whisper_x64.dll
1043+
1044+
- name: Download GGML Windows lib
1045+
uses: actions/download-artifact@v4
1046+
with:
1047+
name: ggml_x64.dll
1048+
1049+
- name: Download GGML Base Windows lib
1050+
uses: actions/download-artifact@v4
1051+
with:
1052+
name: ggml_base_x64.dll
1053+
1054+
- name: Download GGML CPU Windows lib
1055+
uses: actions/download-artifact@v4
1056+
with:
1057+
name: ggml_cpu_x64.dll
1058+
1059+
- name: Download SDL2.dll
1060+
uses: actions/download-artifact@v4
1061+
with:
1062+
name: x64_SDL2.dll
1063+
1064+
- name: List downloaded files
1065+
shell: pwsh
1066+
run: |
1067+
Get-ChildItem -Path "." -Recurse -Filter "*.dll"
1068+
1069+
- name: Move DLL to correct location
1070+
shell: pwsh
1071+
run: |
1072+
New-Item -Path "build\bin\Release" -ItemType Directory -Force
1073+
1074+
Copy-Item -Path "whisper.dll" -Destination "build\bin\Release\whisper.dll" -Force
1075+
Write-Host "Copied whisper.dll to build\bin\Release\whisper.dll directory"
1076+
1077+
Copy-Item -Path "ggml.dll" -Destination "build\bin\Release\ggml.dll" -Force
1078+
Write-Host "Copied ggml.dll to build\bin\Release\ggml.dll directory"
1079+
1080+
Copy-Item -Path "ggml-base.dll" -Destination "build\bin\Release\ggml-base.dll" -Force
1081+
Write-Host "Copied ggml-base.dll to build\bin\Release\ggml-base.dll directory"
1082+
1083+
Copy-Item -Path "ggml-cpu.dll" -Destination "build\bin\Release\ggml-cpu.dll" -Force
1084+
Write-Host "Copied ggml-cpu.dll to build\bin\Release\ggml-cpu.dll directory"
1085+
1086+
Copy-Item -Path "SDL2.dll" -Destination "build\bin\Release\SDL2.dll" -Force
1087+
Write-Host "Copied SDL2.dll to build\bin\Release\SDL2.dll directory"
1088+
1089+
- name: List build release files
1090+
shell: pwsh
1091+
run: |
1092+
Get-ChildItem -Path "build\Release" -Recurse -Filter "*.dll"
1093+
1094+
- name: Build
1095+
run: |
1096+
models\download-ggml-model.cmd tiny.en models/
1097+
cd bindings/java
1098+
chmod +x ./gradlew
1099+
./gradlew build --info
1100+
1101+
- name: Upload jar
1102+
uses: actions/upload-artifact@v4
1103+
with:
1104+
name: whispercpp.jar
1105+
path: bindings/java/build/libs/whispercpp-*.jar
1106+
1107+
- name: Publish package
1108+
if: ${{ github.ref == 'refs/heads/master' }}
1109+
uses: gradle/gradle-build-action@v2.4.2
1110+
with:
1111+
arguments: publish
1112+
build-root-directory: bindings/java
1113+
env:
1114+
MAVEN_USERNAME: ${{ secrets.JIRA_USER }}
1115+
MAVEN_PASSWORD: ${{ secrets.JIRA_PASS }}
1116+
PGP_SECRET: ${{ secrets.GPG_PRIVATE_KEY }}
1117+
PGP_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
10421118

10431119
quantize:
10441120
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' ||

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ if (NOT TARGET ggml)
135135
add_library(ggml ALIAS ggml::ggml)
136136
else()
137137
add_subdirectory(ggml)
138+
if(WIN32)
139+
# The following adds a _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR macro and is a workaround for
140+
# the Windows C++ standard library which does not support constexpr mutexes.
141+
# From the release notes://github.com/microsoft/STL/wiki/Changelog
142+
# Disable constexpr mutex constructor on Windows
143+
# Fixed mutex's constructor to be constexpr. #3824 #4000 #4339
144+
# Note: Programs that aren't following the documented restrictions on binary compatibility may encounter
145+
# null dereferences in mutex machinery. You must follow this rule:
146+
# When you mix binaries built by different supported versions of the toolset, the Redistributable version
147+
# must be at least as new as the latest toolset used by any app component.
148+
# You can define _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR as an escape hatch.
149+
#
150+
# Specifically to whisper.cpp this would cause a crash when using the Java bindings.
151+
# resulting in a Invalid memory access error.
152+
target_compile_definitions(ggml-base PRIVATE _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR)
153+
endif()
138154
endif()
139155
# ... otherwise assume ggml is added by a parent CMakeLists.txt
140156
endif()

bindings/java/build.gradle

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,41 @@ sourceSets {
2727
tasks.register('copyLibwhisperDynlib', Copy) {
2828
from '../../build/src'
2929
include 'libwhisper.dylib'
30-
into 'build/generated/resources/main/darwin'
30+
into 'build/generated/resources/main'
3131
}
3232

3333
tasks.register('copyLibwhisperSo', Copy) {
3434
from '../../build/src'
3535
include 'libwhisper.so'
36-
into 'build/generated/resources/main/linux-x86-64'
36+
into 'build/generated/resources/main'
3737
}
3838

39-
tasks.register('copyWhisperDll', Copy) {
40-
from '../../build/Release'
39+
tasks.register('copyWhisperDLL', Copy) {
40+
from '../../build/bin/Release'
4141
include 'whisper.dll'
42-
into 'build/generated/resources/main/windows-x86-64'
42+
into 'build/generated/resources/main'
43+
}
44+
45+
tasks.register('copyGGML_BASE_DLL', Copy) {
46+
from '../../build/bin/Release'
47+
include 'ggml-base.dll'
48+
into 'build/generated/resources/main'
49+
}
50+
51+
tasks.register('copyGGML_DLL', Copy) {
52+
from '../../build/bin/Release'
53+
include 'ggml.dll'
54+
into 'build/generated/resources/main'
55+
}
56+
57+
tasks.register('copyGGML_CPU_DLL', Copy) {
58+
from '../../build/bin/Release'
59+
include 'ggml-cpu.dll'
60+
into 'build/generated/resources/main'
4361
}
4462

4563
tasks.register('copyLibs') {
46-
dependsOn copyLibwhisperDynlib, copyLibwhisperSo, copyWhisperDll
64+
dependsOn copyLibwhisperDynlib, copyLibwhisperSo, copyWhisperDLL, copyGGML_BASE_DLL, copyGGML_DLL, copyGGML_CPU_DLL
4765
}
4866

4967
test {

bindings/java/src/main/java/io/github/ggerganov/whispercpp/WhisperCppJnaLibrary.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io.github.ggerganov.whispercpp.params.WhisperFullParams;
1010

1111
public interface WhisperCppJnaLibrary extends Library {
12+
1213
WhisperCppJnaLibrary instance = Native.load("whisper", WhisperCppJnaLibrary.class);
1314

1415
String whisper_print_system_info();

0 commit comments

Comments
 (0)