Skip to content

Commit fa5aeef

Browse files
LocalAI [bot]mudlerclaude
authored
ci(release): ship the C-API shared library and header (#25) (#29)
The release bundles only carried parakeet-cli, so integrating via ctypes/dlopen meant compiling from source. Add a separate shared-library bundle per (platform, backend, arch) alongside each CLI bundle. The lib is built in its own build dir with PARAKEET_SHARED=ON and PARAKEET_BUILD_CLI=OFF, so the CLI bundles stay single self-contained binaries. Each lib bundle carries libparakeet.{so,dylib,dll}, the parakeet_capi.h header, LICENSE and README (plus the same cudart/cublas on CUDA). The release job already globs dist/*, so they attach with no further change. Two things that would have silently broken it: - BUILD_SHARED_LIBS=OFF builds ggml's static objects without -fPIC, so folding them into a shared lib fails to link on Linux. The shared-lib configure steps set CMAKE_POSITION_INDEPENDENT_CODE=ON. - The C-API header marks symbols with plain extern "C", no dllexport, so an MSVC DLL would export nothing. Set WINDOWS_EXPORT_ALL_SYMBOLS on the parakeet target when PARAKEET_SHARED is on. No effect on Linux/macOS. Verified on Linux CPU: a self-contained libparakeet.so depending only on standard system libs, with the parakeet_capi_* symbols exported. Co-authored-by: Ettore Di Giacinto <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
1 parent 92a5f03 commit fa5aeef

2 files changed

Lines changed: 123 additions & 0 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,54 @@ jobs:
160160
path: ${{ steps.pack.outputs.bundle }}.tar.gz
161161
if-no-files-found: error
162162

163+
# Shared C-API lib (issue #25): a separate build so the CLI bundle above
164+
# stays a single self-contained binary. PARAKEET_SHARED=ON folds ggml into
165+
# libparakeet.so the same way it is folded into the CLI.
166+
- name: Configure (shared C-API lib)
167+
env:
168+
CUDA_ARCHS: ${{ matrix.cuda_archs }}
169+
run: |
170+
EXTRA=""
171+
if [ "${{ matrix.backend }}" = "cuda" ]; then
172+
EXTRA="-DCMAKE_BUILD_RPATH=\$ORIGIN"
173+
fi
174+
cmake -B build-shared \
175+
-DCMAKE_BUILD_TYPE=Release \
176+
-DGGML_NATIVE=OFF \
177+
-DBUILD_SHARED_LIBS=OFF \
178+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
179+
-DPARAKEET_SHARED=ON \
180+
-DPARAKEET_BUILD_CLI=OFF \
181+
-DPARAKEET_BUILD_TESTS=OFF \
182+
${{ matrix.cmake_args }} \
183+
${CUDA_ARCHS:+"-DCMAKE_CUDA_ARCHITECTURES=${CUDA_ARCHS}"} \
184+
${EXTRA:+"$EXTRA"}
185+
186+
- name: Build (shared C-API lib)
187+
run: cmake --build build-shared -j"$(getconf _NPROCESSORS_ONLN)"
188+
189+
- name: Package (shared C-API lib)
190+
id: pack_lib
191+
run: |
192+
BUNDLE="parakeet-${{ steps.ver.outputs.version }}-lib-linux-${{ matrix.backend }}-${{ matrix.arch }}"
193+
mkdir "$BUNDLE"
194+
cp build-shared/libparakeet.so include/parakeet_capi.h LICENSE README.md "$BUNDLE"/
195+
if [ "${{ matrix.backend }}" = "cuda" ]; then
196+
cp -P /usr/local/cuda/targets/x86_64-linux/lib/libcudart.so* \
197+
/usr/local/cuda/targets/x86_64-linux/lib/libcublas.so* \
198+
/usr/local/cuda/targets/x86_64-linux/lib/libcublasLt.so* \
199+
"$BUNDLE"/
200+
fi
201+
tar -czf "$BUNDLE.tar.gz" "$BUNDLE"
202+
echo "bundle=$BUNDLE" >> "$GITHUB_OUTPUT"
203+
204+
- name: Upload shared C-API lib artifact
205+
uses: actions/upload-artifact@v4
206+
with:
207+
name: ${{ steps.pack_lib.outputs.bundle }}
208+
path: ${{ steps.pack_lib.outputs.bundle }}.tar.gz
209+
if-no-files-found: error
210+
163211
# ---------------------------------------------------------------------------
164212
# macos: metal on arm64 (the metallib is embedded in the binary, nothing to
165213
# ship alongside), plus a cpu-only x64 build cross-compiled on the same
@@ -229,6 +277,38 @@ jobs:
229277
path: ${{ steps.pack.outputs.bundle }}.tar.gz
230278
if-no-files-found: error
231279

280+
# Shared C-API lib (issue #25). Separate build, same reasoning as linux.
281+
- name: Configure (shared C-API lib)
282+
run: |
283+
cmake -B build-shared \
284+
-DCMAKE_BUILD_TYPE=Release \
285+
-DGGML_NATIVE=OFF \
286+
-DBUILD_SHARED_LIBS=OFF \
287+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
288+
-DPARAKEET_SHARED=ON \
289+
-DPARAKEET_BUILD_CLI=OFF \
290+
-DPARAKEET_BUILD_TESTS=OFF \
291+
${{ matrix.cmake_args }}
292+
293+
- name: Build (shared C-API lib)
294+
run: cmake --build build-shared -j"$(getconf _NPROCESSORS_ONLN)"
295+
296+
- name: Package (shared C-API lib)
297+
id: pack_lib
298+
run: |
299+
BUNDLE="parakeet-${{ steps.ver.outputs.version }}-lib-macos-${{ matrix.backend }}-${{ matrix.arch }}"
300+
mkdir "$BUNDLE"
301+
cp build-shared/libparakeet.dylib include/parakeet_capi.h LICENSE README.md "$BUNDLE"/
302+
tar -czf "$BUNDLE.tar.gz" "$BUNDLE"
303+
echo "bundle=$BUNDLE" >> "$GITHUB_OUTPUT"
304+
305+
- name: Upload shared C-API lib artifact
306+
uses: actions/upload-artifact@v4
307+
with:
308+
name: ${{ steps.pack_lib.outputs.bundle }}
309+
path: ${{ steps.pack_lib.outputs.bundle }}.tar.gz
310+
if-no-files-found: error
311+
232312
# ---------------------------------------------------------------------------
233313
# windows: MSVC via Ninja (ilammy/msvc-dev-cmd provides the cl environment,
234314
# which also lets nvcc use cl without the Visual Studio CUDA integration).
@@ -336,6 +416,44 @@ jobs:
336416
path: ${{ steps.pack.outputs.bundle }}.zip
337417
if-no-files-found: error
338418

419+
# Shared C-API lib (issue #25). Separate build, same reasoning as linux.
420+
# WINDOWS_EXPORT_ALL_SYMBOLS (set in CMakeLists) makes the DLL export its
421+
# extern "C" entry points so ctypes/dlopen can find them.
422+
- name: Configure (shared C-API lib)
423+
env:
424+
CUDA_ARCHS: ${{ matrix.cuda_archs }}
425+
run: |
426+
cmake -B build-shared -G Ninja \
427+
-DCMAKE_BUILD_TYPE=Release \
428+
-DGGML_NATIVE=OFF \
429+
-DBUILD_SHARED_LIBS=OFF \
430+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
431+
-DPARAKEET_SHARED=ON \
432+
-DPARAKEET_BUILD_CLI=OFF \
433+
-DPARAKEET_BUILD_TESTS=OFF \
434+
${{ matrix.cmake_args }} \
435+
${CUDA_ARCHS:+"-DCMAKE_CUDA_ARCHITECTURES=${CUDA_ARCHS}"}
436+
437+
- name: Build (shared C-API lib)
438+
run: cmake --build build-shared -j
439+
440+
- name: Package (shared C-API lib)
441+
id: pack_lib
442+
shell: pwsh
443+
run: |
444+
$bundle = "parakeet-${{ steps.ver.outputs.version }}-lib-win-${{ matrix.backend }}-x64"
445+
New-Item -ItemType Directory -Path $bundle | Out-Null
446+
Copy-Item build-shared/parakeet.dll,include/parakeet_capi.h,LICENSE,README.md $bundle/
447+
Compress-Archive -Path $bundle -DestinationPath "$bundle.zip"
448+
"bundle=$bundle" | Out-File -Append $env:GITHUB_OUTPUT
449+
450+
- name: Upload shared C-API lib artifact
451+
uses: actions/upload-artifact@v4
452+
with:
453+
name: ${{ steps.pack_lib.outputs.bundle }}
454+
path: ${{ steps.pack_lib.outputs.bundle }}.zip
455+
if-no-files-found: error
456+
339457
- name: Package CUDA runtime DLLs
340458
if: matrix.backend == 'cuda'
341459
shell: pwsh

‎CMakeLists.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ set(PARAKEET_SRC
9393

9494
if(PARAKEET_SHARED)
9595
add_library(parakeet SHARED ${PARAKEET_SRC})
96+
# The C-API header marks symbols with plain extern "C", no __declspec(dllexport).
97+
# On MSVC that yields a DLL with no exported symbols (and no import .lib), which
98+
# is useless for dlopen/ctypes consumers. Auto-export every symbol so the DLL is
99+
# usable the same way the ELF/Mach-O shared libs are. No effect on Linux/macOS.
100+
set_target_properties(parakeet PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
96101
else()
97102
add_library(parakeet STATIC ${PARAKEET_SRC})
98103
endif()

0 commit comments

Comments
 (0)