62 releases

0.4.24 Nov 29, 2024
0.4.22 Jul 18, 2024
0.4.18 Feb 26, 2024
0.4.11 Nov 27, 2023
0.0.0 Jul 11, 2021

#46 in FFI

Download history 2/week @ 2024-08-24 140/week @ 2024-08-31 13/week @ 2024-09-07 48/week @ 2024-09-14 46/week @ 2024-09-21 11/week @ 2024-09-28 5/week @ 2024-10-12 102/week @ 2024-11-23 47/week @ 2024-11-30

149 downloads per month

MIT license

2.5MB
52K SLoC

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-channel version of Cargo (needed for an unstable flag used by cbindgen to get the macro-expanded contents of the crate source).

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)>

Conan recipes

The library files (lib and DLLs) are published as Conan recipes to the repository at https://pactfoundation.jfrog.io/artifactory/api/conan/pactfoundation-conan. To use it with a CMake project, add that repository as a Conan remote and then use Conan to generate the CMake dependency files for your project. There are two recipes, pact_ffi to use the static lib and pact_ffi_dll to use the dynamic lib.

$ conan remote add pact-foundation https://pactfoundation.jfrog.io/artifactory/api/conan/pactfoundation-conan
$ conan search pact_ffi -r=pact-foundation
Existing package recipes:

pact_ffi/0.0.0@pact/beta
$ conan search pact_ffi_dll -r=pact-foundation
Existing package recipes:

pact_ffi_dll/0.0.0@pact/beta

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

Supported Platforms
OS Architecture Supported Pact FFI Version
OSX x86_64 All
Linux x86_64 All
Windows x86_64 All
OSX arm64 >=0.0.1
Linux arm64 >=0.3.6
Windows arm64 >=0.4.14
Alpine x86_64 static - >=0.2.4
Alpine arm64 static - >=0.4.15
Alpine x86_64 dynamic - >=0.4.17
Alpine arm64 dynamic - >=0.4.17

Dependencies

~45–81MB
~1.5M SLoC