Skip to content

Commit

Permalink
Release v1.0 (#186)
Browse files Browse the repository at this point in the history
* Release v1.0

* Fix building on windows
  • Loading branch information
csukuangfj authored Nov 4, 2022
1 parent 937ca64 commit 078c709
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(sherpa)

# Remember to change
# scripts/conda-cpu/sherpa/meta.yaml
set(SHERPA_VERSION "0.9.1")
set(SHERPA_VERSION "1.0")

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
Expand Down
10 changes: 8 additions & 2 deletions cmake/cmake_extension.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2021-2022 Xiaomi Corporation (author: Fangjun Kuang)
# flake8: noqa

import os
import platform
Expand Down Expand Up @@ -107,7 +108,7 @@ def build_extension(self, ext: setuptools.extension.Extension):
cmake {cmake_args} {sherpa_dir}
make {make_args} install
make {make_args} install/strip
"""
print(f"build command is:\n{build_cmd}")

Expand All @@ -120,7 +121,12 @@ def build_extension(self, ext: setuptools.extension.Extension):
)

suffix = ".exe" if is_windows() else ""
for f in ["sherpa", "sherpa-online", "sherpa-version"]:
# Remember to also change setup.py
binaries = ["sherpa", "sherpa-online", "sherpa-version"]
binaries += ["offline_websocket_client", "offline_websocket_server"]
binaries += ["online_websocket_client", "online_websocket_server"]
binaries += ["online_websocket_client_from_microphone"]
for f in binaries:
src_file = install_dir / "bin" / (f + suffix)
print(f"Copying {src_file} to {out_bin_dir}/")
shutil.copy(f"{src_file}", f"{out_bin_dir}/")
4 changes: 4 additions & 0 deletions cmake/kaldi_native_io.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ function(download_kaldi_native_io)
PUBLIC
${kaldi_native_io_SOURCE_DIR}/
)

set_target_properties(kaldi_native_io_core PROPERTIES OUTPUT_NAME "sherpa_kaldi_native_io_core")

install(TARGETS kaldi_native_io_core DESTINATION lib)
endfunction()

download_kaldi_native_io()
8 changes: 8 additions & 0 deletions cmake/portaudio.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ function(download_portaudio)
message(STATUS "portaudio's binary dir is ${portaudio_BINARY_DIR}")

add_subdirectory(${portaudio_SOURCE_DIR} ${portaudio_BINARY_DIR} EXCLUDE_FROM_ALL)

if(BUILD_SHARED_LIBS)
set_target_properties(portaudio PROPERTIES OUTPUT_NAME "sherpa_portaudio")
install(TARGETS portaudio DESTINATION lib)
else()
set_target_properties(portaudio_static PROPERTIES OUTPUT_NAME "sherpa_portaudio_static")
install(TARGETS portaudio_static DESTINATION lib)
endif()
endfunction()

download_portaudio()
Expand Down
2 changes: 1 addition & 1 deletion scripts/conda-cpu/sherpa/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: sherpa
version: "0.9.1"
version: "1.0"

source:
path: "{{ environ.get('SHERPA_ROOT_DIR') }}"
Expand Down
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
is_windows,
)


if sys.argv[1] != "sdist":
if "K2_INSTALL_PREFIX" not in os.environ:
try:
Expand Down Expand Up @@ -76,8 +75,13 @@ def get_binaries_to_install():
bin_dir = Path("build") / "sherpa" / "bin"
bin_dir.mkdir(parents=True, exist_ok=True)
suffix = ".exe" if is_windows() else ""
# Remember to also change cmake/cmake_extension.py
binaries = ["sherpa", "sherpa-online", "sherpa-version"]
binaries += ["offline_websocket_client", "offline_websocket_server"]
binaries += ["online_websocket_client", "online_websocket_server"]
binaries += ["online_websocket_client_from_microphone"]
exe = []
for f in ["sherpa", "sherpa-online", "sherpa-version"]:
for f in binaries:
t = bin_dir / (f + suffix)
exe.append(str(t))
return exe
Expand Down
2 changes: 2 additions & 0 deletions sherpa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ add_subdirectory(csrc)
add_subdirectory(python)

add_subdirectory(cpp_api)

install(DIRECTORY bin/ DESTINATION bin/)
29 changes: 29 additions & 0 deletions sherpa/cpp_api/websocket/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ if(NOT WIN32)
target_link_libraries(online_websocket_client -pthread)
endif()


if(SHERPA_ENABLE_PORTAUDIO)
add_executable(online_websocket_client_from_microphone
online_websocket_client_from_microphone.cc
Expand All @@ -68,3 +69,31 @@ if(SHERPA_ENABLE_PORTAUDIO)
target_link_libraries(online_websocket_client_from_microphone -pthread)
endif()
endif()

set(bins
offline_websocket_server
offline_websocket_client
online_websocket_server
online_websocket_client
)
if(SHERPA_ENABLE_PORTAUDIO)
list(APPEND bins online_websocket_client_from_microphone)
endif()

foreach(exe IN LISTS bins)
if(NOT WIN32)
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE PYTHON_SITE_PACKAGE_DIR
)
message(STATUS "PYTHON_SITE_PACKAGE_DIR: ${PYTHON_SITE_PACKAGE_DIR}")
target_link_libraries(${exe} "-Wl,-rpath,${PYTHON_SITE_PACKAGE_DIR}/sherpa/lib")
target_link_libraries(${exe} "-Wl,-rpath,${SHERPA_RPATH_ORIGIN}/../lib")
endif()

install(TARGETS
${exe}
DESTINATION bin
)
endforeach()
5 changes: 5 additions & 0 deletions sherpa/cpp_api/websocket/offline_websocket_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ int32_t main(int32_t argc, char *argv[]) {
po.Register("server-ip", &server_ip, "IP address of the websocket server");
po.Register("server-port", &server_port, "Port of the websocket server");

if (argc == 1) {
po.PrintUsage();
exit(EXIT_FAILURE);
}

po.Read(argc, argv);

if (!websocketpp::uri_helper::ipv4_literal(server_ip.begin(),
Expand Down
11 changes: 11 additions & 0 deletions sherpa/cpp_api/websocket/offline_websocket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,19 @@ int32_t main(int32_t argc, char *argv[]) {
config.Register(&po);
decoder_config.Register(&po);

if (argc == 1) {
po.PrintUsage();
exit(EXIT_FAILURE);
}

po.Read(argc, argv);

if (po.NumArgs() != 0) {
SHERPA_LOG(ERROR) << "Unrecognized positional arguments!";
po.PrintUsage();
exit(EXIT_FAILURE);
}

config.Validate();
decoder_config.Validate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ int32_t main(int32_t argc, char *argv[]) {
po.Register("server-ip", &server_ip, "IP address of the websocket server");
po.Register("server-port", &server_port, "Port of the websocket server");

if (argc == 1) {
po.PrintUsage();
exit(EXIT_FAILURE);
}

po.Read(argc, argv);

if (!websocketpp::uri_helper::ipv4_literal(server_ip.begin(),
Expand All @@ -78,7 +83,7 @@ int32_t main(int32_t argc, char *argv[]) {
SHERPA_LOG(FATAL) << "Invalid server port: " << server_port;
}

if (po.NumArgs() != 0) {
if (po.NumArgs() != 1) {
po.PrintUsage();
exit(EXIT_FAILURE);
}
Expand Down
11 changes: 11 additions & 0 deletions sherpa/cpp_api/websocket/online_websocket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,19 @@ int32_t main(int32_t argc, char *argv[]) {
config.Register(&po);
decoder_config.Register(&po);

if (argc == 1) {
po.PrintUsage();
exit(EXIT_FAILURE);
}

po.Read(argc, argv);

if (po.NumArgs() != 0) {
SHERPA_LOG(ERROR) << "Unrecognized positional arguments!";
po.PrintUsage();
exit(EXIT_FAILURE);
}

config.Validate();
decoder_config.Validate();

Expand Down
2 changes: 1 addition & 1 deletion sherpa/csrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ add_executable(sherpa-version version.cc)
target_include_directories(sherpa-version PRIVATE ${CMAKE_BINARY_DIR})

install(TARGETS
sherpa_core kaldi_native_io_core
sherpa_core
DESTINATION lib
)

Expand Down

0 comments on commit 078c709

Please sign in to comment.