Awesome.
Iām not a Rust reviewer, but IMO thatās probably got the order of operations backwards. The main benefit, as I see it, of the refactoring is that it makes it easier to create alternative implementations of libstd not based on libc, either for a port to a non-unixy platform, or for some other reason. I think that is an important advantage, and it doesnāt seem to have negative consequences, but itās not a high priority for others. Regardless, what you proposed seems too big for people to evaluate as one item. Also, I think ādonāt ask for permissionā applies here. So, I recommend just breaking out a few changes into small-enough-to-review pieces and submitting PRs.
Also, people might have read your initial comments as āthe structure of libstd is bad and Iām fixing itā whereas it might be better to convey the message āHereās some patches to make porting libstd easier.ā
As far as I understand your idea, shouldnāt most of what was added to liballoc_system/lib.rs be in a separate file, similar to the added bind.rs? Then the added section of liballoc_system/lib.rs would be something like:
#[cfg(target_family = "bind")]
pub use super::bind::{
allocate,
deallocate,
reallocate,
reallocate_inplace,
usable_size
};
And, in fact, that could be encapsulated in a macro that takes the module from which to re-export items as a parameter, I think.
Your patch mixes two ideas:
- It should be possible to implement libstd without depending on the
libc crate.
- The
libc-less replacement will be primarily implemented in non-Rust code.
I think it would be useful to split these two ideas, because the late-binding-to-another-library approach isnāt the only interesting one. In particular, the invoke-syscall-directly-from-Rust case doesnāt require all the late binding machinery.
Also, your change to OsRng hints at another refactoring: If there was a sys::rand::fill_bytes standalone function, then we could share one implementation of OsRng, and each libstd port would only have to implement sys::rand::fill_bytes. In fact, I think that this refactoring should be done separately, probably before the other refactorings.
Anyway, I think that your overall idea is good and I encourage you to move forward with it. Iām happy to look over your pull requests. (Keep in mind Iām not a Rust stdlib reviewer, so I canāt approve changes.)