From ab4c1a406847ecb65ee858a29b25e65b79cc8f80 Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Wed, 11 Dec 2024 12:13:52 -0500 Subject: [PATCH 1/7] fix: `compile_fail_utils` example test --- tools/compile_fail_utils/tests/example.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/compile_fail_utils/tests/example.rs b/tools/compile_fail_utils/tests/example.rs index 7c2460e955122..f101e73b20653 100644 --- a/tools/compile_fail_utils/tests/example.rs +++ b/tools/compile_fail_utils/tests/example.rs @@ -1,4 +1,4 @@ -fn main() -> bevy_compile_test_utils::ui_test::Result<()> { +fn main() -> compile_fail_utils::ui_test::Result<()> { // Run all tests in the tests/example_tests folder. // If we had more tests we could either call this function // on everysingle one or use test_multiple and past it an array @@ -6,5 +6,5 @@ fn main() -> bevy_compile_test_utils::ui_test::Result<()> { // // Don't forget that when running tests the working directory // is set to the crate root. - bevy_compile_test_utils::test("tests/example_tests") + compile_fail_utils::test("example_tests", "tests/example_tests") } From 9e935f387bd188ceb673eabd5c49576a9d86019e Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Wed, 11 Dec 2024 12:14:12 -0500 Subject: [PATCH 2/7] fix: bless ui test output --- .../tests/example_tests/basic_test.fixed | 24 +++++++++++++++++++ .../tests/example_tests/import.stderr | 6 ++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 tools/compile_fail_utils/tests/example_tests/basic_test.fixed diff --git a/tools/compile_fail_utils/tests/example_tests/basic_test.fixed b/tools/compile_fail_utils/tests/example_tests/basic_test.fixed new file mode 100644 index 0000000000000..74fcd17490f92 --- /dev/null +++ b/tools/compile_fail_utils/tests/example_tests/basic_test.fixed @@ -0,0 +1,24 @@ +// Compiler warnings also need to be annotated. We don't +// want to annotate all the unused variables so let's instruct +// the compiler to ignore them. +#![allow(unused_variables)] + +fn bad_moves() { + let x = String::new(); + // Help diagnostics need to be annotated + let y = x.clone(); + //~^ HELP: consider cloning + + // We expect a failure on this line + println!("{x}"); //~ ERROR: borrow + + + let x = String::new(); + // We expect the help message to mention cloning. + //~v HELP: consider cloning + let y = x.clone(); + + // Check error message using a regex + println!("{x}"); + //~^ ERROR: /(move)|(borrow)/ +} diff --git a/tools/compile_fail_utils/tests/example_tests/import.stderr b/tools/compile_fail_utils/tests/example_tests/import.stderr index c0d36fbe75a07..51fa1f6e00e5a 100644 --- a/tools/compile_fail_utils/tests/example_tests/import.stderr +++ b/tools/compile_fail_utils/tests/example_tests/import.stderr @@ -7,12 +7,12 @@ error[E0599]: no function or associated item named `this_function_does_not_exist note: if you're trying to build a new `Config` consider using one of the following associated functions: Config::rustc Config::cargo - --> $RUSTUP_HOME/.cargo/git/checkouts/ui_test-2b82183a391bb05c/680bb08/src/config.rs:63:5 + --> $RUSTUP_HOME/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ui_test-0.23.0/src/config.rs:70:5 | -63 | pub fn rustc(root_dir: impl Into) -> Self { +70 | pub fn rustc(root_dir: impl Into) -> Self { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ... -108 | pub fn cargo(root_dir: impl Into) -> Self { +221 | pub fn cargo(root_dir: impl Into) -> Self { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error From 240c737d98d91a38b130244e2de1e160f180c911 Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:10:19 -0500 Subject: [PATCH 3/7] chore: no longer exclude crates from the workspace I had to remove the benchmarks' custom release profile, which enabled link-time optimizations. This _may_ cause benchmarks to perform slightly worse, but I haven't tested it yet. --- Cargo.toml | 21 ++++++++++----------- benches/Cargo.toml | 4 ---- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fd61ba79853ba..b9240034c8216 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,20 +13,19 @@ documentation = "https://docs.rs/bevy" rust-version = "1.82.0" [workspace] -exclude = [ - "benches", - "crates/bevy_derive/compile_fail", - "crates/bevy_ecs/compile_fail", - "crates/bevy_reflect/compile_fail", - "tools/compile_fail_utils", -] members = [ + # All of Bevy's official crates are within the `crates` folder! "crates/*", + # Several crates with macros have "compile fail" tests nested inside them, also known as UI + # tests, that verify diagnostic output does not accidentally change. + "crates/*/compile_fail", + # Examples of compiling Bevy for mobile platforms. "examples/mobile", - "tools/ci", - "tools/build-templated-pages", - "tools/build-wasm-example", - "tools/example-showcase", + # Benchmarks + "benches", + # Internal tools that are not published. + "tools/*", + # Bevy's error codes. This is a crate so we can automatically check all of the code blocks. "errors", ] diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 4841570022b0b..9cb25c041bdae 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -32,10 +32,6 @@ rand_chacha = "0.3" [target.'cfg(target_os = "linux")'.dev-dependencies] bevy_winit = { path = "../crates/bevy_winit", features = ["x11"] } -[profile.release] -opt-level = 3 -lto = true - [[bench]] name = "ecs" path = "benches/bevy_ecs/main.rs" From ecc9edd180de9eeff6fca65f5904c2f1b9c6e688 Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:12:01 -0500 Subject: [PATCH 4/7] refactor: rustfmt --- crates/bevy_derive/compile_fail/tests/derive.rs | 6 ++++-- tools/compile_fail_utils/src/lib.rs | 11 +++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/bevy_derive/compile_fail/tests/derive.rs b/crates/bevy_derive/compile_fail/tests/derive.rs index b918abe2733de..1349ca060df26 100644 --- a/crates/bevy_derive/compile_fail/tests/derive.rs +++ b/crates/bevy_derive/compile_fail/tests/derive.rs @@ -1,4 +1,6 @@ fn main() -> compile_fail_utils::ui_test::Result<()> { - compile_fail_utils::test_multiple("derive_deref", ["tests/deref_derive", "tests/deref_mut_derive"]) + compile_fail_utils::test_multiple( + "derive_deref", + ["tests/deref_derive", "tests/deref_mut_derive"], + ) } - diff --git a/tools/compile_fail_utils/src/lib.rs b/tools/compile_fail_utils/src/lib.rs index ff6383cc224cb..aadccac25b607 100644 --- a/tools/compile_fail_utils/src/lib.rs +++ b/tools/compile_fail_utils/src/lib.rs @@ -109,10 +109,17 @@ pub fn test_with_multiple_configs( test_name: impl Into, configs: impl IntoIterator>, ) -> ui_test::Result<()> { - let configs = configs.into_iter().collect::>>()?; + let configs = configs + .into_iter() + .collect::>>()?; let emitter: Box = if env::var_os("CI").is_some() { - Box::new((Text::verbose(), Gha:: { name: test_name.into() })) + Box::new(( + Text::verbose(), + Gha:: { + name: test_name.into(), + }, + )) } else { Box::new(Text::quiet()) }; From 2d763ab8965c733baa264c1bed4c808f338b6808 Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:28:01 -0500 Subject: [PATCH 5/7] fix: do not test benchmarks --- tools/ci/src/commands/test.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/ci/src/commands/test.rs b/tools/ci/src/commands/test.rs index efb4f518dcb7b..3bec775e61aa7 100644 --- a/tools/ci/src/commands/test.rs +++ b/tools/ci/src/commands/test.rs @@ -17,7 +17,9 @@ impl Prepare for TestCommand { vec![PreparedCommand::new::( cmd!( sh, - "cargo test --workspace --lib --bins --tests --benches {no_fail_fast}" + // Test most targets except for doc-tests, examples, and benchmarks. This is based + // of of the list at . + "cargo test --workspace --lib --bins --tests {no_fail_fast}" ), "Please fix failing tests in output above.", )] From 23140ae8a1590f4fc9e08dd101207080a60e09fa Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:33:58 -0500 Subject: [PATCH 6/7] fix: silence `too_many_arguments` lint --- benches/benches/bevy_reflect/function.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/benches/benches/bevy_reflect/function.rs b/benches/benches/bevy_reflect/function.rs index f40b9149eec64..5398cc3da91e2 100644 --- a/benches/benches/bevy_reflect/function.rs +++ b/benches/benches/bevy_reflect/function.rs @@ -83,6 +83,7 @@ fn overload(c: &mut Criterion) { a + b } + #[expect(clippy::too_many_arguments)] fn complex( _: T0, _: T1, From 8a13e12065e9a44e762333c6b69eff238e9f13a2 Mon Sep 17 00:00:00 2001 From: BD103 <59022059+BD103@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:54:01 -0500 Subject: [PATCH 7/7] fix: ci --- benches/Cargo.toml | 3 +++ benches/benches/bevy_reflect/map.rs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 9cb25c041bdae..00d7532f58d03 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -32,6 +32,9 @@ rand_chacha = "0.3" [target.'cfg(target_os = "linux")'.dev-dependencies] bevy_winit = { path = "../crates/bevy_winit", features = ["x11"] } +[lints.clippy] +needless_lifetimes = "allow" + [[bench]] name = "ecs" path = "benches/bevy_ecs/main.rs" diff --git a/benches/benches/bevy_reflect/map.rs b/benches/benches/bevy_reflect/map.rs index 054dcf9570da0..753b90b29de63 100644 --- a/benches/benches/bevy_reflect/map.rs +++ b/benches/benches/bevy_reflect/map.rs @@ -217,7 +217,7 @@ fn dynamic_map_get(criterion: &mut Criterion) { bencher.iter(|| { for i in 0..size as u64 { let key = black_box(i); - black_box(assert!(map.get(&key).is_some())); + assert!(map.get(&key).is_some()); } }); },