candle-core 0.10 and later always pull in tokenizers and the Oniguruma C library
Symptom#
A crate that uses candle-core only to load safetensors and run tensor ops gets C code in its build. A cross check for another target fails in a build script:
error: failed to run custom build command for `onig_sys v69.9.3`
error occurred in cc-rs: failed to find tool "x86_64-linux-gnu-gcc": No such file or directory (os error 2)
cargo tree -i onig_sys shows the path:
onig_sys v69.9.3
└── onig v6.5.3
└── tokenizers v0.22.2
└── candle-core v0.11.0
Cause#
From 0.10, candle-core lists tokenizers (with the onig feature) as a required dependency for every non-wasm target, for its quantized tokenizer module. No feature turns it off. onig_sys compiles the Oniguruma regex library from C. Version 0.9.2 does not depend on tokenizers.
Fix#
When you do not need candle's tokenizer, pin candle 0.9.2:
candle-core = "=0.9.2"
candle-nn = "=0.9.2"
Then check that no C comes back: cargo tree -p <crate> -i onig_sys must print did not match any packages. VarBuilder, Tensor, CustomOp1/CustomOp2 and candle_core::safetensors::load built with no code change after the pin.
Evidence#
rait, 2026-09-24: a candle port of Table Transformer built on macOS, but cargo clippy -p rait-vision --target x86_64-unknown-linux-gnu failed with the onig_sys error above. The crates.io dependency lists show tokenizers as a required dependency of candle-core 0.10.2 and 0.11.0 and absent from 0.9.2. After pinning =0.9.2 the build had no onig_sys, and the model scores and tests were unchanged.
Also found by searching
- cargo clippy --target x86_64-unknown-linux-gnu -> error: failed to run custom build command for `onig_sys` failed to find tool "x86_64-linux-gnu-gcc"
- my Rust crate only uses candle for tensors and safetensors but now compiles C code and breaks cross-compiling
- how do I get rid of the tokenizers and Oniguruma dependency that candle-core pulls in?
- cargo tree -i onig_sys shows tokenizers via candle-core 0.11, no feature flag to disable it, pure Rust build
- error: failed to run custom build command for `onig_sys v69.9.3` failed to find tool "x86_64-linux-gnu-gcc"
- cargo cross-target build fails on onig_sys from tokenizers pulled in by candle-core
- how do I stop candle-core from depending on tokenizers and Oniguruma C code?
- candle-core 0.11 brings in a C regex library for just loading safetensors; need pure rust build