danbev commited on
Commit
469f43c
·
unverified ·
1 Parent(s): 4a21ad6

ci : enable bindings java job (#3070)

Browse files

* 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: https://github.com/ggerganov/whisper.cpp/pull/2949
Resolves: https://github.com/ggerganov/whisper.cpp/issues/2781

.github/workflows/build.yml CHANGED
@@ -561,6 +561,7 @@ jobs:
561
  run: >
562
  cmake -S . -B ./build -A ${{ matrix.arch }}
563
  -DCMAKE_BUILD_TYPE=${{ matrix.build }}
 
564
  -DWHISPER_SDL2=${{ matrix.sdl2 }}
565
 
566
  - name: Build
@@ -572,12 +573,37 @@ jobs:
572
  if: matrix.sdl2 == 'ON'
573
  run: copy "$env:SDL2_DIR/../lib/${{ matrix.s2arc }}/SDL2.dll" build/bin/${{ matrix.build }}
574
 
575
- - name: Upload dll
 
576
  uses: actions/upload-artifact@v4
577
  with:
578
- name: ${{ matrix.jnaPath }}_whisper.dll
 
 
 
 
 
 
579
  path: build/bin/${{ matrix.build }}/whisper.dll
580
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
581
  - name: Upload binaries
582
  if: matrix.sdl2 == 'ON'
583
  uses: actions/upload-artifact@v4
@@ -996,49 +1022,99 @@ jobs:
996
  chmod +x ./gradlew
997
  ./gradlew assembleRelease
998
 
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 }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1042
 
1043
  quantize:
1044
  if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' ||
 
561
  run: >
562
  cmake -S . -B ./build -A ${{ matrix.arch }}
563
  -DCMAKE_BUILD_TYPE=${{ matrix.build }}
564
+ -DBUILD_SHARED_LIBS=ON
565
  -DWHISPER_SDL2=${{ matrix.sdl2 }}
566
 
567
  - name: Build
 
573
  if: matrix.sdl2 == 'ON'
574
  run: copy "$env:SDL2_DIR/../lib/${{ matrix.s2arc }}/SDL2.dll" build/bin/${{ matrix.build }}
575
 
576
+ - name: Upload SDL2.dll
577
+ if: matrix.sdl2 == 'ON'
578
  uses: actions/upload-artifact@v4
579
  with:
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
587
  path: build/bin/${{ matrix.build }}/whisper.dll
588
 
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
+
607
  - name: Upload binaries
608
  if: matrix.sdl2 == 'ON'
609
  uses: actions/upload-artifact@v4
 
1022
  chmod +x ./gradlew
1023
  ./gradlew assembleRelease
1024
 
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/[email protected]
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 }}
1118
 
1119
  quantize:
1120
  if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' ||
CMakeLists.txt CHANGED
@@ -135,6 +135,22 @@ if (NOT TARGET ggml)
135
  add_library(ggml ALIAS ggml::ggml)
136
  else()
137
  add_subdirectory(ggml)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  endif()
139
  # ... otherwise assume ggml is added by a parent CMakeLists.txt
140
  endif()
 
135
  add_library(ggml ALIAS ggml::ggml)
136
  else()
137
  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()
154
  endif()
155
  # ... otherwise assume ggml is added by a parent CMakeLists.txt
156
  endif()
bindings/java/build.gradle CHANGED
@@ -27,23 +27,41 @@ sourceSets {
27
  tasks.register('copyLibwhisperDynlib', Copy) {
28
  from '../../build/src'
29
  include 'libwhisper.dylib'
30
- into 'build/generated/resources/main/darwin'
31
  }
32
 
33
  tasks.register('copyLibwhisperSo', Copy) {
34
  from '../../build/src'
35
  include 'libwhisper.so'
36
- into 'build/generated/resources/main/linux-x86-64'
37
  }
38
 
39
- tasks.register('copyWhisperDll', Copy) {
40
- from '../../build/Release'
41
  include 'whisper.dll'
42
- into 'build/generated/resources/main/windows-x86-64'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  }
44
 
45
  tasks.register('copyLibs') {
46
- dependsOn copyLibwhisperDynlib, copyLibwhisperSo, copyWhisperDll
47
  }
48
 
49
  test {
 
27
  tasks.register('copyLibwhisperDynlib', Copy) {
28
  from '../../build/src'
29
  include 'libwhisper.dylib'
30
+ into 'build/generated/resources/main'
31
  }
32
 
33
  tasks.register('copyLibwhisperSo', Copy) {
34
  from '../../build/src'
35
  include 'libwhisper.so'
36
+ into 'build/generated/resources/main'
37
  }
38
 
39
+ tasks.register('copyWhisperDLL', Copy) {
40
+ from '../../build/bin/Release'
41
  include 'whisper.dll'
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'
61
  }
62
 
63
  tasks.register('copyLibs') {
64
+ dependsOn copyLibwhisperDynlib, copyLibwhisperSo, copyWhisperDLL, copyGGML_BASE_DLL, copyGGML_DLL, copyGGML_CPU_DLL
65
  }
66
 
67
  test {
bindings/java/src/main/java/io/github/ggerganov/whispercpp/WhisperCppJnaLibrary.java CHANGED
@@ -9,6 +9,7 @@ import io.github.ggerganov.whispercpp.params.WhisperContextParams;
9
  import io.github.ggerganov.whispercpp.params.WhisperFullParams;
10
 
11
  public interface WhisperCppJnaLibrary extends Library {
 
12
  WhisperCppJnaLibrary instance = Native.load("whisper", WhisperCppJnaLibrary.class);
13
 
14
  String whisper_print_system_info();
 
9
  import io.github.ggerganov.whispercpp.params.WhisperFullParams;
10
 
11
  public interface WhisperCppJnaLibrary extends Library {
12
+
13
  WhisperCppJnaLibrary instance = Native.load("whisper", WhisperCppJnaLibrary.class);
14
 
15
  String whisper_print_system_info();