Merge remote-tracking branch 'upstream/main'

This commit is contained in:
D0RYU 2025-05-04 00:55:08 -04:00
commit 2b87888176
8 changed files with 166 additions and 53 deletions

View file

@ -15,9 +15,7 @@ jobs:
- name: 🚀 Setup & Run tests - name: 🚀 Setup & Run tests
run: | run: |
nix-shell --run " nix-shell -p cargo rustc --run "
git-lfs fetch
git-lfs pull
cargo test --release --all cargo test --release --all
" "
@ -31,41 +29,47 @@ jobs:
target: target:
- x86_64-unknown-linux-gnu - x86_64-unknown-linux-gnu
- x86_64-pc-windows-msvc - x86_64-pc-windows-msvc
- x86_64-apple-darwin #- x86_64-apple-darwin
- aarch64-unknown-linux-gnu - aarch64-unknown-linux-gnu
- aarch64-pc-windows-msvc - aarch64-pc-windows-msvc
- aarch64-apple-darwin #- aarch64-apple-darwin
include: include:
- target: x86_64-unknown-linux-gnu - target: x86_64-unknown-linux-gnu
binary_name: zenyx-x86_64-linux binary_name: zenyx-x86_64-linux
ext: "" ext: ""
linker: /lib64/ld-linux-x86-64.so.2
command: zigbuild command: zigbuild
args: --target x86_64-unknown-linux-gnu --release args: --target x86_64-unknown-linux-gnu --release
- target: aarch64-unknown-linux-gnu - target: aarch64-unknown-linux-gnu
binary_name: zenyx-aarch64-linux binary_name: zenyx-aarch64-linux
ext: "" ext: ""
linker: /lib/ld-linux-aarch64.so.1
command: zigbuild command: zigbuild
args: --target aarch64-unknown-linux-gnu --release args: --target aarch64-unknown-linux-gnu --release
- target: x86_64-pc-windows-msvc - target: x86_64-pc-windows-msvc
binary_name: zenyx-x86_64-windows binary_name: zenyx-x86_64-windows
ext: ".exe" ext: ".exe"
linker: ""
command: xwin build command: xwin build
args: --target x86_64-pc-windows-msvc --release args: --target x86_64-pc-windows-msvc --release
- target: aarch64-pc-windows-msvc - target: aarch64-pc-windows-msvc
binary_name: zenyx-aarch64-windows binary_name: zenyx-aarch64-windows
ext: ".exe" ext: ".exe"
linker: ""
command: xwin build command: xwin build
args: --target aarch64-pc-windows-msvc --release args: --target aarch64-pc-windows-msvc --release
- target: x86_64-apple-darwin #- target: x86_64-apple-darwin
binary_name: zenyx-x86_64-macos # binary_name: zenyx-x86_64-macos
ext: "" # ext: ""
command: zigbuild # linker: ""
args: --target x86_64-apple-darwin --release #command: zigbuild
- target: aarch64-apple-darwin #args: --target x86_64-apple-darwin --release
binary_name: zenyx-aarch64-macos #target: aarch64-apple-darwin
ext: "" #binary_name: zenyx-aarch64-macos
command: zigbuild #ext: ""
args: --target aarch64-apple-darwin --release #linker: ""
#command: zigbuild
#args: --target aarch64-apple-darwin --release
steps: steps:
- name: 📥 Checkout source - name: 📥 Checkout source
@ -74,8 +78,6 @@ jobs:
- name: 🚀 Install Target & Build release binary - name: 🚀 Install Target & Build release binary
run: | run: |
nix-shell --run " nix-shell --run "
git-lfs fetch --all
git-lfs pull
cargo ${{ matrix.command }} ${{ matrix.args }} cargo ${{ matrix.command }} ${{ matrix.args }}
" "
@ -84,10 +86,19 @@ jobs:
mkdir -p artifacts mkdir -p artifacts
cp target/${{ matrix.target }}/release/zenyx${{ matrix.ext }} artifacts/${{ matrix.binary_name }}${{ matrix.ext }} cp target/${{ matrix.target }}/release/zenyx${{ matrix.ext }} artifacts/${{ matrix.binary_name }}${{ matrix.ext }}
- name: 🛠️ Patchelf
if: ${{
matrix.target == 'x86_64-unknown-linux-gnu' ||
matrix.target == 'aarch64-unknown-linux-gnu'
}}
run: |
nix run --extra-experimental-features nix-command --extra-experimental-features flakes nixpkgs#patchelf -- --set-interpreter ${{ matrix.linker }} \
artifacts/${{ matrix.binary_name }}${{ matrix.ext }}
- name: ⬆️ Upload artifact - name: ⬆️ Upload artifact
uses: https://code.forgejo.org/forgejo/upload-artifact@v4 uses: https://code.forgejo.org/forgejo/upload-artifact@v4
with: with:
name: ${{ matrix.binary_name }}${{ matrix.ext }}.zip name: ${{ matrix.binary_name }}.zip
path: artifacts/${{ matrix.binary_name }}${{ matrix.ext }} path: artifacts/${{ matrix.binary_name }}${{ matrix.ext }}
compression-level: 9 compression-level: 9
if-no-files-found: error if-no-files-found: error

18
Cargo.lock generated
View file

@ -385,6 +385,12 @@ dependencies = [
"piper", "piper",
] ]
[[package]]
name = "build-print"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a2128d00b7061b82b72844a351e80acd29e05afc60e9261e2ac90dca9ecc2ac"
[[package]] [[package]]
name = "built" name = "built"
version = "0.7.7" version = "0.7.7"
@ -1484,6 +1490,7 @@ dependencies = [
"num-traits", "num-traits",
"once_cell", "once_cell",
"petgraph", "petgraph",
"pp-rs",
"rustc-hash", "rustc-hash",
"spirv", "spirv",
"strum 0.26.3", "strum 0.26.3",
@ -2106,6 +2113,15 @@ version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"
[[package]]
name = "pp-rs"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb458bb7f6e250e6eb79d5026badc10a3ebb8f9a15d1fff0f13d17c71f4d6dee"
dependencies = [
"unicode-xid",
]
[[package]] [[package]]
name = "ppv-lite86" name = "ppv-lite86"
version = "0.2.21" version = "0.2.21"
@ -4062,9 +4078,11 @@ name = "zenyx"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"allocator-api2", "allocator-api2",
"build-print",
"bytemuck", "bytemuck",
"cgmath", "cgmath",
"image", "image",
"naga",
"serde", "serde",
"serde_json", "serde_json",
"smol", "smol",

View file

@ -60,3 +60,9 @@ serde = "1.0.219"
[target.aarch64-linux-android.dependencies] [target.aarch64-linux-android.dependencies]
winit = { version = "0.30.9", features = ["android-native-activity"] } winit = { version = "0.30.9", features = ["android-native-activity"] }
[build-dependencies]
build-print = "0.1.1"
bytemuck = "1.22.0"
naga = { version = "25.0.1", features = ["glsl-in", "spv-out"] }
thiserror = "2.0.12"

View file

@ -94,7 +94,7 @@ Distribute, and use Zenyx for any purpose you wish.
| Windows | Primary | ✅ | | | Windows | Primary | ✅ | |
| Linux/*BSD | Primary | ✅ | | | Linux/*BSD | Primary | ✅ | |
| macOS | Secondary | ⚠️ | The current main set of maintainers do not own any native MacOS devices to perform tests with. | | macOS | Secondary | ⚠️ | The current main set of maintainers do not own any native MacOS devices to perform tests with. |
| Android | Help wanted | ❓ | | | Android | Secondary | ✅ | |
| iOS | Not planned | ❓ | | | iOS | Not planned | ❓ | |
| Web | TBD | ❓ | | | Web | TBD | ❓ | |
| Consoles | Not planned | ⛔ | Consoles require specific dev kits,proprietary licenses, and substantial fees that we (Nonsensical-dev,the Zenyx maintainers,and the open source contributors) currently do not have the capacity for. This may change in the future but most likely will not be soon. | | Consoles | Not planned | ⛔ | Consoles require specific dev kits,proprietary licenses, and substantial fees that we (Nonsensical-dev,the Zenyx maintainers,and the open source contributors) currently do not have the capacity for. This may change in the future but most likely will not be soon. |

120
build.rs
View file

@ -1,26 +1,100 @@
use std::{env, process::Command}; use build_print::{info, warn};
use naga::{
ShaderStage,
back::spv::{self, WriterFlags},
front::glsl::{self, Options as GlslOptions, ParseErrors},
valid::{ValidationError, ValidationFlags, Validator},
};
use std::{
env, fs,
path::{Path, PathBuf},
};
use thiserror::Error;
fn main() { #[derive(Debug, Error)]
println!("cargo::rerun-if-changed=shaders"); pub enum BuildError {
let outdir = env::var("OUT_DIR").unwrap(); #[error("I/O error: {0}")]
let vert = Command::new("glslc") Io(#[from] std::io::Error),
.args(["shaders/shader.vert", "-o", &format!("{outdir}/vert.spv")]) #[error("environment variable error: {0}")]
.output() EnvVar(#[from] env::VarError),
.expect("Failed to execute 'glslc'"); #[error("unsupported shader extension: {0}")]
let frag = Command::new("glslc") UnsupportedExt(String),
.args(["shaders/shader.frag", "-o", &format!("{outdir}/frag.spv")]) #[error("GLSL parse errors in `{0}`:\n{1}")]
.output() ParseErrors(String, ParseErrors),
.expect("Failed to execute 'glslc'"); #[error("validation errors in `{0}`: {1}")]
if !vert.status.success() { ValidateErrors(String, ValidationError),
panic!( #[error("SPIR-V write error for `{0}`: {1}")]
"Failed to compile vertex shader: {}", Spv(String, spv::Error),
String::from_utf8(vert.stderr).unwrap() }
)
} impl From<(String, ParseErrors)> for BuildError {
if !frag.status.success() { fn from((s, e): (String, ParseErrors)) -> Self {
panic!( BuildError::ParseErrors(s, e)
"Failed to compile fragment shader: {}",
String::from_utf8(frag.stderr).unwrap()
)
} }
} }
impl From<(String, ValidationError)> for BuildError {
fn from((s, e): (String, ValidationError)) -> Self {
BuildError::ValidateErrors(s, e)
}
}
impl From<(String, spv::Error)> for BuildError {
fn from((s, e): (String, spv::Error)) -> Self {
BuildError::Spv(s, e)
}
}
fn compile_shader(path: &Path, out_dir: &Path) -> Result<(), BuildError> {
let ext = path
.extension()
.and_then(|e| e.to_str())
.map(str::to_string)
.ok_or_else(|| BuildError::UnsupportedExt(path.display().to_string()))?;
let stage = match ext.as_str() {
"vert" => ShaderStage::Vertex,
"frag" => ShaderStage::Fragment,
"comp" => ShaderStage::Compute,
_ => return Err(BuildError::UnsupportedExt(ext)),
};
let src = fs::read_to_string(path)?;
let module = glsl::Frontend::default()
.parse(&GlslOptions::from(stage), &src)
.map_err(|e| (ext.clone(), e))?;
let info = Validator::new(ValidationFlags::all(), Default::default())
.validate(&module)
.map_err(|e| (ext.clone(), e.into_inner()))?;
let mut writer = spv::Writer::new(&spv::Options {
flags: WriterFlags::empty(),
..Default::default()
})
.map_err(|e| (ext.clone(), e))?;
let mut spirv = Vec::new();
writer
.write(&module, &info, None, &None, &mut spirv)
.map_err(|e| (ext.clone(), e))?;
let out_path = out_dir.join(format!("{}.spv", ext));
fs::write(&out_path, bytemuck::cast_slice(&spirv))?;
info!("Compiled {} → {}", path.display(), out_path.display());
Ok(())
}
fn main() -> Result<(), BuildError> {
println!("cargo:rerun-if-changed=shaders");
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
for entry in fs::read_dir("shaders")? {
let path = entry?.path();
if !path.is_file() {
continue;
}
if let Err(e) = compile_shader(&path, &out_dir) {
if matches!(e, BuildError::UnsupportedExt(_)) {
warn!("{}", e);
continue;
}
return Err(e);
}
}
Ok(())
}

View file

@ -13,7 +13,7 @@
stdenv, stdenv,
targetPackages ? pkgs, targetPackages ? pkgs,
}: let }: let
version = (builtins.fromTOML (builtins.readFile ./engine/Cargo.toml)).package.version; version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package.version;
src = nix-gitignore.gitignoreSource [] ./.; src = nix-gitignore.gitignoreSource [] ./.;
in in
rustPlatform.buildRustPackage rec { rustPlatform.buildRustPackage rec {
@ -61,7 +61,7 @@ rustPlatform.buildRustPackage rec {
--set LD_LIBRARY_PATH ${lib.makeLibraryPath buildInputs} --set LD_LIBRARY_PATH ${lib.makeLibraryPath buildInputs}
'' + lib.optionalString stdenv.targetPlatform.isWindows '' '' + lib.optionalString stdenv.targetPlatform.isWindows ''
mkdir -p $out/bin mkdir -p $out/bin
cp ${targetPackages.vulkan-loader}/bin/vulkan-1.dll $out/bin/ cp ${pkgs.vulkan-loader}/bin/vulkan-1.dll $out/bin/
''; '';
doCheck = false; doCheck = false;

View file

@ -41,6 +41,7 @@
cargo-cross cargo-cross
cargo-xwin cargo-xwin
cargo-wizard cargo-wizard
cargo-zigbuild
wine64 wine64
pkg-config pkg-config
]; ];
@ -73,8 +74,14 @@
nativeBuildInputs = with pkgs; [ nativeBuildInputs = with pkgs; [
(rust-bin.stable.latest.default.override { (rust-bin.stable.latest.default.override {
extensions = ["rust-src" "cargo" "rustfmt" "clippy"]; extensions = ["rust-src" "cargo" "rustfmt" "clippy"];
targets = [ "x86_64-pc-windows-msvc" "x86_64-unknown-linux-gnu" ]; targets = [
"x86_64-pc-windows-msvc"
"x86_64-unknown-linux-gnu"
"x86_64-apple-darwin"
"aarch64-pc-windows-msvc"
"aarch64-unknown-linux-gnu"
"aarch64-apple-darwin"
];
}) })
pkg-config pkg-config
] ++ nativeBuildInputs; ] ++ nativeBuildInputs;

View file

@ -141,9 +141,6 @@ struct WgpuState {
instance: wgpu::Instance, instance: wgpu::Instance,
} }
static _ICON: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/assets/Badge.png"));
static _PUMPKIN: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/Pumpkin.obj"));
impl WgpuState { impl WgpuState {
fn new() -> Self { fn new() -> Self {
let backends = Backends::PRIMARY; let backends = Backends::PRIMARY;