Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows workflow #7

Merged
merged 21 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .dockerignore

This file was deleted.

89 changes: 89 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: main

on:
workflow_dispatch:
push:
tags:
- "*"

jobs:
create_release:
name: Create release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false
build_linux:
name: "linux build: ${{ matrix.arch }}"
runs-on: ubuntu-20.04 # use older version on purpose for GLIBC
needs: create_release # we need to know the upload URL
strategy:
fail-fast: true
matrix:
arch: [x64, aarch64, armv7]
steps:
- uses: actions/checkout@v3
- name: configure
run: |
cmake -Bbuild -DCMAKE_INSTALL_PREFIX=_install/piper-phonemize
- name: build
run: |
cmake --build build --config Release
- name: install
run: |
cmake --install build
- name: package
run: |
cd _install && \
tar -czf piper-phonemize_linux_${{ matrix.arch }}.tar.gz piper-phonemize/
- name: upload
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: _install/piper-phonemize_linux_${{ matrix.arch }}.tar.gz
asset_name: piper-phonemize_linux_${{ matrix.arch }}.tar.gz
asset_content_type: application/octet-stream
build_windows:
runs-on: windows-latest
name: "windows build: ${{ matrix.arch }}"
needs: create_release # we need to know the upload URL
strategy:
fail-fast: true
matrix:
arch: [x64]
steps:
- uses: actions/checkout@v3
- name: configure
run: |
cmake -Bbuild -DCMAKE_INSTALL_PREFIX=_install/piper-phonemize
- name: build
run: |
cmake --build build --config Release
- name: install
run: |
cmake --install build
- name: package
run: |
cd _install
Compress-Archive -LiteralPath piper-phonemize -DestinationPath piper-phonemize_windows_amd64.zip
- name: upload
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: _install/piper-phonemize_windows_amd64.zip
asset_name: piper-phonemize_windows_amd64.zip
asset_content_type: application/zip
43 changes: 0 additions & 43 deletions .github/workflows/windows.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ htmlcov
/*.so
/test

espeak-ng-data/

/espeak-ng/
/lib/
/download/
/cmake/
/_install/
180 changes: 148 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,86 +10,185 @@ project(
LANGUAGES CXX
)

string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wl,-rpath,'$ORIGIN'")
string(APPEND CMAKE_C_FLAGS " -Wall -Wextra")
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>")

# lib/Linux-x86_64
# lib/Linux-aarch64
set(ONNXRUNTIME_ROOTDIR ${CMAKE_CURRENT_LIST_DIR}/lib/${CMAKE_HOST_SYSTEM_NAME}-${CMAKE_HOST_SYSTEM_PROCESSOR}/onnxruntime)

# ---- espeak-ng ---

find_package(PkgConfig)
pkg_check_modules(ESPEAK_NG REQUIRED espeak-ng<2)

# ---- Declare library ----
elseif(NOT APPLE)
# Linux flags
string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wl,-rpath,'$ORIGIN'")
string(APPEND CMAKE_C_FLAGS " -Wall -Wextra")
endif()

add_library(
piper_phonemize SHARED
src/phonemize.cpp
src/phoneme_ids.cpp
src/tashkeel.cpp
src/shared.cpp
)

set_target_properties(piper_phonemize PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})
SOVERSION ${PROJECT_VERSION_MAJOR}
)

# ---- onnxruntime ---

# Look for onnxruntime files in <root>/lib
if(NOT DEFINED ONNXRUNTIME_DIR)
if(NOT DEFINED ONNXRUNTIME_VERSION)
set(ONNXRUNTIME_VERSION "1.14.1")
endif()

if(WIN32)
# Windows x86-64
set(ONNXRUNTIME_PREFIX "onnxruntime-win-x64-${ONNXRUNTIME_VERSION}")
set(ONNXRUNTIME_EXT "zip")
else()
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
# Linux x86-64
set(ONNXRUNTIME_PREFIX "onnxruntime-linux-x64-${ONNXRUNTIME_VERSION}")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
# Linux ARM 64-bit
set(ONNXRUNTIME_PREFIX "onnxruntime-linux-aarch64-${ONNXRUNTIME_VERSION}")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l)
# Linux ARM 32-bit
set(ONNXRUNTIME_PREFIX "onnxruntime-linux-arm32-${ONNXRUNTIME_VERSION}")
set(ONNXRUNTIME_URL "https://github.com/synesthesiam/prebuilt-apps/releases/download/v1.0/onnxruntime-linux-arm32-${ONNXRUNTIME_VERSION}.tgz")
else()
message(FATAL_ERROR "Unsupported architecture for onnxruntime")
endif()

set(ONNXRUNTIME_EXT "tgz")
endif()

if(NOT DEFINED ONNXRUNTIME_URL)
set(ONNXRUNTIME_URL "https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/${ONNXRUNTIME_PREFIX}.${ONNXRUNTIME_EXT}")
endif()

set(ONNXRUNTIME_FILENAME "${ONNXRUNTIME_PREFIX}.${ONNXRUNTIME_EXT}")
set(ONNXRUNTIME_DIR "${CMAKE_CURRENT_LIST_DIR}/lib/${ONNXRUNTIME_PREFIX}")

if(NOT EXISTS "${ONNXRUNTIME_DIR}")
if(NOT EXISTS "download/${ONNXRUNTIME_FILENAME}")
# Download onnxruntime release
message("Downloading ${ONNXRUNTIME_URL}")
file(DOWNLOAD "${ONNXRUNTIME_URL}" "download/${ONNXRUNTIME_FILENAME}")
endif()

# Extract .zip or .tgz to a directory like lib/onnxruntime-linux-x64-1.14.1/
file(ARCHIVE_EXTRACT INPUT "download/${ONNXRUNTIME_FILENAME}" DESTINATION "${CMAKE_CURRENT_LIST_DIR}/lib")
endif()
endif()

# ---- espeak-ng ---

if(NOT DEFINED ESPEAK_NG_DIR)
set(ESPEAK_NG_DIR "${CMAKE_CURRENT_BINARY_DIR}/ei")

include(ExternalProject)
ExternalProject_Add(
espeak_ng_external
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/e"
URL "https://github.com/rhasspy/espeak-ng/archive/refs/heads/master.zip"
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${ESPEAK_NG_DIR}
CMAKE_ARGS -DUSE_ASYNC:BOOL=OFF
CMAKE_ARGS -DBUILD_SHARED_LIBS:BOOL=ON
CMAKE_ARGS -DUSE_MBROLA:BOOL=OFF
CMAKE_ARGS -DUSE_LIBSONIC:BOOL=OFF
CMAKE_ARGS -DUSE_LIBPCAUDIO:BOOL=OFF
CMAKE_ARGS -DUSE_KLATT:BOOL=OFF
CMAKE_ARGS -DUSE_SPEECHPLAYER:BOOL=OFF
CMAKE_ARGS -DEXTRA_cmn:BOOL=ON
CMAKE_ARGS -DEXTRA_ru:BOOL=ON
)
add_dependencies(piper_phonemize espeak_ng_external)
endif()


# ---- Declare library ----

target_include_directories(
piper_phonemize PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>"
${ESPEAK_NG_INCLUDE_DIRS}
${ONNXRUNTIME_ROOTDIR}/include
${ESPEAK_NG_DIR}/include
${ONNXRUNTIME_DIR}/include
)

target_link_directories(
piper_phonemize PUBLIC
${ESPEAK_NG_LIBRARY_DIRS}
${ONNXRUNTIME_ROOTDIR}/lib
${ESPEAK_NG_DIR}/lib
${ONNXRUNTIME_DIR}/lib
)

target_link_libraries(
piper_phonemize
${ESPEAK_NG_LIBRARIES}
espeak-ng
onnxruntime
)

target_compile_options(
piper_phonemize PUBLIC
${ESPEAK_NG_CFLAGS_OTHER}
)

target_compile_features(piper_phonemize PUBLIC cxx_std_17)

# ---- Declare executable ----

add_executable(piper_phonemize_exe src/main.cpp)
set_property(TARGET piper_phonemize_exe PROPERTY OUTPUT_NAME piper_phonemize)
add_executable(piper_phonemize_exe src/main.cpp src/phoneme_ids.cpp)

if(NOT WIN32)
set_property(TARGET piper_phonemize_exe PROPERTY OUTPUT_NAME piper_phonemize)
endif()

target_compile_features(piper_phonemize_exe PUBLIC cxx_std_17)

target_include_directories(
piper_phonemize_exe PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>"
${ESPEAK_NG_INCLUDE_DIRS}
${ESPEAK_NG_DIR}/include
)

target_link_directories(
piper_phonemize_exe PUBLIC
${ESPEAK_NG_LIBRARY_DIRS}
${ESPEAK_NG_DIR}/lib
)

target_link_libraries(piper_phonemize_exe PUBLIC
piper_phonemize
${ESPEAK_NG_LIBRARIES})
piper_phonemize
espeak-ng
)

target_compile_options(
piper_phonemize_exe PUBLIC
${ESPEAK_NG_CFLAGS_OTHER}
# ---- Declare test ----

include(CTest)
enable_testing()
add_executable(test_piper_phonemize src/test.cpp src/phoneme_ids.cpp)
add_test(
NAME test_piper_phonemize
COMMAND test_piper_phonemize "${ESPEAK_NG_DIR}/share/espeak-ng-data" "${CMAKE_SOURCE_DIR}/etc/libtashkeel_model.ort"
)

target_compile_features(test_piper_phonemize PUBLIC cxx_std_17)

target_include_directories(
test_piper_phonemize PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>"
${ESPEAK_NG_DIR}/include
)

target_link_directories(
test_piper_phonemize PUBLIC
${ESPEAK_NG_DIR}/lib
)

target_link_libraries(test_piper_phonemize PUBLIC
piper_phonemize
espeak-ng
)

# ---- Declare install targets ----

include(GNUInstallDirs)

install(
TARGETS piper_phonemize
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
Expand All @@ -104,3 +203,20 @@ install(
install(
TARGETS piper_phonemize_exe
ARCHIVE DESTINATION ${CMAKE_INSTALL_BINDIR})

install(
FILES ${CMAKE_SOURCE_DIR}/etc/libtashkeel_model.ort
TYPE DATA)

# Dependencies
install(
DIRECTORY ${ESPEAK_NG_DIR}/
DESTINATION ${CMAKE_INSTALL_PREFIX})

install(
DIRECTORY ${ONNXRUNTIME_DIR}/include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

install(
DIRECTORY ${ONNXRUNTIME_DIR}/lib/
DESTINATION ${CMAKE_INSTALL_LIBDIR})
Loading