rust-libxml icon indicating copy to clipboard operation
rust-libxml copied to clipboard

Request for feedback: Rust-native components as an alternative to extern "C" bindings

Open kernelSHE opened this issue 6 months ago • 3 comments

We’re exploring the development of a crate that would provide alternatives to the extern "C" APIs from this project (e.g., libxml), keeping API compatibility and behavior equivalent. The motivation is that some bugs or unsafe assumptions in C libraries can propagate through the FFI boundary, even if Rust wrappers are careful.  We know rewriting mature C libraries is a big effort, so our idea is to provide optional Rust native code that replaces the C library for the selected ABI. We plan to maintain it actively and collaborate with the community, the crate would be fully maintained and actively developed by external contributors, without replacing the original library.  We’d like to understand the community’s stance: would maintainers and users be open to such a Rust-native crate existing and being maintained alongside the current project?

kernelSHE avatar May 26 '26 12:05 kernelSHE

You should reach out to the c2rust folks, both for libxml and libxslt, which is where my main interest lies today (as the wrapper maintainer for both crates). There is an old 2023 comment expressing as much:

https://github.com/KWARC/rust-libxml/issues/110#issuecomment-1544034182

We have been in touch with them, and they were close to complete at some point, so I suggest joining their effort if you are interested in having the exact same interface.

dginev avatar May 26 '26 13:05 dginev

We have been working on a c2rust-based toolchain whose goal is to replace selected extern "C" ABI/FFI entry points with Rust-native implementations while preserving the original behavior and ABI compatibility.  As a first case study for "rust-libxml", we converted 'xmlBuildQName' from an extern "C" binding into a Rust-native implementation. We also performed detailed semantic equivalence testing against the original C/libxml2 implementation: the same inputs were executed on both versions, and the outputs were compared byte-for-byte. In our current test report, all differential test cases passed with no failures.  The prototype repository is available here: https://github.com/kernelSHE/rust-libxml-safer-interfaces  If this direction is acceptable to the maintainers, we would be happy to continue improving it incrementally and work toward converting the remaining wrapper functions into Rust-native implementations where feasible. We would also welcome any guidance on preferred integration strategy, testing requirements, or API/compatibility constraints before moving further. 

kernelSHE avatar Jun 03 '26 00:06 kernelSHE

Have you seen their libxml2 example? https://c2rust.com/manual/examples/libxml2/index.html

If you work with them to integrate this as an official c2rust result and have them on board, I am definitely eager to have it as one native target for this wrapper. But I would really like to hear from the c2rust team as well on this question.

dginev avatar Jun 03 '26 01:06 dginev