-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use cmake; use MSVC compiler on windows
- Loading branch information
Showing
7 changed files
with
185 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,10 @@ jobs: | |
build-lib-debian-x86_64: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/download-artifact@v3 | ||
- uses: actions/checkout@v4 | ||
- uses: actions/download-artifact@v4 | ||
- name: Docker Setup Buildx | ||
uses: docker/setup-buildx-action@v1.6.0 | ||
uses: docker/setup-buildx-action@v3 | ||
with: | ||
install: true | ||
- name: Setup project dir | ||
|
@@ -21,20 +21,20 @@ jobs: | |
docker build --build-arg="RUN_TESTS=true" -f dockerfile . -t libfvadjni_binary:x86_64 --load | ||
docker run --platform=amd64 -v $(pwd)/dist:/out libfvadjni_binary:x86_64 bash -c "cp src/main/resources/debian-amd64/*.so /out/" | ||
- name: Artifact debian x86_64 | ||
uses: actions/upload-artifact@v3 | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: debian-binary-amd64 | ||
path: dist/*.so | ||
|
||
build-lib-debian-arm64: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/download-artifact@v3 | ||
- uses: actions/checkout@v4 | ||
- uses: actions/download-artifact@v4 | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
uses: docker/setup-qemu-action@v3 | ||
- name: Docker Setup Buildx | ||
uses: docker/setup-buildx-action@v1.6.0 | ||
uses: docker/setup-buildx-action@v3 | ||
with: | ||
install: true | ||
- name: Setup project dir | ||
|
@@ -45,20 +45,20 @@ jobs: | |
docker build -f dockerfile . -t libfvadjni_binary:arm64 --platform arm64 --load | ||
DOCKER_BUILDKIT=1 docker run --platform=arm64 -v $(pwd)/dist:/out libfvadjni_binary:arm64 bash -c "cp src/main/resources/debian-arm64/*.so /out/" | ||
- name: Artifact debian arm64 | ||
uses: actions/upload-artifact@v3 | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: debian-binary-arm64 | ||
path: dist/*.so | ||
|
||
build-lib-debian-arm: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/download-artifact@v3 | ||
- uses: actions/checkout@v4 | ||
- uses: actions/download-artifact@v4 | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
uses: docker/setup-qemu-action@v3 | ||
- name: Docker Setup Buildx | ||
uses: docker/setup-buildx-action@v1.6.0 | ||
uses: docker/setup-buildx-action@v3 | ||
with: | ||
install: true | ||
- name: Setup project dir | ||
|
@@ -69,17 +69,17 @@ jobs: | |
docker build -f dockerfile . -t libfvadjni_binary:armv7l --platform arm --load | ||
DOCKER_BUILDKIT=1 docker run --platform=arm -v $(pwd)/dist:/out libfvadjni_binary:armv7l bash -c "cp src/main/resources/debian-armv7l/*.so /out/" | ||
- name: Artifact debian armv7l | ||
uses: actions/upload-artifact@v3 | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: debian-binary-armv7l | ||
path: dist/*.so | ||
|
||
build-lib-windows: | ||
runs-on: windows-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/download-artifact@v3 | ||
- uses: actions/setup-java@v3 | ||
- uses: actions/checkout@v4 | ||
- uses: actions/download-artifact@v4 | ||
- uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'zulu' | ||
java-version: '17' | ||
|
@@ -92,77 +92,91 @@ jobs: | |
shell: powershell | ||
run: | | ||
.\build_win.ps1 | ||
mv src\main\resources\win-amd64\libfvadjni.dll .\dist\ | ||
mv src\main\resources\win-amd64\libfvad-jni.dll .\dist\ | ||
- name: Artifact windows x86_64 | ||
uses: actions/upload-artifact@v3 | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: windows-binary-x86_64 | ||
path: dist/libfvadjni.dll | ||
path: dist/*.dll | ||
|
||
build-lib-macos: | ||
runs-on: macos-latest | ||
build-lib-macos-amd64: | ||
runs-on: macos-13 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/download-artifact@v3 | ||
- uses: actions/setup-java@v3 | ||
- uses: actions/checkout@v4 | ||
- uses: actions/download-artifact@v4 | ||
- uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'zulu' | ||
java-version: '17' | ||
# - name: Set up Maven | ||
# uses: stCarolas/[email protected] | ||
# with: | ||
# maven-version: 3.9.2 | ||
- name: Setup project dir | ||
run: | | ||
export DYLD_LIBRARY_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/ | ||
mkdir -p dist | ||
mkdir -p dist_arm64 | ||
git submodule update --init | ||
- name: Build binary | ||
run: | | ||
export DYLD_LIBRARY_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/ | ||
./build_macos.sh amd64 | ||
./build_macos.sh arm64 | ||
# mvn test | ||
mv src/main/resources/macos-amd64/libfvadjni.dylib dist/ | ||
mv src/main/resources/macos-arm64/libfvadjni.dylib dist_arm64/ | ||
mv src/main/resources/macos-amd64/*.dylib dist/ | ||
- name: Artifact macos amd64 | ||
uses: actions/upload-artifact@v3 | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: macos-binary-amd64 | ||
path: dist/libfvadjni.dylib | ||
path: dist/*.dylib | ||
|
||
|
||
build-lib-macos-arm64: | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/download-artifact@v4 | ||
- uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'zulu' | ||
java-version: '17' | ||
- name: Setup project dir | ||
run: | | ||
export DYLD_LIBRARY_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/ | ||
mkdir -p dist_arm64 | ||
git submodule update --init | ||
- name: Build binary | ||
run: | | ||
export DYLD_LIBRARY_PATH=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/ | ||
./build_macos.sh arm64 | ||
mv src/main/resources/macos-arm64/*.dylib dist_arm64/ | ||
- name: Artifact macos arm64 | ||
uses: actions/upload-artifact@v3 | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: macos-binary-arm64 | ||
path: dist_arm64/libfvadjni.dylib | ||
path: dist_arm64/*.dylib | ||
|
||
deploy: | ||
if: startsWith(github.ref, 'refs/tags/') | ||
needs: [build-lib-debian-x86_64,build-lib-debian-arm,build-lib-debian-arm64,build-lib-windows,build-lib-macos] | ||
needs: [build-lib-debian-x86_64,build-lib-debian-arm,build-lib-debian-arm64,build-lib-windows,build-lib-macos-amd64,build-lib-macos-arm64] | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/download-artifact@v3 | ||
- uses: actions/download-artifact@v4 | ||
- name: check tree | ||
run: ls -R | ||
- name: setup resources | ||
run: | | ||
mv ./debian-binary-amd64/*.so ./src/main/resources/debian-amd64/ | ||
mv ./debian-binary-arm64/*.so ./src/main/resources/debian-arm64/ | ||
mv ./debian-binary-armv7l/*.so ./src/main/resources/debian-armv7l/ | ||
mv ./windows-binary-x86_64/libfvadjni.dll ./src/main/resources/win-amd64/libfvadjni.dll | ||
mv ./macos-binary-amd64/libfvadjni.dylib ./src/main/resources/macos-amd64/libfvadjni.dylib | ||
mv ./macos-binary-arm64/libfvadjni.dylib ./src/main/resources/macos-arm64/libfvadjni.dylib | ||
mv ./windows-binary-x86_64/*.dll ./src/main/resources/win-amd64/ | ||
mv ./macos-binary-amd64/*.dylib ./src/main/resources/macos-amd64/ | ||
mv ./macos-binary-arm64/*.dylib ./src/main/resources/macos-arm64/ | ||
- name: Set up Maven Central Repository | ||
uses: actions/setup-java@v1 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: 17 | ||
distribution: 'zulu' | ||
server-id: sonatype-nexus-staging | ||
server-username: MAVEN_USERNAME | ||
server-password: MAVEN_PASSWORD | ||
server-password: MAVEN_CENTRAL_TOKEN | ||
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} | ||
gpg-passphrase: MAVEN_GPG_PASSPHRASE | ||
- name: Deploy with Maven | ||
|
@@ -175,7 +189,7 @@ jobs: | |
echo "LIBFVAD_VERSION=$LIBFVAD_VERSION" >> $GITHUB_OUTPUT | ||
env: | ||
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} | ||
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} | ||
MAVEN_CENTRAL_TOKEN: ${{ secrets.OSSRH_TOKEN }} | ||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} | ||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
project(libfvad-jni C CXX) | ||
|
||
# ---- Set options ---- | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
set(JAVA_AWT_LIBRARY NotNeeded) | ||
set(JAVA_JVM_LIBRARY NotNeeded) | ||
find_package(JNI REQUIRED) | ||
if (JNI_FOUND) | ||
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}") | ||
endif() | ||
|
||
if(MSVC) | ||
# Force compiler to use UTF-8 for IPA constants | ||
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>") | ||
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>") | ||
elseif(NOT APPLE) | ||
string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wl,-rpath,'$ORIGIN'") | ||
string(APPEND CMAKE_C_FLAGS " -Wall -Wextra") | ||
set(CMAKE_INSTALL_RPATH '$ORIGIN') | ||
elseif(APPLE) | ||
set(CMAKE_INSTALL_RPATH "@loader_path") | ||
endif() | ||
|
||
# ---- Declare libraries ---- | ||
|
||
add_library(libfvad-jni SHARED src/main/native/io_github_givimad_libfvadjni_VoiceActivityDetector.cpp) | ||
|
||
if(NOT DEFINED LIBFVAD_DIR) | ||
set(LIBFVAD_DIR "${CMAKE_CURRENT_BINARY_DIR}/libfvad.s") | ||
set(LIBFVAD_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/libfvad") | ||
include(ExternalProject) | ||
ExternalProject_Add( | ||
libfvad-external | ||
PREFIX "${LIBFVAD_INSTALL_DIR}" | ||
URL "${CMAKE_CURRENT_LIST_DIR}/src/main/native/libfvad" | ||
CMAKE_ARGS -DCMAKE_INSTALL_RPATH:STRING=${CMAKE_INSTALL_RPATH} -DCMAKE_INSTALL_PREFIX:PATH=${LIBFVAD_DIR} -DCMAKE_OSX_ARCHITECTURES:STRING=${CMAKE_OSX_ARCHITECTURES} -DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=${CMAKE_OSX_DEPLOYMENT_TARGET} | ||
) | ||
add_dependencies(libfvad-jni libfvad-external) | ||
endif() | ||
|
||
# ---- Declare executable ---- | ||
|
||
if((NOT MSVC) AND (NOT APPLE)) | ||
# Linux flags | ||
string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wl,-rpath,'$ORIGIN'") | ||
string(APPEND CMAKE_C_FLAGS " -Wall -Wextra") | ||
# target_link_libraries(libfvad-jni -static-libgcc -static-libstdc++) | ||
endif() | ||
|
||
if(MSVC) | ||
target_link_libraries(libfvad-jni | ||
fvad | ||
) | ||
else() | ||
target_link_libraries(libfvad-jni | ||
libfvad.a | ||
) | ||
endif() | ||
target_link_directories(libfvad-jni PUBLIC | ||
${LIBFVAD_DIR}/lib | ||
${LIBFVAD_DIR}/lib/static | ||
) | ||
|
||
target_include_directories(libfvad-jni PUBLIC | ||
${JNI_INCLUDE_DIRS} | ||
src/main/native | ||
${LIBFVAD_DIR}/include | ||
) | ||
|
||
# ---- Declare install targets ---- | ||
|
||
install( | ||
TARGETS libfvad-jni | ||
DESTINATION ${CMAKE_INSTALL_PREFIX} | ||
) | ||
|
||
# Dependencies | ||
|
||
install( | ||
DIRECTORY ${LIBFVAD_DIR}/lib/ | ||
DESTINATION ${CMAKE_INSTALL_PREFIX} | ||
USE_SOURCE_PERMISSIONS | ||
FILES_MATCHING | ||
PATTERN "*.so.*" | ||
PATTERN "*.so" | ||
PATTERN "*.dylib" | ||
) | ||
|
||
install( | ||
DIRECTORY ${LIBFVAD_DIR}/bin/ | ||
DESTINATION ${CMAKE_INSTALL_PREFIX} | ||
USE_SOURCE_PERMISSIONS | ||
FILES_MATCHING | ||
PATTERN "*.dll" | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,5 @@ | ||
Set-PSDebug -Trace 1 | ||
|
||
cd src\main\native\libfvad | ||
cmake . -G "MinGW Makefiles" | ||
cmake --build . | ||
cd ..\..\..\..\ | ||
|
||
g++ -c -std=c++11 -O3 -DNDEBUG -fPIC -I $env:JAVA_HOME\include -I $env:JAVA_HOME\include\win32 -I src\main\native\libfvad\include -I src\main\native src\main\native\io_github_givimad_libfvadjni_VoiceActivityDetector.cpp -o src\main\native\io_github_givimad_libfvadjni_VoiceActivityDetector.o | ||
|
||
g++ -shared -static -I src\main\native\libfvad\include -I src\main\native -o src\main\resources\win-amd64\libfvadjni.dll src\main\native\libfvad\src\CMakeFiles\fvad.dir\*.c.obj src\main\native\libfvad\src\CMakeFiles\fvad.dir\vad\*.c.obj src\main\native\libfvad\src\CMakeFiles\fvad.dir\signal_processing\*.c.obj src\main\native\libfvad\src\libfvad.a src\main\native\io_github_givimad_libfvadjni_VoiceActivityDetector.o | ||
|
||
if ($LastExitCode -ne 0) { | ||
Write-Error "Unable to build library" | ||
Exit 1 | ||
} | ||
|
||
rm -fo src\main\native\*.o | ||
cd src\main\native\libfvad | ||
git clean -d -f -x | ||
cd ..\..\..\..\ | ||
Set-PSDebug -Trace 0 | ||
cmake -B build -DCMAKE_INSTALL_PREFIX=src/main/resources/win-amd64 | ||
cmake --build build --config Release | ||
cmake --install build | ||
rm -r -fo build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.