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>
This commit is contained in:
raldone01 2025-02-09 19:45:45 +00:00 committed by GitHub
parent 669d139c13
commit 1b7db895b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
132 changed files with 326 additions and 270 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ crates/**/target
benches/**/target
tools/**/target
**/*.rs.bk
rustc-ice-*.txt
# DX12 wgpu backend
dxcompiler.dll

View File

@ -29,6 +29,10 @@ members = [
# Bevy's error codes. This is a crate so we can automatically check all of the code blocks.
"errors",
]
exclude = [
# Integration tests are not part of the workspace
"tests-integration",
]
[workspace.lints.clippy]
doc_markdown = "warn"
@ -494,6 +498,13 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
bytemuck = "1.7"
bevy_render = { path = "crates/bevy_render", version = "0.16.0-dev", default-features = false }
# The following explicit dependencies are needed for proc macros to work inside of examples as they are part of the bevy crate itself.
bevy_ecs = { path = "crates/bevy_ecs", version = "0.16.0-dev", default-features = false }
bevy_state = { path = "crates/bevy_state", version = "0.16.0-dev", default-features = false }
bevy_asset = { path = "crates/bevy_asset", version = "0.16.0-dev", default-features = false }
bevy_reflect = { path = "crates/bevy_reflect", version = "0.16.0-dev", default-features = false }
bevy_image = { path = "crates/bevy_image", version = "0.16.0-dev", default-features = false }
bevy_gizmos = { path = "crates/bevy_gizmos", version = "0.16.0-dev", default-features = false }
# Needed to poll Task examples
futures-lite = "2.0.1"
async-std = "1.13"

View File

@ -267,7 +267,7 @@ fn none_changed_detection(criterion: &mut Criterion) {
}
}
fn insert_if_bit_enabled<const B: u16>(entity: &mut EntityWorldMut, i: u16) {
if i & 1 << B != 0 {
if i & (1 << B) != 0 {
entity.insert(Data::<B>(1.0));
}
}

View File

@ -22,7 +22,7 @@ fn setup(system_count: usize) -> (World, Schedule) {
}
fn insert_if_bit_enabled<const B: u16>(entity: &mut EntityWorldMut, i: u16) {
if i & 1 << B != 0 {
if i & (1 << B) != 0 {
entity.insert(A::<B>(1.0));
}
}

View File

@ -105,49 +105,49 @@ fn add_archetypes(world: &mut World, count: u16) {
e.insert(A::<10>(1.0));
e.insert(A::<11>(1.0));
e.insert(A::<12>(1.0));
if i & 1 << 1 != 0 {
if i & (1 << 1) != 0 {
e.insert(A::<13>(1.0));
}
if i & 1 << 2 != 0 {
if i & (1 << 2) != 0 {
e.insert(A::<14>(1.0));
}
if i & 1 << 3 != 0 {
if i & (1 << 3) != 0 {
e.insert(A::<15>(1.0));
}
if i & 1 << 4 != 0 {
if i & (1 << 4) != 0 {
e.insert(A::<16>(1.0));
}
if i & 1 << 5 != 0 {
if i & (1 << 5) != 0 {
e.insert(A::<18>(1.0));
}
if i & 1 << 6 != 0 {
if i & (1 << 6) != 0 {
e.insert(A::<19>(1.0));
}
if i & 1 << 7 != 0 {
if i & (1 << 7) != 0 {
e.insert(A::<20>(1.0));
}
if i & 1 << 8 != 0 {
if i & (1 << 8) != 0 {
e.insert(A::<21>(1.0));
}
if i & 1 << 9 != 0 {
if i & (1 << 9) != 0 {
e.insert(A::<22>(1.0));
}
if i & 1 << 10 != 0 {
if i & (1 << 10) != 0 {
e.insert(A::<23>(1.0));
}
if i & 1 << 11 != 0 {
if i & (1 << 11) != 0 {
e.insert(A::<24>(1.0));
}
if i & 1 << 12 != 0 {
if i & (1 << 12) != 0 {
e.insert(A::<25>(1.0));
}
if i & 1 << 13 != 0 {
if i & (1 << 13) != 0 {
e.insert(A::<26>(1.0));
}
if i & 1 << 14 != 0 {
if i & (1 << 14) != 0 {
e.insert(A::<27>(1.0));
}
if i & 1 << 15 != 0 {
if i & (1 << 15) != 0 {
e.insert(A::<28>(1.0));
}
}

View File

@ -19,7 +19,7 @@ struct Data<const X: u16>(f32);
pub struct Benchmark<'w>(World, QueryState<(&'w Velocity, &'w mut Position)>);
fn insert_if_bit_enabled<const B: u16>(entity: &mut EntityWorldMut, i: u16) {
if i & 1 << B != 0 {
if i & (1 << B) != 0 {
entity.insert(Data::<B>(1.0));
}
}

View File

@ -1532,7 +1532,6 @@ mod tests {
#[test]
fn test_derive_app_label() {
use super::AppLabel;
use crate::{self as bevy_app};
#[derive(AppLabel, Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
struct UnitLabel;
@ -1664,7 +1663,6 @@ mod tests {
#[test]
fn test_extract_sees_changes() {
use super::AppLabel;
use crate::{self as bevy_app};
#[derive(AppLabel, Clone, Copy, Hash, PartialEq, Eq, Debug)]
struct MySubApp;

View File

@ -20,6 +20,9 @@ extern crate std;
extern crate alloc;
// Required to make proc macros work in bevy itself.
extern crate self as bevy_app;
mod app;
mod main_schedule;
mod panic_handler;

View File

@ -282,7 +282,7 @@ unsafe impl<A: AsAssetId> QueryFilter for AssetChanged<A> {
#[cfg(test)]
mod tests {
use crate::{self as bevy_asset, AssetEvents, AssetPlugin, Handle};
use crate::{AssetEvents, AssetPlugin, Handle};
use alloc::{vec, vec::Vec};
use core::num::NonZero;
use std::println;

View File

@ -1,8 +1,5 @@
use crate::asset_changed::AssetChanges;
use crate::{
self as bevy_asset, Asset, AssetEvent, AssetHandleProvider, AssetId, AssetServer, Handle,
UntypedHandle,
};
use crate::{Asset, AssetEvent, AssetHandleProvider, AssetId, AssetServer, Handle, UntypedHandle};
use alloc::{sync::Arc, vec::Vec};
use bevy_ecs::{
prelude::EventWriter,

View File

@ -1,6 +1,5 @@
use alloc::vec::Vec;
use crate as bevy_asset;
use crate::{Asset, UntypedHandle};
use bevy_reflect::TypePath;

View File

@ -149,6 +149,9 @@
extern crate alloc;
extern crate std;
// Required to make proc macros work in bevy itself.
extern crate self as bevy_asset;
pub mod io;
pub mod meta;
pub mod processor;
@ -627,7 +630,6 @@ pub struct AssetEvents;
#[cfg(test)]
mod tests {
use crate::{
self as bevy_asset,
folder::LoadedFolder,
handle::Handle,
io::{

View File

@ -5,8 +5,8 @@ use alloc::{
};
use crate::{
self as bevy_asset, loader::AssetLoader, processor::Process, Asset, AssetPath,
DeserializeMetaError, VisitAssetDependencies,
loader::AssetLoader, processor::Process, Asset, AssetPath, DeserializeMetaError,
VisitAssetDependencies,
};
use downcast_rs::{impl_downcast, Downcast};
use ron::ser::PrettyConfig;

View File

@ -247,7 +247,6 @@ mod tests {
use alloc::{string::String, vec::Vec};
use core::any::TypeId;
use crate as bevy_asset;
use crate::{Asset, AssetApp, AssetPlugin, ReflectAsset, UntypedHandle};
use bevy_app::App;
use bevy_ecs::reflect::AppTypeRegistry;

View File

@ -352,7 +352,7 @@ mod tests {
use bevy_reflect::TypePath;
use bevy_tasks::block_on;
use crate::{self as bevy_asset, Asset};
use crate::Asset;
use super::*;

View File

@ -1710,7 +1710,6 @@ fn sorted_remove<T: Eq + Ord + Copy>(source: &mut Vec<T>, remove: &[T]) {
#[cfg(test)]
mod tests {
use crate as bevy_ecs;
use crate::{component::HookContext, prelude::*, world::DeferredWorld};
use alloc::vec;

View File

@ -1268,7 +1268,6 @@ mod tests {
use core::panic::Location;
use crate::{
self as bevy_ecs,
change_detection::{
Mut, NonSendMut, Ref, ResMut, TicksMut, CHECK_TICK_THRESHOLD, MAX_CHANGE_AGE,
},

View File

@ -1,7 +1,6 @@
//! Types for declaring and storing [`Component`]s.
use crate::{
self as bevy_ecs,
archetype::ArchetypeFlags,
bundle::BundleInfo,
change_detection::MAX_CHANGE_AGE,

View File

@ -816,12 +816,11 @@ impl<'w> EntityClonerBuilder<'w> {
mod tests {
use super::ComponentCloneCtx;
use crate::{
self as bevy_ecs,
component::{Component, ComponentCloneBehavior, ComponentDescriptor, StorageType},
entity::{hash_map::EntityHashMap, Entity, EntityCloner},
hierarchy::{ChildOf, Children},
reflect::{AppTypeRegistry, ReflectComponent, ReflectFromWorld},
resource::Resource,
prelude::{ChildOf, Children, Resource},
reflect::AppTypeRegistry,
reflect::{ReflectComponent, ReflectFromWorld},
system::Commands,
world::{FromWorld, World},
};
@ -835,6 +834,7 @@ mod tests {
mod reflect {
use super::*;
use crate::{
component::{Component, ComponentCloneBehavior},
entity::EntityCloner,
reflect::{AppTypeRegistry, ReflectComponent, ReflectFromWorld},
system::Commands,

View File

@ -470,7 +470,6 @@ mod tests {
use crate::query::{QueryState, With};
use crate::system::Query;
use crate::world::Mut;
use crate::{self as bevy_ecs};
use super::UniqueEntityIter;

View File

@ -57,7 +57,6 @@ impl VisitEntitiesMut for Entity {
#[cfg(test)]
mod tests {
use crate::{
self as bevy_ecs,
entity::{hash_map::EntityHashMap, MapEntities, SceneEntityMapper},
world::World,
};

View File

@ -21,7 +21,6 @@
//! [`World`]: crate::prelude::World
//! [`Query` performance]: crate::prelude::Query#performance
use crate as bevy_ecs;
use crate::{
component::{ComponentId, Components, StorageType},
query::FilteredAccess,

View File

@ -1,4 +1,3 @@
use crate as bevy_ecs;
use crate::component::ComponentId;
use crate::world::World;
use crate::{component::Component, traversal::Traversal};

View File

@ -1,4 +1,3 @@
use crate as bevy_ecs;
use alloc::vec::Vec;
use bevy_ecs::{
event::{Event, EventCursor, EventId, EventInstance},
@ -398,7 +397,7 @@ impl<E: Event> ExactSizeIterator for SendBatchIds<E> {
#[cfg(test)]
mod tests {
use crate::{self as bevy_ecs, event::Events};
use crate::event::Events;
use bevy_ecs_macros::Event;
#[test]

View File

@ -1,4 +1,3 @@
use crate as bevy_ecs;
use bevy_ecs::event::{
Event, EventIterator, EventIteratorWithId, EventMutIterator, EventMutIteratorWithId, Events,
};

View File

@ -1,4 +1,3 @@
use crate as bevy_ecs;
#[cfg(feature = "multi_threaded")]
use bevy_ecs::batching::BatchingStrategy;
use bevy_ecs::event::{Event, EventCursor, EventId, EventInstance, Events};

View File

@ -31,7 +31,6 @@ pub use writer::EventWriter;
#[cfg(test)]
mod tests {
use crate as bevy_ecs;
use alloc::{vec, vec::Vec};
use bevy_ecs::{event::*, system::assert_is_read_only_system};
use bevy_ecs_macros::Event;

View File

@ -1,4 +1,3 @@
use crate as bevy_ecs;
#[cfg(feature = "multi_threaded")]
use bevy_ecs::batching::BatchingStrategy;
use bevy_ecs::event::{Event, EventCursor, EventId, EventInstance, Events};

View File

@ -1,4 +1,3 @@
use crate as bevy_ecs;
#[cfg(feature = "multi_threaded")]
use bevy_ecs::event::EventMutParIter;
use bevy_ecs::{

View File

@ -1,4 +1,3 @@
use crate as bevy_ecs;
#[cfg(feature = "multi_threaded")]
use bevy_ecs::event::EventParIter;
use bevy_ecs::{

View File

@ -1,4 +1,3 @@
use crate as bevy_ecs;
use alloc::vec::Vec;
use bevy_ecs::{
change_detection::{DetectChangesMut, MutUntyped},

View File

@ -1,4 +1,3 @@
use crate as bevy_ecs;
use bevy_ecs::{
change_detection::Mut,
component::Tick,

View File

@ -1,4 +1,3 @@
use crate as bevy_ecs;
use bevy_ecs::{
event::{Event, EventId, Events, SendBatchIds},
system::{ResMut, SystemParam},

View File

@ -9,7 +9,6 @@
#[cfg(feature = "bevy_reflect")]
use crate::reflect::{ReflectComponent, ReflectFromWorld};
use crate::{
self as bevy_ecs,
bundle::Bundle,
component::{Component, HookContext},
entity::Entity,

View File

@ -201,7 +201,7 @@ mod tests {
// and also Entity flag.
let high = 0x7FFFFFFF;
let low = 0xC;
let bits: u64 = high << u32::BITS | low;
let bits: u64 = (high << u32::BITS) | low;
let id = Identifier::try_from_bits(bits).unwrap();

View File

@ -33,6 +33,9 @@ compile_error!("bevy_ecs cannot safely compile for a 16-bit platform.");
extern crate alloc;
// Required to make proc macros work in bevy itself.
extern crate self as bevy_ecs;
pub mod archetype;
pub mod batching;
pub mod bundle;
@ -128,7 +131,6 @@ pub mod __macro_exports {
#[cfg(test)]
mod tests {
use crate as bevy_ecs;
use crate::{
bundle::Bundle,
change_detection::Ref,

View File

@ -1,6 +1,6 @@
//! Provides the [`Name`] [`Component`], used for identifying an [`Entity`].
use crate::{self as bevy_ecs, component::Component, entity::Entity, query::QueryData};
use crate::{component::Component, entity::Entity, query::QueryData};
use alloc::{
borrow::{Cow, ToOwned},

View File

@ -110,8 +110,8 @@ fn component_clone_observed_by(commands: &mut Commands, ctx: &mut ComponentClone
#[cfg(test)]
mod tests {
use crate::{
self as bevy_ecs, entity::EntityCloner, event::Event, observer::Trigger,
resource::Resource, system::ResMut, world::World,
entity::EntityCloner, event::Event, observer::Trigger, resource::Resource, system::ResMut,
world::World,
};
#[derive(Resource, Default)]

View File

@ -864,7 +864,6 @@ mod tests {
use bevy_platform_support::collections::HashMap;
use bevy_ptr::OwningPtr;
use crate as bevy_ecs;
use crate::component::ComponentId;
use crate::{
observer::{Observer, ObserverDescriptor, ObserverState, OnReplace},

View File

@ -275,7 +275,6 @@ impl<'w, D: QueryData, F: QueryFilter> QueryBuilder<'w, D, F> {
#[cfg(test)]
mod tests {
use crate as bevy_ecs;
use crate::{prelude::*, world::FilteredEntityRef};
use std::dbg;

View File

@ -111,7 +111,6 @@ pub enum QuerySingleError {
#[cfg(test)]
mod test {
use crate as bevy_ecs;
use crate::prelude::World;
use alloc::format;
use bevy_ecs_macros::Component;

View File

@ -2481,10 +2481,7 @@ mod tests {
use bevy_ecs_macros::QueryData;
use super::*;
use crate::{
self as bevy_ecs,
system::{assert_is_system, Query},
};
use crate::system::{assert_is_system, Query};
#[derive(Component)]
pub struct A;

View File

@ -1309,7 +1309,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter, I: Iterator<Item: EntityBorrow>>
/// // We need to collect the internal iterator before iterating mutably
/// let mut parent_query_iter = query.iter_many_mut(entity_list)
/// .sort::<Entity>();
///
///
/// let mut scratch_value = 0;
/// while let Some(mut part_value) = parent_query_iter.fetch_next_back()
/// {
@ -2582,7 +2582,6 @@ mod tests {
use crate::component::Component;
use crate::entity::Entity;
use crate::prelude::World;
use crate::{self as bevy_ecs};
#[derive(Component, Debug, PartialEq, PartialOrd, Clone, Copy)]
struct A(f32);

View File

@ -104,7 +104,6 @@ impl<T> DebugCheckedUnwrap for Option<T> {
#[cfg(test)]
mod tests {
use crate::{
self as bevy_ecs,
archetype::Archetype,
component::{Component, ComponentId, Components, Tick},
prelude::{AnyOf, Changed, Entity, Or, QueryState, Res, ResMut, Resource, With, Without},

View File

@ -2010,7 +2010,6 @@ impl<D: QueryData, F: QueryFilter> From<QueryBuilder<'_, D, F>> for QueryState<D
#[cfg(test)]
mod tests {
use crate as bevy_ecs;
use crate::{
component::Component, entity_disabling::DefaultQueryFilters, prelude::*,
query::QueryEntityError, world::FilteredEntityRef,

View File

@ -388,7 +388,6 @@ fn remove_reflect_with_registry_ref(
#[cfg(test)]
mod tests {
use crate::{
self as bevy_ecs,
bundle::Bundle,
component::Component,
prelude::{AppTypeRegistry, ReflectComponent},

View File

@ -5,7 +5,6 @@ use core::{
ops::{Deref, DerefMut},
};
use crate as bevy_ecs;
use crate::{resource::Resource, world::World};
use bevy_reflect::{
std_traits::ReflectDefault, PartialReflect, Reflect, ReflectFromReflect, TypePath,

View File

@ -286,7 +286,6 @@ pub fn clone_relationship_target<T: RelationshipTarget>(
#[cfg(test)]
mod tests {
use crate as bevy_ecs;
use crate::world::World;
use crate::{component::Component, entity::Entity};
use alloc::vec::Vec;

View File

@ -249,7 +249,6 @@ impl<'w, R: Relationship> RelatedSpawnerCommands<'w, R> {
#[cfg(test)]
mod tests {
use super::*;
use crate as bevy_ecs;
use crate::prelude::{ChildOf, Children, Component};
#[derive(Component, Clone, Copy)]

View File

@ -119,7 +119,6 @@ impl<const N: usize> RelationshipSourceCollection for SmallVec<[Entity; N]> {
#[cfg(test)]
mod tests {
use super::*;
use crate as bevy_ecs;
use crate::prelude::{Component, World};
use crate::relationship::RelationshipTarget;

View File

@ -1,7 +1,6 @@
//! Alerting events when a component is removed from an entity.
use crate::{
self as bevy_ecs,
component::{Component, ComponentId, ComponentIdFor, Tick},
entity::Entity,
event::{Event, EventCursor, EventId, EventIterator, EventIteratorWithId, Events},

View File

@ -1263,7 +1263,6 @@ where
#[cfg(test)]
mod tests {
use super::{common_conditions::*, Condition};
use crate as bevy_ecs;
use crate::query::With;
use crate::{
change_detection::ResMut,

View File

@ -311,7 +311,6 @@ mod __rust_begin_short_backtrace {
#[cfg(test)]
mod tests {
use crate::{
self as bevy_ecs,
prelude::{IntoSystemConfigs, IntoSystemSetConfigs, Resource, Schedule, SystemSet},
schedule::ExecutorKind,
system::{Commands, Res, WithParamWarnPolicy},

View File

@ -22,8 +22,6 @@ use crate::{
world::{unsafe_world_cell::UnsafeWorldCell, World},
};
use crate as bevy_ecs;
use super::__rust_begin_short_backtrace;
/// Borrowed data used by the [`MultiThreadedExecutor`].
@ -796,7 +794,6 @@ impl MainThreadExecutor {
#[cfg(test)]
mod tests {
use crate::{
self as bevy_ecs,
prelude::Resource,
schedule::{ExecutorKind, IntoSystemConfigs, Schedule},
system::Commands,

View File

@ -29,7 +29,6 @@ mod tests {
use alloc::{string::ToString, vec, vec::Vec};
use core::sync::atomic::{AtomicU32, Ordering};
pub use crate as bevy_ecs;
pub use crate::{
prelude::World,
resource::Resource,
@ -730,8 +729,6 @@ mod tests {
use alloc::collections::BTreeSet;
use super::*;
// Required to make the derive macro behave
use crate as bevy_ecs;
use crate::prelude::*;
#[derive(Resource)]

View File

@ -25,7 +25,6 @@ use thiserror::Error;
use tracing::info_span;
use crate::{
self as bevy_ecs,
component::{ComponentId, Components, Tick},
prelude::Component,
resource::Resource,
@ -2020,7 +2019,6 @@ mod tests {
use bevy_ecs_macros::ScheduleLabel;
use crate::{
self as bevy_ecs,
prelude::{Res, Resource},
schedule::{
tests::ResMut, IntoSystemConfigs, IntoSystemSetConfigs, Schedule,

View File

@ -225,7 +225,7 @@ mod tests {
#[test]
fn test_schedule_label() {
use crate::{self as bevy_ecs, world::World};
use crate::world::World;
#[derive(Resource)]
struct Flag(bool);
@ -257,8 +257,6 @@ mod tests {
#[test]
fn test_derive_schedule_label() {
use crate::{self as bevy_ecs};
#[derive(ScheduleLabel, Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
struct UnitLabel;
@ -359,8 +357,6 @@ mod tests {
#[test]
fn test_derive_system_set() {
use crate::{self as bevy_ecs};
#[derive(SystemSet, Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
struct UnitSet;

View File

@ -17,8 +17,6 @@ use log::error;
#[cfg(test)]
use log::debug;
use crate as bevy_ecs;
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone)]
enum Action {
/// Stepping is disabled; run all systems
@ -831,8 +829,6 @@ mod tests {
use alloc::{format, vec};
use std::println;
pub use crate as bevy_ecs;
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
struct TestSchedule;

View File

@ -479,7 +479,6 @@ impl BlobArray {
#[cfg(test)]
mod tests {
use crate as bevy_ecs;
use bevy_ecs::prelude::*;
#[derive(Component)]

View File

@ -498,7 +498,6 @@ const fn padding_needed_for(layout: &Layout, align: usize) -> usize {
#[cfg(test)]
mod tests {
use super::BlobVec;
use crate as bevy_ecs; // required for derive macros
use crate::{component::Component, ptr::OwningPtr, world::World};
use alloc::{
rc::Rc,

View File

@ -661,7 +661,6 @@ impl SparseSets {
mod tests {
use super::SparseSets;
use crate::{
self as bevy_ecs,
component::{Component, ComponentDescriptor, ComponentId, ComponentInfo},
entity::Entity,
storage::SparseSet,

View File

@ -815,7 +815,6 @@ impl Drop for Table {
#[cfg(test)]
mod tests {
use crate as bevy_ecs;
use crate::{
component::{Component, Components, Tick},
entity::Entity,

View File

@ -712,7 +712,6 @@ unsafe impl<'w, 's, T: FnOnce(&mut FilteredResourcesMutBuilder)>
#[cfg(test)]
mod tests {
use crate as bevy_ecs;
use crate::{
entity::Entities,
prelude::{Component, Query},

View File

@ -17,7 +17,6 @@ use core::panic::Location;
use log::error;
use crate::{
self as bevy_ecs,
bundle::{Bundle, InsertMode},
change_detection::Mut,
component::{Component, ComponentId, Mutable},
@ -2203,7 +2202,6 @@ impl<'a, T: Component> EntityEntryCommands<'a, T> {
#[cfg(test)]
mod tests {
use crate::{
self as bevy_ecs,
component::{require, Component},
resource::Resource,
system::Commands,

View File

@ -1,7 +1,6 @@
use bevy_utils::Parallel;
use crate::{
self as bevy_ecs,
entity::Entities,
prelude::World,
system::{Deferred, SystemBuffer, SystemMeta, SystemParam},

View File

@ -136,7 +136,6 @@ all_tuples!(
#[cfg(test)]
mod tests {
use crate as bevy_ecs;
use crate::{schedule::Schedule, system::Local, world::World};
use alloc::vec::Vec;
use bevy_ecs_macros::Resource;

View File

@ -330,7 +330,6 @@ mod tests {
use std::println;
use crate::{
self as bevy_ecs,
archetype::{ArchetypeComponentId, Archetypes},
bundle::Bundles,
change_detection::DetectChanges,

View File

@ -60,7 +60,6 @@ where
#[cfg(test)]
mod tests {
use crate::{
self as bevy_ecs,
event::Event,
observer::Trigger,
system::{In, IntoSystem},

View File

@ -381,7 +381,6 @@ impl Debug for RunSystemError {
#[cfg(test)]
mod tests {
use super::*;
use crate as bevy_ecs;
use crate::prelude::*;
#[test]

View File

@ -2582,10 +2582,7 @@ unsafe impl SystemParam for FilteredResourcesMut<'_, '_> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{
self as bevy_ecs, // Necessary for the `SystemParam` Derive when used inside `bevy_ecs`.
system::assert_is_system,
};
use crate::system::assert_is_system;
use core::cell::RefCell;
// Compile test for https://github.com/bevyengine/bevy/pull/2838.

View File

@ -1,7 +1,6 @@
#[cfg(feature = "bevy_reflect")]
use crate::reflect::ReflectComponent;
use crate::{
self as bevy_ecs,
change_detection::Mut,
entity::Entity,
system::{input::SystemInput, BoxedSystem, IntoSystem, System},
@ -498,7 +497,6 @@ impl<I: SystemInput, O> core::fmt::Debug for RegisteredSystemError<I, O> {
mod tests {
use crate::prelude::*;
use crate::{self as bevy_ecs};
#[derive(Resource, Default, PartialEq, Debug)]
struct Counter(u8);

View File

@ -335,7 +335,7 @@ impl SystemBuffer for CommandQueue {
#[cfg(test)]
mod test {
use super::*;
use crate::{self as bevy_ecs, resource::Resource};
use crate::resource::Resource;
use alloc::{borrow::ToOwned, string::String, sync::Arc};
use core::{
panic::AssertUnwindSafe,

View File

@ -1,7 +1,6 @@
//! Internal components used by bevy with a fixed component id.
//! Constants are used to skip [`TypeId`] lookups in hot paths.
use super::*;
use crate::{self as bevy_ecs};
#[cfg(feature = "bevy_reflect")]
use bevy_reflect::Reflect;

View File

@ -4417,7 +4417,6 @@ mod tests {
use crate::component::HookContext;
use crate::{
self as bevy_ecs,
change_detection::MutUntyped,
component::ComponentId,
prelude::*,

View File

@ -3763,9 +3763,6 @@ mod tests {
};
use std::{println, sync::Mutex};
// For bevy_ecs_macros
use crate as bevy_ecs;
type ID = u8;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]

View File

@ -251,11 +251,7 @@ mod tests {
use bevy_reflect::Reflect;
use crate::{
// For bevy_ecs_macros
self as bevy_ecs,
prelude::{AppTypeRegistry, Component, DetectChanges, World},
};
use crate::prelude::{AppTypeRegistry, Component, DetectChanges, World};
#[derive(Component, Reflect)]
struct RFoo(i32);

View File

@ -1222,7 +1222,6 @@ impl EntityBorrow for UnsafeEntityCell<'_> {
#[cfg(test)]
mod tests {
use super::*;
use crate as bevy_ecs;
#[test]
#[should_panic = "is forbidden"]

View File

@ -31,7 +31,7 @@ fn bevy_encase_path() -> syn::Path {
segments,
}
})
.unwrap_or_else(|| bevy_manifest.get_path(ENCASE))
.unwrap_or_else(|_err| bevy_manifest.get_path(ENCASE))
}
implement!(bevy_encase_path());

View File

@ -1,7 +1,5 @@
//! A module adding debug visualization of [`Aabb`]s.
use crate as bevy_gizmos;
use bevy_app::{Plugin, PostUpdate};
use bevy_color::{Color, Oklcha};
use bevy_ecs::{

View File

@ -1,6 +1,5 @@
//! A module for the [`GizmoConfig<T>`] [`Resource`].
use crate::{self as bevy_gizmos};
pub use bevy_gizmos_macros::GizmoConfigGroup;
#[cfg(all(

View File

@ -19,6 +19,9 @@
//!
//! See the documentation on [Gizmos](crate::gizmos::Gizmos) for more examples.
// Required to make proc macros work in bevy itself.
extern crate self as bevy_gizmos;
/// System set label for the systems handling the rendering of gizmos.
#[derive(SystemSet, Clone, Debug, Hash, PartialEq, Eq)]
pub enum GizmoRenderSystem {

View File

@ -2,7 +2,7 @@
use core::f32::consts::PI;
use crate::{self as bevy_gizmos, primitives::dim3::GizmoPrimitive3d};
use crate::primitives::dim3::GizmoPrimitive3d;
use bevy_app::{Plugin, PostUpdate};
use bevy_color::{

View File

@ -9,12 +9,10 @@ license = "MIT OR Apache-2.0"
keywords = ["bevy"]
[dependencies]
toml_edit = { version = "0.22.7", default-features = false, features = [
"parse",
] }
syn = "2.0"
quote = "1.0"
proc-macro2 = "1.0"
cargo-manifest-proc-macros = "0.3.3"
[lints]
workspace = true

View File

@ -1,83 +1,55 @@
extern crate proc_macro;
use proc_macro::TokenStream;
use std::{env, path::PathBuf, sync::LazyLock};
use toml_edit::{DocumentMut, Item};
use std::sync::MutexGuard;
/// The path to the `Cargo.toml` file for the Bevy project.
pub struct BevyManifest {
manifest: DocumentMut,
use cargo_manifest_proc_macros::{
CargoManifest, CrateReExportingPolicy, KnownReExportingCrate, PathPiece,
TryResolveCratePathError,
};
use proc_macro::TokenStream;
struct BevyReExportingPolicy;
impl CrateReExportingPolicy for BevyReExportingPolicy {
fn get_re_exported_crate_path(&self, crate_name: &str) -> Option<PathPiece> {
crate_name.strip_prefix("bevy_").map(|s| {
let mut path = PathPiece::new();
path.push(syn::parse_str::<syn::PathSegment>(s).unwrap());
path
})
}
}
const BEVY: &str = "bevy";
const BEVY_INTERNAL: &str = "bevy_internal";
const KNOWN_RE_EXPORTING_CRATE_BEVY: KnownReExportingCrate = KnownReExportingCrate {
re_exporting_crate_package_name: BEVY,
crate_re_exporting_policy: &BevyReExportingPolicy {},
};
const ALL_KNOWN_RE_EXPORTING_CRATES: &[&KnownReExportingCrate] = &[&KNOWN_RE_EXPORTING_CRATE_BEVY];
/// The path to the `Cargo.toml` file for the Bevy project.
pub struct BevyManifest(MutexGuard<'static, CargoManifest>);
impl BevyManifest {
/// Returns a global shared instance of the [`BevyManifest`] struct.
pub fn shared() -> &'static LazyLock<Self> {
static LAZY_SELF: LazyLock<BevyManifest> = LazyLock::new(|| BevyManifest {
manifest: env::var_os("CARGO_MANIFEST_DIR")
.map(PathBuf::from)
.map(|mut path| {
path.push("Cargo.toml");
if !path.exists() {
panic!(
"No Cargo manifest found for crate. Expected: {}",
path.display()
);
}
let manifest = std::fs::read_to_string(path.clone()).unwrap_or_else(|_| {
panic!("Unable to read cargo manifest: {}", path.display())
});
manifest.parse::<DocumentMut>().unwrap_or_else(|_| {
panic!("Failed to parse cargo manifest: {}", path.display())
})
})
.expect("CARGO_MANIFEST_DIR is not defined."),
});
&LAZY_SELF
pub fn shared() -> Self {
Self(CargoManifest::shared())
}
/// Attempt to retrieve the [path](syn::Path) of a particular package in
/// the [manifest](BevyManifest) by [name](str).
pub fn maybe_get_path(&self, name: &str) -> Option<syn::Path> {
fn dep_package(dep: &Item) -> Option<&str> {
if dep.as_str().is_some() {
None
} else {
dep.get("package").map(|name| name.as_str().unwrap())
}
}
let find_in_deps = |deps: &Item| -> Option<syn::Path> {
let package = if let Some(dep) = deps.get(name) {
return Some(Self::parse_str(dep_package(dep).unwrap_or(name)));
} else if let Some(dep) = deps.get(BEVY) {
dep_package(dep).unwrap_or(BEVY)
} else if let Some(dep) = deps.get(BEVY_INTERNAL) {
dep_package(dep).unwrap_or(BEVY_INTERNAL)
} else {
return None;
};
let mut path = Self::parse_str::<syn::Path>(package);
if let Some(module) = name.strip_prefix("bevy_") {
path.segments.push(Self::parse_str(module));
}
Some(path)
};
let deps = self.manifest.get("dependencies");
let deps_dev = self.manifest.get("dev-dependencies");
deps.and_then(find_in_deps)
.or_else(|| deps_dev.and_then(find_in_deps))
pub fn maybe_get_path(&self, name: &str) -> Result<syn::Path, TryResolveCratePathError> {
self.0
.try_resolve_crate_path(name, ALL_KNOWN_RE_EXPORTING_CRATES)
}
/// Returns the path for the crate with the given name.
pub fn get_path(&self, name: &str) -> syn::Path {
self.maybe_get_path(name)
.unwrap_or_else(|| Self::parse_str(name))
//.expect("Failed to get path for crate")
.unwrap_or_else(|_err| Self::parse_str(name))
}
/// Attempt to parse the provided [path](str) as a [syntax tree node](syn::parse::Parse)
@ -97,7 +69,7 @@ impl BevyManifest {
}
/// Attempt to get a subcrate [path](syn::Path) under Bevy by [name](str)
pub fn get_subcrate(&self, subcrate: &str) -> Option<syn::Path> {
pub fn get_subcrate(&self, subcrate: &str) -> Result<syn::Path, TryResolveCratePathError> {
self.maybe_get_path(BEVY)
.map(|bevy_path| {
let mut segments = bevy_path.segments;
@ -107,6 +79,6 @@ impl BevyManifest {
segments,
}
})
.or_else(|| self.maybe_get_path(&format!("bevy_{subcrate}")))
.or_else(|_err| self.maybe_get_path(&format!("bevy_{subcrate}")))
}
}

View File

@ -1,7 +1,4 @@
use bevy_macro_utils::{
fq_std::{FQClone, FQOption, FQResult},
BevyManifest,
};
use bevy_macro_utils::fq_std::{FQClone, FQOption, FQResult};
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse::Parse, parse_macro_input, Attribute, ItemTrait, Token};
@ -34,7 +31,7 @@ pub(crate) fn reflect_trait(_args: &TokenStream, input: TokenStream) -> TokenStr
let trait_ident = &item_trait.ident;
let trait_vis = &item_trait.vis;
let reflect_trait_ident = crate::ident::get_reflect_ident(&item_trait.ident.to_string());
let bevy_reflect_path = BevyManifest::shared().get_path("bevy_reflect");
let bevy_reflect_path = crate::meta::get_bevy_reflect_path();
let struct_doc = format!(
" A type generated by the #[reflect_trait] macro for the `{trait_ident}` trait.\n\n This allows casting from `dyn Reflect` to `dyn {trait_ident}`.",

View File

@ -1,8 +1,8 @@
use crate::generics::impl_generic_info_methods;
use crate::{
self as bevy_reflect, type_info::impl_type_methods, utility::reflect_hasher, ApplyError,
Generics, MaybeTyped, PartialReflect, Reflect, ReflectKind, ReflectMut, ReflectOwned,
ReflectRef, Type, TypeInfo, TypePath,
type_info::impl_type_methods, utility::reflect_hasher, ApplyError, Generics, MaybeTyped,
PartialReflect, Reflect, ReflectKind, ReflectMut, ReflectOwned, ReflectRef, Type, TypeInfo,
TypePath,
};
use alloc::{boxed::Box, vec::Vec};
use bevy_reflect_derive::impl_type_path;

View File

@ -178,7 +178,6 @@ pub(crate) use impl_custom_attribute_methods;
#[cfg(test)]
mod tests {
use super::*;
use crate as bevy_reflect;
use crate::{type_info::Typed, TypeInfo, VariantInfo};
use alloc::{format, string::String};
use core::ops::RangeInclusive;

View File

@ -1,9 +1,9 @@
use bevy_reflect_derive::impl_type_path;
use crate::{
self as bevy_reflect, enum_debug, enum_hash, enum_partial_eq, ApplyError, DynamicStruct,
DynamicTuple, Enum, PartialReflect, Reflect, ReflectKind, ReflectMut, ReflectOwned, ReflectRef,
Struct, Tuple, TypeInfo, VariantFieldIter, VariantType,
enum_debug, enum_hash, enum_partial_eq, ApplyError, DynamicStruct, DynamicTuple, Enum,
PartialReflect, Reflect, ReflectKind, ReflectMut, ReflectOwned, ReflectRef, Struct, Tuple,
TypeInfo, VariantFieldIter, VariantType,
};
use alloc::{boxed::Box, string::String};

View File

@ -317,7 +317,6 @@ impl<'a> VariantField<'a> {
// Tests that need access to internal fields have to go here rather than in mod.rs
#[cfg(test)]
mod tests {
use crate as bevy_reflect;
use crate::*;
#[derive(Reflect, Debug, PartialEq)]

View File

@ -10,7 +10,6 @@ pub use variants::*;
#[cfg(test)]
mod tests {
use crate as bevy_reflect;
use crate::*;
use alloc::boxed::Box;

View File

@ -359,7 +359,6 @@ impl UnitVariantInfo {
#[cfg(test)]
mod tests {
use super::*;
use crate as bevy_reflect;
use crate::{Reflect, Typed};
#[test]

View File

@ -1,5 +1,4 @@
use crate::{
self as bevy_reflect,
__macro_exports::RegisterForReflection,
func::{
args::{ArgCount, ArgList},

View File

@ -252,7 +252,6 @@ pub(crate) use impl_generic_info_methods;
#[cfg(test)]
mod tests {
use super::*;
use crate as bevy_reflect;
use crate::{Reflect, Typed};
use alloc::string::String;
use core::fmt::Debug;

View File

@ -1,4 +1,4 @@
use crate::{self as bevy_reflect, impl_type_path};
use crate::impl_type_path;
impl_type_path!(::foldhash::fast::FoldHasher);
impl_type_path!(::foldhash::fast::FixedState);

View File

@ -1,4 +1,3 @@
use crate as bevy_reflect;
use crate::{std_traits::ReflectDefault, ReflectDeserialize, ReflectSerialize};
use assert_type_match::assert_type_match;
use bevy_reflect_derive::{impl_reflect, impl_reflect_opaque};

View File

@ -1,7 +1,4 @@
use crate::{
self as bevy_reflect, impl_reflect_opaque, prelude::ReflectDefault, ReflectDeserialize,
ReflectSerialize,
};
use crate::{impl_reflect_opaque, prelude::ReflectDefault, ReflectDeserialize, ReflectSerialize};
impl_reflect_opaque!(::petgraph::graph::NodeIndex(
Default,

View File

@ -4,10 +4,10 @@ use core::any::Any;
use smallvec::{Array as SmallArray, SmallVec};
use crate::{
self as bevy_reflect, utility::GenericTypeInfoCell, ApplyError, FromReflect, FromType,
Generics, GetTypeRegistration, List, ListInfo, ListIter, MaybeTyped, PartialReflect, Reflect,
ReflectFromPtr, ReflectKind, ReflectMut, ReflectOwned, ReflectRef, TypeInfo, TypeParamInfo,
TypePath, TypeRegistration, Typed,
utility::GenericTypeInfoCell, ApplyError, FromReflect, FromType, Generics, GetTypeRegistration,
List, ListInfo, ListIter, MaybeTyped, PartialReflect, Reflect, ReflectFromPtr, ReflectKind,
ReflectMut, ReflectOwned, ReflectRef, TypeInfo, TypeParamInfo, TypePath, TypeRegistration,
Typed,
};
impl<T: SmallArray + TypePath + Send + Sync> List for SmallVec<T>

View File

@ -1,6 +1,4 @@
use crate::{
self as bevy_reflect, std_traits::ReflectDefault, ReflectDeserialize, ReflectSerialize,
};
use crate::{std_traits::ReflectDefault, ReflectDeserialize, ReflectSerialize};
use bevy_reflect_derive::impl_reflect_opaque;
impl_reflect_opaque!(::smol_str::SmolStr(

View File

@ -4,7 +4,7 @@
)]
use crate::{
self as bevy_reflect, impl_type_path, map_apply, map_partial_eq, map_try_apply,
impl_type_path, map_apply, map_partial_eq, map_try_apply,
prelude::ReflectDefault,
reflect::impl_full_reflect,
set_apply, set_partial_eq, set_try_apply,
@ -2441,8 +2441,8 @@ crate::func::macros::impl_function_traits!(&'static Location<'static>);
#[cfg(test)]
mod tests {
use crate::{
self as bevy_reflect, Enum, FromReflect, PartialReflect, Reflect, ReflectSerialize,
TypeInfo, TypeRegistry, Typed, VariantInfo, VariantType,
Enum, FromReflect, PartialReflect, Reflect, ReflectSerialize, TypeInfo, TypeRegistry,
Typed, VariantInfo, VariantType,
};
use alloc::{collections::BTreeMap, string::String, vec};
use bevy_platform_support::collections::HashMap;

View File

@ -1,5 +1,3 @@
use crate as bevy_reflect;
use crate::{std_traits::ReflectDefault, ReflectDeserialize, ReflectSerialize};
use bevy_reflect_derive::impl_reflect_opaque;

Some files were not shown because too many files have changed in this diff Show More