assert platform-minimum requirements at build time #3797
Merged
+13
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds assertions in
build.rs
which ensures that the platform being built for supports the minimum required by Tokio.Motivation
Tokio currently makes a number of soft assumptions about the size of a
usize
(andisize
), usually through the form of casting au32
like:Arguably the preferable way to do this would be to perform a checked conversion using
TryFrom
, but it would be a lot of work to trace all of them down and it might not always be immediately feasible when it comes to things like bit flags.It is unlikely that someone will ever attempt to build Tokio for a platform where
usize
is not at least 4 bytes, but at least when they do, they should be firmly shown that it's a bad idea until assumptions aroundusize
et. al. have been fixed.Solution
Add assertions to
build.rs
. I started tinkering with constant assertions, but Rust1.45
is a bit too limiting to make them ergonomical. While it's possible thatbuild.rs
is run with a differentrustc
than the one used to compile the project, one would have to do something strange to have it do so.