Skip to content

06. Language Bindings

Aaron Boxer edited this page Mar 25, 2026 · 1 revision

6. Language Bindings

Grok has language bindings for Python, C#, Java (via SWIG) and Rust (via bindgen).

Python bindings are enabled by default and will build automatically if SWIG and Python 3 development files are installed. C# and Java bindings are opt-in.

Dependencies

Ubuntu / Debian

sudo apt install python3-dev swig
# For C#: install .NET SDK 8.0+ (https://dotnet.microsoft.com/download)
# For Java: sudo apt install default-jdk  (JDK 17+)

Fedora

sudo dnf install python3-devel swig
# For C#: install .NET SDK 8.0+ (https://dotnet.microsoft.com/download)
# For Java: sudo dnf install java-latest-openjdk-devel

macOS

brew install swig python
# For C#: install .NET SDK 8.0+ (https://dotnet.microsoft.com/download)
# For Java: brew install openjdk  (JDK 17+)

Windows

  • Install SWIG and add it to PATH
  • Install Python 3 from python.org
  • For C#: install .NET SDK 8.0+
  • For Java: install a JDK 17+ and ensure JAVA_HOME is set

Build

Python (default)

The Python bindings are controlled by GRK_BUILD_CORE_SWIG_BINDINGS (ON by default). If SWIG or Python3 development headers are missing the build will skip the bindings and print a status message.

cmake -B build
cmake --build build --target grok_core

C#

Enable with GRK_BUILD_CSHARP_SWIG_BINDINGS:

cmake -B build -DGRK_BUILD_CSHARP_SWIG_BINDINGS=ON
cmake --build build --target grok_core_csharp

The generated C# sources and native library are placed in build/bin/csharp/. A .NET project can reference these files directly, or use the provided bindings/swig/csharp/GrokCore.csproj as a library project.

Java

Enable with GRK_BUILD_JAVA_SWIG_BINDINGS:

cmake -B build -DGRK_BUILD_JAVA_SWIG_BINDINGS=ON
cmake --build build --target grok_core_java

The generated Java sources are under build/bin/java/org/grok/core/. The native JNI library (libgrok_core_java.so / .dylib / .dll) is in build/bin/.

To compile and use:

javac -d classes build/bin/java/org/grok/core/*.java
java -Djava.library.path=build/bin -cp classes org.grok.core.YourApp

Rust

Rust bindings are in bindings/rust/ and use bindgen to auto-generate Rust FFI bindings from grok.h. See bindings/rust/ for a build example with build.rs.

Environment Setup

After building, you need to ensure that the native libraries are findable at runtime. The build places all output under build/bin/.

Python — Linux / macOS

export PYTHONPATH=$PWD/build/bin:$PYTHONPATH
export LD_LIBRARY_PATH=$PWD/build/bin:$LD_LIBRARY_PATH   # Linux
export DYLD_LIBRARY_PATH=$PWD/build/bin:$DYLD_LIBRARY_PATH  # macOS

Python — Windows (PowerShell)

$env:PYTHONPATH = "$PWD\build\bin;$env:PYTHONPATH"
$env:PATH = "$PWD\build\bin;$env:PATH"

Python — Windows (cmd)

set PYTHONPATH=%CD%\build\bin;%PYTHONPATH%
set PATH=%CD%\build\bin;%PATH%

Clone this wiki locally