From 691a8c1d0038665702120d3727c1d7069a9edc52 Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Sat, 22 Oct 2022 11:38:48 +0000 Subject: [PATCH 1/3] CI: Update the expected memsize of the EntryInfo struct for Rust 1.66 nightly - Add rustc_version crate to the build-dependencies to check the Rust version. (Only enabled when `RUSTFLAGS='--cfg rustver'` is set) --- .github/workflows/CI.yml | 4 + .github/workflows/CIQuantaDisabled.yml | 4 + .github/workflows/LinuxCrossCompileTest.yml | 2 + .vscode/settings.json | 4 +- Cargo.toml | 3 + build.rs | 12 ++- src/common/concurrent/entry_info.rs | 91 ++++++++++++--------- 7 files changed, 79 insertions(+), 41 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 5e5a92ea..3b17af93 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -79,6 +79,8 @@ jobs: with: command: test args: --features sync + env: + RUSTFLAGS: '--cfg rustver' - name: Run tests (debug, sync feature, thread-pool test for sync::Cache) uses: actions-rs/cargo@v1 @@ -97,6 +99,8 @@ jobs: with: command: test args: --release --features sync + env: + RUSTFLAGS: '--cfg rustver' - name: Run tests (future feature, but no sync feature) uses: actions-rs/cargo@v1 diff --git a/.github/workflows/CIQuantaDisabled.yml b/.github/workflows/CIQuantaDisabled.yml index 4cf66b15..f4820ca7 100644 --- a/.github/workflows/CIQuantaDisabled.yml +++ b/.github/workflows/CIQuantaDisabled.yml @@ -73,12 +73,16 @@ jobs: with: command: test args: --no-default-features --features 'sync, atomic64' + env: + RUSTFLAGS: '--cfg rustver' - name: Run tests (release, but no quanta feature) uses: actions-rs/cargo@v1 with: command: test args: --release --no-default-features --features 'sync, atomic64' + env: + RUSTFLAGS: '--cfg rustver' - name: Run tests (future feature, but no quanta and sync features) uses: actions-rs/cargo@v1 diff --git a/.github/workflows/LinuxCrossCompileTest.yml b/.github/workflows/LinuxCrossCompileTest.yml index 64840b71..e94981a1 100644 --- a/.github/workflows/LinuxCrossCompileTest.yml +++ b/.github/workflows/LinuxCrossCompileTest.yml @@ -65,6 +65,8 @@ jobs: use-cross: true command: test args: --release --features sync --target ${{ matrix.platform.target }} ${{ matrix.platform.cargo-opts }} + env: + RUSTFLAGS: '--cfg rustver' - name: Run tests (future feature) uses: actions-rs/cargo@v1 diff --git a/.vscode/settings.json b/.vscode/settings.json index 5e984168..aaf8f5a6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -39,9 +39,11 @@ "repr", "reqwest", "runtimes", + "rustc", "rustdoc", "RUSTFLAGS", "rustfmt", + "rustver", "semver", "SIGABRT", "SIGILL", @@ -64,4 +66,4 @@ "cSpell.enableFiletypes": [ "toml" ] -} \ No newline at end of file +} diff --git a/Cargo.toml b/Cargo.toml index 48f6cff8..e643fb21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -98,6 +98,9 @@ trybuild = "1.0" [target.'cfg(skeptic)'.build-dependencies] skeptic = "0.13.5" +[target.'cfg(rustver)'.build-dependencies] +rustc_version = "0.4.0" + # https://docs.rs/about/metadata [package.metadata.docs.rs] # Build the doc with some features enabled. diff --git a/build.rs b/build.rs index 61802ec7..88e341e8 100644 --- a/build.rs +++ b/build.rs @@ -4,5 +4,15 @@ fn main() { skeptic::generate_doc_tests(&["README.md"]); } -#[cfg(not(skeptic))] +#[cfg(rustver)] +fn main() { + use rustc_version::version; + let version = version().expect("Can't get the rustc version"); + println!( + "cargo:rustc-env=RUSTC_SEMVER={}.{}", + version.major, version.minor + ); +} + +#[cfg(not(any(skeptic, rustver)))] fn main() {} diff --git a/src/common/concurrent/entry_info.rs b/src/common/concurrent/entry_info.rs index c8c5c445..38b85000 100644 --- a/src/common/concurrent/entry_info.rs +++ b/src/common/concurrent/entry_info.rs @@ -95,53 +95,66 @@ impl AccessTime for EntryInfo { mod test { use super::EntryInfo; + // Run with: + // RUSTFLAGS='--cfg rustver' cargo test --lib --features sync -- common::concurrent::entry_info::test --nocapture + // RUSTFLAGS='--cfg rustver' cargo test --lib --no-default-features --features sync -- common::concurrent::entry_info::test --nocapture + // // Note: the size of the struct may change in a future version of Rust. - #[cfg_attr(not(any(target_os = "linux", target_os = "macos")), ignore)] + #[cfg_attr( + not(all(rustver, any(target_os = "linux", target_os = "macos"))), + ignore + )] #[test] fn check_struct_size() { use std::mem::size_of; - // Rust 1.62: - // - // | pointer width | quanta | no quanta (Linux) | no quanta (macOS) | - // | ------------- | ------ | ----------------- | ----------------- | - // | 64-bit | 24 | 72 | 56 | - // | 32-bit | 24 | 72 | n/a | - - let size = if cfg!(feature = "quanta") { - 24 - } else if cfg!(target_os = "linux") { - 72 + #[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] + enum TargetArch { + Linux64, + Linux32, + MacOS64, + } + + use TargetArch::*; + + // e.g. "1.64" + let ver = option_env!("RUSTC_SEMVER").expect("Please run with RUSTFLAGS='--cfg rustver'"); + let is_quanta_enabled = cfg!(feature = "quanta"); + let arch = if cfg!(target_os = "linux") { + if cfg!(target_pointer_width = "64") { + Linux64 + } else if cfg!(target_pointer_width = "32") { + Linux32 + } else { + panic!("Unsupported pointer width for Linux"); + } } else if cfg!(target_os = "macos") { - 56 + MacOS64 } else { - unreachable!(); + panic!("Unsupported target architecture"); + }; + + let expected_sizes = match (arch, is_quanta_enabled) { + (Linux64, true) => vec![("1.51", 24)], + (Linux32, true) => vec![("1.51", 24)], + (MacOS64, true) => vec![("1.62", 24)], + (Linux64, false) => vec![("1.66", 56), ("1.51", 72)], + (Linux32, false) => vec![("1.66", 56), ("1.62", 72), ("1.51", 40)], + (MacOS64, false) => vec![("1.62", 56)], }; - // Rust 1.61 or older: - // - // | pointer width | quanta | no quanta (Linux) | - // | ------------- | ------ | ----------------- | - // | 64-bit | 24 | 72 | - // | 32-bit | 24 | 40 | - // - // let size = if cfg!(target_pointer_width = "64") { - // if cfg!(feature = "quanta") { - // 24 - // } else { - // 72 - // } - // } else if cfg!(target_pointer_width = "32") { - // if cfg!(feature = "quanta") { - // 24 - // } else { - // 40 - // } - // } else { - // // ignore - // return; - // }; - - assert_eq!(size_of::(), size); + let mut expected = None; + for (ver_str, size) in expected_sizes { + expected = Some(size); + if ver >= ver_str { + break; + } + } + + if let Some(size) = expected { + assert_eq!(size_of::(), size); + } else { + panic!("No expected size for {:?} with Rust version {}", arch, ver); + } } } From bc2c3a132a5e9213ece28d23924c3a15e4a9b325 Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Sat, 22 Oct 2022 12:11:14 +0000 Subject: [PATCH 2/3] CI: Update the expected memsize of the EntryInfo struct for Rust 1.66 nightly Update the Cargo config for 32-bit targets. --- .cargo/config | 6 +++--- src/common/concurrent/entry_info.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.cargo/config b/.cargo/config index 56401ad7..eaf5578f 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,8 +1,8 @@ [target.armv5te-unknown-linux-musleabi] -rustflags = ["--cfg", "armv5te"] +rustflags = ["--cfg", "armv5te", "--cfg", "rustver"] [target.mips-unknown-linux-musl] -rustflags = ["--cfg", "mips"] +rustflags = ["--cfg", "mips", "--cfg", "rustver"] [target.mipsel-unknown-linux-musl] -rustflags = ["--cfg", "mips"] +rustflags = ["--cfg", "mips", "--cfg", "rustver"] diff --git a/src/common/concurrent/entry_info.rs b/src/common/concurrent/entry_info.rs index 38b85000..82efc71e 100644 --- a/src/common/concurrent/entry_info.rs +++ b/src/common/concurrent/entry_info.rs @@ -118,7 +118,7 @@ mod test { use TargetArch::*; // e.g. "1.64" - let ver = option_env!("RUSTC_SEMVER").expect("Please run with RUSTFLAGS='--cfg rustver'"); + let ver = option_env!("RUSTC_SEMVER").expect("RUSTC_SEMVER env var not set"); let is_quanta_enabled = cfg!(feature = "quanta"); let arch = if cfg!(target_os = "linux") { if cfg!(target_pointer_width = "64") { From a178aab30dec99fa8dac41f5189cd0f9c92e5480 Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Mon, 24 Oct 2022 22:12:35 +0800 Subject: [PATCH 3/3] CI: Update the expected memsize of the EntryInfo struct for Rust 1.66 nightly To workaround the following Cargo issue with cross compiling, force enable rustc_version crate when testing Linux corss targets: https://github.com/rust-lang/cargo/issues/4423 --- .ci_extras/build_linux_cross.rs | 8 ++++++++ .github/workflows/LinuxCrossCompileTest.yml | 4 +++- .vscode/settings.json | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 .ci_extras/build_linux_cross.rs diff --git a/.ci_extras/build_linux_cross.rs b/.ci_extras/build_linux_cross.rs new file mode 100644 index 00000000..08f5d44f --- /dev/null +++ b/.ci_extras/build_linux_cross.rs @@ -0,0 +1,8 @@ +fn main() { + use rustc_version::version; + let version = version().expect("Can't get the rustc version"); + println!( + "cargo:rustc-env=RUSTC_SEMVER={}.{}", + version.major, version.minor + ); +} diff --git a/.github/workflows/LinuxCrossCompileTest.yml b/.github/workflows/LinuxCrossCompileTest.yml index e94981a1..fc8b9411 100644 --- a/.github/workflows/LinuxCrossCompileTest.yml +++ b/.github/workflows/LinuxCrossCompileTest.yml @@ -46,10 +46,12 @@ jobs: target: ${{ matrix.platform.target }} override: true - - name: Remove integration tests + - name: Remove integration tests and force enable rustc_version crate run: | rm -rf tests sed -i '/actix-rt\|async-std\|reqwest\|skeptic/d' Cargo.toml + sed -i 's/target.*rustver.*\.//' Cargo.toml + sed -i 's/build = "build.rs"/build = ".ci_extras\/build_linux_cross.rs"/' Cargo.toml cat Cargo.toml - uses: Swatinem/rust-cache@v1 diff --git a/.vscode/settings.json b/.vscode/settings.json index aaf8f5a6..5ad01033 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -19,6 +19,7 @@ "deqs", "Deque", "Deques", + "devcontainer", "docsrs", "Einziger", "else's",