RFC: Float-free libcore by strake · Pull Request #1596 · rust-lang/rfcs (original) (raw)
I think the fundamental issue is: Rust assumes that all targets support f32 and f64.
Almost all targets have floating point support (either in hardware or in software), but there are a few exceptions (e.g. x86_64 with SSE disabled). On these targets, (almost) every use of f32 and f64 is illegal and leads to a compile time error (e.g. LLVM ERROR: SSE register return with SSE disabled on x86_64 with SSE disabled).
We have the following options:
- Implement some kind of software float for these targets. Cleanest solution, but requires a lot of work.
- Add a
#[no_float]-like attribute for crates without floating point. We would still see a compile time error when (transitively) usingf32andf64, but we could emit nicer error messages. - Leave everything as it is and let the programmer of the niche target figure it out. No additonal work or mental burden for crate authors, but the programmer might see ugly LLVM errors for these targets.
Personally, I'm happy with option 3, because only few special-purpose targets have neither hard- nor soft-float. However, I think there should be some way to build libcore for these targets without manually patching it.
This could be either a cargo feature or an option in the target file. Personally, I prefer the target file option because… well, it's a property of the target. It allows other library authors to conditionally exclude floats if they want to. It also makes it easy to build a cross sysroot using xargo.
This RFC does not make anything worse. It just adds a new target property to describe that a target supports neither hard- nor soft-floats. Then it uses this property to allow compiling libcore for these targets. Like before, “every no_std-capable crate would potentially and unexpectedly fail to compile in a not(has_floating_point) environment”, but now we can at least compile libcore and add special cases for other crates (if we want to).