Currently, all the ffi code is in `chronik-ffi`. However, other crates might want to depend on the ffi code.
However, `chronik-ffi` is the staticlib that is linked to bitcoind at the end, it'll be the "root" crate depending on all the crates comprising Chronik.
For that reason, other crates cannot depend on `chronik-ffi`, as it will create a circular reference, which is not allowed for crates.
Say a crate `chronik-log` wants to reference `log_println`, defined in `chronik-ffi`. Also, `chronik-ffi` wants to use the logging defined in `chronik-log`.
It would create circular dependencies: `chronik-log` -> `chronik-ffi` -> `chronik-log`.
Therefore, we have to split the ffi into two parts:
1. `chronik-bridge`: This defines shared types and functions defined in C++, e.g. `log_println`.
2. `chronik-lib`: This defines all the functions that C++ will need to call, like `setup_bridge` and methods from `CValidationInterface`.
This way, there's no circular dependencies: `chronik-bridge` -> `chronik-log` -> `chronik-lib`.
Note: There's a linking issue, and we apparently need to link to chronik-bridge twice. We added this because linking otherwise fails on gcc. This was quite tricky to solve, and Fabien and I aren't sure yet why this fixes it.
In short, somehow lld (with clang) compiles fine, whereas ld and gold fail to compile it.
This *might* be a bug with either of the linkers, and we'll need more investigation.
Fabien's guess is that the symbols are not propagated to libchronik.a because it doesn't use it (he checked and it's not in the lib)
and gets optimized out or something like that.
My guess is as good as yours.
I left a "TODO" comment in CMake so maybe someone wiser than us can stumble over it and solve it, or it gets fixed in either of the
two linkers.