Skip to content

helper to generate / update FFI cdecls#1904

Merged
Frenzie merged 2 commits into
koreader:masterfrom
benoit-pierre:pr/ffi-cdecl
Aug 23, 2024
Merged

helper to generate / update FFI cdecls#1904
Frenzie merged 2 commits into
koreader:masterfrom
benoit-pierre:pr/ffi-cdecl

Conversation

@benoit-pierre

@benoit-pierre benoit-pierre commented Aug 12, 2024

Copy link
Copy Markdown
Member

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

Frenzie commented Aug 12, 2024

Copy link
Copy Markdown
Member

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

@benoit-pierre

Copy link
Copy Markdown
Member Author

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

NiLuJe commented Aug 13, 2024

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member Author

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

After compiling base, use `make ffi-cdecl` to install everything
needed to staging, including a small helper script. Example use:

```
./build/x86_64-pc-linux-gnu/staging/bin/ffi-cdecl -I . -d lept ffi-cdecl/leptonica_cdecl.c
```
@benoit-pierre benoit-pierre marked this pull request as ready for review August 23, 2024 15:19
@Frenzie Frenzie merged commit 27066ba into koreader:master Aug 23, 2024
@benoit-pierre benoit-pierre deleted the pr/ffi-cdecl branch August 23, 2024 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants