#api #c-ffi

bin+lib trixy

A rust crate used to generate multi-language apis for your application

9 unstable releases (3 breaking)

new 0.3.2 Jul 20, 2024
0.3.1 Jul 7, 2024
0.2.2 May 31, 2024
0.1.1 May 4, 2024
0.0.0 Dec 23, 2023

#82 in FFI

Download history 14/week @ 2024-03-31 32/week @ 2024-04-14 242/week @ 2024-04-28 45/week @ 2024-05-05 236/week @ 2024-05-19 131/week @ 2024-05-26 16/week @ 2024-06-02 5/week @ 2024-06-09 1/week @ 2024-06-16 196/week @ 2024-07-07 69/week @ 2024-07-14

265 downloads per month

LGPL-3.0-or-later

335KB
6.5K SLoC

Trixy

A crate to generate a multi-language foreign function interface.

Features

  • Support for custom types, derived from a set of primitive types.
  • Support for callbacks, thought c function pointers.
  • Support for error handling, when checking a functions arguments (NULL pointer and such things).

Supported languages:

  • c

Dependencies

Trixy only needs:

  • clang-format to format the generated c header files.

The Trixy Language

The API to generate is specified in a Trixy file. The language of these files is an subset of rust and should thus be easy to learn and pick up.

A grammar file is provided here encoded in Extended Backus-Naur Form. The grammar file is rendered as railroad diagrams in PDF here, run ./docs/generate_docs to regenerate the PDF file.

Testing

Trixy contains integration tests in the ./tests directory. These are maintained with the ./scripts/tests.sh script. Take a look at it's --help output for further usage information.

This crate also contains a binary, which can help with manual testing and inspecting of the generated AST. The cargo run --features 'build-binary' -- --help output should provide all required information.

Tests are (as of now) only positive, i.e. they can only test successful situations. Failing test will probably be supported in the future.

Contributing

We have a nix flake, which provides the required dependencies to work with Trixy and the associated scripts in the ./scripts directory.

Please also make sure to run the ./scripts/renew_copyright_header.sh after you added a new file, to ensure that every file contains a license header.

Dependencies

~0–1.3MB
~23K SLoC