-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Split out OS-specific bits in the runtime to help support freestanding targets. #185
Conversation
I like the general idea of creating a platform abstraction crate for the standard library. |
When initially extracting libcore, I found it quite helpful to have a mostly-working copy of libcore before drafting an RFC just to see what would actually work and what would have to be left behind. It may be beneficial to have a mostly-working version of what you would like for this as well. I, too, like the concept of centralizing platform-specific bits. It may be tough to abstract over unix/windows in all situations. If you're abstracting over I/O, for example, the interface is likely just libnative. For things like threads and mutexes, however, it can be useful to have a centralized location for them and they all have basically the same interface. |
I wonder then if perhaps the more 'correct' solution is to integrate these bits into libnative, rather than creating a new crate for the purpose. Moving things like |
RE the libcore mention - I can definitely start working on doing this splitting work to see what can be done easily and what requires more sweeping changes. If we can agree on the correct crate for this work to be done in (os, native, rustrt, etc), I can work on this. |
Will this new crate live in between libcore and liballoc? If so, using liballoc on a new system might require I imagine it wouldn't because the interface can be incomplete. |
@pczarn you raise a really good point, though with the current interface, writing a custom Ignoring the concept of custom allocators, which could (maybe?) solve the dependency there, I think moving the raw system allocation glue to |
It doesn't belong in |
It might belong in between |
On IRC I was thinking of the benefits of having multiple OS crates. Probably the most basic argument is to avoid adding extra dependencies to things that don't need it. Obviously liballoc need not relay on IO. More importantly though I'll take an OS crate over the current situation. libstd facade was a big step in the right direction, but something along these lines is needed to finish it! |
Not be self-promoting, but my proposal here mentions this issue http://discuss.rust-lang.org/t/traits-ml-modules/272 . |
@miselin Integrating into libnative will not work I think because of the dependencies. libnative is the last thing linked when building a Rust exe - nothing depends on it. |
For reference, this is the most relevant part of the dependency graph. gist / Old source |
That is a bit out of date. Pretty sure |
And just to be aware - there is technically some OS specific stuff still hidden in LLVM frame lowering for segmented stack prologues (stack limits). Until something like #131 comes in anyway. Edit: Wrong rfc |
The LLVM-specific stuff certainly still exists, but yes - RFC #131 would solve that problem in a much better way. @pczarn - the problem with the location of |
Sorry - wrong RFC. I was lazy. |
An initial POC of this is now in my fork of the Rust repo. |
The only allocation is a raw call to malloc in |
I have updated the POC branch in my fork. I have done a trivial removal of |
You'll probably need to look at Edit: Transmute to raw pointer is the same as forget. But you will need to |
I've updated the POC branch with work so far on having I am thinking about updating the RFC to add something like an |
I'm assuming support for custom allocators in the future. I don't think |
@pczarn what timeline is there for custom allocators? (@alexcrichton, @brson might also have an idea?) |
@miselin, the design won't be finished before 1.0, and not long after that, either... I guess. Actually, a pluggable default allocator is important to break the dependency on OS-specific heap. |
@miselin It looks like the main issue you are having breaking the dependency between |
As @miselin and I were talking about on IRC, there are some potential pitfalls if a freestanding implementation for In general, the problem stems from an inability to specify dependencies within My preference would be to break up a potential |
As I just ported Rust to DragonFlyBSD, I am all in favor for this idea. Having target_os specific code scattered all around in different places is a bad thing IMHO, and you quickly can shoot yourself in the shoe when you forget something. Having a single "libos" makes testing for that specific target OS a lot easier I guess. For the library part (not rustc itself), I had to make target specific changes to The hardest part though is porting |
@ryanra one of my other problems with multiple OS crates is that it solves a problem for freestanding purposes that no other target ever has to worry about (because each other target has an established set of system libraries). I acknowledge the recursion problem this can cause, but I think creating N crates isn't the right solution. @bharrisau yup. I think we can get away with depending on things like I can certainly keep working on moving things into I did a quick check just now on a couple crates, and...
|
And From my quick look, |
It's starting to form into 4 layers
|
I completely missed where Yes, I agree. That is the goal - modify/create |
If |
In some ways, Some things will have an 'optimised' solution in Windows or Linux, but might still be doable in standard ANSI C. In that case, you can probably leave the |
I've updated the RFC with results from a quick scan over the code base. The POC branch has been updated to reflect the name EDIT: Relinking POC branch because it is now quite a few comments back. |
@ryanra Sorry I meant to say that is the best that can be done for a single OS create -- I originally advocated for multiple crates too. So if Also, if the platform implementations for existing OSes implement their own syscalls (which would be faster too) need anything that's not a wrap of a native library depend on libc? |
I don't think this is neither easy nor feasible, considering that the way of making a syscall on Linux differs depending on CPU architectures to start with. |
I've updated the RFC again. I'll put the most important part of the latest change here in this thread, which is what I've come up with so far in doing the POC: The outcome of this POC so far indicates that, with the
@Ericson2314 I'm not sure there is another place to move EDIT: or you could use |
I've been looking over the @miselin's proof of concept. My basic opinion is most code that uses This is a lot less feasible for Also a couple of random points:
I forked miselin's work to explore these ideas and will post links when ready. |
I'd be in favor of having separate And without these, |
@bharrisau Even though rlibc doesn't replace libc, why can't we still make these language items? |
@alexchandel with multiple crates, are you wanting to cherry-pick the crates that you do implement in this case? (eg, "I don't care about file I/O, so I won't write @Ericson2314 I think being able to remove the existence of |
@miselin I meant remove libc from the other creates. We are well on our way to limiting usage of libc and |
Another POC, basically taking As I see it, moving the io stuff out of So
|
@Ericson2314 I had a quick look, but it seems like One of the things What are your thoughts on this? |
I definitely agree with @alexchandel. In most of my recent projects we have embedded systems that do have networking, but have pretty much no use for filesystem. |
@miselin I agree that is a good goal. The problem is that the OS bits of rustc both depend and are dependent on the more portable bits. I'll try next to move the platform-agnostic stuff out of librustrt, but I'm not sure how far I'll get.
|
For what it's worth, my statement before should actually probably be "to abstract away all of the platform specifics, in a crate (or crates) that can be trivially implemented outside of the Rust source tree." |
6357402
to
e0acdf4
Compare
The planned state of the runtime, I/O interfaces, and synchronization primitives has shifted significantly from when this was open. With #230 now accepted, it's likely that the number of layers of abstraction between the standard library and the system you're running on is going to be greatly reduced. As a result, this RFC has since become a little out of date and may need significant re-wording to take into account #230. Additionally, there's quite a bit of discussion here which may need to get re-incorporated into the RFC. These will definitely be part of the driving principles of the rearchitecting of the runtime, however! Consequently, I'm going to close this for now, in the spirit of having as few in-flight RFCs for modifying the runtime as possible. I suspect that many of the concerns in this RFC will be addressed when #230 is completed, as well! Thanks again for the RFC, and I'm sure that the progress on #230 will definitely welcome comments throughout! |
Readable/formatted/published version.