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 <[email protected]>
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,

crates/bevy_asset/src/folder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use alloc::vec::Vec;
22

3-
use crate as bevy_asset;
43
use crate::{Asset, UntypedHandle};
54
use bevy_reflect::TypePath;
65

crates/bevy_asset/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@
149149
extern crate alloc;
150150
extern crate std;
151151

152+
// Required to make proc macros work in bevy itself.
153+
extern crate self as bevy_asset;
154+
152155
pub mod io;
153156
pub mod meta;
154157
pub mod processor;
@@ -627,7 +630,6 @@ pub struct AssetEvents;
627630
#[cfg(test)]
628631
mod tests {
629632
use crate::{
630-
self as bevy_asset,
631633
folder::LoadedFolder,
632634
handle::Handle,
633635
io::{

crates/bevy_asset/src/meta.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use alloc::{
55
};
66

77
use crate::{
8-
self as bevy_asset, loader::AssetLoader, processor::Process, Asset, AssetPath,
9-
DeserializeMetaError, VisitAssetDependencies,
8+
loader::AssetLoader, processor::Process, Asset, AssetPath, DeserializeMetaError,
9+
VisitAssetDependencies,
1010
};
1111
use downcast_rs::{impl_downcast, Downcast};
1212
use ron::ser::PrettyConfig;

crates/bevy_asset/src/reflect.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ mod tests {
247247
use alloc::{string::String, vec::Vec};
248248
use core::any::TypeId;
249249

250-
use crate as bevy_asset;
251250
use crate::{Asset, AssetApp, AssetPlugin, ReflectAsset, UntypedHandle};
252251
use bevy_app::App;
253252
use bevy_ecs::reflect::AppTypeRegistry;

crates/bevy_asset/src/server/loaders.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ mod tests {
352352
use bevy_reflect::TypePath;
353353
use bevy_tasks::block_on;
354354

355-
use crate::{self as bevy_asset, Asset};
355+
use crate::Asset;
356356

357357
use super::*;
358358

crates/bevy_ecs/src/bundle.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,6 @@ fn sorted_remove<T: Eq + Ord + Copy>(source: &mut Vec<T>, remove: &[T]) {
17101710

17111711
#[cfg(test)]
17121712
mod tests {
1713-
use crate as bevy_ecs;
17141713
use crate::{component::HookContext, prelude::*, world::DeferredWorld};
17151714
use alloc::vec;
17161715

crates/bevy_ecs/src/change_detection.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,6 @@ mod tests {
12681268
use core::panic::Location;
12691269

12701270
use crate::{
1271-
self as bevy_ecs,
12721271
change_detection::{
12731272
Mut, NonSendMut, Ref, ResMut, TicksMut, CHECK_TICK_THRESHOLD, MAX_CHANGE_AGE,
12741273
},

crates/bevy_ecs/src/component.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Types for declaring and storing [`Component`]s.
22
33
use crate::{
4-
self as bevy_ecs,
54
archetype::ArchetypeFlags,
65
bundle::BundleInfo,
76
change_detection::MAX_CHANGE_AGE,

crates/bevy_ecs/src/entity/clone_entities.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,11 @@ impl<'w> EntityClonerBuilder<'w> {
816816
mod tests {
817817
use super::ComponentCloneCtx;
818818
use crate::{
819-
self as bevy_ecs,
820819
component::{Component, ComponentCloneBehavior, ComponentDescriptor, StorageType},
821820
entity::{hash_map::EntityHashMap, Entity, EntityCloner},
822-
hierarchy::{ChildOf, Children},
823-
reflect::{AppTypeRegistry, ReflectComponent, ReflectFromWorld},
824-
resource::Resource,
821+
prelude::{ChildOf, Children, Resource},
822+
reflect::AppTypeRegistry,
823+
reflect::{ReflectComponent, ReflectFromWorld},
825824
system::Commands,
826825
world::{FromWorld, World},
827826
};
@@ -835,6 +834,7 @@ mod tests {
835834
mod reflect {
836835
use super::*;
837836
use crate::{
837+
component::{Component, ComponentCloneBehavior},
838838
entity::EntityCloner,
839839
reflect::{AppTypeRegistry, ReflectComponent, ReflectFromWorld},
840840
system::Commands,

crates/bevy_ecs/src/entity/entity_set.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,6 @@ mod tests {
470470
use crate::query::{QueryState, With};
471471
use crate::system::Query;
472472
use crate::world::Mut;
473-
use crate::{self as bevy_ecs};
474473

475474
use super::UniqueEntityIter;
476475

crates/bevy_ecs/src/entity/visit_entities.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ impl VisitEntitiesMut for Entity {
5757
#[cfg(test)]
5858
mod tests {
5959
use crate::{
60-
self as bevy_ecs,
6160
entity::{hash_map::EntityHashMap, MapEntities, SceneEntityMapper},
6261
world::World,
6362
};

crates/bevy_ecs/src/entity_disabling.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
//! [`World`]: crate::prelude::World
2222
//! [`Query` performance]: crate::prelude::Query#performance
2323
24-
use crate as bevy_ecs;
2524
use crate::{
2625
component::{ComponentId, Components, StorageType},
2726
query::FilteredAccess,

crates/bevy_ecs/src/event/base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate as bevy_ecs;
21
use crate::component::ComponentId;
32
use crate::world::World;
43
use crate::{component::Component, traversal::Traversal};

crates/bevy_ecs/src/event/collections.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate as bevy_ecs;
21
use alloc::vec::Vec;
32
use bevy_ecs::{
43
event::{Event, EventCursor, EventId, EventInstance},
@@ -398,7 +397,7 @@ impl<E: Event> ExactSizeIterator for SendBatchIds<E> {
398397

399398
#[cfg(test)]
400399
mod tests {
401-
use crate::{self as bevy_ecs, event::Events};
400+
use crate::event::Events;
402401
use bevy_ecs_macros::Event;
403402

404403
#[test]

crates/bevy_ecs/src/event/event_cursor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate as bevy_ecs;
21
use bevy_ecs::event::{
32
Event, EventIterator, EventIteratorWithId, EventMutIterator, EventMutIteratorWithId, Events,
43
};

crates/bevy_ecs/src/event/iterators.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate as bevy_ecs;
21
#[cfg(feature = "multi_threaded")]
32
use bevy_ecs::batching::BatchingStrategy;
43
use bevy_ecs::event::{Event, EventCursor, EventId, EventInstance, Events};

crates/bevy_ecs/src/event/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ pub use writer::EventWriter;
3131

3232
#[cfg(test)]
3333
mod tests {
34-
use crate as bevy_ecs;
3534
use alloc::{vec, vec::Vec};
3635
use bevy_ecs::{event::*, system::assert_is_read_only_system};
3736
use bevy_ecs_macros::Event;

crates/bevy_ecs/src/event/mut_iterators.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate as bevy_ecs;
21
#[cfg(feature = "multi_threaded")]
32
use bevy_ecs::batching::BatchingStrategy;
43
use bevy_ecs::event::{Event, EventCursor, EventId, EventInstance, Events};

crates/bevy_ecs/src/event/mutator.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate as bevy_ecs;
21
#[cfg(feature = "multi_threaded")]
32
use bevy_ecs::event::EventMutParIter;
43
use bevy_ecs::{

crates/bevy_ecs/src/event/reader.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate as bevy_ecs;
21
#[cfg(feature = "multi_threaded")]
32
use bevy_ecs::event::EventParIter;
43
use bevy_ecs::{

crates/bevy_ecs/src/event/registry.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate as bevy_ecs;
21
use alloc::vec::Vec;
32
use bevy_ecs::{
43
change_detection::{DetectChangesMut, MutUntyped},

crates/bevy_ecs/src/event/update.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate as bevy_ecs;
21
use bevy_ecs::{
32
change_detection::Mut,
43
component::Tick,

crates/bevy_ecs/src/event/writer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate as bevy_ecs;
21
use bevy_ecs::{
32
event::{Event, EventId, Events, SendBatchIds},
43
system::{ResMut, SystemParam},

crates/bevy_ecs/src/hierarchy.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#[cfg(feature = "bevy_reflect")]
1010
use crate::reflect::{ReflectComponent, ReflectFromWorld};
1111
use crate::{
12-
self as bevy_ecs,
1312
bundle::Bundle,
1413
component::{Component, HookContext},
1514
entity::Entity,

crates/bevy_ecs/src/identifier/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ mod tests {
201201
// and also Entity flag.
202202
let high = 0x7FFFFFFF;
203203
let low = 0xC;
204-
let bits: u64 = high << u32::BITS | low;
204+
let bits: u64 = (high << u32::BITS) | low;
205205

206206
let id = Identifier::try_from_bits(bits).unwrap();
207207

crates/bevy_ecs/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ compile_error!("bevy_ecs cannot safely compile for a 16-bit platform.");
3333

3434
extern crate alloc;
3535

36+
// Required to make proc macros work in bevy itself.
37+
extern crate self as bevy_ecs;
38+
3639
pub mod archetype;
3740
pub mod batching;
3841
pub mod bundle;
@@ -128,7 +131,6 @@ pub mod __macro_exports {
128131

129132
#[cfg(test)]
130133
mod tests {
131-
use crate as bevy_ecs;
132134
use crate::{
133135
bundle::Bundle,
134136
change_detection::Ref,

0 commit comments

Comments
 (0)