Skip to content

Commit 0113c29

Browse files
BoxyUwUaevyrie
authored andcommitted
CI runs cargo miri test -p bevy_ecs (bevyengine#4310)
# Objective Fixes bevyengine#1529 Run bevy_ecs in miri ## Solution - Don't set thread names when running in miri rust-lang/miri/issues/1717 - Update `event-listener` to `2.5.2` as previous versions have UB that is detected by miri: [event-listener commit](smol-rs/event-listener@1fa31c5) - Ignore memory leaks when running in miri as they are impossible to track down rust-lang/miri/issues/1481 - Make `table_add_remove_many` test less "many" because miri is really quite slow :) - Make CI run `RUSTFLAGS="-Zrandomize-layout" MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-tag-raw-pointers -Zmiri-disable-isolation" cargo +nightly miri test -p bevy_ecs`
1 parent d9152ea commit 0113c29

File tree

5 files changed

+62
-9
lines changed

5 files changed

+62
-9
lines changed

.github/bors.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ status = [
1313
"check-missing-examples-in-docs",
1414
"check-unused-dependencies",
1515
"ci",
16+
"miri",
1617
"check-benches",
1718
]
1819

.github/workflows/ci.yml

+32
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,38 @@ jobs:
7070
# See tools/ci/src/main.rs for the commands this runs
7171
run: cargo run -p ci -- nonlocal
7272

73+
miri:
74+
runs-on: ubuntu-latest
75+
steps:
76+
- uses: actions/checkout@v3
77+
- uses: actions/cache@v2
78+
with:
79+
path: |
80+
~/.cargo/bin/
81+
~/.cargo/registry/index/
82+
~/.cargo/registry/cache/
83+
~/.cargo/git/db/
84+
target/
85+
key: ${{ runner.os }}-cargo-ci-${{ hashFiles('**/Cargo.toml') }}
86+
- uses: actions-rs/toolchain@v1
87+
with:
88+
toolchain: nightly
89+
components: miri
90+
override: true
91+
- name: Install alsa and udev
92+
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev
93+
- name: CI job
94+
run: cargo miri test -p bevy_ecs
95+
env:
96+
# -Zrandomize-layout makes sure we dont rely on the layout of anything that might change
97+
RUSTFLAGS: -Zrandomize-layout
98+
# -Zmiri-disable-isolation is needed because our executor uses `fastrand` which accesses system time.
99+
# -Zmiri-ignore-leaks is needed because running bevy_ecs tests finds a memory leak but its impossible
100+
# to track down because allocids are nondeterministic.
101+
# -Zmiri-tag-raw-pointers is not strictly "necessary" but enables a lot of extra UB checks relating
102+
# to raw pointer aliasing rules that we should be trying to uphold.
103+
MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-ignore-leaks -Zmiri-tag-raw-pointers
104+
73105
check-benches:
74106
runs-on: ubuntu-latest
75107
needs: ci

crates/bevy_ecs/src/lib.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,18 @@ mod tests {
637637
#[test]
638638
fn table_add_remove_many() {
639639
let mut world = World::default();
640-
let mut entities = Vec::with_capacity(10_000);
641-
for _ in 0..1000 {
640+
#[cfg(miri)]
641+
let (mut entities, to) = {
642+
let to = 10;
643+
(Vec::with_capacity(to), to)
644+
};
645+
#[cfg(not(miri))]
646+
let (mut entities, to) = {
647+
let to = 10_000;
648+
(Vec::with_capacity(to), to)
649+
};
650+
651+
for _ in 0..to {
642652
entities.push(world.spawn().insert(B(0)).id());
643653
}
644654

crates/bevy_tasks/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ keywords = ["bevy"]
1010

1111
[dependencies]
1212
futures-lite = "1.4.0"
13-
event-listener = "2.4.0"
13+
event-listener = "2.5.2"
1414
async-executor = "1.3.0"
1515
async-channel = "1.4.2"
1616
num_cpus = "1.0.1"

crates/bevy_tasks/src/task_pool.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,23 @@ impl TaskPool {
121121
let ex = Arc::clone(&executor);
122122
let shutdown_rx = shutdown_rx.clone();
123123

124-
let thread_name = if let Some(thread_name) = thread_name {
125-
format!("{} ({})", thread_name, i)
126-
} else {
127-
format!("TaskPool ({})", i)
124+
// miri does not support setting thread names
125+
// TODO: change back when https://github.com/rust-lang/miri/issues/1717 is fixed
126+
#[cfg(not(miri))]
127+
let mut thread_builder = {
128+
let thread_name = if let Some(thread_name) = thread_name {
129+
format!("{} ({})", thread_name, i)
130+
} else {
131+
format!("TaskPool ({})", i)
132+
};
133+
thread::Builder::new().name(thread_name)
134+
};
135+
#[cfg(miri)]
136+
let mut thread_builder = {
137+
let _ = i;
138+
let _ = thread_name;
139+
thread::Builder::new()
128140
};
129-
130-
let mut thread_builder = thread::Builder::new().name(thread_name);
131141

132142
if let Some(stack_size) = stack_size {
133143
thread_builder = thread_builder.stack_size(stack_size);

0 commit comments

Comments
 (0)