Created
July 4, 2025 09:41
-
-
Save izelnakri/fb39313b7f68558fad1802adb8fa0555 to your computer and use it in GitHub Desktop.
OneAPI whisper.cpp ongoing in-development build process
This file contains hidden or 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
# OneAPI whisper.cpp ongoing in-development build process | |
# devShell works(with FHS), `$ nix run .` doesn't work yet, needs OneAPI on nixpkgs/derivation. | |
{ | |
description = "Development environment for whisper.cpp with Intel compilers and SYCL"; | |
inputs = { | |
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | |
flake-utils.url = "github:numtide/flake-utils"; | |
}; | |
outputs = { self, nixpkgs, flake-utils }: | |
flake-utils.lib.eachDefaultSystem (system: | |
let | |
pkgs = nixpkgs.legacyPackages.${system}; | |
getAllPkgConfigPaths = pkgs: inputs: | |
let | |
allDeps = pkgs.lib.closePropagation inputs; | |
in | |
pkgs.lib.makeSearchPathOutput "out" "lib/pkgconfig" allDeps + ":" + | |
pkgs.lib.makeSearchPathOutput "out" "share/pkgconfig" allDeps + ":" + | |
pkgs.lib.makeSearchPathOutput "dev" "lib/pkgconfig" allDeps + ":" + | |
pkgs.lib.makeSearchPathOutput "dev" "share/pkgconfig" allDeps; | |
FHSTargetPkgs = with pkgs; [ | |
glibc.dev # NOTE: Required: #include <stdio.h> | |
gcc-unwrapped # NOTE: essential! for pass binutils-2.44/bin/ld: cannot find crtbegin.o: No such file or directory | |
zlib # NOTE: loading shared libraries: libz.so | |
# intel-compute-runtime.drivers # NOTE: Good addition to expose the driver for CI | |
level-zero # NOTE: Required: Intel GPU driver interface | |
SDL2 # NOTE: Required dependency | |
]; | |
fhsEnv = pkgs.buildFHSEnv rec { | |
name = "whisper-cpp-dev"; | |
targetPkgs = pkgs: (with pkgs; FHSTargetPkgs); | |
profile = '' | |
export LANG=C.UTF-8 | |
export LC_ALL=C.UTF-8 | |
export ONEAPI_ROOT="$HOME/intel/oneapi" # Intel compiler paths (adjust these to your installation) | |
# export LIBRARY_PATH="${pkgs.lib.makeLibraryPath FHSTargetPkgs}:$LIBRARY_PATH" | |
# export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath FHSTargetPkgs}:$LD_LIBRARY_PATH" | |
# The order matters - system headers should come last: | |
# export CPATH="${pkgs.lib.makeIncludePath FHSTargetPkgs}:$CPATH" # add :$CPATH | |
# export C_INCLUDE_PATH="${pkgs.lib.makeIncludePath FHSTargetPkgs}:$C_INCLUDE_PATH" | |
# export CPLUS_INCLUDE_PATH="${pkgs.lib.makeIncludePath FHSTargetPkgs}:$CPLUS_INCLUDE_PATH" # NOTE: used by whisper.cpp | |
# Setup OpenVINO after setting up basic environment | |
source ${pkgs.openvino}/setupvars.sh 2>/dev/null || echo "OpenVINO setup completed with warnings" | |
if [ -d "$ONEAPI_ROOT" ]; then | |
source "$ONEAPI_ROOT/setvars.sh" --force 2>/dev/null || true | |
fi | |
export CC=icx | |
export CXX=icpx | |
echo "π Entering whisper.cpp development environment with Intel compilers" | |
echo "π Intel OneAPI root: $ONEAPI_ROOT" | |
echo "π§ CC=$CC, CXX=$CXX" | |
''; | |
runScript = "zsh"; | |
}; | |
in | |
{ | |
devShells.default = pkgs.mkShell rec { | |
name = "whisper-cpp-fhs-dev"; | |
buildInputs = FHSTargetPkgs ++ [ fhsEnv ]; | |
PKG_CONFIG_PATH = getAllPkgConfigPaths pkgs (buildInputs); | |
shellHook = '' | |
echo "π Setting up FHS environment for whisper.cpp development..." | |
echo "ποΈ This will provide a standard Linux environment for Intel compilers" | |
echo "To enter the FHS environment, run:" | |
echo " whisper-cpp-dev" | |
echo "π Auto-entering FHS environment..." | |
exec whisper-cpp-dev | |
''; # Shell hook that runs before entering FHS | |
}; | |
devShells.manual = pkgs.mkShell { | |
name = "whisper-cpp-manual"; | |
buildInputs = [ fhsEnv ]; | |
shellHook = '' | |
echo "π§ Manual FHS environment ready" | |
echo "Run 'whisper-cpp-dev' to enter FHS environment" | |
echo "Current directory: $(pwd)" | |
# Set up any non-FHS environment variables here | |
''; # Alternative: Manual FHS shell (doesn't auto-enter) | |
}; | |
# TODO: Make this work still, it tells me icx not found, maybe add direct FHS environment (for `nix run`) | |
packages.default = pkgs.stdenv.mkDerivation rec { | |
pname = "whisper-cli"; | |
version = "unstable"; | |
src = ./.; | |
nativeBuildInputs = with pkgs; [ | |
cmake | |
ninja | |
pkg-config | |
SDL2 | |
zlib | |
]; | |
buildInputs = with pkgs; [ | |
SDL2 | |
zlib | |
level-zero | |
]; | |
ONEAPI_ROOT = "${builtins.getEnv "HOME"}/intel/oneapi"; # Today, unfortunately, you must still install oneAPI separately. | |
cmakeFlags = [ | |
"-DWHISPER_SDL2=ON" | |
"-DWHISPER_OPENVINO=1" | |
"-DGGML_SYCL=ON" | |
"-DCMAKE_C_COMPILER=/home/izelnakri/intel/oneapi/compiler/latest/bin/icx" | |
"-DCMAKE_CXX_COMPILER=/home/izelnakri/intel/oneapi/compiler/latest/bin/icpx" | |
]; | |
# TODO: Issue is there is NO ONEAPI on the sandbox environment, that needs to change | |
configurePhase = '' | |
export ONEAPI_ROOT="/home/izelnakri/intel/oneapi" # TODO: Make this in the FUTURE(not now) ~/ or $HOME | |
export PATH="$ONEAPI_ROOT/compiler/latest/bin:$PATH" | |
export LD_LIBRARY_PATH="$ONEAPI_ROOT/compiler/latest/lib:$LD_LIBRARY_PATH" | |
echo "IZELL" | |
source ${pkgs.openvino}/setupvars.sh 2>/dev/null || echo "OpenVINO setup completed with warnings" | |
[ -d "$ONEAPI_ROOT" ] && source "$ONEAPI_ROOT/setvars.sh" --force 2>/dev/null || true | |
export CC="$ONEAPI_ROOT/compiler/latest/bin/icx" | |
export CXX="$ONEAPI_ROOT/compiler/latest/bin/icpx" | |
export CMAKE_C_COMPILER="$ONEAPI_ROOT/compiler/latest/bin/icx" | |
export CMAKE_CXX_COMPILER="$ONEAPI_ROOT/compiler/latest/bin/icpx" | |
echo "IZELL FINISH" | |
echo $(command -v icx) | |
echo "PATH IS" | |
echo $PATH | |
echo $CMAKE_C_COMPILER | |
echo $CMAKE_CXX_COMPILER | |
mkdir -p build | |
cd build | |
cmake .. -G Ninja ${pkgs.lib.strings.concatStringsSep " " cmakeFlags} | |
''; | |
buildPhase = '' | |
echo "IZELL STARTED BUILD PHASE" | |
echo $(command -v icx) | |
echo $PATH | |
cd build | |
ninja | |
''; | |
installPhase = '' | |
mkdir -p $out/bin | |
cp build/bin/whisper-cli $out/bin/ | |
''; | |
}; | |
apps.default = { | |
type = "app"; | |
program = "${self.packages.${system}.default}/bin/whisper-cli"; | |
}; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment