Skip to content

Commit

Permalink
Merge pull request #9 from nekowinston/build/add-nix-flake
Browse files Browse the repository at this point in the history
build: add nix flake
  • Loading branch information
abb128 authored May 17, 2023
2 parents e20a766 + 9979ff5 commit 1bb4289
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ bindings/csharp/AprilAsrDemo/obj
bindings/python/build
bindings/python/dist
april-docs/src/csharp/html
april-docs/src/april_asr
april-docs/src/april_asr
/result
/result-dev
26 changes: 24 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
cmake_minimum_required(VERSION 3.5)
include(CheckIncludeFile)
include(GNUInstallDirs)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

project(aprilasr)
project(aprilasr
VERSION 2023.05.12
DESCRIPTION "aprilasr is a minimal library that provides an API for offline streaming speech-to-text applications"
HOMEPAGE_URL "https://github.com/abb128/april-asr")

if(WIN32)
set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
Expand Down Expand Up @@ -107,6 +111,8 @@ set(april_sources
src/sonic/sonic.c
)

file(GLOB_RECURSE april_headers "*.h")

if(DEFINED USE_TINYCTHREAD)
set(HAVE_C11_THREADS FALSE)
else()
Expand All @@ -133,8 +139,24 @@ target_link_libraries(aprilasr_static ${onnx_link_libraries})
add_library(aprilasr SHARED ${april_sources})
target_link_libraries(aprilasr ${onnx_link_libraries})

set_target_properties(aprilasr PROPERTIES PUBLIC_HEADER "${april_headers}")

add_executable(main example.cpp)
target_link_libraries(main PRIVATE aprilasr_static ${onnx_link_libraries})

add_executable(srt example_srt.cpp)
target_link_libraries(srt PRIVATE aprilasr_static ${onnx_link_libraries})
target_link_libraries(srt PRIVATE aprilasr_static ${onnx_link_libraries})

install(TARGETS aprilasr
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
@ONLY
)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig
)
11 changes: 11 additions & 0 deletions aprilasr.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@CMAKE_INSTALL_PREFIX@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@/@PROJECT_NAME@
libdir=@CMAKE_INSTALL_FULL_LIBDIR@

Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
URL: @PROJECT_HOMEPAGE_URL@
Version: @PROJECT_VERSION@
Requires:
Cflags: -I"${includedir}"
Libs: -L"${libdir}" -l@PROJECT_NAME@
78 changes: 78 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
description = "april-asr flake";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs-onnxruntime114.url = "github:nixos/nixpkgs/c7d48290f9da479dcab26eac5db6299739c595c2";
};
outputs = {
self,
nixpkgs,
nixpkgs-onnxruntime114,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [
# TODO: remove once https://github.com/NixOS/nixpkgs/pull/226734 is merged
(
final: prev: {
onnxruntime = nixpkgs-onnxruntime114.legacyPackages.${prev.system}.onnxruntime;
}
)
];
};
inherit (pkgs) lib;
inherit (pkgs.stdenv.hostPlatform) isDarwin;
in {
packages = rec {
onnxruntime_1_14 =
if isDarwin
then pkgs.onnxruntime
else
(pkgs.onnxruntime.overrideAttrs
(final: {
buildInputs = final.buildInputs ++ [pkgs.protobuf];
}))
.override {
pythonSupport = false;
useOneDNN = false;
};
april-asr = pkgs.stdenv.mkDerivation {
src = ./.;
name = "april-asr";

nativeBuildInputs = with pkgs; [
cmake
pkg-config
];
buildInputs = [onnxruntime_1_14];

outputs = ["out" "dev"];

meta = with lib; {
description = "Speech-to-text library in C";
homepage = "https://github.com/abb128/april-asr";
license = licenses.gpl3;
};
};
default = april-asr;
};
devShells.default = pkgs.mkShell {
inherit (self.packages.${system}.default) buildInputs nativeBuildInputs;
shellHook = ''
export LD_LIBRARY_PATH=${self.packages.${system}.onnxruntime_1_14}/lib
'';
};
}
);
}

0 comments on commit 1bb4289

Please sign in to comment.