Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Update the expected memsize of the EntryInfo struct for Rust 1.66 nightly #186

Merged
merged 3 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -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"]
8 changes: 8 additions & 0 deletions .ci_extras/build_linux_cross.rs
Original file line number Diff line number Diff line change
@@ -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
);
}
4 changes: 4 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/CIQuantaDisabled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/LinuxCrossCompileTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -65,6 +67,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
Expand Down
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"deqs",
"Deque",
"Deques",
"devcontainer",
"docsrs",
"Einziger",
"else's",
Expand All @@ -39,9 +40,11 @@
"repr",
"reqwest",
"runtimes",
"rustc",
"rustdoc",
"RUSTFLAGS",
"rustfmt",
"rustver",
"semver",
"SIGABRT",
"SIGILL",
Expand All @@ -64,4 +67,4 @@
"cSpell.enableFiletypes": [
"toml"
]
}
}
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 11 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
91 changes: 52 additions & 39 deletions src/common/concurrent/entry_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("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") {
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::<EntryInfo>(), 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::<EntryInfo>(), size);
} else {
panic!("No expected size for {:?} with Rust version {}", arch, ver);
}
}
}