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

C-Bindings #10

Open
lightsprint09 opened this issue Oct 26, 2021 · 3 comments
Open

C-Bindings #10

lightsprint09 opened this issue Oct 26, 2021 · 3 comments

Comments

@lightsprint09
Copy link

Hi,

I am not familiar with Rust but I have experience compiling rust to be used for Apple platform development (iOS, macOS etc).
To do this I would like to see some C-Bindings for this awesome project.

@nicomazz
Copy link
Owner

Actually, I do have some C bindings in another repo (I use this project from an android), but the code there is not so polished, and I'm very short of time. I'm happy to provide you with the code, and would be nice if you can do a pull request with it! (I don't think it requires much rust knowledge)

@lightsprint09
Copy link
Author

Sounds good. I can not promise to find the time but will give it a try.

@nicomazz
Copy link
Owner

nicomazz commented Nov 4, 2021

Here you go: download link
Note that this is just the zip containing the bindings I wrote a lot of time ago to use this library from Android.

Unfortunately I don't have time to touch the code at all, so I didn't even try to hide random comments or useless logs. The code is not super nice, but you should be able to easily change it and use it from c.

What you can do is the following. You can find functions like:

#[no_mangle]
pub unsafe extern "C" fn Java_DataManagment_NavigatorBridge_00024Companion_getWalkTimeSeconds(
    _: JNIEnv,
    _: JClass,
    meters: jint,
) -> jint {
    RaptorNavigator::seconds_by_walk(meters as usize)
        .try_into()
        .unwrap()
}

the weird name is due to the need of android JNI. In your case, you can make the previous like:

#[no_mangle]
pub unsafe extern "C" fn getWalkTimeSeconds(
    meters: i32,
) -> i32 {
    RaptorNavigator::seconds_by_walk(meters as usize)
        .try_into()
        .unwrap()
}

and compile it. The build output should be a library easily usable from c.

Note that the crate in the zip depends on fastgtfs being in the top level folder:

fastgtfs = {path = "../fastgtfs"}

P.S. I'm sure that there are better ways to create c bindings for rust code nowadays, automatically. (see https://github.com/rust-lang/rust-bindgen for example)

PR are welcomed :)

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