Repository: kurbos/bevy-shell-template Branch: main Commit: ae9267c6de3a Files: 29 Total size: 36.6 KB Directory structure: gitextract_k22ki78g/ ├── .github/ │ ├── FUNDING.yml │ ├── dependabot.yml │ └── workflows/ │ ├── ci.yml │ ├── release-dockerhub.yml │ ├── release-gh-pages.yml │ ├── release-ios.yml │ └── release-native.yml ├── .gitignore ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── launchers/ │ ├── ios/ │ │ ├── Cargo.toml │ │ ├── run-ios-sim.sh │ │ ├── rust-toolchain.toml │ │ └── src/ │ │ └── main.rs │ ├── native/ │ │ ├── Cargo.toml │ │ ├── run-native.sh │ │ ├── rust-toolchain.toml │ │ └── src/ │ │ └── main.rs │ └── wasm/ │ ├── Cargo.toml │ ├── Docker.nginx.conf │ ├── Dockerfile │ ├── Trunk.toml │ ├── index.html │ ├── rust-toolchain.toml │ └── src/ │ └── main.rs ├── rustfmt.toml └── src/ └── lib.rs ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/FUNDING.yml ================================================ # These are supported funding model platforms github: [simbleau] custom: ["buymeacoffee.com/simbleau"] ================================================ FILE: .github/dependabot.yml ================================================ --- version: 2 updates: - package-ecosystem: "github-actions" directory: "/" schedule: interval: "weekly" - package-ecosystem: "cargo" directory: "/" schedule: interval: "weekly" - package-ecosystem: "docker" directory: "/" schedule: interval: "weekly" ================================================ FILE: .github/workflows/ci.yml ================================================ name: CI on: [push, pull_request] jobs: lint: runs-on: ubuntu-latest steps: - name: Setup | Checkout uses: actions/checkout@v3 - name: Setup | Ubuntu dependencies run: sudo apt install libasound2-dev libudev-dev pkg-config - name: Setup | Toolchain (clippy) uses: actions-rs/toolchain@v1 with: toolchain: nightly default: true components: clippy - name: Lint | Clippy uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} args: --all-targets -- -D warnings - name: Setup | Toolchain (rustfmt) uses: actions-rs/toolchain@v1 with: toolchain: nightly default: true components: rustfmt - name: Lint | Rustfmt run: cargo fmt -- --check build: strategy: fail-fast: false matrix: os: [macos-latest, windows-latest, ubuntu-latest] runs-on: ${{ matrix.os }} steps: - name: Setup | Checkout uses: actions/checkout@v3 - name: Setup | Rust uses: actions-rs/toolchain@v1 with: toolchain: nightly profile: minimal - name: Setup | Ubuntu dependencies if: matrix.os == 'ubuntu-latest' run: sudo apt install libasound2-dev libudev-dev pkg-config - name: Build run: cargo build build-wasm: runs-on: ubuntu-latest steps: - name: Setup | Checkout uses: actions/checkout@v3 - name: Setup | Trunk uses: jetli/trunk-action@v0.4.0 with: version: "latest" - name: Build | Trunk run: | cd launchers/wasm trunk build - name: Post Setup | Upload dist uses: actions/upload-artifact@v3 with: path: ./launchers/wasm/dist/ docker-wasm: needs: build-wasm runs-on: ubuntu-latest steps: - name: Setup | Checkout uses: actions/checkout@v3 - name: Setup | Download dist uses: actions/download-artifact@v3 - name: Setup | Place dist run: mv ./artifact ./launchers/wasm/dist - name: Setup | Docker Buildx uses: docker/setup-buildx-action@v2 - name: Setup | Build Docker Image uses: docker/build-push-action@v4 with: context: ./launchers/wasm push: false test: needs: build strategy: fail-fast: false matrix: os: [macos-latest, windows-latest, ubuntu-latest] runs-on: ${{ matrix.os }} steps: - name: Setup | Checkout uses: actions/checkout@v3 - name: Setup | Rust uses: actions-rs/toolchain@v1 with: toolchain: nightly profile: minimal - name: Setup | Ubuntu dependencies if: matrix.os == 'ubuntu-latest' run: sudo apt install libasound2-dev libudev-dev pkg-config - name: Test run: cargo test ================================================ FILE: .github/workflows/release-dockerhub.yml ================================================ name: Release DockerHub on: push: tags: ["v*"] env: RELEASE_NAME: bevy_shell jobs: build: runs-on: ubuntu-latest steps: - name: Setup | Checkout uses: actions/checkout@v3 - name: Setup | Trunk uses: jetli/trunk-action@v0.4.0 with: version: "latest" - name: Build | Trunk run: | cd launchers/wasm trunk build --release - name: Post Build | Upload dist uses: actions/upload-artifact@v3 with: path: ./launchers/wasm/dist/ dockerhub: needs: build runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 - name: Setup | Get version tag run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - name: Setup | Download dist uses: actions/download-artifact@v3 - name: Setup | Place dist run: mv ./artifact ./launchers/wasm/dist/ - name: Setup | QEMU uses: docker/setup-qemu-action@v2 - name: Setup | Docker Buildx uses: docker/setup-buildx-action@v2 - name: Setup | DockerHub Login uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Release | DockerHub Push uses: docker/build-push-action@v4 with: context: ./launchers/wasm platforms: linux/amd64,linux/arm64 push: true tags: | ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.RELEASE_NAME }}:${{ env.RELEASE_VERSION }} ================================================ FILE: .github/workflows/release-gh-pages.yml ================================================ name: Release WASM (GitHub Pages) on: push: tags: ["v*"] env: PUBLIC_URL: /bevy-shell-template/ jobs: build: runs-on: ubuntu-latest steps: - name: Setup | Checkout uses: actions/checkout@v3 - name: Setup | Trunk uses: jetli/trunk-action@v0.4.0 with: version: "latest" - name: Build | Trunk run: | cd launchers/wasm trunk build --release --public-url ${{ env.PUBLIC_URL }} - name: Post Build | Upload dist uses: actions/upload-artifact@v3 with: path: ./launchers/wasm/dist/ deploy: needs: build runs-on: ubuntu-latest steps: - name: Setup | Download dist uses: actions/download-artifact@v3 - name: Setup | Place dist run: mv ./artifact ./dist - name: Deploy | Github Pages uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./dist/ ================================================ FILE: .github/workflows/release-ios.yml ================================================ name: Release iOS on: push: tags: ["v*"] env: RELEASE_NAME: bevy_shell jobs: release: runs-on: macos-latest steps: - name: Checkout code uses: actions/checkout@v3 - name: Setup | Install dependencies run: cargo install cargo-bundle - name: Build | iOS run: | cd ./launchers/ios cargo bundle --release --format ios --target x86_64-apple-ios - name: Stage | Rename run: | mv ./launchers/ios/target/x86_64-apple-ios/release/ios-launcher ./${{ env.RELEASE_NAME }} - name: Stage | Zip release uses: vimtor/action-zip@v1 with: files: ./${{ env.RELEASE_NAME }} recursive: false dest: ./${{ env.RELEASE_NAME }}-x86_64-apple-ios.zip - name: Release | Upload uses: softprops/action-gh-release@v1 with: draft: false prerelease: false fail_on_unmatched_files: true files: ./${{ env.RELEASE_NAME }}-x86_64-apple-ios.zip ================================================ FILE: .github/workflows/release-native.yml ================================================ name: Release Native on: push: tags: ["v*"] env: RELEASE_NAME: bevy_shell jobs: release: strategy: fail-fast: false matrix: target: - x86_64-unknown-linux-gnu - x86_64-apple-darwin - x86_64-pc-windows-msvc include: - target: x86_64-unknown-linux-gnu os: ubuntu-latest name: x86_64-unknown-linux-gnu.tar.gz - target: x86_64-apple-darwin os: macos-latest name: x86_64-apple-darwin.tar.gz - target: x86_64-pc-windows-msvc os: windows-latest name: x86_64-pc-windows-msvc.zip runs-on: ${{ matrix.os }} steps: - name: Setup | Checkout uses: actions/checkout@v3 - name: Setup | Rust uses: actions-rs/toolchain@v1 with: toolchain: nightly override: true profile: minimal target: ${{ matrix.target }} - name: Setup | Ubuntu dependencies if: matrix.os == 'ubuntu-latest' run: sudo apt install libasound2-dev libudev-dev pkg-config - name: Build run: | cd launchers/native cargo build --release --target ${{ matrix.target }} - name: Post Build | Prepare artifacts [Windows] if: matrix.os == 'windows-latest' run: | cd launchers/native 7z a ../../${{ matrix.name }} static/ cd - cd target/${{ matrix.target }}/release mv native-launcher.exe ${{ env.RELEASE_NAME }}.exe 7z a ../../../${{ matrix.name }} ${{ env.RELEASE_NAME }}.exe cd - 7z a ${{ matrix.name }} assets/ mv ${{ matrix.name }} ${{ env.RELEASE_NAME }}-${{ matrix.name }} - name: Post Build | Prepare artifacts [-nix] if: matrix.os != 'windows-latest' run: | cd launchers/native mv static/ ../../ cd - cd target/${{ matrix.target }}/release mv native-launcher ../../../${{ env.RELEASE_NAME }} cd - tar cvzf ${{ matrix.name }} assets/ static/ ${{ env.RELEASE_NAME }} mv ${{ matrix.name }} ${{ env.RELEASE_NAME }}-${{ matrix.name }} - name: Release | Upload uses: softprops/action-gh-release@v1 with: files: ${{ env.RELEASE_NAME }}-${{ matrix.name }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ================================================ FILE: .gitignore ================================================ # Generated by Cargo # will have compiled files and executables target/ # Prevent asset duplication /launchers/native/assets/ /launchers/ios/assets/ /launchers/wasm/assets/ # Generated by Trunk /launchers/wasm/dist/ # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html # Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk # Files auto generated by macOS .DS_Store ================================================ FILE: Cargo.toml ================================================ [package] name = "game" version = "0.1.0" edition = "2021" [workspace] members = [ "launchers/wasm", "launchers/native", ] exclude = [ "launchers/ios" # Special handling required ] [profile.dev] opt-level = 1 [profile.release] panic = 'abort' codegen-units = 1 opt-level = 'z' lto = true [dependencies] bevy = "0.9.1" image = "0.24.5" winit = "0.28.1" ================================================ FILE: LICENSE-APACHE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS Copyright 2022 Spencer C. Imbleau, Sebastian J. Hamel Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: LICENSE-MIT ================================================ Copyright (c) 2022 Spencer C. Imbleau, Sebastian J. Hamel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================
# 🕊️ Bevy Shell - Template *An opinionated, monolithic template for Bevy with cross-platform CI/CD, native + WASM + mobile launchers, and managed cross-platform deployment.*
# ✨ Features - Single, monolithic repository for a cross-platform Bevy App - Automated CI on pushes and merge requests to `main` - Cross-platform delivery of your Bevy app through GitHub releases - Windows, Linux, MacOS, Web ([Demo](https://kurbos.github.io/bevy-shell-template/)), iOS, Android (TODO: PRs accepted!) - Options to deploy Web to DockerHub (self-host) or GitHub Pages (free) - Settings for automated dependency management through Renovate - Best practices in GitOps and IaC # ✅ Quickstart - [Use](https://github.com/kurbos/bevy-shell-template/generate) or [Fork](https://github.com/kurbos/bevy-shell-template/fork) this template - [Setup RenovateBot](https://github.com/marketplace/renovate) with permissions to your repository to automatically detect dependency updates - Setup your WASM build with one of: - [GitHub Pages](#github-pages) *(I'm new to hosting, no equipment)* - [Docker](#docker) *(I know what I'm doing)* - **Optional**: Modify your Bevy App, which is self-contained in [`src/`](src/) - You can preview your WASM version with `trunk serve` ([Trunk](https://trunkrs.dev) required) - You can preview the Native version with `cargo run` - [Cut a release](#release-cutting) to cross-deploy your game across WASM, Windows, Mac, and Linux --- # 💁🏻 Information Below is detailed information for the features of this template ## 📦 Multi-platform CI/CD This template uses GitOps to deploy a multi-platform release. GitHub Actions powers [testing pipelines](https://github.com/kurbos/bevy-shell-template/actions) and [release deployment](https://github.com/kurbos/bevy-shell-template/releases) to ensure a solid foundation for production release infrastructure. ### Automated testing Pushing to the main branch automatically triggers CI pipelines: - Unit Testing - Build - Ubuntu - Build - Windows - Build - MacOS - Build - iOS - TODO: Build - Android - Build - WebAssembly 🔸 You can ensure all pull requests must pass CI testing before merging through [GitHub's branch protection rules](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/managing-a-branch-protection-rule). ### Automated dependency management [Renovate](https://github.com/marketplace/renovate) is a free open source bot on GitHub for your repositories to automatically create pull requests for dependency updates on your projects. This template's [Renovate settings file](.github/renovate.json) allows for automatic merging of minor and patch updates, if all CI tests pass. You can change these settings yourself. 🔸 More information is available at [renovatebot.com](https://renovatebot.com/) ### Release cutting Creating a release on your template will trigger the release pipeline, which packages [download bundles]((https://github.com/kurbos/bevy-shell-template/releases/latest)) for all major platforms, including mobile and web. The pipeline will create a branch `gh-pages` with the WASM bundle to serve by GitHub Pages ([demo](https://kurbos.github.io/bevy-shell-template)), or DockerHub image ([example](https://hub.docker.com/repository/docker/simbleau/my_game)), depending on the [hosting strategy](#-hosting) you choose to setup. > 🔥 **WARNING: We enforce releases are tagged with a semantic version name**, e.g. "*v0.1.0*", not "*v1*" > This can be modified on the [`release-*` workflow files](.github/workflows/). ## 📡 Web Hosting There are two ways to host the WASM build of your Bevy game, with Docker or GitHub Pages. You could be creative to adapt this to other hosting platforms, but we will only explain these two. You would likely choose one, not both. If you don't have hosting equipment or know what you're doing, choose GitHub Pages. ### GitHub Pages To automatically serve your WASM bundle like [our demo](https://kurbos.github.io/bevy-shell-template/), here are the steps: - Modify the [GitHub Pages GitHub Action file](.github/workflows/release-gh-pages.yml)'s variarable `PUBLIC_URL` with the slug for your GitHub Pages hosting. - If the repo name is the same as the repo owner, this should be `/`, otherwise, it will should be `//` (e.g. `/bevy-shell-template/`) - *Optional*: Delete the [DockerHub GitHub Action](.github/workflows/release-dockerhub.yml), as you probably don't need it. - [Cut a release](#release-cutting) and wait for pipeline completion - On your GitHub template repo, visit Settings > Pages - Select `gh-pages` branch from the dropdown menu and press "Save". ### Docker To serve your WASM bundle with Docker, here are the steps: - Signup to DockerHub - Navigate to your project Settings > Secrets > Actions - Create two repository GitHub Action secrets: - `DOCKERHUB_USERNAME` Your DockerHub username (e.g. *simbleau*) - `DOCKERHUB_TOKEN` A [DockerHub access token](https://docs.docker.com/docker-hub/access-tokens/) with write privileges - Modify the [DockerHub GitHub Action file](.github/workflows/release-dockerhub.yml)'s variable `RELEASE_NAME` with your desired image name (e.g. `my_game`) - *Optional*: Delete the [GitHub Pages GitHub Action](.github/workflows/release-gh-pages.yml), as you probably don't need it. - [Cut a release](#release-cutting) and wait for pipeline completion - On your server hardware with Docker installed, run `docker run -p 80:80 /:latest`, which should pull from DockerHub automatically. - Your WASM build should be served via `http://localhost:80`, where `localhost` is your server's address 🔸 The [`Dockerfile`](launchers/wasm/Dockerfile) uses NGINX, and uses [`Docker.nginx.conf`](launchers/wasm/Docker.nginx.conf) for configuration. ## 🚀 Launchers ### WASM (Web) To build and run the WASM app locally we recommend [Trunk](https://trunkrs.dev/): > Serve with `trunk serve` and open [`http://127.0.0.1:8080`](http://127.0.0.1:8080) in your browser - Assets are streamed through the hosting provider, so that the initial WASM bundle is smaller. - We use all the WASM optimizations discussed described [here](https://rustwasm.github.io/book/reference/code-size.html) in the Rust and WebAssembly book. - There is an initial loading screen provided through [Yew](https://yew.rs) while the WASM bundle loads. ### Native (Windows, MacOS, Linux) > Run with `cargo run` - Assets are bundled with the release when cut. - There is no loading screen. ### Native (iOS, Android) **TODO: Android is not yet supported** > Run with `launchers/ios/run-ios-sim.sh` - Assets are bundled with the release when cut. - There is no loading screen. ================================================ FILE: launchers/ios/Cargo.toml ================================================ [package] name = "ios-launcher" version = "0.1.0" edition = "2021" description = "a description is necessary for an iOS app" [package.metadata.bundle] name = "ios-launcher" identifier = "com.example.ios-launcher" icon = ["static/icon.png"] resources = ["assets/", "static/"] [dependencies] game = { path = "../.." } bevy = "0.9.1" image = "0.24.5" winit = "0.27.5" ================================================ FILE: launchers/ios/run-ios-sim.sh ================================================ #!/bin/bash set -e TARGET="${TARGET:-x86_64-apple-ios}" which dasel || brew install dasel APP_NAME="$(dasel -f Cargo.toml '.package.name')" BUNDLE_ID="$(dasel -f Cargo.toml '.package.metadata.bundle.identifier')" BUNDLE_CMD="cargo bundle --target $TARGET" echo "Copying assets" if [ ! -d ../../assets ]; then echo "Error: work dir must be iOS launcher directory before running this script" exit 1 fi cp -r ../../assets/ assets/ echo "Bundling app for iOS" which cargo-bundle || cargo install cargo-bundle $BUNDLE_CMD xcrun simctl boot "iPhone 14" || true open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app xcrun simctl install booted "target/$TARGET/debug/bundle/ios/$APP_NAME.app" xcrun simctl launch --console booted "$BUNDLE_ID" ================================================ FILE: launchers/ios/rust-toolchain.toml ================================================ [toolchain] channel = "stable" targets = [ "aarch64-apple-ios", "x86_64-apple-ios", ] profile = "minimal" ================================================ FILE: launchers/ios/src/main.rs ================================================ use bevy::{prelude::*, window::WindowId, winit::WinitWindows}; use image; use std::io::Cursor; use winit::window::Icon; fn set_window_icon(windows: NonSend) { let window = windows.get_window(WindowId::primary()).expect("no window"); let (icon_rgba, icon_width, icon_height) = { let icon_buf = Cursor::new(include_bytes!("../static/appicon.png")); let rgba = image::load(icon_buf, image::ImageFormat::Png) .expect("Failed to open icon path") .into_rgba8(); let (width, height) = rgba.dimensions(); let icon_raw = rgba.into_raw(); (icon_raw, width, height) }; let icon = Icon::from_rgba(icon_rgba, icon_width, icon_height) .expect("error making icon"); window.set_window_icon(Some(icon)); } fn main() { let mut app = game::app(true); info!("Starting launcher: iOS"); app.add_startup_system(set_window_icon); app.run(); } ================================================ FILE: launchers/native/Cargo.toml ================================================ [package] name = "native-launcher" version = "0.1.0" edition = "2021" workspace = "../.." [dependencies] game = { path = "../.." } bevy = "0.9.1" image = "0.24.5" winit = "0.28.1" ================================================ FILE: launchers/native/run-native.sh ================================================ #!/bin/bash set -e echo "Copying assets" if [ ! -d ../../assets ]; then echo "Error: work dir must be native launcher directory before running this script" exit 1 fi cp -r ../../assets/ assets/ cargo run ================================================ FILE: launchers/native/rust-toolchain.toml ================================================ [toolchain] channel = "stable" targets = [ "x86_64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-gnu" ] profile = "minimal" ================================================ FILE: launchers/native/src/main.rs ================================================ use bevy::{prelude::*, window::WindowId, winit::WinitWindows}; use std::io::Cursor; use winit::window::Icon; fn set_window_icon(windows: NonSend) { let window = windows.get_window(WindowId::primary()).expect("no window"); let (icon_rgba, icon_width, icon_height) = { let icon_buf = Cursor::new(include_bytes!("../static/appicon.png")); let rgba = image::load(icon_buf, image::ImageFormat::Png) .expect("Failed to open icon path") .into_rgba8(); let (width, height) = rgba.dimensions(); let icon_raw = rgba.into_raw(); (icon_raw, width, height) }; let icon = Icon::from_rgba(icon_rgba, icon_width, icon_height) .expect("error making icon"); window.set_window_icon(Some(icon)); } fn main() { let mut app = game::app(false); info!("Starting launcher: Native"); app.add_startup_system(set_window_icon); app.run(); } ================================================ FILE: launchers/wasm/Cargo.toml ================================================ [package] name = "wasm-launcher" version = "0.1.0" edition = "2021" workspace = "../.." [dependencies] game = { path = "../.." } bevy = "0.9.1" web-sys = { version="0.3.61", features=["Document", "Window"] } yew = "0.19.3" stylist = { version= "0.10.1", features=["yew_integration"] } ================================================ FILE: launchers/wasm/Docker.nginx.conf ================================================ server { server_name _; listen 80 default_server; listen [::]:80 default_server; root /usr/share/nginx/html; index index.html; location / { # First attempt to serve request as file, then # as directory, then fall back to redirecting to index.html try_files $uri $uri/ /index.html; } } ================================================ FILE: launchers/wasm/Dockerfile ================================================ FROM nginx as webserver COPY ./dist /usr/share/nginx/html RUN rm /etc/nginx/conf.d/default.conf COPY ./Docker.nginx.conf /etc/nginx/conf.d/Docker.conf ENTRYPOINT ["nginx"] CMD ["-g", "daemon off;"] ================================================ FILE: launchers/wasm/Trunk.toml ================================================ # Learn more: https://trunkrs.dev/configuration/#trunk-toml [build] # The index HTML file to drive the bundling process. target = "index.html" [watch] watch = [ "../../src", # Game source "src", # WASM launcher source "static/", "index.html" ] [[hooks]] stage = "pre_build" command = "cp" command_arguments = ["-r", "../../assets", "."] ================================================ FILE: launchers/wasm/index.html ================================================ Loading... Bevy ================================================ FILE: launchers/wasm/rust-toolchain.toml ================================================ [toolchain] targets = [ "wasm32-unknown-unknown", ] ================================================ FILE: launchers/wasm/src/main.rs ================================================ use bevy::prelude::*; use game::LAUNCHER_TITLE; use stylist::yew::styled_component; use stylist::{css, global_style}; use yew::prelude::*; fn set_window_title(title: &str) { web_sys::window() .map(|w| w.document()) .flatten() .expect("Unable to get DOM") .set_title(title); } fn set_global_css() { global_style! { r#" html { min-height: 100%; position: relative; } body { height: 100%; padding: 0; margin: 0; } "# } .expect("Unable to mount global style"); } #[styled_component(Root)] fn view() -> Html { set_window_title(LAUNCHER_TITLE); set_global_css(); let css = css!( r#" position: absolute; overflow: hidden; width: 100%; height: 100%; "# ); html! {
} } fn main() { // Mount the DOM yew::start_app::(); // Start the Bevy App let mut app = game::app(false); info!("Starting launcher: WASM"); app.run(); } ================================================ FILE: rustfmt.toml ================================================ # Wrap all comments and lines to 80 characters max_width = 80 comment_width = 80 wrap_comments = true ================================================ FILE: src/lib.rs ================================================ use bevy::{prelude::*, window::WindowMode}; pub const LAUNCHER_TITLE: &str = "Bevy Shell - Template"; pub fn app(fullscreen: bool) -> App { let mode = if fullscreen { WindowMode::BorderlessFullscreen } else { WindowMode::Windowed }; let mut app = App::new(); app.add_plugins(DefaultPlugins.set(WindowPlugin { window: WindowDescriptor { title: LAUNCHER_TITLE.to_string(), canvas: Some("#bevy".to_string()), fit_canvas_to_parent: true, mode, ..default() }, ..default() })) .add_startup_system(load_icon); app } fn load_icon(mut commands: Commands, asset_server: Res) { commands.spawn(Camera2dBundle::default()); commands.spawn(SpriteBundle { texture: asset_server.load("bevy.png"), ..default() }); }