Skip to content

Commit

Permalink
fix: examples ci
Browse files Browse the repository at this point in the history
  • Loading branch information
eerii committed Jul 13, 2024
1 parent b965537 commit 4af65c4
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 68 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ jobs:
uses: nicknovitski/nix-develop@v1

- name: Rust cache
uses: swatinem/rust-cache@v2
with:
shared-key: "linux-debug"
uses: swatinem/rust-cache@v2

- name: Cargo test
run: cargo test --workspace
Expand All @@ -91,8 +89,6 @@ jobs:

- name: Rust cache
uses: swatinem/rust-cache@v2
with:
shared-key: "linux-release"

- name: Cargo test
run: cargo test --workspace --release --no-default-features --features release
Expand Down
18 changes: 7 additions & 11 deletions .github/workflows/examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ jobs:
features: "release"
- name: jump
features: "release"
fail-fast: false

runs-on: ubuntu-latest

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

- name: Install nix
uses: nixbuild/nix-quick-install-action@v28
Expand All @@ -39,15 +40,16 @@ jobs:
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
shared-key: "web-release"
shared-key: "examples"

- name: Build
run: |
cargo build --release --example ${{ matrix.name }} --no-default-features --features ${{ matrix.features }} --target wasm32-unknown-unknown
- name: Prepare package
run: |
wasm-bindgen --no-typescript --out-name ${{ env.binary }} --out-dir wasm --target web target/wasm32-unknown-unknown/release/${{ env.binary }}.wasm
wasm-bindgen --no-typescript --out-name ${{ env.binary }} --out-dir wasm --target web target/wasm32-unknown-unknown/release/examples/${{ matrix.name }}.wasm
sed -i "s/hello-bevy/${{ env.binary }}/g" wasm/index.html
- name: Optimize Wasm
if: ${{ env.optimize == 'true' }}
Expand All @@ -56,14 +58,8 @@ jobs:
mv ${{ env.binary }}_bg.wasm base.wasm
wasm-opt base.wasm -o ${{ env.binary }}_bg.wasm -Os
- name: Package as a zip
working-directory: ./wasm
run: |
sed -i "s/hello-bevy/${{ env.binary }}/g" index.html
zip --recurse-paths ../${{ matrix.name }}.zip .
- name: Upload binaries to artifacts
uses: actions/upload-artifact@v4
with:
path: ${{ matrix.name }}.zip
name: wasm
path: wasm/*
name: ${{ matrix.name }}
74 changes: 32 additions & 42 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Based on https://github.com/bevyengine/bevy_github_ci_template/blob/main/.github/workflows/release.yaml
# For cache to work in tags, you need to create it first in main
# The recommended way to do this is to dispatch a job manually, then the subsequent tag releases can use that cache
name: release

on:
push:
tags:
- "*[0-9]+.[0-9]+"
tags: [ "*[0-9]+.[0-9]+" ]
workflow_dispatch:
inputs:
version:
Expand Down Expand Up @@ -37,7 +38,7 @@ jobs:

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

- name: Install nix
uses: nixbuild/nix-quick-install-action@v28
Expand All @@ -48,17 +49,16 @@ jobs:
arguments: ".#web"

- name: Rust cache
uses: swatinem/rust-cache@v2
with:
shared-key: "web-release"
uses: swatinem/rust-cache@v2

- name: Build
run: |
cargo build --release --example ${{ matrix.name }} --no-default-features --features ${{ matrix.features }} --target wasm32-unknown-unknown
cargo build --release --target wasm32-unknown-unknown --no-default-features --features ${{ env.features }}
- name: Prepare package
run: |
wasm-bindgen --no-typescript --out-name ${{ env.binary }} --out-dir wasm --target web target/wasm32-unknown-unknown/release/${{ env.binary }}.wasm
sed -i "s/hello-bevy/${{ env.binary }}/g" wasm/index.html
- name: Optimize Wasm
if: ${{ env.optimize == 'true' }}
Expand All @@ -67,18 +67,17 @@ jobs:
mv ${{ env.binary }}_bg.wasm base.wasm
wasm-opt base.wasm -o ${{ env.binary }}_bg.wasm -Os
- name: Package as a zip
working-directory: ./wasm
run: |
sed -i "s/hello-bevy/${{ env.binary }}/g" index.html
zip --recurse-paths ../${{ matrix.name }}.zip .
- name: Upload binaries to artifacts
uses: actions/upload-artifact@v4
with:
path: ${{ env.binary }}.zip
path: wasm/*
name: wasm

- name: Package as a zip
working-directory: ./wasm
run: |
zip --recurse-paths ../${{ env.binary }}.zip .
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
Expand All @@ -97,7 +96,7 @@ jobs:

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

- name: Install nix
uses: nixbuild/nix-quick-install-action@v28
Expand All @@ -107,8 +106,6 @@ jobs:

- name: Rust cache
uses: swatinem/rust-cache@v2
with:
shared-key: "linux-release"

- name: Build
run: |
Expand All @@ -120,17 +117,17 @@ jobs:
cp target/x86_64-unknown-linux-gnu/release/${{ env.binary }} linux/
strip linux/${{ env.binary }}
- name: Package as a zip
working-directory: ./linux
run: |
zip --recurse-paths ../${{ env.binary }}.zip .
- name: Upload binaries to artifacts
uses: actions/upload-artifact@v4
with:
path: ${{ env.binary }}.zip
path: linux/*
name: linux

- name: Package as a zip
working-directory: ./linux
run: |
zip --recurse-paths ../${{ env.binary }}.zip .
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
Expand All @@ -149,7 +146,7 @@ jobs:

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

- name: Remove debug config (windows)
run: Remove-Item -Path .cargo/config.toml
Expand All @@ -170,16 +167,16 @@ jobs:
mkdir windows
cp target/x86_64-pc-windows-msvc/release/${{ env.binary }}.exe windows/
- name: Package as a zip
run: |
Compress-Archive -Path windows/* -DestinationPath ${{ env.binary }}.zip
- name: Upload binaries to artifacts
uses: actions/upload-artifact@v4
with:
path: ${{ env.binary }}.zip
path: windows/*
name: windows

- name: Package as a zip
run: |
Compress-Archive -Path windows/* -DestinationPath ${{ env.binary }}.zip
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
Expand All @@ -199,7 +196,7 @@ jobs:

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

- name: Remove debug config
run: rm -f .cargo/config.toml
Expand All @@ -211,8 +208,6 @@ jobs:

- name: Rust cache
uses: swatinem/rust-cache@v2
with:
key: "arm"

- name: Build release for Apple Silicon
run: |
Expand All @@ -223,19 +218,14 @@ jobs:
with:
targets: x86_64-apple-darwin

- name: Rust cache
uses: swatinem/rust-cache@v2
with:
key: "x86"

- name: Build release for x86 Apple
run: |
SDKROOT=$(xcrun -sdk macosx --show-sdk-path) cargo build --release --target=x86_64-apple-darwin --no-default-features --features ${{ env.features }}
- name: Create Universal Binary
run: |
lipo -create -output target/release/${{ env.binary }} target/aarch64-apple-darwin/release/${{ env.binary }} target/x86_64-apple-darwin/release/${{ env.binary }}
- name: Prepare package
run: |
mkdir -p ${{ env.binary }}.app/Contents/MacOS
Expand Down Expand Up @@ -277,16 +267,16 @@ jobs:
- check-upload-to-itch
- release-wasm
- release-linux
# - release-windows # [CHANGE]: Uncomment this if you want to automaticall deploy mac and windows builds to itch
# - release-macos # It is disabled by default because they take a loong time
- release-windows
- release-macos
if: ${{ needs.check-upload-to-itch.outputs.should-upload == 'yes' }}

env:
version: ${{needs.get-version.outputs.version}}

steps:
- name: Download artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
path: ./builds

Expand All @@ -307,6 +297,6 @@ jobs:
./butler push \
--fix-permissions \
--userversion="${{ env.version }}" \
builds/$channel/* \
builds/$channel \
${{ env.itch_target }}:$channel
done
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ release = [ # Only in release (build with --release --no-default-features --feat
"bevy_embedded_assets",
"common",
"tts",
"touch",
]
common = ["input", "menu", "ui", "persist"]
common = ["input", "menu", "persist", "ui"]

3d_camera = []
input = ["leafwing-input-manager"]
Expand All @@ -35,6 +36,7 @@ navigation = ["bevy-alt-ui-navigation-lite"]
persist = ["bevy-persistent"]
pixel_perfect = []
resizable = []
touch = ["input"]
trace = ["release", "bevy/trace_tracy"]
ui = ["sickle_ui"]

Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ to run a release build locally:
cargo run --release --no-default-features --features release
```

on nixos, you might have trouble if you are downloading the linux precompiled binary from releases. this is because nixos does not follow fhs and it doesn't have a global library path. a workarround for running games there is to use this command:

```sh
NIXPKGS_ALLOW_UNFREE=1 nix-shell -p steam-run --run "steam-run GAME_PATH"
```
if the `tts` feature is enabled, you may need to install [speech dispatcher](https://wiki.archlinux.org/title/Speech_dispatcher) on linux.

### profiling 📈

Expand Down
2 changes: 1 addition & 1 deletion examples/jump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn update_player(
};

// Move
let axis = input.axis_pair(&Action::Move);
let axis = input.clamped_axis_pair(&Action::Move);
let dir = axis.unwrap_or_default().x();
if dir.abs() > 0. {
player.velocity.x = dir * MOVE_VEL;
Expand Down
5 changes: 2 additions & 3 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fn init(mut cmd: Commands) {
input_map
.insert(Action::Jump, KeyCode::Space)
.insert(Action::Jump, GamepadButtonType::South)
.insert(Action::Jump, MouseButton::Left)
.insert(Action::Move, KeyboardVirtualDPad::WASD)
.insert(Action::Move, GamepadStick::LEFT)
.insert(Action::Pause, KeyCode::Escape)
Expand All @@ -66,9 +67,7 @@ fn handle_input(
input: Query<&ActionState<Action>>,
mut next_state: ResMut<NextState<crate::GameState>>,
) {
let Ok(input) = input.get_single() else {
return;
};
let Ok(input) = input.get_single() else { return };

if input.just_pressed(&Action::Pause) {
next_state.set(crate::GameState::Menu)
Expand Down
1 change: 1 addition & 0 deletions src/ui/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ fn on_mouse_move(
.cursor_position()
.map(|cursor| Aabb2d::new(cursor, Vec2::ZERO))
{
warn!("{:?}", mouse);
for (entity, node, trans) in focusables.iter() {
let focused = focused.get_single().ok().unwrap_or(Entity::PLACEHOLDER);
if entity == focused {
Expand Down

0 comments on commit 4af65c4

Please sign in to comment.