Compare commits

..

5 Commits

3 changed files with 31 additions and 16 deletions

View File

@@ -11,8 +11,6 @@ env:
jobs: jobs:
build: build:
name: Build (${{ matrix.target }}) name: Build (${{ matrix.target }})
env:
VCPKG_SYSTEM_LIBRARIES: "OFF"
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
@@ -47,15 +45,16 @@ jobs:
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
path: target/vcpkg path: target/vcpkg
key: ${{ runner.os }}-vcpkg-${{ hashFiles('Cargo.toml', 'Cargo.lock') }} key: vcpkg-${{ runner.os }}-${{ matrix.target }}-${{ hashFiles('Cargo.toml', 'Cargo.lock') }}
restore-keys: | restore-keys: |
${{ runner.os }}-vcpkg- ${{ runner.os }}-vcpkg
vcpkg-${{ runner.os }}-${{ matrix.target }}-
- name: Vcpkg Linux Dependencies - name: Vcpkg Linux Dependencies
if: runner.os == 'Linux' if: runner.os == 'Linux'
run: | run: |
sudo apt-get update sudo apt-get update
sudo apt-get install -y build-essential gettext libltdl-dev sudo apt-get install -y build-essential gettext libltdl-dev zlib1g-dev
- name: Vcpkg - name: Vcpkg
run: | run: |
@@ -111,8 +110,21 @@ jobs:
version: 8 version: 8
run_install: true run_install: true
- name: Build - name: Build with Emscripten
run: ./build.sh -er # release mode, skip emsdk run: |
cargo build --target=wasm32-unknown-emscripten --release
- name: Assemble
run: |
echo "Generating CSS"
pnpx postcss-cli ./assets/site/styles.scss -o ./assets/site/build.css
echo "Copying WASM files"
mkdir -p dist
cp assets/site/{build.css,favicon.ico,index.html} dist
output_folder="target/wasm32-unknown-emscripten/release"
cp $output_folder/pacman.{wasm,js} $output_folder/deps/pacman.data dist
- name: Upload Artifact - name: Upload Artifact
uses: actions/upload-pages-artifact@v3 uses: actions/upload-pages-artifact@v3

View File

@@ -42,7 +42,8 @@ rev = "2024.05.24" # release 2024.05.24 # to check for a new one, check https://
[package.metadata.vcpkg.target] [package.metadata.vcpkg.target]
x86_64-pc-windows-msvc = { triplet = "x64-windows-static-md" } x86_64-pc-windows-msvc = { triplet = "x64-windows-static-md" }
x86_64-unknown-linux-gnu = { triplet = "x64-linux" } x86_64-unknown-linux-gnu = { triplet = "x64-linux" }
# x86_64-apple-darwin = { triplet = "x64-osx-release" } x86_64-apple-darwin = { triplet = "x64-osx" }
aarch64-apple-darwin = { triplet = "arm64-osx" }
[target.'cfg(target_os = "emscripten")'.dependencies] [target.'cfg(target_os = "emscripten")'.dependencies]
libc = "0.2.16" libc = "0.2.16"

View File

@@ -78,15 +78,17 @@ mod imp {
#[cfg(target_os = "emscripten")] #[cfg(target_os = "emscripten")]
mod imp { mod imp {
use super::*; use super::*;
use std::fs; use sdl2::rwops::RWops;
use std::path::Path; use std::io::Read;
pub fn get_asset_bytes(asset: Asset) -> Result<Cow<'static, [u8]>, AssetError> { pub fn get_asset_bytes(asset: Asset) -> Result<Cow<'static, [u8]>, AssetError> {
let path = Path::new("assets/game").join(asset.path()); let path = format!("assets/game/{}", asset.path());
if !path.exists() { let mut rwops = RWops::from_file(&path, "rb").map_err(|_| AssetError::NotFound(asset.path().to_string()))?;
return Err(AssetError::NotFound(asset.path().to_string())); let len = rwops.len().ok_or_else(|| AssetError::NotFound(asset.path().to_string()))?;
} let mut buf = vec![0u8; len];
let bytes = fs::read(&path)?; rwops
Ok(Cow::Owned(bytes)) .read_exact(&mut buf)
.map_err(|e| AssetError::Io(std::io::Error::new(std::io::ErrorKind::Other, e)))?;
Ok(Cow::Owned(buf))
} }
} }