Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper to generate / update FFI cdecls #1904

Merged
merged 2 commits into from
Aug 23, 2024

Conversation

benoit-pierre
Copy link
Contributor

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

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
Copy link
Member

Frenzie commented Aug 12, 2024

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
Contributor 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
Copy link
Member

NiLuJe commented Aug 13, 2024

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
Contributor 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
```
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