New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for C-style dynamic libraries to be produced #171
Conversation
Actually some methods need to be exposed still ( |
Before I continue I should ask @kivikakk whether this is even a desired change. The main function is easy enough to expose, roughly: #[no_mangle]
#[allow(unused)]
pub extern "C" fn c_markdown_to_html(md_char: *const c_char, options: &ComrakOptions) -> *const c_char {
// Convert C string to Rust string
let c_md = unsafe {
assert!(!md_char.is_null());
CStr::from_ptr(md_char)
};
let md = c_md.to_str().unwrap();
let arena = Arena::new();
let root = parse_document(&arena, md, options);
let mut s = Vec::new();
format_html(root, options, &mut s).unwrap();
unsafe {
CString::from_vec_unchecked(s).as_ptr()
}
} But I would need all the functions the current C library supports, including modifying nodes ( |
Yes, absolutely! Thank you for starting this work. If we need to rejig some internals slightly for that to happen, that'd be fine too—it'd be lovely to have this usable through a C interface. Some simple test harnesses around it will be necessary, but that could even be literally running the CommonMark spec through commonmarker with the Comrak backend. |
@kivikakk 👋 Hello!!! 👋 I'm back to finish this PR. 😆 In the time since I opened this PR, I've become marginally better at Rust FFI handling, so I've rewritten whatever garbage was previously here with some new thoughts. I've added here a little Rust lib that exposes a few methods, defined in To be honest, the last time I tried doing this, I got horribly stuck on memory handling when exposing the |
Hey Garen, so lovely to hear from you again 😊 This is awesome. I gave it a run (after overcoming my brief confusion at trying to |
@kivikakk 👋 There are three tests failing oddly, which I will definitely address, but I believe this PR is ready for review in all other places! |
This is looking awesome. Just from a quick look, a stray |
Rebased onto main. If you like the look of it as is, please feel free to merge! 🚀 |
Thank you! It looks great. 😄 |
Awesome! Thank you so much & nicely done! |
I'd like to be able to use comrak for commonmarker, but before doing that this project needs to be able to generate a C-style dynamic library. This PR adds the
crate-type
necessary to do that.