pdftract/distribution/homebrew/pdftract.rb.template
jedarden 71872aaf73 feat(pdftract-1eaxm): implement libpdftract C FFI library
Implement the libpdftract native FFI library as a cdylib + staticlib
with cbindgen-generated headers and full extern "C" API.

Components:
- crates/pdftract-libpdftract/ with cdylib + staticlib targets
- All 9 contract methods + utility functions as extern "C"
- cbindgen config and generated pdftract.h header
- pkg-config template (pdftract.pc.in)
- Homebrew formula template (distribution/homebrew/)
- vcpkg port template (distribution/vcpkg/)
- C conformance test (tests/conformance.c)

API features:
- Owned JSON strings returned via CString::into_raw()
- Caller frees with pdftract_free() (not libc free())
- Thread-local error storage (pdftract_last_error)
- Thread-safe and reentrant (no global mutable state)
- ABI version function for compatibility checking

Verification:
- cargo build produces libpdftract.so and libpdftract.a
- Conformance test compiles and runs successfully
- Thread safety verified with 4 concurrent threads

References:
- Plan line 3477: SDK Architecture / The Ten SDKs
- Bead: pdftract-1eaxm

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 08:55:12 -04:00

46 lines
1.3 KiB
Text

# Homebrew formula for pdftract
# This file is a template - variables are replaced during release
class Pdftract < Formula
release = "{{RELEASE}}"
version = release[/(\d+\.\d+\.\d+)/, 1]
desc "PDF text extraction library with C FFI"
homepage "https://github.com/jedarden/pdftract"
url "https://github.com/jedarden/pdftract/releases/download/v#{version}/libpdftract-v#{version}-x86_64-unknown-linux-gnu.tar.gz"
sha256 "{{LINUX_SHA256}}"
depends_on "pkg-config"
def install
lib.install "lib/libpdftract.so"
lib.install "lib/libpdftract.a"
include.install "include/pdftract.h"
lib.install "lib/pkgconfig/pdftract.pc"
# Set the correct prefix in the pkg-config file
inreplace lib/"pkgconfig/pdftract.pc", "@PREFIX@", prefix
end
test do
(testpath/"test.c").write <<~EOS
#include <pdftract.h>
#include <stdio.h>
#include <assert.h>
int main(void) {
const char* version = pdftract_version();
assert(version != NULL);
printf("pdftract version: %s\\n", version);
uint32_t abi = pdftract_abi_version();
printf("ABI version: 0x%08x\\n", abi);
pdftract_free(NULL); // Should not crash
return 0;
}
EOS
system ENV.cc, "test.c", "-I#{include}", "-L#{lib}", "-lpdftract", "-o", "test"
system "./test"
end
end