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

Switch to core::ffi::c_* for C types instead of libc::c_* #297

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ahomescu
Copy link
Contributor

Based on #294, switches to std::os::raw types by default and adds optional --use-libc-types transpiler argument.

@ahomescu ahomescu added the enhancement New feature or request label Sep 15, 2020
@ahomescu ahomescu self-assigned this Sep 15, 2020
@ahomescu ahomescu changed the title Std raw types Switch to std::os::raw for C types instead of libc Sep 15, 2020
@chrysn
Copy link
Contributor

chrysn commented Sep 15, 2020

Bindgen has an option --ctypes-prefix "some_crate::libc" that allows the user to set the path, which is convenient in embedded environments. It defaults to ::std::os::raw. I think the option would make sense for C2Rust as well.

@kkysen
Copy link
Contributor

kkysen commented Jun 17, 2022

We should update this to use the core::ffi::c_* types now that they're in core, so we don't have to worry about not being able to use the std::os::raw types in no_std crates. They're still unstable, but they look like they're going to be stabilized shortly: rust-lang/rust#94501. They're still on nightly, but we depend on many nightly features already. I'd think the core types should be preferable to the libc ones, since you could be translating C code that doesn't use libc at all. And once the core::ffi::c_* types are stabilized, we can also use the std::ffi::c_* re-exports if we ever want to generate std instead of core.

@kkysen kkysen changed the title Switch to std::os::raw for C types instead of libc Switch to core::ffi::c_* for C types instead of libc::c_* Jun 17, 2022
@chrysn
Copy link
Contributor

chrysn commented Jun 19, 2022

Much of the generated code is already well usable on stable Rust; even if it's stabilized soon it'd be months until it's on stable.

I thus still like the --ctype-prefix option that is being implemented -- when used with nightly, core::ffi and std::ffi (any good reason to use that, now that core doesn't even need to be an extern crate any more?) can be good defaults.

@kkysen
Copy link
Contributor

kkysen commented Jun 19, 2022

Yeah, I agree. A --ctypes-prefix option is much more flexible, and in the future once things are stabilized, we can default to core::ffi.

@kkysen
Copy link
Contributor

kkysen commented Jul 16, 2022

core::ffi::c_* was just stabilized in 1.64: rust-lang/rust#94501 (comment).

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

Successfully merging this pull request may close these issues.

3 participants