feat(ffi): stateless C-ABI shared library for in-process embedding - #173
Open
lekt9 wants to merge 1 commit into
Open
feat(ffi): stateless C-ABI shared library for in-process embedding#173lekt9 wants to merge 1 commit into
lekt9 wants to merge 1 commit into
Conversation
Add src/ffi.zig + a `zig build ffi` target that emits libkuri_ffi (.dylib/.so), exporting a stateless C-ABI fetch path: kuri_fetch(url, mode) -> NUL-terminated bytes (markdown|html), kuri_free, kuri_ffi_abi_version No server, no Bridge, no shared state — reuses validator.validateUrl (SSRF guard) + http_fetch.fetchHttp + markdown.htmlToMarkdown. Pure-Zig deps + spawned curl; needs no quickjs / curl-impersonate linkage. Lets a host (e.g. Bun bun:ffi dlopen) drive kuri's fetch/render in-process instead of running the long-lived kuri server. Verified: built native (aarch64-macos, 4.9MB .dylib); Bun FFI dlopen → kuri_fetch on https://example.com → markdown rendered in-process in ~2.5s. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an optional
zig build ffitarget that emits libkuri_ffi (.dylib/.so/.dll), exposing a small stateless C ABI so a host can drive kuri's fetch/render path in-process — no HTTP server, no sharedBridgestate, no subprocess.API
How it works
src/ffi.zigreuses the same helperskuri-fetchuses —validator.validateUrl(SSRF guard) →http_fetch.fetchHttp→markdown.htmlToMarkdown. Pure Zig + spawnedcurl, so the lib links no quickjs and no curl-impersonate — just libc. It cross-compiles cleanly for every target with Zig's bundled libc (verified: aarch64/x86_64-macos, x86_64/aarch64-linux, x86_64-windows).Why
Lets an embedding host (e.g. Bun
bun:ffidlopen) call kuri's fetch directly instead of running the long-lived server — handy for stateless one-shot fetches. Purely additive: one new build step + one new file; no existing target or behavior changes.Verified
zig build ffi→libkuri_ffi.dylib(native + cross targets).dlopen→kuri_fetch("https://example.com", 0)→ markdown rendered in-process.