-
Notifications
You must be signed in to change notification settings - Fork 53
06. 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.
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+)
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
brew install swig python
# For C#: install .NET SDK 8.0+ (https://dotnet.microsoft.com/download)
# For Java: brew install openjdk (JDK 17+)
- 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_HOMEis set
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
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.
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 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.
After building, you need to ensure that the native libraries are findable
at runtime. The build places all output under build/bin/.
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$env:PYTHONPATH = "$PWD\build\bin;$env:PYTHONPATH"
$env:PATH = "$PWD\build\bin;$env:PATH"set PYTHONPATH=%CD%\build\bin;%PYTHONPATH%
set PATH=%CD%\build\bin;%PATH%