Skip to main content

README

Source Code​

https://github.com/pact-foundation/pact-reference/tree/master/rust/pact_ffi

This crate provides a Foreign Function Interface (FFI) to the Pact-Rust crates, with the intent of enabling Pact's core matching mechanisms to be used by implementations in other languages.

Documentation​

Documentation for the FFI functions and types is available at https://docs.rs/pact_ffi/latest/pact_ffi/index.html, and documentation on the integration JSON format is IntegrationJson.md.

Dependencies​

This crates requires:

  • cbindgen, a tool for automatically generating the header file needed for C users of the crate.
  • A nightly Rust toolchain, used only by cbindgen for an unstable flag that gets the macro-expanded contents of the crate source. The library itself builds with the toolchain pinned in rust-toolchain.toml.

It will additionally attempt to find and use Doxygen to generate C-friendly documentation (you can of course alternatively use cargo doc to get Rustdoc documentation).

Note: Linking to the generated static library on Linux requires you to also link to pthread, dl and m.

Building with CMake​

For convenience, this tool integrates with CMake, which is setup to:

  1. Run Cargo to build the library file.
  2. Run Cbindgen to build the header file.
  3. Run Doxygen to build the documentation.

To use this CMake build, you can do the following:

$ mkdir build
$ cd build
$ cmake ..
$ cmake --build .

You can also optionally install the built artifacts as follows:

$ cmake --install . --prefix=<install location (omit to install globally)>

Examples​

This project also includes example uses which depend on the crate via CMake.

Before building an example, make sure to run the following from the overall CMake build directory (./build):

$ cmake --install . --prefix ./install

Then, from the example's directory, do the following:

$ mkdir build
$ cd build
$ cmake ..
$ cmake --build .

Architecture​

You can read about the architecture and design choices of this crate in ARCHITECTURE.md.

Compatibility​

<details><summary>Supported Platforms</summary>

OSArchitectureSupportedPact FFI Version
OSXx86_64✅All
Linuxx86_64✅All
Windowsx86_64✅All
OSXarm64✅>=0.0.1
Linuxarm64✅>=0.3.6
Windowsarm64✅>=0.4.14
Alpinex86_64✅static - >=0.2.4
Alpinearm64✅static - >=0.4.15
Alpinex86_64✅dynamic - >=0.4.17
Alpinearm64✅dynamic - >=0.4.17

</details>