-
-
Notifications
You must be signed in to change notification settings - Fork 335
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
Rust package #355
Rust package #355
Conversation
Ok, I've managed to link the libraries individually to their module |
The package root of a Rust crate is definitely defined by the location of its Cargo.toml. So, my recommendation is to add two repos: (maybe) brainflow-rs and brainflow-rs-sys to brainflow-dev. |
"Regarding the publishing to crates.io I'm now 99.9999% sure that it's impossible to include the parent directory (unless you want to add a Cargo.toml to the root directory of the repo)." There is no need to add a parent directory, we need to create smth like lib folder under rust-package\brainflow and copy binaries there from CMake |
ah, so you want to add precompiled binaries? That would work but limits of course the available target platforms |
<<ah, so you want to add precompiled binaries? That would work but limits of course the available target platforms Exactly, and its how it works for other bindings. Python/Java/etc users don't need to compile C\C++ source code. And as of right now it covers Win32\x64, Linux x64(all distros) and MacOS starting from 10.13(ARM and x64) For other platforms(raspberry for example or windows + arm) users still can run it but need to compile it manually by themselves first. I also have plans to add packages for ARM(#344) but since there were just a few requests for it, its not high priority task |
Its what I meant by brainflow's build system) |
I slowly begin to understand^^ |
- Put -sys related code directly into brainflow - Remove submodule - Add rust-package/brainflow-sys/{lib,inc} to gitignore
Ok, from my side this looks ready for merging and publishing... btw I just noticed that the links to the Brainflow bindings in the subfolder readmes do not work... |
Tests and examples can follow later |
There's one more thing where I'd like to get your opinion: in Rust it's common to name getter function just like their variable name i.e. num_rows() instead of get_num_rows(). At the moment I have both versions included but if it's okay with you I'd take out the get_ ones. Alternatively, we could use a feature to enable them. |
I value consistency between languages more than language-specific guidelines, so let's keep only get_* versions |
<<btw I just noticed that the links to the Brainflow bindings in the subfolder readmes do not work... thanks, I will fix them in another commit |
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.
Looks great, thanks for implementing it! Let's keep only get_* version of methods to match other languages and it will be good to go
/// You need to call it before any other BoardShim object methods. | ||
pub fn prepare_session(&self) -> Result<()> { | ||
let res = unsafe { | ||
BOARD_CONTROLLER.lock().unwrap().prepare_session( |
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.
One question about lock and mutexes. Inside C\C++ code there is a mutex for such methods and they are thread-safe. So, do we really need it here? If its to ensure that the library is loaded only in one thread then it's ok to have it
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.
Due to the dynamic loading of the libraries I need to create a global object, otherwise it wouldn't be possible to use it in the static functions. And since it has to be mutable the mutex is necessary here.
I must say this whole dynamic loading at runtime is only because of the 4 logging functions that share the same name...it would be much easier and nicer if there wouldn't be the name clash i.e. if the log functions would already have a distinctive name - the one they get in the language bindings anyway e.g. enable_logger -> enable_ml_logger
also, in addition to tests and CI pipelines we still have some tasks about docs(check this link https://brainflow.readthedocs.io/en/stable/BrainFlowDev.html#instructions-to-build-docs-locally):
Also, need to update website, I will take care of it(and about readmes) One more task: update Dockerfile to install rust binding https://github.com/brainflow-dev/brainflow/blob/master/Docker/Dockerfile |
I think there is nothing to be done in the Dockerfile for now. Maybe if we publish to crates.io. And there is indeed the possibility to build the docs for sphinx but I'd postpone that to some distant future. So, from my side it's good to go :) |
Todo: