From bf8960c0e65fa9f5bb8666a8086694b2f7c79198 Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Mon, 17 May 2021 12:43:46 +0200 Subject: [PATCH 1/3] assert platform-minimum requirements at build time --- tokio/build.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tokio/build.rs b/tokio/build.rs index fe5c8300560..2221dece083 100644 --- a/tokio/build.rs +++ b/tokio/build.rs @@ -19,4 +19,29 @@ fn main() { ); } } + + assert_platform_minimums(); +} + +/// Assert platform-minimum requirements for Tokio to work correctly. This might +/// be feasible to do as a constant fn, once MSRC is bumped a bit more. +fn assert_platform_minimums() { + use std::mem; + use std::sync::atomic::{AtomicIsize, AtomicUsize}; + + if mem::size_of::() < 4 { + panic!("Tokio only works correctly if usize is at least 4 bytes."); + } + + if mem::size_of::() < 4 { + panic!("Tokio only works correctly if isize is at least 4 bytes."); + } + + if mem::size_of::() < 4 { + panic!("Tokio only works correctly if AtomicUsize is at least 4 bytes."); + } + + if mem::size_of::() < 4 { + panic!("Tokio only works correctly if AtomicIsize is at least 4 bytes."); + } } From 394dad5df725f863a744b4572f62cee35992c93a Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Mon, 17 May 2021 15:31:26 +0200 Subject: [PATCH 2/3] perform platform check w/ attributes --- tokio/build.rs | 25 ------------------------- tokio/src/lib.rs | 9 +++++++++ 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/tokio/build.rs b/tokio/build.rs index 2221dece083..fe5c8300560 100644 --- a/tokio/build.rs +++ b/tokio/build.rs @@ -19,29 +19,4 @@ fn main() { ); } } - - assert_platform_minimums(); -} - -/// Assert platform-minimum requirements for Tokio to work correctly. This might -/// be feasible to do as a constant fn, once MSRC is bumped a bit more. -fn assert_platform_minimums() { - use std::mem; - use std::sync::atomic::{AtomicIsize, AtomicUsize}; - - if mem::size_of::() < 4 { - panic!("Tokio only works correctly if usize is at least 4 bytes."); - } - - if mem::size_of::() < 4 { - panic!("Tokio only works correctly if isize is at least 4 bytes."); - } - - if mem::size_of::() < 4 { - panic!("Tokio only works correctly if AtomicUsize is at least 4 bytes."); - } - - if mem::size_of::() < 4 { - panic!("Tokio only works correctly if AtomicIsize is at least 4 bytes."); - } } diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs index 15aeced6d1e..0794af5f76b 100644 --- a/tokio/src/lib.rs +++ b/tokio/src/lib.rs @@ -341,6 +341,15 @@ //! //! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section +// Test that pointer width is compatible. This asserts that e.g. usize is at +// least 32 bits, which a lot of components in Tokio currently assumes. +// +// TODO: improve once we have MSRV access to const eval to make more flexible. +#[cfg(not(any(target_pointer_width = "32", target_pointer_width = "64", target_pointer_width = "128")))] +compile_error! { + "Tokio requires the platform pointer width to be 32, 64, or 128 bits" +} + // Includes re-exports used by macros. // // This module is not intended to be part of the public API. In general, any From ab944db32dbd461c44f1d7bb849fe6a6dd51c08c Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Tue, 18 May 2021 00:27:44 +0200 Subject: [PATCH 3/3] rustfmt --- tokio/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs index 0794af5f76b..42eb7755587 100644 --- a/tokio/src/lib.rs +++ b/tokio/src/lib.rs @@ -345,7 +345,11 @@ // least 32 bits, which a lot of components in Tokio currently assumes. // // TODO: improve once we have MSRV access to const eval to make more flexible. -#[cfg(not(any(target_pointer_width = "32", target_pointer_width = "64", target_pointer_width = "128")))] +#[cfg(not(any( + target_pointer_width = "32", + target_pointer_width = "64", + target_pointer_width = "128" +)))] compile_error! { "Tokio requires the platform pointer width to be 32, 64, or 128 bits" }