infix
A JIT-Powered FFI Library for C
|
This guide provides detailed instructions for building the infix
library from source and integrating it into your own projects. infix
is designed to be easy to compile and supports several popular build systems.
To build infix
, you will need:
Choose the build system that best fits your environment.
xmake is the recommended build system for most platforms as it provides a simple, cross-platform build experience.
Build:
bash xmake
Run Tests:
bash xmake test
Now, you can simply include the header (#include <infix.h>
) in your source files and build your project with xmake
.
This is what I use to develop infix
itself but it might be great for just building the lib without installing cmake or xmake. Perl is everywhere!*
CMake can generate native build files for your environment (e.g., Makefiles on Linux, Visual Studio solutions on Windows).
Standard Build & Install:
Configure: From the root of the infix
project, run CMake to generate the build files in a build
directory.
bash @section autotoc_md133 Creates a 'build' directory and prepares it for compilation cmake -B build
Build: Compile the library using the generated files.
bash @section autotoc_md134 Compiles libinfix.a (or infix.lib on Windows) inside the 'build' directory cmake --build build
Test: Run the compiled unit tests.
Install: Install the library and headers to the location specified by CMAKE_INSTALL_PREFIX
.
bash @section autotoc_md135 Installs headers to /usr/local/include, library to /usr/local/lib, etc. @section autotoc_md136 On Linux/macOS, you may need sudo. cmake --install build
Custom Install Location:
To install infix
to a custom directory (e.g., inside your project), use the CMAKE_INSTALL_PREFIX
option during the configure step.
A standard Makefile is provided for POSIX-like systems.
Build:
bash make
Run Tests:
bash make test
Install:
bash @section autotoc_md139 This usually requires root privileges sudo make install
If you are using Microsoft Visual C++, open a Developer Command Prompt for VS and use nmake
.
Build:
bash nmake /f Makefile.win
Since infix
uses a unity build, you can compile it into a static library with a single command. This is useful for minimal environments or for embedding directly into another build system.
On Linux/macOS (GCC/Clang):
On Windows (MSVC):
After building and installing infix
, you can link it into your application.
If you installed infix
to a standard location, you can use find_package
in your project's CMakeLists.txt
.
If you installed infix
, a infix.pc
file will be available for pkg-config
. This is useful in Makefiles or for autotools-based projects.
Example Makefile:
Add infix
as a dependency in your xmake.lua
.
infix
source code in a subdirectory of your project (e.g., libs/infix
).infix
static library (e.g., using CMake)..vscode
directory in your project root with the following files:**c_cpp_properties.json
** (for IntelliSense)
**tasks.json
** (for Building)
Because infix
uses a "unity build," you do not need to build it as a separate static or shared library. You can compile it directly into your project. This is the simplest method and allows for better compiler optimizations.
src/
and include/
directories from the infix
repository into your project's source tree (e.g., into a third_party/infix
subdirectory).infix
include
path to your compiler's include search paths (e.g., -Ithird_party/infix/include
).infix.c
file to your project's list of source files to be compiled.To integrate
infix
into your project, you only need to addsrc/infix.c
to your list of source files to compile and add theinclude/
directory to your include paths.
That's it. Your project will now build with the infix
library compiled directly in.
The CMake install target is the standard way to integrate with packaging systems. The key is to use the DESTDIR
environment variable during the install step.
Example for a Debian rules
file:
To submit infix
to the public xmake-repo
, you would create a packages/i/infix/xmake.lua
file in a fork of the repository.