c2rust icon indicating copy to clipboard operation
c2rust copied to clipboard

Consider emitting the c-types provided by `std`/`core`, instead of depending on `libc`

Open Luro02 opened this issue 5 years ago • 5 comments

The standard library provides std::os::raw, which defines c_*-types that can be used for ffi. Those types are identical to the types provided by libc.

It would be nice if c2rust would emit the types provided by the standard library, instead of depending on an external crate. (it is annoying to replace all occurences of libc::* with the std equivalent).

Luro02 avatar Sep 11 '20 08:09 Luro02

The main thing to consider is that the std::os::raw types are only available with libstd but not in no_std mode, while the libc crate supports no_std.

It would be nice if c2rust would emit the types provided by the standard library, instead of depending on an external crate.

We could add an option --use-std-types to the transpiler, but I think we still need to support both sets of types. Alternatively, we could switch to std::os::raw types as the default and add an option for the libc types.

(it is annoying to replace all occurences of libc::* with the std equivalent).

The c2rust-refactor tool should be able to automate that, e.g., using rewrite_ty.

ahomescu avatar Sep 11 '20 21:09 ahomescu

Relevant issue https://github.com/rust-lang/rust/issues/36193

Luro02 avatar Sep 12 '20 06:09 Luro02

@Luro02 I implemented this and created a pull request, feel free to use the std_raw_types branch while it gets reviewed.

ahomescu avatar Sep 15 '20 03:09 ahomescu

Very cool, thank you 🤗

Luro02 avatar Sep 15 '20 07:09 Luro02