Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub workflows for CI #20

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/ci_linux.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: ci_linux

on:
pull_request:
workflow_dispatch:
push:
branches: [main]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Build default features
run: cargo build
- name: Test default features
run: cargo test

- name: Build single_threaded_async
run: cargo build --features single_threaded_async
- name: Test single_threaded_async
run: cargo test --features single_threaded_async
32 changes: 32 additions & 0 deletions .github/workflows/ci_web.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: ci_web

on:
pull_request:
workflow_dispatch:
push:
branches: [main]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:

- name: Add wasm32 target
run: rustup target add wasm32-unknown-unknown

- uses: actions/checkout@v3

- name: Build package
run: cargo build --target wasm32-unknown-unknown --release --features single_threaded_async

# Notes:
# * Targeting wasm32 only works with the single_threaded_async feature because
# wasm32 doesn't support threading at the moment.
# * The regular cargo test pipeline cannot run tests that were compiled to wasm.
# There may be ways to develop test executables specific to wasm32, but this
# seems like overkill for now.
41 changes: 41 additions & 0 deletions .github/workflows/ci_windows.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: ci_windows
on:
pull_request:
workflow_dispatch:
push:
branches: [main]

jobs:
build:
runs-on: windows-latest

steps:
- name: checkout
uses: actions/checkout@v3

# Run build
- name: Install Rustup using win.rustup.rs
run: |
# Disable the download progress bar which can cause perf issues
$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe
.\rustup-init.exe -y --default-host=x86_64-pc-windows-msvc --default-toolchain=none
del rustup-init.exe
rustup target add x86_64-pc-windows-msvc
shell: powershell

- name: Build default features
run: cargo build
shell: cmd

- name: Test default features
run: cargo test
shell: cmd

- name: Build single_threaded_async
run: cargo build --features single_threaded_async
shell: cmd

- name: Test single_threaded_async
run: cargo test --features single_threaded_async
shell: cmd
29 changes: 29 additions & 0 deletions .github/workflows/style.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: style

on:
pull_request:
workflow_dispatch:
push:
branches: [main]

env:
CARGO_TERM_COLOR: always

jobs:
style:

runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v3

- name: rustfmt
run: |
rustup component add rustfmt

- name: style
run: cargo fmt --all --check

- name: minimal feature build
run: cargo check --no-default-features
2 changes: 1 addition & 1 deletion macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/

use proc_macro::TokenStream;
use syn::DeriveInput;
use quote::quote;
use syn::DeriveInput;

#[proc_macro_derive(Stream)]
pub fn simple_stream_macro(item: TokenStream) -> TokenStream {
Expand Down
6 changes: 1 addition & 5 deletions src/async_execution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ where
}

pub(crate) fn task_cancel_sender(_world: &mut World) -> CancelSender {

#[cfg(not(feature = "single_threaded_async"))]
{
AsyncComputeTaskPoolSender
Expand All @@ -73,10 +72,7 @@ pub(crate) struct AsyncComputeTaskPoolSender;
impl AsyncComputeTaskPoolSender {
/// This is only used to create a task to cancel an existing task, so we
/// always detach
pub(crate) fn send<F>(
&self,
f: impl FnOnce() -> F,
)
pub(crate) fn send<F>(&self, f: impl FnOnce() -> F)
where
F: Future + Send + 'static,
F::Output: Send + 'static,
Expand Down
43 changes: 22 additions & 21 deletions src/async_execution/single_threaded_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@

use bevy_ecs::prelude::World;

pub(crate) use bevy_tasks::Task as TaskHandle;
use async_task::Runnable;
pub(crate) use bevy_tasks::Task as TaskHandle;
use tokio::sync::mpsc::{
unbounded_channel,
UnboundedSender as TokioSender,
UnboundedReceiver as TokioReceiver,
unbounded_channel, UnboundedReceiver as TokioReceiver, UnboundedSender as TokioSender,
};

use std::{future::Future, pin::Pin};

type CancellingTask = Box<dyn FnOnce() -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + 'static>;
type CancellingTask =
Box<dyn FnOnce() -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + 'static>;

pub(crate) struct SingleThreadedExecution {
cancel_sender: TokioSender<CancellingTask>,
Expand All @@ -40,7 +39,12 @@ impl SingleThreadedExecution {
fn new() -> Self {
let (cancel_sender, cancel_receiver) = unbounded_channel();
let (runnable_sender, runnable_receiver) = unbounded_channel();
Self { cancel_sender, cancel_receiver, runnable_sender, runnable_receiver }
Self {
cancel_sender,
cancel_receiver,
runnable_sender,
runnable_receiver,
}
}

pub(crate) fn get(world: &mut World) -> &Self {
Expand All @@ -54,16 +58,19 @@ impl SingleThreadedExecution {
if !world.contains_non_send::<SingleThreadedExecution>() {
world.insert_non_send_resource(SingleThreadedExecution::new());
}
world.non_send_resource_mut::<SingleThreadedExecution>().poll(limit);
world
.non_send_resource_mut::<SingleThreadedExecution>()
.poll(limit);
}

pub(crate) fn poll(&mut self, limit: Option<usize>) {
let mut count = 0;
while let Ok(f) = self.cancel_receiver.try_recv() {
let sender = self.runnable_sender.clone();
let future = f();
let (runnable, task) = async_task::spawn_local(
future, move |runnable| { sender.send(runnable).ok(); });
let (runnable, task) = async_task::spawn_local(future, move |runnable| {
sender.send(runnable).ok();
});
runnable.run();
task.detach();

Expand All @@ -88,17 +95,14 @@ impl SingleThreadedExecution {
}
}

pub(crate) fn spawn<T>(
&self,
future: impl Future<Output = T> + 'static,
) -> TaskHandle<T>
pub(crate) fn spawn<T>(&self, future: impl Future<Output = T> + 'static) -> TaskHandle<T>
where
T: Send + 'static,
{
let sender = self.runnable_sender.clone();
let (runnable, task) = async_task::spawn_local(
future, move |runnable| { sender.send(runnable).ok(); },
);
let (runnable, task) = async_task::spawn_local(future, move |runnable| {
sender.send(runnable).ok();
});
let _ = self.runnable_sender.send(runnable);
TaskHandle::new(task)
}
Expand All @@ -115,12 +119,9 @@ pub(crate) struct SingleThreadedExecutionSender {
}

impl SingleThreadedExecutionSender {
pub(crate) fn send<F>(
&self,
f: impl FnOnce() -> F + Send + 'static,
)
pub(crate) fn send<F>(&self, f: impl FnOnce() -> F + Send + 'static)
where
F: Future<Output = ()> + Send + 'static
F: Future<Output = ()> + Send + 'static,
{
let u: CancellingTask = Box::new(move || Box::pin(f()));
self.sender.send(u).ok();
Expand Down
Loading
Loading