Skip to content

Commit

Permalink
Merge pull request #15 from ten3roberts/update-ci
Browse files Browse the repository at this point in the history
Update ci toolchain
  • Loading branch information
ten3roberts authored Feb 12, 2024
2 parents b9e93f7 + adb0ff8 commit 2d65fd4
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 123 deletions.
71 changes: 12 additions & 59 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,112 +14,65 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install nightly
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal

- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@nextest
- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: nextest
args: run --all-features
run: cargo nextest run --all-features

test_miri:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install nightly
uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
override: true
components: miri

- uses: taiki-e/install-action@nextest

- name: Run cargo miri
uses: actions-rs/cargo@v1
with:
command: miri
args: nextest run -j16 --no-default-features --features std,serde,flume,derive
run: cargo miri nextest run -j16 --no-default-features --features std,serde,flume,derive

test_nostd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install nightly
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal

- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@nextest

- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: nextest
args: run --no-default-features
run: cargo nextest run --no-default-features

lint_doc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install nightly
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal

- uses: dtolnay/rust-toolchain@stable
- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: doc
args: --all-features
run: cargo doc --all-features

test_doc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install nightly
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal

- uses: dtolnay/rust-toolchain@stable
- name: Run cargo test (doc)
uses: actions-rs/cargo@v1
with:
command: test
args: --doc --all-features
run: cargo test --doc --all-features

coverage:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Install nightly
uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
override: true
profile: minimal
components: miri

- uses: taiki-e/install-action@cargo-tarpaulin

- name: Run cargo tarpaulin
uses: actions-rs/cargo@v1
with:
command: tarpaulin
args: --all-features --out Xml --engine llvm
run: cargo tarpaulin --all-features --out Xml --engine llvm

- name: Upload to codecov.io
uses: codecov/codecov-action@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@1.70.0
- uses: dtolnay/rust-toolchain@master
with:
target: wasm32-unknown-unknown
targets: wasm32-unknown-unknown
- run: cargo build --release --package asteroids --target wasm32-unknown-unknown --manifest-path=asteroids/Cargo.toml
- run: mv ./target/wasm32-unknown-unknown/release/asteroids.wasm ./asteroids/public
- name: Upload Artefact
Expand Down
7 changes: 1 addition & 6 deletions src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,6 @@ impl<T: ComponentValue> Component<T> {
pub fn name(&self) -> &'static str {
self.vtable.name
}

/// Returns all metadata components
pub fn get_meta(&self) -> ComponentBuffer {
self.vtable.meta.get(self.desc())
}
}

impl<T: ComponentValue> Metadata<T> for Component<T> {
Expand Down Expand Up @@ -451,7 +446,7 @@ impl ComponentDesc {
self.key.target.is_some()
}

pub(crate) fn get_meta(&self) -> ComponentBuffer {
pub(crate) fn create_meta(&self) -> ComponentBuffer {
self.vtable.meta.get(*self)
}

Expand Down
51 changes: 9 additions & 42 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,11 @@ macro_rules! component {
$(#[$outer])*
$vis fn $name($obj: $crate::Entity) -> $crate::Component<$ty> {

static COMPONENT_ID: ::core::sync::atomic::AtomicU32 = ::core::sync::atomic::AtomicU32::new($crate::entity::EntityIndex::MAX);
fn meta(_desc: $crate::component::ComponentDesc) -> $crate::buffer::ComponentBuffer {
let mut _buffer = $crate::buffer::ComponentBuffer::new();

<$crate::metadata::Name as $crate::metadata::Metadata<$ty>>::attach(_desc, &mut _buffer);
<$crate::Component<$ty> as $crate::metadata::Metadata<$ty>>::attach(_desc, &mut _buffer);

$(
$(
<$metadata as $crate::metadata::Metadata::<$ty>>::attach(_desc, &mut _buffer);
)*
)*

_buffer
}

static META: $crate::vtable::LazyComponentBuffer = $crate::vtable::LazyComponentBuffer::new(meta);
static VTABLE: &$crate::vtable::ComponentVTable<$ty> =
&$crate::vtable::ComponentVTable::new(stringify!($name), &META);
use $crate::entity::EntityKind;
use $crate::relation::RelationExt;

static COMPONENT_ID: ::core::sync::atomic::AtomicU32 = ::core::sync::atomic::AtomicU32::new($crate::entity::EntityIndex::MAX);
static VTABLE: &$crate::vtable::ComponentVTable<$ty> = $crate::component_vtable!($name: $ty $(=> [$($metadata),*])?);
$crate::Component::static_init(&COMPONENT_ID, EntityKind::COMPONENT, VTABLE).of($obj)
}

Expand All @@ -142,26 +126,10 @@ macro_rules! component {

$(#[$outer])*
$vis fn $name() -> $crate::Component<$ty> {
static COMPONENT_ID: ::core::sync::atomic::AtomicU32 = ::core::sync::atomic::AtomicU32::new($crate::entity::EntityIndex::MAX);
fn meta(_desc: $crate::component::ComponentDesc) -> $crate::buffer::ComponentBuffer {
let mut _buffer = $crate::buffer::ComponentBuffer::new();

<$crate::metadata::Name as $crate::metadata::Metadata<$ty>>::attach(_desc, &mut _buffer);
<$crate::Component<$ty> as $crate::metadata::Metadata<$ty>>::attach(_desc, &mut _buffer);

$(
$(
<$metadata as $crate::metadata::Metadata::<$ty>>::attach(_desc, &mut _buffer);
)*
)*

_buffer
}

static META: $crate::vtable::LazyComponentBuffer = $crate::vtable::LazyComponentBuffer::new(meta);
static VTABLE: &$crate::vtable::ComponentVTable<$ty> =
&$crate::vtable::ComponentVTable::new(stringify!($name), &META);
use $crate::entity::EntityKind;

static COMPONENT_ID: ::core::sync::atomic::AtomicU32 = ::core::sync::atomic::AtomicU32::new($crate::entity::EntityIndex::MAX);
static VTABLE: &$crate::vtable::ComponentVTable<$ty> = $crate::component_vtable!($name: $ty $(=> [$($metadata),*])?);
$crate::Component::static_init(&COMPONENT_ID, EntityKind::COMPONENT, VTABLE)
}

Expand Down Expand Up @@ -204,11 +172,10 @@ macro_rules! component_vtable {

}

static META: $crate::vtable::LazyComponentBuffer = $crate::vtable::LazyComponentBuffer::new(meta);
static VTABLE: &$crate::vtable::ComponentVTable<$ty> =
&$crate::vtable::ComponentVTable::new(stringify!($name), &META);
static VTABLE: $crate::vtable::ComponentVTable<$ty> =
$crate::vtable::ComponentVTable::new(stringify!($name), $crate::vtable::LazyComponentBuffer::new(meta));

VTABLE
&VTABLE
}

};
Expand Down
2 changes: 1 addition & 1 deletion src/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ mod test {
foo: String => [crate::Debuggable],
}

let meta = foo().get_meta();
let meta = foo().desc().create_meta();

assert!(meta.get(debuggable()).is_some());
assert_eq!(meta.get(name()), Some(&"foo".into()));
Expand Down
6 changes: 3 additions & 3 deletions src/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct UntypedVTable {
pub(crate) dangling: fn() -> NonNull<u8>,
/// A metadata is a component which is attached to the component, such as
/// metadata or name
pub(crate) meta: &'static LazyComponentBuffer,
pub(crate) meta: LazyComponentBuffer,
}

impl UntypedVTable {
Expand All @@ -55,7 +55,7 @@ impl UntypedVTable {
/// Creates a new vtable of type `T`
pub(crate) const fn new<T: ComponentValue>(
name: &'static str,
meta: &'static LazyComponentBuffer,
meta: LazyComponentBuffer,
) -> Self {
unsafe fn drop_ptr<T>(x: *mut u8) {
x.cast::<T>().drop_in_place()
Expand Down Expand Up @@ -99,7 +99,7 @@ impl<T> core::ops::Deref for ComponentVTable<T> {

impl<T: ComponentValue> ComponentVTable<T> {
/// Creates a new *typed* vtable of `T`
pub const fn new(name: &'static str, meta: &'static LazyComponentBuffer) -> Self {
pub const fn new(name: &'static str, meta: LazyComponentBuffer) -> Self {
Self {
inner: UntypedVTable::new::<T>(name, meta),
marker: PhantomData,
Expand Down
4 changes: 2 additions & 2 deletions src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl World {
}

let id = desc.key().id;
let mut meta = desc.get_meta();
let mut meta = desc.create_meta();
meta.set(component_info(), desc);
meta.set(name(), desc.name().into());

Expand Down Expand Up @@ -917,7 +917,7 @@ impl World {

let desc = component.desc();

let mut meta = desc.get_meta();
let mut meta = desc.create_meta();
meta.set(component_info(), desc);
meta.set(components::name(), desc.name().into());

Expand Down
17 changes: 9 additions & 8 deletions tests/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ use glam::{vec2, Vec2};
fn custom_component() {
let mut world = World::new();

static META: LazyComponentBuffer = LazyComponentBuffer::new(|desc| {
let mut buf = ComponentBuffer::new();
<Debuggable as Metadata<Vec2>>::attach(desc, &mut buf);
buf
});

static VTABLE: &ComponentVTable<Vec2> = &ComponentVTable::new("position", &META);
static VTABLE: ComponentVTable<Vec2> = ComponentVTable::new(
"position",
LazyComponentBuffer::new(|desc| {
let mut buf = ComponentBuffer::new();
<Debuggable as Metadata<Vec2>>::attach(desc, &mut buf);
buf
}),
);

let position = world.spawn_component(VTABLE);
let position = world.spawn_component(&VTABLE);

let id = Entity::builder()
.set(position, vec2(1.0, 6.4))
Expand Down

0 comments on commit 2d65fd4

Please sign in to comment.