koreader / koreader-base

Base framework offering a Lua scriptable environment for creating document readers
http://koreader.rocks/
GNU Affero General Public License v3.0
136 stars 106 forks source link

helper to generate / update FFI cdecls #1904

Closed benoit-pierre closed 2 months ago

benoit-pierre commented 2 months ago

Only for native emulator builds with GCC: after compiling base, use make gcc-lua-cdecl to compile and install to staging a small helper script and everything needed to run it. Example use:

▹ ./build/x86_64-pc-linux-gnu-debug/staging/bin/ffi-cdecl.sh -I . -d lept -n ffi-cdecl/leptonica_cdecl.c
/usr/bin/gcc -fplugin=[…]/base/build/x86_64-pc-linux-gnu-debug/staging/lib/gcc/plugin/gcclua.so -fplugin-arg-gcclua-script=[…]/base/build/x86_64-pc-linux-gnu-debug/staging/share/lua/5.1/ffi-cdecl.lua -I[…]/base/build/x86_64-pc-linux-gnu-debug/staging/include/ffi-cdecl -I[…]/base/build/x86_64-pc-linux-gnu-debug/staging/include -I. -I[…]/base/build/x86_64-pc-linux-gnu-debug/staging/include -I[…]/base/build/x86_64-pc-linux-gnu-debug/staging/include/leptonica -I[…]/base/build/x86_64-pc-linux-gnu-debug/staging/include/libpng16 -fplugin-arg-gcclua-output=/proc/self/fd/1 -S -o /dev/null ffi-cdecl/leptonica_cdecl.c
▹ ./build/x86_64-pc-linux-gnu-debug/staging/bin/ffi-cdecl.sh -I . -d lept ffi-cdecl/leptonica_cdecl.c
local ffi = require("ffi")

ffi.cdef[[
typedef signed char l_int8;
typedef unsigned char l_uint8;
typedef short int l_int16;
typedef short unsigned int l_uint16;
typedef int l_int32;
[…]
PIX *pixThresholdToBinary(PIX *, l_int32);
int pixWriteMemPng(l_uint8 **, size_t *, PIX *, l_float32);
int pixWritePng(const char *, PIX *, l_float32);
]]

This change is Reviewable

Frenzie commented 2 months ago

Cute, though I'm not entirely sure what to think about what amounts to duplicating https://github.com/koreader/ffi-cdecl/

benoit-pierre commented 2 months ago

That's what I started with. But on the meson branch, with all the nice pkg-config entries, I wanted something more convenient to use. Plus support for newer GCCs.

NiLuJe commented 2 months ago

Cute, though I'm not entirely sure what to think about what amounts to duplicating https://github.com/koreader/ffi-cdecl/

Wouldn't look so bad if we could pull in ffi-cdecl.lua directly instead of duplicating it (at a quick glance, only the package search paths are different?).

On the upside, that made me realize that I managed to miss the fact that you fixed the GCC 13 enum issue last summer ;p.

(i.e., https://github.com/koreader/ffi-cdecl/ needs to bump its deps, too).

benoit-pierre commented 2 months ago

OK, updated to use koreader/ffi-cdecl. With support for cross-compilers too.