From 131989d9f321f8b335417d3ca2cddb5e831b883d Mon Sep 17 00:00:00 2001 From: lily Date: Wed, 23 Apr 2025 17:42:45 -0400 Subject: [PATCH 1/9] fix(nix): incorrect namespace for `vulkan-loader`, add `cargo-zigbuild` --- default.nix | 6 +++--- flake.nix | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/default.nix b/default.nix index 1aa9adf..02ab55a 100644 --- a/default.nix +++ b/default.nix @@ -13,7 +13,7 @@ stdenv, targetPackages ? pkgs, }: let - version = (builtins.fromTOML (builtins.readFile ./engine/Cargo.toml)).package.version; + version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package.version; src = nix-gitignore.gitignoreSource [] ./.; in rustPlatform.buildRustPackage rec { @@ -61,7 +61,7 @@ rustPlatform.buildRustPackage rec { --set LD_LIBRARY_PATH ${lib.makeLibraryPath buildInputs} '' + lib.optionalString stdenv.targetPlatform.isWindows '' 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; @@ -72,4 +72,4 @@ rustPlatform.buildRustPackage rec { platforms = lib.platforms.all; mainProgram = "zenyx"; }; -} \ No newline at end of file +} diff --git a/flake.nix b/flake.nix index 21466a2..101719c 100644 --- a/flake.nix +++ b/flake.nix @@ -41,6 +41,7 @@ cargo-cross cargo-xwin cargo-wizard + cargo-zigbuild wine64 pkg-config ]; From 7fbec03ecc1c06a0b6ac0d74f8a5b2e68f33ecd5 Mon Sep 17 00:00:00 2001 From: lily Date: Wed, 23 Apr 2025 17:56:40 -0400 Subject: [PATCH 2/9] fix: removed unused `_ICON` and `_PUMPKIN` variables --- src/main.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2764eed..0105e37 100644 --- a/src/main.rs +++ b/src/main.rs @@ -141,9 +141,6 @@ struct WgpuState { 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 { fn new() -> Self { let backends = Backends::PRIMARY; From 6884e806469c42d2a2898ed10fa7f37777ec5864 Mon Sep 17 00:00:00 2001 From: lily Date: Wed, 23 Apr 2025 17:59:15 -0400 Subject: [PATCH 3/9] fix(ci): remove unneeded LFS pull --- .forgejo/workflows/build-release.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.forgejo/workflows/build-release.yml b/.forgejo/workflows/build-release.yml index 91efadd..292370f 100644 --- a/.forgejo/workflows/build-release.yml +++ b/.forgejo/workflows/build-release.yml @@ -16,8 +16,6 @@ jobs: - name: 🚀 Setup & Run tests run: | nix-shell --run " - git-lfs fetch - git-lfs pull cargo test --release --all " @@ -74,8 +72,6 @@ jobs: - name: 🚀 Install Target & Build release binary run: | nix-shell --run " - git-lfs fetch --all - git-lfs pull cargo ${{ matrix.command }} ${{ matrix.args }} " @@ -90,4 +86,4 @@ jobs: name: ${{ matrix.binary_name }}${{ matrix.ext }}.zip path: artifacts/${{ matrix.binary_name }}${{ matrix.ext }} compression-level: 9 - if-no-files-found: error \ No newline at end of file + if-no-files-found: error From c86be3ca3dcd5ee0675bf465b3d7adc5dfcee083 Mon Sep 17 00:00:00 2001 From: lily Date: Wed, 23 Apr 2025 18:13:49 -0400 Subject: [PATCH 4/9] fix(nix): add missing targets to `flake.nix` --- flake.nix | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 101719c..f6f029f 100644 --- a/flake.nix +++ b/flake.nix @@ -31,7 +31,7 @@ (import rust-overlay) ]; }; - + nativeBuildInputs = with pkgs; [ vulkan-tools vulkan-tools-lunarg @@ -61,7 +61,7 @@ packages = { inherit (pkgs) zenyx; default = pkgs.zenyx; - windows = let + windows = let pkgsCross = import nixpkgs { system = "x86_64-linux"; crossSystem = nixpkgs.lib.systems.examples.mingwW64; @@ -74,8 +74,14 @@ nativeBuildInputs = with pkgs; [ (rust-bin.stable.latest.default.override { 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 ] ++ nativeBuildInputs; From 25068a76793db114eb25da75e0e4b0f22871dc22 Mon Sep 17 00:00:00 2001 From: Chance Date: Sun, 27 Apr 2025 01:28:21 -0400 Subject: [PATCH 5/9] feat(build): compile SPIR-V with rust native code --- Cargo.lock | 24 +++++++++++ Cargo.toml | 6 +++ build.rs | 120 +++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 127 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fb809d9..77318c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -384,6 +384,12 @@ dependencies = [ "piper", ] +[[package]] +name = "build-print" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a2128d00b7061b82b72844a351e80acd29e05afc60e9261e2ac90dca9ecc2ac" + [[package]] name = "built" version = "0.7.7" @@ -1359,6 +1365,7 @@ dependencies = [ "num-traits", "once_cell", "petgraph", + "pp-rs", "rustc-hash", "spirv", "strum", @@ -1944,6 +1951,15 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "ppv-lite86" version = "0.2.21" @@ -2775,6 +2791,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "v_frame" version = "0.3.8" @@ -3686,9 +3708,11 @@ name = "zenyx" version = "0.1.0" dependencies = [ "allocator-api2", + "build-print", "bytemuck", "cgmath", "image", + "naga", "smol", "terminator", "thiserror 2.0.12", diff --git a/Cargo.toml b/Cargo.toml index 732a166..9cb8778 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,3 +58,9 @@ allocator-api2 = "0.2.21" [target.aarch64-linux-android.dependencies] 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" diff --git a/build.rs b/build.rs index 5235544..c7aec40 100644 --- a/build.rs +++ b/build.rs @@ -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() { - println!("cargo::rerun-if-changed=shaders"); - let outdir = env::var("OUT_DIR").unwrap(); - let vert = Command::new("glslc") - .args(["shaders/shader.vert", "-o", &format!("{outdir}/vert.spv")]) - .output() - .expect("Failed to execute 'glslc'"); - let frag = Command::new("glslc") - .args(["shaders/shader.frag", "-o", &format!("{outdir}/frag.spv")]) - .output() - .expect("Failed to execute 'glslc'"); - if !vert.status.success() { - panic!( - "Failed to compile vertex shader: {}", - String::from_utf8(vert.stderr).unwrap() - ) - } - if !frag.status.success() { - panic!( - "Failed to compile fragment shader: {}", - String::from_utf8(frag.stderr).unwrap() - ) +#[derive(Debug, Error)] +pub enum BuildError { + #[error("I/O error: {0}")] + Io(#[from] std::io::Error), + #[error("environment variable error: {0}")] + EnvVar(#[from] env::VarError), + #[error("unsupported shader extension: {0}")] + UnsupportedExt(String), + #[error("GLSL parse errors in `{0}`:\n{1}")] + ParseErrors(String, ParseErrors), + #[error("validation errors in `{0}`: {1}")] + ValidateErrors(String, ValidationError), + #[error("SPIR-V write error for `{0}`: {1}")] + Spv(String, spv::Error), +} + +impl From<(String, ParseErrors)> for BuildError { + fn from((s, e): (String, ParseErrors)) -> Self { + BuildError::ParseErrors(s, e) } } + +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(()) +} From a157812529f3a1b706814f284efb1bf7daf6402d Mon Sep 17 00:00:00 2001 From: Chance Date: Sun, 27 Apr 2025 14:47:28 -0400 Subject: [PATCH 6/9] fix(ci): patchelf linux binaries --- .forgejo/workflows/build-release.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.forgejo/workflows/build-release.yml b/.forgejo/workflows/build-release.yml index 292370f..7203a3b 100644 --- a/.forgejo/workflows/build-release.yml +++ b/.forgejo/workflows/build-release.yml @@ -80,10 +80,15 @@ jobs: mkdir -p artifacts cp target/${{ matrix.target }}/release/zenyx${{ matrix.ext }} artifacts/${{ matrix.binary_name }}${{ matrix.ext }} + - name: 🛠️ Pathelf + if: ${{ matrix.target }} == x86_64-unknown-linux-gnu || ${{ matrix.target }} == aarch64-unknown-linux-gnu + run: | + nix run nixpkgs#patchelf -- --set-interpreter /lib64/ld-linux-x86-64.so.2 artifacts/${{ matrix.binary_name }}${{ matrix.ext }} + - name: ⬆️ Upload artifact uses: https://code.forgejo.org/forgejo/upload-artifact@v4 with: - name: ${{ matrix.binary_name }}${{ matrix.ext }}.zip + name: ${{ matrix.binary_name }}.zip path: artifacts/${{ matrix.binary_name }}${{ matrix.ext }} compression-level: 9 if-no-files-found: error From 5e2cb15e13544eb4ea2f4feaa64730c3e1f21713 Mon Sep 17 00:00:00 2001 From: Chance Date: Sun, 27 Apr 2025 15:04:40 -0400 Subject: [PATCH 7/9] chore(readme): update platform support table --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a3e525d..22c9743 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ Distribute, and use Zenyx for any purpose you wish. | Windows | Primary | ✅ | | | Linux/*BSD | Primary | ✅ | | | 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 | ❓ | | | 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. | From c455aa5cd68ada7aff4d31677b9f8fa288398c23 Mon Sep 17 00:00:00 2001 From: caznix Date: Thu, 1 May 2025 19:32:56 +0000 Subject: [PATCH 8/9] fix(ci): remove macOS and fix linking --- .forgejo/workflows/build-release.yml | 42 +++++++++++++++++----------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/.forgejo/workflows/build-release.yml b/.forgejo/workflows/build-release.yml index 7203a3b..1d80eb5 100644 --- a/.forgejo/workflows/build-release.yml +++ b/.forgejo/workflows/build-release.yml @@ -15,7 +15,7 @@ jobs: - name: 🚀 Setup & Run tests run: | - nix-shell --run " + nix-shell -p cargo rustc --run " cargo test --release --all " @@ -29,41 +29,47 @@ jobs: target: - x86_64-unknown-linux-gnu - x86_64-pc-windows-msvc - - x86_64-apple-darwin + #- x86_64-apple-darwin - aarch64-unknown-linux-gnu - aarch64-pc-windows-msvc - - aarch64-apple-darwin + #- aarch64-apple-darwin include: - target: x86_64-unknown-linux-gnu binary_name: zenyx-x86_64-linux ext: "" + linker: /lib64/ld-linux-x86-64.so.2 command: zigbuild args: --target x86_64-unknown-linux-gnu --release - target: aarch64-unknown-linux-gnu binary_name: zenyx-aarch64-linux ext: "" + linker: /lib/ld-linux-aarch64.so.1 command: zigbuild args: --target aarch64-unknown-linux-gnu --release - target: x86_64-pc-windows-msvc binary_name: zenyx-x86_64-windows ext: ".exe" + linker: "" command: xwin build args: --target x86_64-pc-windows-msvc --release - target: aarch64-pc-windows-msvc binary_name: zenyx-aarch64-windows ext: ".exe" + linker: "" command: xwin build args: --target aarch64-pc-windows-msvc --release - - target: x86_64-apple-darwin - binary_name: zenyx-x86_64-macos - ext: "" - command: zigbuild - args: --target x86_64-apple-darwin --release - - target: aarch64-apple-darwin - binary_name: zenyx-aarch64-macos - ext: "" - command: zigbuild - args: --target aarch64-apple-darwin --release + #- target: x86_64-apple-darwin + # binary_name: zenyx-x86_64-macos + # ext: "" + # linker: "" + #command: zigbuild + #args: --target x86_64-apple-darwin --release + #target: aarch64-apple-darwin + #binary_name: zenyx-aarch64-macos + #ext: "" + #linker: "" + #command: zigbuild + #args: --target aarch64-apple-darwin --release steps: - name: 📥 Checkout source @@ -80,10 +86,14 @@ jobs: mkdir -p artifacts cp target/${{ matrix.target }}/release/zenyx${{ matrix.ext }} artifacts/${{ matrix.binary_name }}${{ matrix.ext }} - - name: 🛠️ Pathelf - if: ${{ matrix.target }} == x86_64-unknown-linux-gnu || ${{ matrix.target }} == aarch64-unknown-linux-gnu + - name: 🛠️ Patchelf + if: ${{ + matrix.target == 'x86_64-unknown-linux-gnu' || + matrix.target == 'aarch64-unknown-linux-gnu' + }} run: | - nix run nixpkgs#patchelf -- --set-interpreter /lib64/ld-linux-x86-64.so.2 artifacts/${{ matrix.binary_name }}${{ matrix.ext }} + nix run --extra-experimental-features nix-command --extra-experimental-features flakes nixpkgs#patchelf ${{ matrix.linker }} -- --set-interpreter "" \ + artifacts/${{ matrix.binary_name }}${{ matrix.ext }} - name: ⬆️ Upload artifact uses: https://code.forgejo.org/forgejo/upload-artifact@v4 From ebef712ee0f0049049027e965bf4e7407e5fad49 Mon Sep 17 00:00:00 2001 From: BitSyndicate Date: Thu, 1 May 2025 22:34:10 +0200 Subject: [PATCH 9/9] fix(ci): actually set linker dynamically --- .forgejo/workflows/build-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/build-release.yml b/.forgejo/workflows/build-release.yml index 1d80eb5..69aea21 100644 --- a/.forgejo/workflows/build-release.yml +++ b/.forgejo/workflows/build-release.yml @@ -92,7 +92,7 @@ jobs: matrix.target == 'aarch64-unknown-linux-gnu' }} run: | - nix run --extra-experimental-features nix-command --extra-experimental-features flakes nixpkgs#patchelf ${{ matrix.linker }} -- --set-interpreter "" \ + 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