Skip to content

refactor liblibc into finer-grained crates #17547

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
aturon opened this issue Sep 26, 2014 · 16 comments
Closed

refactor liblibc into finer-grained crates #17547

aturon opened this issue Sep 26, 2014 · 16 comments
Labels
A-FFI Area: Foreign function interface (FFI)

Comments

@aturon
Copy link
Member

aturon commented Sep 26, 2014

The libc crate currently provides a large set of bindings to C APIs. Some of these are cross-platform. But the crate also exports a large number of platform-specific APIs.

It was initially carefully organized according to various standards, but over time it has become a dumping ground for bindings.

As part of the runtime removal RFC we would like to refactor the crate into smaller pieces:

  • liblibc should provide fully cross-platform C APIs. This should roughly correspond to the export list currently at the top of liblibc/lib.rs, and encompasses universal C bindings.
  • libunix should provide APIs that are available for any #[cfg(unix)] platform.
  • libwindows should provide APIs that are available for any #[cfg(windows)] platform.

Ultimately, we are likely to add additional crates like liblinux to provide even more specific sets of bindings.

Due to the top-level exports in liblibc, it should be possible to do this refactoring without overly painful breakage.

@aturon
Copy link
Member Author

aturon commented Sep 26, 2014

cc @alexcrichton @brson

@aturon
Copy link
Member Author

aturon commented Sep 26, 2014

If you're interested in taking this on, please leave a comment on this issue so we can coordinate work with other ongoing changes to the libraries.

@retep998
Copy link
Member

I'd personally prefer to split it based on whether it is part of the C standard, part of POSIX, or part of WinAPI. On Windows there are many windows-specific versions of the posix functions, so it seems like a better idea to keep them in libposix.

@aturon
Copy link
Member Author

aturon commented Sep 26, 2014

It's also worth considering automating the generation of these bindings as part of this refactoring.

@retep998
Copy link
Member

As part of this refactoring, in many crates there are definitions for winapi/posix things and they should be moved into these crates. I'd opt for these crates to be universal crates containing bindings to everything rather than just what is used in rustc.

@thestinger
Copy link
Contributor

Portability across different C standard library implementations is unrealistic if it's not auto-generated. It can't be split as suggested in the issue if it's done sanely. It should all be auto-generated from the headers with no Rust-specific design or organization involved.

@mahkoh
Copy link
Contributor

mahkoh commented Sep 26, 2014

I've written posix bindings for x86_64 and x86 linux before and I've generated the structures for x86 with a program (see the posgen directory.)

I strongly advice you to do the same here (but with a much older glibc.) Those structures can be very hard to wrap and I wouldn't expect hand-wrapped structures to be correct.

@sinistersnare
Copy link
Contributor

why not something like liblic and libplatform for platform specific C bindings?

@thestinger
Copy link
Contributor

@sinistersnare: Rust-specific organization means it can't be auto-generated from headers. It will involve a lot of design / organization work and it will always be non-portable and missing functionality. Any proposal involving organization not there on the C end is a bad one.

@Ericson2314
Copy link
Contributor

I also think auto generating bindings is an excellent idea as i rather get link errors in rust land. Splitting C bindings by standard, and additional having kernel-specific libs strikes me as a good idea.

@thestinger do you think these goals are compatible?

@retep998
Copy link
Member

How are we going to re-export things in liblibc when liblibc provides the base definitions that other libraries like libwindows will need? Surely we can't have cyclical crate dependencies?

@aturon
Copy link
Member Author

aturon commented Oct 18, 2014

@retep998 I'm not sure I follow the question. Which re-exports do you have in mind? The idea here was just that liblibc would export the cross-platform subset of things it exports today, and other crates could build on that. But as @thestinger points out, any organization not present in the header files will make it harder/impossible to automate binding generation.

@retep998
Copy link
Member

@aturon So what you propose is that libwindows contains everything that can be used on Windows, including primitives such as c_ulong, and then liblibc re-exports the cross platform stuff?

@retep998
Copy link
Member

retep998 commented Nov 4, 2014

I'm slowly working on my own winapi bindings out of tree at https://github.com/retep998/winapi-rs
If anyone has any suggestions regarding organization of the bindings, feel free.

@alexcrichton
Copy link
Member

@retep998 I would personally expect libwinapi to depend on liblibc for types like c_ulong and such. I would also personally organize a library like libwinapi as just a flat namespace (like a C header file). The internal organization may wish to be more flavorful, but I've found that it's easiest if the organization in the Rust crate looks the same as the C header file.

I do also think though that liblibc has too many things today, and we may want to refactor it into finer grained dependencies (but I don't wanna go too overboard with this).

@kmcallister kmcallister added the A-FFI Area: Foreign function interface (FFI) label Jan 16, 2015
@steveklabnik
Copy link
Member

Work on the libc create is ongoing as part of rust-lang/rfcs#1291, and there hasn't been discussion here in almost a year, so I'm going to give it a close in favor of that.

lnicola pushed a commit to lnicola/rust that referenced this issue Jul 11, 2024
internal: Clean up runnable lsp extension

This feels like a natural addition to me, and also allows us to drop the expect-test hardcoding from the extension. Additionally, `cargoExtraArgs` is pointless, all the client will do is merge it with `cargoArgs` so the server can do that instead of delegating that to the client.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-FFI Area: Foreign function interface (FFI)
Projects
None yet
Development

No branches or pull requests

9 participants