summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: d5c9152c8ec17619ce636be100382bcc9462bce7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# Maintainer: Saim <saim20 at github dot com>
pkgname=willow
pkgver=2.1.1
pkgrel=1
pkgdesc="Simple offline configurable voice assistant for gnome"
arch=('x86_64')
url="https://github.com/Saim20/willow"
license=('MIT')
depends=(
    'gnome-shell>=45'
    'sdbus-cpp'
    'jsoncpp'
    'libpulse'
    'ydotool'
)
makedepends=(
    'cmake'
    'git'
    'gcc'
)
optdepends=(
    'cuda: for NVIDIA GPU acceleration'
    'vulkan-icd-loader: for Vulkan GPU acceleration (AMD/Intel/NVIDIA)'
    'vulkan-headers: for Vulkan GPU acceleration build support'
)
options=('!debug')
install=willow.install
source=("willow::git+https://github.com/Saim20/willow.git")
sha256sums=('SKIP')

# Build options - users can enable these before building
# To enable CUDA: export ENABLE_CUDA=1 before running makepkg
# To enable Vulkan: export ENABLE_VULKAN=1 before running makepkg
# Or edit this file and set _enable_cuda=1 or _enable_vulkan=1
: ${ENABLE_CUDA:=1}
: ${ENABLE_VULKAN:=0}
_enable_cuda=${ENABLE_CUDA}
_enable_vulkan=${ENABLE_VULKAN}

prepare() {
    cd "$srcdir/$pkgname"
    
    # Interactive GPU acceleration setup (only if not already set)
    if [ -z "${ENABLE_CUDA+x}" ] && [ -z "${ENABLE_VULKAN+x}" ]; then
        printf "\n"
        printf "===================================================================\n"
        printf "GPU Acceleration Options\n"
        printf "===================================================================\n"
        printf "\n"
        
        # Check for CUDA
        if command -v nvcc &> /dev/null || [ -d "/opt/cuda" ]; then
            printf "NVIDIA CUDA detected. Enable CUDA acceleration? [y/N] "
            read -r response
            if [[ "$response" =~ ^[Yy]$ ]]; then
                export ENABLE_CUDA=1
                _enable_cuda=1
                printf "✓ CUDA enabled\n"
            else
                export ENABLE_CUDA=0
                _enable_cuda=0
                printf "CUDA disabled\n"
            fi
        else
            printf "CUDA toolkit not detected. Skipping CUDA.\n"
            export ENABLE_CUDA=0
            _enable_cuda=0
        fi
        
        printf "\n"
        
        # Check for Vulkan
        if pacman -Qi vulkan-headers &> /dev/null; then
            printf "Vulkan SDK detected. Enable Vulkan acceleration? [y/N] "
            read -r response
            if [[ "$response" =~ ^[Yy]$ ]]; then
                export ENABLE_VULKAN=1
                _enable_vulkan=1
                printf "✓ Vulkan enabled\n"
            else
                export ENABLE_VULKAN=0
                _enable_vulkan=0
                printf "Vulkan disabled\n"
            fi
        else
            printf "Vulkan SDK not detected. Skipping Vulkan.\n"
            printf "(Install with: sudo pacman -S vulkan-headers vulkan-icd-loader)\n"
            export ENABLE_VULKAN=0
            _enable_vulkan=0
        fi
        
        printf "\n"
        printf "Tip: Set ENABLE_CUDA=1 or ENABLE_VULKAN=1 before makepkg to skip prompts\n"
        printf "===================================================================\n"
        printf "\n"
    fi
    
    # Clone whisper.cpp if not present
    if [ ! -d "whisper.cpp" ]; then
        printf "Cloning whisper.cpp...\n"
        git clone --depth 1 https://github.com/ggerganov/whisper.cpp.git
    fi
}

build() {
    cd "$srcdir/$pkgname"
    
    # Build the C++ service with whisper.cpp
    cd service
    
    # Create build directory
    rm -rf build
    mkdir -p build
    cd build
    
    # Configure with CMake
    local cmake_args=(
        -DCMAKE_BUILD_TYPE=Release
        -DCMAKE_INSTALL_PREFIX=/usr
        -DWHISPER_CPP_DIR="$srcdir/$pkgname/whisper.cpp"
    )
    
    # Add GPU acceleration options
    if [ "$_enable_cuda" = "1" ]; then
        cmake_args+=(-DGGML_CUDA=ON)
        printf "\n✓ Building with CUDA support\n\n"
    fi
    
    if [ "$_enable_vulkan" = "1" ]; then
        cmake_args+=(-DGGML_VULKAN=ON)
        printf "\n✓ Building with Vulkan support\n\n"
    fi
    
    cmake "${cmake_args[@]}" ..
    
    # Build
    make -j$(nproc)
    
    printf "\n"
    printf "===================================================================\n"
    printf "Build Configuration:\n"
    printf "  CUDA: $_enable_cuda\n"
    printf "  Vulkan: $_enable_vulkan\n"
    printf "===================================================================\n"
    printf "\n"
}

check() {
    cd "$srcdir/$pkgname/service/build"
    
    # Basic sanity checks
    if [ ! -f "willow-service" ]; then
        printf "ERROR: willow-service binary not found!\n"
        return 1
    fi
    
    # Check if binary is executable
    if [ ! -x "willow-service" ]; then
        printf "ERROR: willow-service is not executable!\n"
        return 1
    fi
    
    printf "✓ Binary checks passed\n"
}

package() {
    cd "$srcdir/$pkgname"
    
    # Install service binary and D-Bus files
    cd service/build
    make DESTDIR="$pkgdir" install
    
    cd "$srcdir/$pkgname"
    
    # Install systemd service
    install -Dm644 systemd/willow.service \
        "$pkgdir/usr/lib/systemd/user/willow.service"
    
    # Install GNOME extension
    local ext_dir="$pkgdir/usr/share/gnome-shell/extensions/willow@saim"
    mkdir -p "$ext_dir"
    cp -r gnome-extension/willow@saim/* "$ext_dir/"
    
    # Compile GSettings schema
    glib-compile-schemas "$ext_dir/schemas/" || true
    
    # Install default configuration
    install -Dm644 config.json \
        "$pkgdir/usr/share/willow/config.json"
    
    # Install context configuration for smart workflows
    install -Dm644 context.json \
        "$pkgdir/usr/share/willow/context.json"
    
    # Install LICENSE
    install -Dm644 LICENSE \
        "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
    
    # Install documentation
    install -Dm644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"
    install -Dm644 SMART_WORKFLOWS.md "$pkgdir/usr/share/doc/$pkgname/SMART_WORKFLOWS.md"
    install -Dm644 SMART_WORKFLOWS_QUICKSTART.md "$pkgdir/usr/share/doc/$pkgname/SMART_WORKFLOWS_QUICKSTART.md"
    
    # Install download helper script
    install -Dm755 download-model.sh "$pkgdir/usr/bin/willow-download-model"
}