Skip to content
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

[Feature Suggestion] FFI for Rust #3

Closed
Infrasonics opened this issue Nov 29, 2020 · 2 comments
Closed

[Feature Suggestion] FFI for Rust #3

Infrasonics opened this issue Nov 29, 2020 · 2 comments
Assignees

Comments

@Infrasonics
Copy link
Collaborator

Hello,

currently I'm using clockkit in a project which I wrote in Rust. SWIG is not supporting Rust at the moment. To use it, I made a temporary FFI which works fine as long as there are no exceptions thrown (Rust doesn't have those). For now that is fine in my case. But in order to make it useful for others too, I wouldn'd mind doing things properly. Before investing the time though, I wanted to ask whether you would be willing to include the wrapper file in clockkit (and probably answer some questions so the interface ends up sensible).

My two main concerns here are:

  1. My proposed FFI is a bit different from the ones you are currently providing for Ruby and Tcl, as follows:
    1.1 In order to create a PhaseLockedClock with a configuration file for which one does not need root access, I exposed the corresponding method in ConfigReader.
    1.2 To handle the lifetime properly I made a clock an object like it is in C++ too.
    1.3 Methods currently exposed are:
    • is_synchronized()
    • get_offset()
    • get_value() (raw timesstamp as integer)
    • and some methods to give a DateTime value as a timestamp
  2. From what I've read, it is good practice to make so called sys-crates buildable without network access. The easiest way to do that would be to simply put the third party code into the crate.
    • Would that be acceptable to you?
    • I would ask you to tag at least one version with a number so it can be properly referenced

To indicate various state changes, the Rust methods would return Results with enum instances corresponding to the exceptions, e.g. clockkit::error::Error::OutOfSync. The candidates I have identified so far are:
- OutOfSync
- Timeout
- PacketError
As this will be a high level interface I am unsure about the value of "lower level" exceptions like the performance counter frequency error or a clock rollover.

In addition to that, I would probably provide a patch to move the printing of the configuration in ConfigReader to a method. That method could be called in clockkit.cpp so the output would not change, yet the exposed FFI would not print anything when creating a clock as part of another project.

I would appreciate to hear your feedback on this; and hope that, with another easy interface to this cool project, more people will be able to make use of it.

@camilleg
Copy link
Owner

camilleg commented Nov 30, 2020

Yes, by all means let's add such a wrapper to clockkit.
Addressing concern no. 1 hardly damages the current FFIs, and may simplify later FFIs to other non-exception languages.
For concern no. 2 I defer to your Rust expertise. Let's tag that as v1.2.

Just to get things rolling, for now those lower-level exceptions might just be ignored, in the venerable tradition of "if you can't handle an error condition, don't test for it."

@camilleg camilleg self-assigned this Dec 1, 2020
@camilleg camilleg closed this as completed Mar 2, 2022
@camilleg
Copy link
Owner

camilleg commented Mar 2, 2022

Everything's been implemented for a while now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants