Skip to content

Commit

Permalink
feat: remove trunk dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
eerii committed Jul 12, 2024
1 parent 7178922 commit 44cf25e
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 95 deletions.
31 changes: 15 additions & 16 deletions .github/workflows/examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ on:
type: string

env:
binary: hello-bevy
binary: hello-bevy # CHANGE: This needs to match the project name in Cargo.toml
optimize: false # CHANGE: This produces a smaller and faster web build, but it takes a long time

jobs:
build-wasm:
strategy:
matrix:
name: [dvd jump]
include:
- name: dvd
features: "release"
Expand All @@ -37,29 +37,28 @@ jobs:
- name: Rust cache
uses: swatinem/rust-cache@v2
with:
shared-key: "linux-release"
shared-key: "web-release"

- name: Build
run: |
rm src/main.rs
cd src
ln -sf ../examples/jump.rs main.rs
cd ..
trunk build --release --no-default-features --features ${{ matrix.features }}
cargo build --release --example ${{ matrix.name }} --no-default-features --features ${{ matrix.features }} --target wasm32-unknown-unknown
- name: Optimize Wasm
uses: NiklasEi/wasm-opt-action@v2
with:
file: wasm/dist/*.wasm
- 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
- name: Make paths relative
- name: Optimize Wasm
if: ${{ env.optimize == 'true' }}
working-directory: ./wasm
run: |
sed -i 's/\/${{ env.binary }}/.\/${{ env.binary }}/g' wasm/dist/index.html
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/dist
working-directory: ./wasm
run: |
zip --recurse-paths ../../${{ matrix.name }}.zip .
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
Expand Down
35 changes: 18 additions & 17 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ on:
type: string

env:
binary: hello-bevy # [CHANGE]: This needs to match the project name in cargo.toml
add_binaries_to_github_release: true
itch_target: eerii/hello-bevy # [CHANGE]: If you want to deploy to itch, set this as your username/project-url
features: "release" # [CHANGE]: Add features here if you need them
binary: hello-bevy # CHANGE: This needs to match the project name in Cargo.toml
itch_target: eerii/hello-bevy # CHANGE: If you want to deploy to itch, set this as your username/project-url
features: "release" # CHANGE: Add features here if you need them
optimize: false # CHANGE: This produces a smaller and faster web build, but it takes a long time

jobs:
get-version:
Expand Down Expand Up @@ -47,24 +47,29 @@ jobs:

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

- name: Build
run: |
trunk build --release --no-default-features --features ${{ env.features }}
cargo build --release --example ${{ matrix.name }} --no-default-features --features ${{ matrix.features }} --target wasm32-unknown-unknown
- name: Optimize Wasm
uses: NiklasEi/wasm-opt-action@v2
with:
file: wasm/dist/*.wasm
- 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
- name: Make paths relative
- name: Optimize Wasm
if: ${{ env.optimize == 'true' }}
working-directory: ./wasm
run: |
sed -i 's/\/${{ env.binary }}/.\/${{ env.binary }}/g' wasm/dist/index.html
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/dist
working-directory: ./wasm
run: |
zip --recurse-paths ../../${{ env.binary }}.zip .
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
Expand All @@ -73,7 +78,6 @@ jobs:
name: wasm

- name: Upload binaries to release
if: ${{ env.add_binaries_to_github_release == 'true' }}
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -126,7 +130,6 @@ jobs:
name: linux

- name: Upload binaries to release
if: ${{ env.add_binaries_to_github_release == 'true' }}
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -176,7 +179,6 @@ jobs:
name: windows

- name: Upload binaries to release
if: ${{ env.add_binaries_to_github_release == 'true' }}
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -246,7 +248,6 @@ jobs:
name: mac

- name: Upload binaries to release
if: ${{ env.add_binaries_to_github_release == 'true' }}
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ graphs
capture*
*.tracy
.direnv
wasm/hello-bevy*
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ to run a debug build use cargo:
cargo run
```

and to start a local web build, use trunk:

```sh
trunk serve
```

you can also play around with some of the included examples with `cargo run --example <name>`. and if you want to get started quickly, copy any example to `src/main.rs`!

in order to have a development environment up and ready, run `nix develop` or use [`nix-direnv`](https://github.com/nix-community/nix-direnv) installed create a `.envrc` like this:
Expand Down
120 changes: 70 additions & 50 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,60 +24,80 @@
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
toolchain = pkgs.rust-bin.nightly.latest.default.override {
extensions = [
"clippy"
"rustfmt"
"rust-src"
];
};
inherit (pkgs) lib mkShell stdenv;

general-deps = with pkgs; [
# Vulkan
vulkan-tools
vulkan-loader
vulkan-validation-layers
# Linkers
mold
clang
# Rust
cargo-watch
rust-analyzer-unwrapped
# Toml
taplo
];

linux-deps = with pkgs; [
openssl
pkg-config
alsa-lib
udev
speechd
# Wayland
libxkbcommon
wayland
# Xorg
xorg.libX11
xorg.libX11
xorg.libXcursor
xorg.libXi
xorg.libXrandr
];

web-deps = with pkgs; [ wasm-bindgen-cli binaryen ];

extensions = [
"clippy"
"rustfmt"
"rust-src"
];
in
{
devShells.default =
with pkgs;
mkShell rec {
buildInputs = [
# Linux
openssl
pkg-config
alsa-lib
udev
speechd
# Wayland
libxkbcommon
wayland
# Xorg
xorg.libX11
xorg.libX11
xorg.libXcursor
xorg.libXi
xorg.libXrandr
# Vulkan
vulkan-tools
vulkan-loader
vulkan-validation-layers
# Linkers
mold
clang
# Rust
cargo-watch
rust-analyzer-unwrapped
toolchain
# Toml
taplo
# Web
wasm-bindgen-cli
trunk
];
devShells = {
# Regular shell
default =
let
toolchain = pkgs.rust-bin.nightly.latest.default.override { inherit extensions; };
in
mkShell rec {
buildInputs = [ toolchain ] ++ general-deps ++ lib.optionals stdenv.isLinux linux-deps;

# For speechd
shellHook = ''
export LIBCLANG_PATH="${pkgs.libclang.lib}/lib"
'';

# For speechd
shellHook = ''
export LIBCLANG_PATH="${pkgs.libclang.lib}/lib"
'';
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
};
# For web builds
web =
let
toolchain = pkgs.rust-bin.nightly.latest.default.override {
targets = [ "wasm32-unknown-unknown" ];
};
in
mkShell rec {
buildInputs = [ toolchain ] ++ general-deps ++ web-deps;

RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
};
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
};
};
}
);
}
1 change: 0 additions & 1 deletion src/ui/menu/mappings.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Key mappings menu submodule
// TODO: Allow remapping
// TODO: Same order every time
// TODO: Mouse and other icons

use bevy::{prelude::*, reflect::Enum};
Expand Down
16 changes: 11 additions & 5 deletions wasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@

<title>Hello Bevy</title> <!-- CHANGE: Write your game name -->

<link data-trunk rel="inline" href="style.css"/>
<link data-trunk rel="rust" href="../Cargo.toml"/>
<link rel="stylesheet" href="style.css"/>
</head>

<body>
<link data-trunk rel="inline" href="audio.js"/>

<div class="game-container">
<canvas id="bevy">
Javascript and support for canvas is required
Expand All @@ -24,7 +21,16 @@ <h1 class="text-loading">Loading</h1>
</div>
</div>

<script>
<script type="module">
import './audio.js'
import init from './hello-bevy.js' // This is changed automatically in the release actions, it should match Cargo.toml

init().catch((error) => {
if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) {
throw error;
}
});

const bevy = document.getElementById('bevy');
const loadingTitle = document.getElementById('loading');
const observer = new MutationObserver(() => {
Expand Down

0 comments on commit 44cf25e

Please sign in to comment.