libnurt and nurt.h

The library libnurt is the crate nurt-ffi. It exposes the engine of nurt-core through the functions declared in crates/nurt-ffi/include/nurt.h. The header is maintained by hand and is the reference of the interface; the exported symbols are listed in crates/nurt-ffi/nurt.symbols. Only nurt-ffi exports C symbols. The crate builds a Rust library, a shared library and a static library.

System Libraries
Linux (glibc) shared libnurt.so.1 (the SONAME carries the major version of the interface) and static libnurt.a
Linux (musl) static libnurt.a
macOS shared libnurt.1.dylib and static libnurt.a
Windows shared nurt.dll with the import library nurt.dll.lib, and static nurt.lib (define NURT_STATIC)

The release publishes the library in its own archive nurt-lib-<version>-<target> with nurt.h and nurt.pc. Library archives are built for Linux glibc, Linux musl and Windows MSVC, each for x86-64 and aarch64. The example examples/c/hello.c calls the library from C.

The exported functions fall into groups: version and information (nurt_abi_version, nurt_abi_check, nurt_version, nurt_info), the engine (nurt_engine_open, nurt_engine_close, nurt_engine_config_get), the language (nurt_parse, nurt_print, nurt_correct, nurt_check), execution (nurt_run_json, nurt_exec_start, nurt_exec_wait, nurt_exec_cancel, nurt_exec_free, nurt_page), descriptions and state (nurt_catalog, nurt_describe, nurt_help, nurt_schema, nurt_history, nurt_space, nurt_session_end), extensions (nurt_ext_load, nurt_ext_list) and memory and diagnostics (nurt_buf_free, nurt_last_error, nurt_set_log_callback).

The rules of the ABI

  • Data. Strings are UTF-8 with a terminating zero. Complex values are JSON in the published formats (nurt-ast/1, nurt-bound/1, nurt-request/1, nurt-response/1, nurt-config/1, events, errors). Results are returned in a nurt_buf { ptr, len, cap } released with nurt_buf_free. When a call fails, its output buffers stay empty.
  • Two kinds of failure. nurt_status reports only failures of the call. An error of the language (syntax, binding, assertion, stale target) returns NURT_OK and arrives inside the JSON result as error with a stable E_* code.
  • Panics. Every exported function runs inside a panic boundary; a panic is caught and reported as NURT_E_INTERNAL. The library is built with panic = "unwind" for this reason.
  • Threads. Every function is thread-safe and several engines exist in one process side by side. Events of an execution reach nurt_event_cb from one library thread per execution, in increasing seq, ending with exec.finished.
  • Test engine. With the cargo feature stub the engine is replaced by a double that answers from recorded cases; release builds leave the feature off.
Status Value Meaning
NURT_OK 0 the call succeeded
NURT_E_TIMEOUT 1 nurt_exec_wait: still running
NURT_E_CANCELLED 2 nurt_exec_wait: ended by cancellation
NURT_E_ARG 3 null pointer, text that is not UTF-8, or invalid JSON
NURT_E_ABI 4 incompatible interface version
NURT_E_IO 5 configuration, journal, state directory or extension cannot be read
NURT_E_INTERNAL 6 internal failure, including a caught panic

Version numbers

The language, the syntax tree, the command catalog, the report format and the C interface carry their own version numbers, separate from the product version 0.1.2; a change between 0.x versions is recorded in the changelog.

Interface Version Rule
C ABI NURT_ABI_MAJOR 1, NURT_ABI_MINOR 0 nurt_abi_version() returns (major << 16) | minor. A binding calls nurt_abi_check(NURT_ABI_VERSION) once; it fails with NURT_E_ABI when the major versions differ or the library is older than the header. Within one major version the interface only grows.
Formats nurt: "1.0" in the request, the response and the report; nurt: "1.1" in the syntax trees Within major version 1 only optional members and new node kinds or values are added. A reader accepts a minor version that is not newer than its own.
Serve protocol nurt-rpc/1 See protocols.
Extension interface nurt:ext@1.0 A manifest is accepted when its major version equals that of the host and its minor version is not newer.

The reference is the C interface reference, and the short form is the C interface in the architecture documents.

Extensions

Extensions add commands, document formats and grammars without changing the program. The crate nurt-ext implements the mechanism. An extension is a directory under ext.dir (the environment variable NURT_EXT_DIR) with the manifest nurt-ext.toml and a component or a library. An installation reads and checks the manifest, checks that every file it names exists, copies the directory through a staging directory and switches it in by rename, so an interrupted installation leaves the previous version in place. The commands of an extension are named <extension>.<command>, and the manifest declares their parameters, the record kinds they accept and produce, and the permissions they need.

Kind Mechanism Execution bounds
WebAssembly component hosted by wasmtime; world extension of the package nurt:ext@1.0.0 with host calls read-file, list-dir, write-file and log, and the function stage.run execution fuel 10 000 000 000 units per call; linear memory 512 MiB; every call runs in a new instance; files only within permissions.read and permissions.write, checked when the extension asks for a path and again when its writes are applied
Native library exports nurt_ext_api, nurt_ext_run and nurt_ext_free; loaded with ext.native = true and a build with the native feature runs in the process of the engine

See the extensions reference.

The bindings

The directory bindings/ holds five bindings. Each of them has two backends: the library backend loads libnurt into the calling process, and the process backend starts nurt serve --stdio and speaks JSON-RPC 2.0 (nurt-rpc/1) to it. The bindings therefore relate to the engine through these two interfaces, and each of them returns the same JSON documents.

Binding Package Backends Requirements
Go module github.com/DanacoOfficial/nurt/bindings/go process (default, pure Go); library through cgo with the tag nurt_cgo Go 1.23 or later; only the standard library
Node.js nurt library (Node-API addon nurt.node, crate nurt-node); process; auto by default Node.js 18 or later, Bun and Deno; the addon needs a runtime with Node-API
.NET Danaco.Nurt Library, Process, Auto by default targets .NET 8 and .NET Standard 2.0
Java pl.danaco-group:nurt, pl.danaco-group:nurt-ffm nurt runs nurt serve --stdio (Java 17 or later); nurt-ffm adds the library backend through the Foreign Function and Memory API (Java 22 or later) no runtime dependencies
Python nurt library through ctypes; process; auto by default platform wheels contain the nurt executable and libnurt

The crate nurt-bind belongs to the engine: it binds syntax trees to the catalog, a step of the engine. The Node.js addon is the crate nurt-node; the other bindings are packages of their own languages. The bindings share the conformance cases in conformance/bindings, which each binding runs against the implementation named by environment variables such as NURT_TEST_COMMAND (Go) and NURT_TEST_SERVE and NURT_TEST_LIBRARY (.NET). Measured results are on the testing page.

Next

Protocols describes the process backend, the Model Context Protocol server and the language server. For integration guidance see the integrator guide.