diff --git a/.github/bors.toml b/.github/bors.toml index 4e8d0332954d4..7d7911af1b40f 100644 --- a/.github/bors.toml +++ b/.github/bors.toml @@ -13,6 +13,7 @@ status = [ "check-missing-examples-in-docs", "check-unused-dependencies", "ci", + "miri", "check-benches", ] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c49157a7fd824..05382f5ff7a69 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,6 +70,38 @@ jobs: # See tools/ci/src/main.rs for the commands this runs run: cargo run -p ci -- nonlocal + miri: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-ci-${{ hashFiles('**/Cargo.toml') }} + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + components: miri + override: true + - name: Install alsa and udev + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libwayland-dev libxkbcommon-dev + - name: CI job + run: cargo miri test -p bevy_ecs + env: + # -Zrandomize-layout makes sure we dont rely on the layout of anything that might change + RUSTFLAGS: -Zrandomize-layout + # -Zmiri-disable-isolation is needed because our executor uses `fastrand` which accesses system time. + # -Zmiri-ignore-leaks is needed because running bevy_ecs tests finds a memory leak but its impossible + # to track down because allocids are nondeterministic. + # -Zmiri-tag-raw-pointers is not strictly "necessary" but enables a lot of extra UB checks relating + # to raw pointer aliasing rules that we should be trying to uphold. + MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-ignore-leaks -Zmiri-tag-raw-pointers + check-benches: runs-on: ubuntu-latest needs: ci diff --git a/crates/bevy_ecs/src/lib.rs b/crates/bevy_ecs/src/lib.rs index cb559641d6a16..1183e71cd6e39 100644 --- a/crates/bevy_ecs/src/lib.rs +++ b/crates/bevy_ecs/src/lib.rs @@ -637,8 +637,18 @@ mod tests { #[test] fn table_add_remove_many() { let mut world = World::default(); - let mut entities = Vec::with_capacity(10_000); - for _ in 0..1000 { + #[cfg(miri)] + let (mut entities, to) = { + let to = 10; + (Vec::with_capacity(to), to) + }; + #[cfg(not(miri))] + let (mut entities, to) = { + let to = 10_000; + (Vec::with_capacity(to), to) + }; + + for _ in 0..to { entities.push(world.spawn().insert(B(0)).id()); } diff --git a/crates/bevy_tasks/Cargo.toml b/crates/bevy_tasks/Cargo.toml index 555aad5b34055..1c3117c181500 100644 --- a/crates/bevy_tasks/Cargo.toml +++ b/crates/bevy_tasks/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["bevy"] [dependencies] futures-lite = "1.4.0" -event-listener = "2.4.0" +event-listener = "2.5.2" async-executor = "1.3.0" async-channel = "1.4.2" num_cpus = "1.0.1" diff --git a/crates/bevy_tasks/src/task_pool.rs b/crates/bevy_tasks/src/task_pool.rs index 597ebc334c872..ebd6ba6b41f4c 100644 --- a/crates/bevy_tasks/src/task_pool.rs +++ b/crates/bevy_tasks/src/task_pool.rs @@ -121,13 +121,23 @@ impl TaskPool { let ex = Arc::clone(&executor); let shutdown_rx = shutdown_rx.clone(); - let thread_name = if let Some(thread_name) = thread_name { - format!("{} ({})", thread_name, i) - } else { - format!("TaskPool ({})", i) + // miri does not support setting thread names + // TODO: change back when https://github.com/rust-lang/miri/issues/1717 is fixed + #[cfg(not(miri))] + let mut thread_builder = { + let thread_name = if let Some(thread_name) = thread_name { + format!("{} ({})", thread_name, i) + } else { + format!("TaskPool ({})", i) + }; + thread::Builder::new().name(thread_name) + }; + #[cfg(miri)] + let mut thread_builder = { + let _ = i; + let _ = thread_name; + thread::Builder::new() }; - - let mut thread_builder = thread::Builder::new().name(thread_name); if let Some(stack_size) = stack_size { thread_builder = thread_builder.stack_size(stack_size);