Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I wonder what the author means by the alloc crate not being stable? The alloc crate is stable since 1.36.0: https://github.com/rust-lang/rust/blob/master/RELEASES.md#ve...

Regarding the reproducible builds concern around paths being integrated into the binary, a flag exists to get rid of paths: --remap-path-prefix

https://doc.rust-lang.org/rustc/command-line-arguments.html#...

On nightly, there is also remap-cwd-prefix added by the chromium team to address some of the shortcomings with remap-path-prefix: https://github.com/rust-lang/rust/issues/89434

Overall I'm really impressed that an individual wrote 100 thousand lines of Rust. That's a lot!



You can write libraries against alloc on stable, but not any executables, because executables not using std need to specify the alloc_error_handler, which you can't do on stable yet: https://github.com/rust-lang/rust/issues/51540


Oh I see, I stand corrected then. Thanks for pointing that out!


Yep, this is a great article, but that section (the whole "Rust Isn’t Finished" section) jumped out as a place where there were some simple ways he could have made his life easier. It could also have been a failure of the Rust community to teach a good workflow.

You don't need to force every contributor to upgrade every six weeks in lockstep, since releases of Rust and std are backwards compatible. Upgrade at your leisure, and run tests in CI with the minimum version you want to support. If you're doing something crazier that requires ABI compatibility between separate builds (or you just want consistency), you can add a `rust-toolchain` file that upgrades the compiler on dev machines automatically, as seamlessly as Cargo downloads new dependency versions.


To clarify a bit, the key thing here is that the OP is maintaining their own patches to Rust's standard library. While the API of std is itself backwards compatible, its implementation uses a whole mess of unstable nightly features. That means that std for Rust 1.x can't necessarily be built with Rust 1.(x-1). EDIT: Nor can std for Rust 1.(x-1) be necessarily built by Rust 1.x.

It's true that you don't have to force every contributor to upgrade every six weeks, but you do very likely need to have every contributor use the same version of Rust. (Which can be accomplished with a rust-toolchain file, as you mention.)

The problem here is that if you don't do this upgrade whenever a new Rust release is made, you're just putting off that work to some other point. Maybe you do it every 12 weeks instead of 6 weeks, that would probably be okay. But I'd imagine waiting a year, for example, could be unpleasant.


This is correct.

When you tell someone to install Rust, they go to rustup.rs and install the latest version. Therefore, we need to have a libstd port for the latest version. Which effectively means we need to release libstd as soon as possible after the compiler is released. Our `sys` directory is at https://github.com/betrusted-io/rust/tree/1.61.0-xous/librar... and isn't too complicated. It's about 50 patches that need to be carried forward every six weeks.

Fortunately libstd doesn't change too much, at leaset not the parts we need. And I can usually pre-port the patches by applying them to `beta`, which means the patches against the release version usually apply cleanly.

It's still better than requiring nightly, which has absolutely no stability guarantees. By targeting stable, we don't run into issues of bitrot where we accidentally rely on features that have been removed. Rather than adjusting every service in the operating system, we just need to port one library: libstd

I've considered trying to upstream these, but I'm not sure how the rust team would feel about it.


> OP is maintaining their own patches to Rust's standard library

Oops, that's the bit I must have missed. That does sound like an ordeal and I don't have an easy answer.


This is one thing I struggle with when learning Rust.

I want to have some examples of purely idiomatic Rust code solving some bog-standard problems, that way I can copy what that project's doing while I get comfortable enough with the language and learn to make my own decisions.


> I wonder what the author means by the alloc crate not being stable? The alloc crate is stable since 1.36.0:

He is referring to the allocator api[1], not the std lib module

[1] https://github.com/rust-lang/rust/issues/32838


It doesn't seem to me that this feature is what the blog post is referring to:

> I often ask myself “when is the point we’ll get off the Rust release train”, and the answer I think is when they finally make “alloc” no longer a nightly API. At the moment, `no-std` targets have no access to the heap, unless they hop on the “nightly” train, in which case you’re back into the Python-esque nightmare of your code routinely breaking with language releases.

You can absolutely do your own allocator with no-std. All you need for this is the alloc crate and the global_alloc feature, while global_alloc was stabilized before the alloc crate. Then you can call your own custom OS routines from that global allocator. No need to fork std over that.

Now, maybe their custom use case needs something different, and then it's a fair criticism, but for that I would have expected a different wording of the issue, hopefully together with a more detailed explanation of those use cases and how the stable part of the existing alloc crate does not meet them.


If, like OP, you're writing an operating system (or a language VM) it is absolutely a thing that you will want to have different allocators for different use cases, so being able to set a global allocator is "not quite enough". You will want certain generics (like hashes) to be able to take advantage of different allocators, or even different instances of allocators (say, give each thread it's own arena). This is very not easy in rust, which effectively requires data structures to be associated with specific allocators at the type-level - which makes code sharing between the "same" data structure tied to different allocators quite difficult.

For reference, the Erlang VM, which is often joked as being "an operating system unto itself" has 11? IIRC allocators.


The rust compiler makes use of custom arenas for allocation, quite heavily in fact. And does it without using the nightly-only custom allocator alloc types. Instead, there are functions that let you build structures inside the arena, plus a bunch of macro logic that builds on it. And while rustc generally uses a lot of nightly features, there is nothing fundamental about it that requires nightly.

Also, again, it's a fair concern that you want to be doing custom allocators, but this is not the same as claiming that no-std applications can't use the heap at all, which is what the blog post did. For simple heap usage, a global allocator is enough.





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: