Skip to content

Commit 1b7db89

Browse files
Harden proc macro path resolution and add integration tests. (#17330)
This pr uses the `extern crate self as` trick to make proc macros behave the same way inside and outside bevy. # Objective - Removes noise introduced by `crate as` in the whole bevy repo. - Fixes #17004. - Hardens proc macro path resolution. ## TODO - [x] `BevyManifest` needs cleanup. - [x] Cleanup remaining `crate as`. - [x] Add proper integration tests to the ci. ## Notes - `cargo-manifest-proc-macros` is written by me and based/inspired by the old `BevyManifest` implementation and [`bkchr/proc-macro-crate`](https://github.com/bkchr/proc-macro-crate). - What do you think about the new integration test machinery I added to the `ci`? More and better integration tests can be added at a later stage. The goal of these integration tests is to simulate an actual separate crate that uses bevy. Ideally they would lightly touch all bevy crates. ## Testing - Needs RA test - Needs testing from other users - Others need to run at least `cargo run -p ci integration-test` and verify that they work. --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
1 parent 669d139 commit 1b7db89

File tree

132 files changed

+325
-269
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+325
-269
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ crates/**/target
77
benches/**/target
88
tools/**/target
99
**/*.rs.bk
10+
rustc-ice-*.txt
1011

1112
# DX12 wgpu backend
1213
dxcompiler.dll

Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ members = [
2929
# Bevy's error codes. This is a crate so we can automatically check all of the code blocks.
3030
"errors",
3131
]
32+
exclude = [
33+
# Integration tests are not part of the workspace
34+
"tests-integration",
35+
]
3236

3337
[workspace.lints.clippy]
3438
doc_markdown = "warn"
@@ -494,6 +498,13 @@ serde = { version = "1", features = ["derive"] }
494498
serde_json = "1"
495499
bytemuck = "1.7"
496500
bevy_render = { path = "crates/bevy_render", version = "0.16.0-dev", default-features = false }
501+
# The following explicit dependencies are needed for proc macros to work inside of examples as they are part of the bevy crate itself.
502+
bevy_ecs = { path = "crates/bevy_ecs", version = "0.16.0-dev", default-features = false }
503+
bevy_state = { path = "crates/bevy_state", version = "0.16.0-dev", default-features = false }
504+
bevy_asset = { path = "crates/bevy_asset", version = "0.16.0-dev", default-features = false }
505+
bevy_reflect = { path = "crates/bevy_reflect", version = "0.16.0-dev", default-features = false }
506+
bevy_image = { path = "crates/bevy_image", version = "0.16.0-dev", default-features = false }
507+
bevy_gizmos = { path = "crates/bevy_gizmos", version = "0.16.0-dev", default-features = false }
497508
# Needed to poll Task examples
498509
futures-lite = "2.0.1"
499510
async-std = "1.13"

benches/benches/bevy_ecs/change_detection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ fn none_changed_detection(criterion: &mut Criterion) {
267267
}
268268
}
269269
fn insert_if_bit_enabled<const B: u16>(entity: &mut EntityWorldMut, i: u16) {
270-
if i & 1 << B != 0 {
270+
if i & (1 << B) != 0 {
271271
entity.insert(Data::<B>(1.0));
272272
}
273273
}

benches/benches/bevy_ecs/components/archetype_updates.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn setup(system_count: usize) -> (World, Schedule) {
2222
}
2323

2424
fn insert_if_bit_enabled<const B: u16>(entity: &mut EntityWorldMut, i: u16) {
25-
if i & 1 << B != 0 {
25+
if i & (1 << B) != 0 {
2626
entity.insert(A::<B>(1.0));
2727
}
2828
}

benches/benches/bevy_ecs/empty_archetypes.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,49 +105,49 @@ fn add_archetypes(world: &mut World, count: u16) {
105105
e.insert(A::<10>(1.0));
106106
e.insert(A::<11>(1.0));
107107
e.insert(A::<12>(1.0));
108-
if i & 1 << 1 != 0 {
108+
if i & (1 << 1) != 0 {
109109
e.insert(A::<13>(1.0));
110110
}
111-
if i & 1 << 2 != 0 {
111+
if i & (1 << 2) != 0 {
112112
e.insert(A::<14>(1.0));
113113
}
114-
if i & 1 << 3 != 0 {
114+
if i & (1 << 3) != 0 {
115115
e.insert(A::<15>(1.0));
116116
}
117-
if i & 1 << 4 != 0 {
117+
if i & (1 << 4) != 0 {
118118
e.insert(A::<16>(1.0));
119119
}
120-
if i & 1 << 5 != 0 {
120+
if i & (1 << 5) != 0 {
121121
e.insert(A::<18>(1.0));
122122
}
123-
if i & 1 << 6 != 0 {
123+
if i & (1 << 6) != 0 {
124124
e.insert(A::<19>(1.0));
125125
}
126-
if i & 1 << 7 != 0 {
126+
if i & (1 << 7) != 0 {
127127
e.insert(A::<20>(1.0));
128128
}
129-
if i & 1 << 8 != 0 {
129+
if i & (1 << 8) != 0 {
130130
e.insert(A::<21>(1.0));
131131
}
132-
if i & 1 << 9 != 0 {
132+
if i & (1 << 9) != 0 {
133133
e.insert(A::<22>(1.0));
134134
}
135-
if i & 1 << 10 != 0 {
135+
if i & (1 << 10) != 0 {
136136
e.insert(A::<23>(1.0));
137137
}
138-
if i & 1 << 11 != 0 {
138+
if i & (1 << 11) != 0 {
139139
e.insert(A::<24>(1.0));
140140
}
141-
if i & 1 << 12 != 0 {
141+
if i & (1 << 12) != 0 {
142142
e.insert(A::<25>(1.0));
143143
}
144-
if i & 1 << 13 != 0 {
144+
if i & (1 << 13) != 0 {
145145
e.insert(A::<26>(1.0));
146146
}
147-
if i & 1 << 14 != 0 {
147+
if i & (1 << 14) != 0 {
148148
e.insert(A::<27>(1.0));
149149
}
150-
if i & 1 << 15 != 0 {
150+
if i & (1 << 15) != 0 {
151151
e.insert(A::<28>(1.0));
152152
}
153153
}

benches/benches/bevy_ecs/iteration/par_iter_simple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct Data<const X: u16>(f32);
1919
pub struct Benchmark<'w>(World, QueryState<(&'w Velocity, &'w mut Position)>);
2020

2121
fn insert_if_bit_enabled<const B: u16>(entity: &mut EntityWorldMut, i: u16) {
22-
if i & 1 << B != 0 {
22+
if i & (1 << B) != 0 {
2323
entity.insert(Data::<B>(1.0));
2424
}
2525
}

crates/bevy_app/src/app.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,6 @@ mod tests {
15321532
#[test]
15331533
fn test_derive_app_label() {
15341534
use super::AppLabel;
1535-
use crate::{self as bevy_app};
15361535

15371536
#[derive(AppLabel, Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
15381537
struct UnitLabel;
@@ -1664,7 +1663,6 @@ mod tests {
16641663
#[test]
16651664
fn test_extract_sees_changes() {
16661665
use super::AppLabel;
1667-
use crate::{self as bevy_app};
16681666

16691667
#[derive(AppLabel, Clone, Copy, Hash, PartialEq, Eq, Debug)]
16701668
struct MySubApp;

crates/bevy_app/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ extern crate std;
2020

2121
extern crate alloc;
2222

23+
// Required to make proc macros work in bevy itself.
24+
extern crate self as bevy_app;
25+
2326
mod app;
2427
mod main_schedule;
2528
mod panic_handler;

crates/bevy_asset/src/asset_changed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ unsafe impl<A: AsAssetId> QueryFilter for AssetChanged<A> {
282282

283283
#[cfg(test)]
284284
mod tests {
285-
use crate::{self as bevy_asset, AssetEvents, AssetPlugin, Handle};
285+
use crate::{AssetEvents, AssetPlugin, Handle};
286286
use alloc::{vec, vec::Vec};
287287
use core::num::NonZero;
288288
use std::println;

crates/bevy_asset/src/assets.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use crate::asset_changed::AssetChanges;
2-
use crate::{
3-
self as bevy_asset, Asset, AssetEvent, AssetHandleProvider, AssetId, AssetServer, Handle,
4-
UntypedHandle,
5-
};
2+
use crate::{Asset, AssetEvent, AssetHandleProvider, AssetId, AssetServer, Handle, UntypedHandle};
63
use alloc::{sync::Arc, vec::Vec};
74
use bevy_ecs::{
85
prelude::EventWriter,

0 commit comments

Comments
 (0)