HomePhabricator

[Chronik] Add minimal Rust <-> C++ bridge

Description

[Chronik] Add minimal Rust <-> C++ bridge

Summary:
Establish a bridge using the cxx crate. The definition is in chronik-ffi/src/ffi.rs, see https://cxx.rs/extern-rust.html and https://cxx.rs/extern-c++.html.

On the C++ side, we expose log_println, which prints a string using LogPrintf. In the future we can add more parameters (like file/line no) and use LogInstance().LogPrintStr.

On the Rust side, we expose setup_bridge, which uses log_println to print a message.

cxx generates the files in a fixed location, and we update the CMake list file to add the generated headers and C++ source files.

Corrosion builds chronik-ffi-static, which we add to the chronik target.

We set the Rust_CARGO_TARGET triplet for Corrosion for known targets, see https://doc.rust-lang.org/nightly/rustc/platform-support.html. All the platform targets from cmake/platforms are supported, except OSX, which has a known issue with the cxx dependency.

Depends on D11862.

Test Plan:

  1. ninja
  2. ./src/bitcoind -regtest prints "Starting Chronik..." in the logs
  3. Ctrl+C to terminate bitcoind prints "Stopping Chronik..." in the logs (as before)

Reviewers: Fabien, #bitcoin_abc

Reviewed By: Fabien, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D11863

Details

Provenance
tobias_ruckAuthored on Aug 16 2022, 13:34
tobias_ruckPushed on Sep 1 2022, 20:36
Reviewer
Restricted Project
Differential Revision
D11863: [Chronik] Add minimal Rust <-> C++ bridge
Parents
rABC3423895bebb5: [Chronik] Fix `CARGO_BUILD_DIR`, incorrectly based on CMAKE_CURRENT_BINARY_DIR…
Branches
Unknown
Tags
Unknown