-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add build scripts and workflows for Windows, macOS, and Linux
- Loading branch information
Showing
4 changed files
with
550 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,166 @@ | ||
name: "Build" | ||
|
||
on: | ||
push: | ||
branches: | ||
- "main" | ||
tags: | ||
- "*" | ||
pull_request: | ||
branches: | ||
- "main" | ||
|
||
concurrency: | ||
group: "${{ github.workflow }}-${{ github.ref }}" | ||
cancel-in-progress: "${{ github.ref != 'refs/heads/main' }}" | ||
|
||
jobs: | ||
BuildMac: | ||
runs-on: "macos-13" | ||
|
||
strategy: | ||
matrix: | ||
config: | ||
- "Release" | ||
|
||
defaults: | ||
run: | ||
shell: "bash" | ||
|
||
steps: | ||
- name: "Get version" | ||
run: | | ||
if [[ $GITHUB_REF =~ ^refs/tags/ ]] | ||
then version="${GITHUB_REF#refs/tags/}" | ||
else version=main | ||
fi | ||
printf "version=%s" "$version" > "$GITHUB_OUTPUT" | ||
id: "get-version" | ||
|
||
- name: "Checkout" | ||
uses: "actions/checkout@v4" | ||
|
||
- name: "Run build-macos.sh" | ||
run: "./build-macos.sh ${{ matrix.config }} ${{ steps.get-version.outputs.version }}" | ||
|
||
- name: "Upload artifact" | ||
uses: "actions/upload-artifact@v4" | ||
with: | ||
name: "opencv-macos-${{ matrix.config }}" | ||
path: "release/*.tar.gz" | ||
|
||
BuildLinux: | ||
runs-on: "ubuntu-22.04" | ||
|
||
strategy: | ||
matrix: | ||
config: | ||
- "Release" | ||
|
||
defaults: | ||
run: | ||
shell: "bash" | ||
|
||
steps: | ||
- name: "Get version" | ||
run: | | ||
if [[ $GITHUB_REF =~ ^refs/tags/ ]] | ||
then version="${GITHUB_REF#refs/tags/}" | ||
else version=main | ||
fi | ||
printf "version=%s" "$version" > "$GITHUB_OUTPUT" | ||
id: "get-version" | ||
|
||
- name: "Checkout" | ||
uses: "actions/checkout@v4" | ||
|
||
- name: "Run build-linux.sh" | ||
run: "./build-linux.sh ${{ matrix.config }} ${{ steps.get-version.outputs.version }}" | ||
|
||
- uses: "actions/upload-artifact@v4" | ||
with: | ||
name: "opencv-linux-${{ matrix.config }}" | ||
path: "release/*.tar.gz" | ||
|
||
BuildWindows: | ||
runs-on: "windows-2022" | ||
|
||
strategy: | ||
matrix: | ||
config: | ||
- "Release" | ||
cublas: [cpu, 12.2.0, 11.8.0] | ||
|
||
steps: | ||
- name: "Get version" | ||
shell: bash | ||
run: | | ||
if [[ $GITHUB_REF =~ ^refs/tags/ ]] | ||
then version="${GITHUB_REF#refs/tags/}" | ||
else version=main | ||
fi | ||
printf "version=%s" "$version" > "$GITHUB_OUTPUT" | ||
id: "get-version" | ||
|
||
- name: "Checkout" | ||
uses: "actions/checkout@v4" | ||
|
||
- name: Install CUDA Toolkit | ||
if: ${{ matrix.cublas != 'cpu' }} | ||
id: cuda-toolkit | ||
uses: Jimver/[email protected] | ||
with: | ||
cuda: '${{ matrix.cublas }}' | ||
|
||
- name: Set CUDA_TOOLKIT_ROOT_DIR if CUDA is installed | ||
if: ${{ matrix.cublas != 'cpu' }} | ||
run: | | ||
"CUDA_TOOLKIT_ROOT_DIR=$env:CUDA_PATH" >> $env:GITHUB_ENV | ||
- name: "Run Build-Windows.ps1" | ||
run: "./Build-Windows.ps1" | ||
|
||
- uses: "actions/upload-artifact@v4" | ||
with: | ||
name: "whispercpp-windows-${{ matrix.cublas }}" | ||
path: "release/*.zip" | ||
|
||
Release: | ||
runs-on: "ubuntu-22.04" | ||
|
||
if: "github.event_name == 'push' && contains(github.ref, 'refs/tags/')" | ||
|
||
needs: | ||
# - "BuildMac" | ||
# - "BuildLinux" | ||
- "BuildWindows" | ||
|
||
permissions: | ||
contents: "write" | ||
|
||
defaults: | ||
run: | ||
shell: "bash" | ||
|
||
steps: | ||
- name: "Get version" | ||
run: | | ||
if [[ $GITHUB_REF =~ ^refs/tags/ ]] | ||
then version="${GITHUB_REF#refs/tags/}" | ||
else version=main | ||
fi | ||
printf "version=%s" "$version" > "$GITHUB_OUTPUT" | ||
id: "get-version" | ||
|
||
- name: "Download build artifacts" | ||
uses: "actions/download-artifact@v4" | ||
|
||
- name: "Create Release" | ||
uses: "softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5" | ||
with: | ||
draft: true | ||
tag_name: "${{ steps.get-version.outputs.version }}" | ||
name: "${{ steps.get-version.outputs.version }}" | ||
files: | | ||
${{ github.workspace }}/**/*.tar.gz | ||
${{ github.workspace }}/**/*.zip |
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,152 @@ | ||
cmake_minimum_required(VERSION 3.21) | ||
|
||
project(Whispercpp_prebuilt) | ||
|
||
include(ExternalProject) | ||
|
||
option(WHISPERCPP_WITH_CUDA "Build Whisper with CUDA support" OFF) | ||
|
||
set(CMAKE_OSX_ARCHITECTURES_ "arm64$<SEMICOLON>x86_64") | ||
|
||
set(Whispercpp_Build_GIT_TAG "f22d27a385d34b1e544031efe8aa2e3d73922791") | ||
|
||
if(${CMAKE_BUILD_TYPE} STREQUAL Release OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo) | ||
set(Whispercpp_BUILD_TYPE Release) | ||
else() | ||
set(Whispercpp_BUILD_TYPE Debug) | ||
endif() | ||
|
||
if(UNIX AND NOT APPLE) | ||
# On linux add the `-fPIC` flag to the compiler | ||
set(WHISPER_EXTRA_CXX_FLAGS "-fPIC") | ||
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_BLAS=OFF -DWHISPER_CUBLAS=OFF -DWHISPER_OPENBLAS=OFF -DWHISPER_NO_AVX=ON | ||
-DWHISPER_NO_AVX2=ON) | ||
endif() | ||
if(APPLE) | ||
# check the "MACOS_ARCH" env var to figure out if this is x86 or arm64 | ||
if(NOT DEFINED ENV{MACOS_ARCH}) | ||
message(FATAL_ERROR "The MACOS_ARCH environment variable is not set. Please set it to either `x86` or `arm64`") | ||
endif(NOT DEFINED ENV{MACOS_ARCH}) | ||
set(CMAKE_OSX_ARCHITECTURES_ "$ENV{MACOS_ARCH}") | ||
if($ENV{MACOS_ARCH} STREQUAL "x86_64") | ||
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_METAL=OFF -DWHISPER_COREML=OFF -DWHISPER_NO_AVX=OFF | ||
-DWHISPER_NO_AVX2=OFF -DWHISPER_NO_F16C=OFF) | ||
else() | ||
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_METAL=OFF -DWHISPER_COREML=OFF -DWHISPER_NO_AVX=ON -DWHISPER_NO_AVX2=ON | ||
-DWHISPER_NO_F16C=ON -DWHISPER_NO_FMA=ON) | ||
endif() | ||
set(WHISPER_EXTRA_CXX_FLAGS | ||
"-Wno-shorten-64-to-32 -Wno-unused-parameter -Wno-unused-function -Wno-unguarded-availability-new") | ||
endif() | ||
|
||
if(WIN32) | ||
if(WHISPERCPP_WITH_CUDA) | ||
# Build with CUDA Check that CUDA_TOOLKIT_ROOT_DIR is set | ||
if(NOT DEFINED CUDA_TOOLKIT_ROOT_DIR) | ||
message(FATAL_ERROR "CUDA_TOOLKIT_ROOT_DIR is not set. Please set it to the root directory of your CUDA " | ||
"installation, e.g. `C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.4`") | ||
endif(NOT DEFINED CUDA_TOOLKIT_ROOT_DIR) | ||
|
||
set(WHISPER_ADDITIONAL_ENV "CUDAToolkit_ROOT=${CUDA_TOOLKIT_ROOT_DIR}") | ||
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_BLAS=OFF -DWHISPER_CUBLAS=ON -DWHISPER_OPENBLAS=OFF | ||
-DCMAKE_GENERATOR_TOOLSET=cuda=${CUDA_TOOLKIT_ROOT_DIR}) | ||
else() | ||
# Build with OpenBLAS | ||
set(OpenBLAS_URL "https://github.com/xianyi/OpenBLAS/releases/download/v0.3.24/OpenBLAS-0.3.24-x64.zip") | ||
set(OpenBLAS_SHA256 "6335128ee7117ea2dd2f5f96f76dafc17256c85992637189a2d5f6da0c608163") | ||
ExternalProject_Add( | ||
OpenBLAS | ||
URL ${OpenBLAS_URL} | ||
URL_HASH SHA256=${OpenBLAS_SHA256} | ||
DOWNLOAD_NO_PROGRESS true | ||
CONFIGURE_COMMAND "" | ||
BUILD_COMMAND "" | ||
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR> <INSTALL_DIR>) | ||
ExternalProject_Get_Property(OpenBLAS INSTALL_DIR) | ||
set(OpenBLAS_DIR ${INSTALL_DIR}) | ||
set(WHISPER_ADDITIONAL_ENV "OPENBLAS_PATH=${OpenBLAS_DIR}") | ||
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_BLAS=ON -DWHISPER_CUBLAS=OFF) | ||
endif() | ||
|
||
ExternalProject_Add( | ||
Whispercpp_Build | ||
DOWNLOAD_EXTRACT_TIMESTAMP true | ||
GIT_REPOSITORY https://github.com/ggerganov/whisper.cpp.git | ||
GIT_TAG ${Whispercpp_Build_GIT_TAG} | ||
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${Whispercpp_BUILD_TYPE} | ||
BUILD_BYPRODUCTS | ||
<INSTALL_DIR>/lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX} | ||
<INSTALL_DIR>/bin/${CMAKE_SHARED_LIBRARY_PREFIX}whisper${CMAKE_SHARED_LIBRARY_SUFFIX} | ||
<INSTALL_DIR>/lib/${CMAKE_IMPORT_LIBRARY_PREFIX}whisper${CMAKE_IMPORT_LIBRARY_SUFFIX} | ||
CMAKE_GENERATOR ${CMAKE_GENERATOR} | ||
INSTALL_COMMAND | ||
${CMAKE_COMMAND} --install <BINARY_DIR> --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E copy | ||
<BINARY_DIR>/${Whispercpp_BUILD_TYPE}/whisper.lib <INSTALL_DIR>/lib && ${CMAKE_COMMAND} -E copy | ||
<SOURCE_DIR>/ggml.h <INSTALL_DIR>/include | ||
CONFIGURE_COMMAND | ||
${CMAKE_COMMAND} -E env ${WHISPER_ADDITIONAL_ENV} ${CMAKE_COMMAND} <SOURCE_DIR> -B <BINARY_DIR> -G | ||
${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} | ||
-DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 | ||
-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} | ||
-DCMAKE_C_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DBUILD_SHARED_LIBS=ON -DWHISPER_BUILD_TESTS=OFF | ||
-DWHISPER_BUILD_EXAMPLES=OFF ${WHISPER_ADDITIONAL_CMAKE_ARGS}) | ||
|
||
if(NOT WHISPERCPP_WITH_CUDA) | ||
add_dependencies(Whispercpp_Build OpenBLAS) | ||
endif(NOT WHISPERCPP_WITH_CUDA) | ||
else() | ||
# On Linux and MacOS build a static Whisper library | ||
ExternalProject_Add( | ||
Whispercpp_Build | ||
DOWNLOAD_EXTRACT_TIMESTAMP true | ||
GIT_REPOSITORY https://github.com/ggerganov/whisper.cpp.git | ||
GIT_TAG ${Whispercpp_Build_GIT_TAG} | ||
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${Whispercpp_BUILD_TYPE} | ||
BUILD_BYPRODUCTS <INSTALL_DIR>/lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX} | ||
CMAKE_GENERATOR ${CMAKE_GENERATOR} | ||
INSTALL_COMMAND ${CMAKE_COMMAND} --install <BINARY_DIR> --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E | ||
copy <SOURCE_DIR>/ggml.h <INSTALL_DIR>/include | ||
CONFIGURE_COMMAND | ||
${CMAKE_COMMAND} -E env ${WHISPER_ADDITIONAL_ENV} ${CMAKE_COMMAND} <SOURCE_DIR> -B <BINARY_DIR> -G | ||
${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} | ||
-DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 | ||
-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} | ||
-DCMAKE_C_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DBUILD_SHARED_LIBS=OFF -DWHISPER_BUILD_TESTS=OFF | ||
-DWHISPER_BUILD_EXAMPLES=OFF ${WHISPER_ADDITIONAL_CMAKE_ARGS}) | ||
endif(WIN32) | ||
|
||
ExternalProject_Get_Property(Whispercpp_Build INSTALL_DIR) | ||
|
||
# add the Whisper library to the link line | ||
if(WIN32) | ||
# copy lib/ include/ and bin/ from ${INSTALL_DIR} to the release directory in the root of the project | ||
install(DIRECTORY ${INSTALL_DIR}/lib DESTINATION ${CMAKE_SOURCE_DIR}/release) | ||
install(DIRECTORY ${INSTALL_DIR}/include DESTINATION ${CMAKE_SOURCE_DIR}/release) | ||
install(DIRECTORY ${INSTALL_DIR}/bin DESTINATION ${CMAKE_SOURCE_DIR}/release) | ||
|
||
if(NOT WHISPERCPP_WITH_CUDA) | ||
# add openblas to the link line | ||
install(DIRECTORY ${OpenBLAS_DIR}/lib DESTINATION ${CMAKE_SOURCE_DIR}/release) | ||
install(DIRECTORY ${OpenBLAS_DIR}/include DESTINATION ${CMAKE_SOURCE_DIR}/release) | ||
install(DIRECTORY ${OpenBLAS_DIR}/bin DESTINATION ${CMAKE_SOURCE_DIR}/release) | ||
else(NOT WHISPERCPP_WITH_CUDA) | ||
# normalize CUDA path with file(TO_CMAKE_PATH) | ||
file(TO_CMAKE_PATH ${CUDA_TOOLKIT_ROOT_DIR} CUDA_TOOLKIT_ROOT_DIR) | ||
# find the CUDA DLLs for cuBLAS in the bin directory of the CUDA installation e.g. cublas64_NN.dll | ||
file(GLOB CUBLAS_DLLS "${CUDA_TOOLKIT_ROOT_DIR}/bin/cublas64_*.dll") | ||
# find cublasLt DLL, e.g. cublasLt64_11.dll | ||
file(GLOB CUBLASLT_DLLS "${CUDA_TOOLKIT_ROOT_DIR}/bin/cublasLt64_*.dll") | ||
# find cudart DLL, e.g. cudart64_110.dll | ||
file(GLOB CUDART_DLLS "${CUDA_TOOLKIT_ROOT_DIR}/bin/cudart64_*.dll") | ||
# if any of the files cannot be found, abort | ||
if(NOT CUBLAS_DLLS | ||
OR NOT CUBLASLT_DLLS | ||
OR NOT CUDART_DLLS) | ||
message(FATAL_ERROR "Could not find cuBLAS, cuBLASLt or cuDART DLLs in ${CUDA_TOOLKIT_ROOT_DIR}/bin") | ||
endif() | ||
# copy the DLLs to the OBS plugin directory | ||
install(FILES ${CUBLAS_DLLS} ${CUBLASLT_DLLS} ${CUDART_DLLS} DESTINATION ${CMAKE_SOURCE_DIR}/release/bin) | ||
endif(NOT WHISPERCPP_WITH_CUDA) | ||
else() | ||
|
||
endif(WIN32) |
Oops, something went wrong.