Rust bindings
The neverblink-linkml crate calls the same native library as the Python bindings, so there’s no JVM and no process per schema.
Installation
Section titled “Installation”cargo add neverblink-linkmlThe build downloads the library of the crate’s release from GitHub, and checks it against the SHA-256 in the crate.
| OS | Architectures |
|---|---|
| Linux (glibc) | x86-64, ARM64 |
| macOS | Apple silicon, Intel |
| Windows | x86-64, ARM64 |
At run time, the crate looks for the library in this order:
LINKML_SCALA_LIB: the library, or the directory holding it.- Next to the executable. The build copies the library next to the binaries in
target/, so ship it beside your binary. - Where the build downloaded it.
To build offline, or with a library you built yourself, set LINKML_SCALA_LIB when building and turn off the default download feature. It is possible to build the library for other platforms – for reference please see how sdist is built in Python bindings.
use ohi_linkml::{load_file, LoadOptions, Severity, ShaclGeneratorOptions};
let schema = load_file("model.yaml", &LoadOptions::default())?;println!("{}", schema.json_schema(&Default::default())?);println!("{}", schema.shacl(&ShaclGeneratorOptions { open: true, ..Default::default() })?);for issue in schema.issues(Some(Severity::Warning)) { println!("{} {}", issue["severity"], issue["message"]);}The API follows the Python bindings:
load_file,load_stringandload_pathload a schema.load_owlandload_ossieimport an ontology.- Each generator is a method of
Schemathat takes its own options struct, such asJsonSchemaGeneratorOptions. - The option structs are made by the Rust generator from
model/converter, in the moduleohi_linkml::options. TheirDefaulthas the defaults of the options, and they load and dump with serde, such as anOwlImportConfigfrom its YAML. - Generators that write several files return a
BTreeMapof file name to content. - Dropping a
Schemareleases it.
Reports, statistics and build info are serde_json::Values, in the shape of the LinkML models in model/.
Schema is Send and Sync, and every function can be called from any thread. The calls into the library run one at a time.
Calls run on the stack of the thread that makes them. A spawned thread’s default 2 MiB is enough for the schemas we tested, including large ones like the CIM, but very deep is_a chains need more. Running out of stack crashes the process instead of returning an error. For such schemas, call from a thread with a bigger stack, such as one from std::thread::Builder::new().stack_size(8 * 1024 * 1024).
Building it yourself
Section titled “Building it yourself”You need JDK 17+, clang and cargo. Then:
./mill-native nativelib.native.rustTestThat builds the library and runs the crate’s tests in rust/ against it. To use that library from your own crate, set LINKML_SCALA_LIB=out/nativelib/native/sharedLibrary.dest.