-
Notifications
You must be signed in to change notification settings - Fork 0
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
Calling MQF from Rust #3
Conversation
@@ -109,7 +109,7 @@ extern "C" { | |||
|
|||
void qf_destroy(QF *qf); | |||
|
|||
void qf_copy(QF *dest, QF *src); | |||
void qf_copy(QF *dest, const QF *src); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shokrof how do you feel about making src
into a const QF *
? This makes my life easier (because of mutability and ownership rules in Rust), and should still be valid wherever qf_copy
was called before, right?
I think we need to implement a c wrapper for rust to catch exceptions and communicate the messages in a "Rusty" way. I use exceptions to signal when mqf is full and If you are trying to access out of the boundaries items. |
A mix of https://github.com/luizirber/ukhs/blob/master/bbhash-sys/ffi.cpp and rust-lang/rust-bindgen#1208 should be enough. Ideally it would be better to have exceptions never cross thru a C call (wrap in a |
@luizirber Here you are #4 Build with |
CMake options to suppress building binaries & tests
fn main() { | ||
let dst = Config::new(".") | ||
.define("BUILD_STATIC_LIBS", "ON") | ||
.build_target("MQF") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mr-eyes I ended up reverting the CMake changes, this was enough to avoid all the other targets (including binaries and tests)
"debug" => "_debug", | ||
_ => "", | ||
}; | ||
println!("cargo:rustc-link-lib=static=stxxl{}", mode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shokrof I can't skip linking stxxl here, since libMQF.a brings the on-disk MQF and if it is not included there are many symbols missing when I try to run the tests. Not sure how to (or even if it is desirable) to modularize what gets added to the static/dynamic library,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean the c++ test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the Rust tests. The code builds, but when I try to link the static library to the Rust code (to run the tests) there are missing symbols.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can create a new target for you that only has MQF if it will make your life easier
Currently there is enough functionality exposed to have a working SBT with internal MQF nodes in sourmash-bio/sourmash#772, so how do people feel about:
Oh, and also releasing it to crates.io (the Rust package repository)? |
@luizirber @shokrof This is really going above my head :) |
@luizirber Do we need to add a special target on the cmake to do the rust bindings? |
Oops, sorry! I suggested merging because it is already a minimum-viable wrapper, and it can be improved over time (instead of trying to make everything perfect now). Punting to issues and making new PRs is something we do in sourmash, to avoid having huge PRs to review and merge. Publishing to crates.io is preferred to installing from git in the Rust world, and it is actually a blocker for me updating the sourmash crate, because crates published in crates.io can't have dependencies external to crates.io. Does this help a bit? =]
|
No, it's all taken care by Cargo (the Rust package manager). You would need a cmake target if you want to create a Rust static library, but that doesn't make much sense for this project. In sourmash I generate a Rust static lib because that's what the Python side sees (including generating a C header to link against the right functions in the Rust static lib, which is something not being used in the project). |
if we have a new version, will Cargo update itself automatically or you have to run some commands? |
You need to bump the version in |
it is ok. I got it |
Yay! But it was merged before I added the cargo metadata, please see #5 =] |
This uses bindgen to generate Rust bindings from the
gqf.h
header. Slowly adding more functions, but this initial PoC is based on the "simple counting test" intests/CountingTests.cpp
TODO
unsafe
in the public API!)Resolve some quirks with linking the C++ stdlib (I had to use Troubleshooting: linking withPunted to Linking with C++ stdlib #6cc
failed rust-fuzz/afl.rs#141 (comment) and https://flames-of-code.netlify.com/blog/rust-and-cmake-cplusplus/#another-static-library in an Ubuntu system, but there are probably better ways)stxll
static lib is generated with different names depending on being release or debug. Add logic tobuild.rs
Figure out how to catch C++ exceptions (right now everything just blows up). Some pointers: Support C++ exceptions without undefined behaviour rust-lang/rust-bindgen#1208Punted to Figure out how to catch C++ exceptions (right now everything just blows up). #7