├── .github ├── dependabot.yml └── workflows │ ├── automation.yml │ └── pr.yml ├── .gitignore ├── LICENSE ├── README.md ├── doc.awk ├── flake.lock ├── flake.nix ├── packages └── qoi.nix ├── src ├── mach.nix ├── outputs.nix ├── package.nix ├── test.nix └── versions.nix └── templates ├── core ├── .gitattributes ├── .gitignore ├── README.md ├── build.zig ├── build.zig.zon ├── build.zig.zon2json-lock ├── flake.nix └── src │ ├── App.zig │ └── shader.wgsl ├── engine ├── .gitattributes ├── .gitignore ├── build.zig ├── build.zig.zon ├── build.zig.zon2json-lock ├── flake.nix └── src │ ├── App.zig │ ├── Renderer.zig │ └── shader.wgsl └── flake.nix /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Set update schedule for GitHub Actions 2 | 3 | version: 2 4 | updates: 5 | 6 | - package-ecosystem: "github-actions" 7 | directory: "/" 8 | schedule: 9 | # Check for updates to GitHub Actions every week 10 | interval: "weekly" 11 | -------------------------------------------------------------------------------- /.github/workflows/automation.yml: -------------------------------------------------------------------------------- 1 | name: automation 2 | 3 | on: 4 | schedule: 5 | - cron: "0 0 * * *" 6 | workflow_dispatch: 7 | 8 | jobs: 9 | automation: 10 | runs-on: ubuntu-latest 11 | 12 | permissions: 13 | id-token: write 14 | contents: write 15 | 16 | steps: 17 | - run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 18 | - uses: actions/checkout@v4 19 | - uses: DeterminateSystems/nix-installer-action@main 20 | with: 21 | determinate: true 22 | - uses: DeterminateSystems/flakehub-cache-action@main 23 | - uses: cachix/cachix-action@master 24 | with: 25 | name: mach-flake 26 | authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' 27 | skipAddingSubstituter: true 28 | - run: | 29 | nix flake update 30 | nix run .#mach-update 31 | nix run .#test-all 32 | - uses: test-room-7/action-update-file@v2.0.0 33 | with: 34 | branch: ${{ github.head_ref || github.ref_name }} 35 | file-path: src/versions.nix 36 | commit-msg: Update versions.nix 37 | github-token: ${{ secrets.GITHUB_TOKEN }} 38 | - uses: test-room-7/action-update-file@v2.0.0 39 | with: 40 | branch: ${{ github.head_ref || github.ref_name }} 41 | file-path: README.md 42 | commit-msg: Update README 43 | github-token: ${{ secrets.GITHUB_TOKEN }} 44 | - uses: test-room-7/action-update-file@v2.0.0 45 | with: 46 | branch: ${{ github.head_ref || github.ref_name }} 47 | file-path: templates/** 48 | commit-msg: Update templates 49 | github-token: ${{ secrets.GITHUB_TOKEN }} 50 | - run: nix run .#mach-update-flakes 51 | - uses: test-room-7/action-update-file@v2.0.0 52 | with: 53 | branch: ${{ github.head_ref || github.ref_name }} 54 | file-path: templates/** 55 | commit-msg: Update templates rev 56 | github-token: ${{ secrets.GITHUB_TOKEN }} 57 | -------------------------------------------------------------------------------- /.github/workflows/pr.yml: -------------------------------------------------------------------------------- 1 | name: pr 2 | 3 | on: 4 | pull_request: 5 | workflow_dispatch: 6 | 7 | jobs: 8 | pr: 9 | runs-on: ${{ matrix.os }} 10 | 11 | permissions: 12 | id-token: write 13 | contents: write 14 | 15 | strategy: 16 | matrix: 17 | os: [ubuntu-latest, macos-latest] 18 | 19 | steps: 20 | - if: matrix.os == 'ubuntu-latest' 21 | run: sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 22 | - uses: actions/checkout@v4 23 | - uses: DeterminateSystems/nix-installer-action@main 24 | with: 25 | determinate: true 26 | - uses: DeterminateSystems/flakehub-cache-action@main 27 | - run: | 28 | nix run .#mach-update-flakes 29 | nix run .#test-all 30 | nix run .#readme 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | templates/*/flake.lock 2 | templates/*/result 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (Expat) 2 | 3 | Copyright (c) 2024 Vetoniemi Jari Juhani 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mach Engine Flake 2 | 3 | Flake that allows you to get started with Mach engine quickly. 4 | 5 | https://machengine.org/ 6 | 7 | * Cachix: `cachix use mach-flake` 8 | 9 | --- 10 | 11 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 12 | 13 | * Mach Zig: `0.14.0-dev.2577+271452d22 @ 2024-12-30` 14 | * Mach Engine: `af1cf9865bbd7e79e05c1a86560945afd2342891` 15 | 16 | ### Mach Engine 17 | 18 | ```bash 19 | nix flake init -t github:Cloudef/mach-flake#engine 20 | nix run . 21 | # for more options check the flake.nix file 22 | ``` 23 | 24 | ### Mach Core 25 | 26 | ```bash 27 | nix flake init -t github:Cloudef/mach-flake#core 28 | nix run . 29 | # for more options check the flake.nix file 30 | ``` 31 | 32 | ### Using Mach nominated Zig directly 33 | 34 | ```bash 35 | nix run github:Cloudef/mach-flake -- version 36 | nix run github:Cloudef/mach-flake#2024_11_0 -- version 37 | ``` 38 | 39 | ## Shell for building and running a Mach project 40 | 41 | ```bash 42 | nix develop github:Cloudef/mach-flake 43 | ``` 44 | 45 | ## Crude documentation 46 | 47 | Below is auto-generated dump of important outputs in this flake. 48 | 49 | ```nix 50 | #! Structures. 51 | 52 | #:! Helper function for building and running Mach projects. 53 | #:! For more options see zig-env from 54 | mach-env = { 55 | # Zig version to use. Normally there is no need to change this. 56 | zig ? zigv.latest, 57 | ... 58 | }: { ... }; 59 | 60 | #! mach nativeBuildInputs for a target 61 | machNativeBuildInputs = []; 62 | 63 | #! mach buildInputs for a target 64 | machBuildInputsForTarget = target: []; 65 | 66 | #! mach zigWrapperLibs for a target 67 | machWrapperLibsForTarget = target: with env.binaryPkgsForTarget target; [] 68 | ++ env.pkgs.lib.optionals ((env.target target).os == "linux") [ 69 | vulkan-loader libGL 70 | xorg.libX11 xorg.libXext xorg.libXfixes xorg.libXi xorg.libXrender 71 | xorg.libXrandr xorg.libXinerama xorg.libXcursor xorg.xorgproto 72 | wayland-scanner wayland libxkbcommon libdecor 73 | alsa-lib pulseaudio 74 | ]; 75 | 76 | 77 | #! All mach dependencies required for building, linking and running 78 | machDeps = machNativeBuildInputs 79 | ++ (machBuildInputsForTarget system) 80 | ++ (machWrapperLibsForTarget system); 81 | 82 | #! --- Outputs of mach-env {} function. 83 | #! access: (mach-env {}).thing 84 | 85 | #! Flake app helper (without root dir restriction). 86 | app-no-root = deps: script: env.app-no-root (deps ++ machDeps) script; 87 | 88 | #! Flake app helper. 89 | app = deps: script: env.app (deps ++ machDeps) script; 90 | 91 | #! Creates dev shell. 92 | mkShell = { 93 | nativeBuildInputs ? [], 94 | ... 95 | } @attrs: env.mkShell (attrs // { 96 | nativeBuildInputs = nativeBuildInputs ++ machDeps; 97 | }); 98 | 99 | #! Packages mach project. 100 | #! For more information see the flake at 101 | package = machPackage; 102 | 103 | #! Update Mach deps in build.zig.zon 104 | #! Handy helper if you decide to update mach-flake 105 | #! This does not update your build.zig.zon2json-lock file 106 | updateMachDeps = let 107 | mach = (env.fromZON ./templates/engine/build.zig.zon).dependencies.mach; 108 | in with pkgs; env.app [ gnused jq env.zig2nix ] '' 109 | replace() { 110 | while { 111 | read -r url; 112 | read -r hash; 113 | } do 114 | sed -i -e "s;$url;$2;" -e "s;$hash;$3;" build.zig.zon 115 | done < <(zig2nix zon2json build.zig.zon | jq -r ".dependencies.\"$1\" | .url, .hash") 116 | } 117 | replace mach "${mach.url}" "${mach.hash}" 118 | ''; 119 | 120 | 121 | #! QOI - The “Quite OK Image Format” for fast, lossless image compression 122 | #! Packages the `qoiconv` binary. 123 | #! 124 | extraPkgs.qoi = env.pkgs.callPackage ./packages/qoi.nix {}; 125 | 126 | #! Autofix tool 127 | #! https://github.com/ziglang/zig/issues/17584 128 | extraPkgs.autofix = autofix-for-zig zig; 129 | 130 | #! --- Architecture dependent flake outputs. 131 | #! access: `mach.outputs.thing.${system}` 132 | 133 | #! Helper function for building and running Mach projects. 134 | inherit mach-env; 135 | 136 | #! Expose mach nominated zig versions and extra packages. 137 | #! 138 | packages = (mapAttrs' (k: v: nameValuePair ("zig-mach-" + k) v) zigv) // test-env.extraPkgs; 139 | 140 | #! Develop shell for building and running Mach projects. 141 | #! nix develop .#zig_version 142 | #! example: nix develop .#latest 143 | #! example: nix develop .#2024_11_0 144 | devShells = flake-outputs.devShells // { 145 | default = flake-outputs.devShells.latest; 146 | }; 147 | 148 | #! --- Generic flake outputs. 149 | #! access: `mach.outputs.thing` 150 | 151 | #! Mach engine project template 152 | #! nix flake init -t templates#engine 153 | templates.engine = rec { 154 | path = ./templates/engine; 155 | description = "Mach engine project"; 156 | welcomeText = welcome-template description '' 157 | - Mach engine: https://machengine.org/engine/ 158 | ''; 159 | }; 160 | 161 | #! Mach core project template 162 | #! nix flake init -t templates#core 163 | templates.core = rec { 164 | path = ./templates/core; 165 | description = "Mach core project"; 166 | welcomeText = welcome-template description '' 167 | - Mach core: https://machengine.org/core/ 168 | ''; 169 | }; 170 | ``` 171 | -------------------------------------------------------------------------------- /doc.awk: -------------------------------------------------------------------------------- 1 | IN_SCRIPT == 0 && /#!/ { 2 | PRINT = 1; 3 | if (SCOLON > 0) { 4 | print(""); 5 | SCOLON = 0; 6 | INDENT = 0; 7 | } 8 | } 9 | 10 | IN_SCRIPT == 0 && /#:!/ { 11 | PRINT = 1; 12 | COLON = 1; 13 | } 14 | 15 | IN_SCRIPT == 0 && COLON == 1 && /}.*:/ { 16 | PRINT = 0; 17 | COLON = 0; 18 | SCOLON = 0; 19 | INDENT = 0; 20 | print("}: { ... };\n"); 21 | } 22 | 23 | { COMMENT = 0 }; 24 | 25 | /#/ { COMMENT = 1 }; 26 | 27 | PRINT == 1 && COMMENT == 0 && IN_SCRIPT == 0 && /=/ { SCOLON += 1; } 28 | PRINT == 1 && COMMENT == 0 && IN_SCRIPT == 0 && /with/ { SCOLON += 1; } 29 | PRINT == 1 && COMMENT == 0 && IN_SCRIPT == 0 && /inherit/ { SCOLON += 1; } 30 | 31 | INDENT > 0 && COMMENT == 0 && IN_SCRIPT == 0 && /}[);: ]+/ && ! /[ ]+{/ { INDENT -= 1; } 32 | INDENT > 0 && COMMENT == 0 && IN_SCRIPT == 0 && /^[ ]*in[ ]+/ { INDENT -= 1; } 33 | SCOLON > 0 && COMMENT == 0 && IN_SCRIPT == 1 && /'';/ { INDENT -= 1; IN_SCRIPT = 0; } 34 | 35 | PRINT == 1 { 36 | if (IN_SCRIPT) { 37 | for (i = 0; i < 9; i++) gsub(/^[ \t]/, "", $0); 38 | } else { 39 | gsub(/^[ \t]+/, "", $0); 40 | } 41 | for (i = 0; i < INDENT; i++) printf(" "); 42 | print($0); 43 | } 44 | 45 | SCOLON > 0 && COMMENT == 0 && IN_SCRIPT == 0 && /[ ]+{/ && ! /}[);: ]+/ { INDENT += 1; }A 46 | SCOLON > 0 && COMMENT == 0 && IN_SCRIPT == 0 && /[ ]+let/ { INDENT += 1; } 47 | SCOLON > 0 && COMMENT == 0 && IN_SCRIPT == 0 && /''$/ { INDENT += 1; IN_SCRIPT = 1; } 48 | 49 | SCOLON > 0 && COMMENT == 0 && IN_SCRIPT == 0 && /;/ { 50 | SCOLON -= 1; 51 | if (SCOLON == 0) { 52 | PRINT = 0; 53 | INDENT = 0; 54 | print(""); 55 | } 56 | } 57 | 58 | PRINT == 1 && SCOLON == 0 && IN_SCRIPT == 0 && /^\s*$/ { 59 | PRINT = 0; 60 | } 61 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "flake-utils": { 4 | "inputs": { 5 | "systems": "systems" 6 | }, 7 | "locked": { 8 | "lastModified": 1731533236, 9 | "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", 10 | "owner": "numtide", 11 | "repo": "flake-utils", 12 | "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", 13 | "type": "github" 14 | }, 15 | "original": { 16 | "owner": "numtide", 17 | "repo": "flake-utils", 18 | "type": "github" 19 | } 20 | }, 21 | "nixpkgs": { 22 | "locked": { 23 | "lastModified": 1743125403, 24 | "narHash": "sha256-ax5yY7IA9XaO+qHiu2XNs7oivWlD4+YG+G8+VaAl8bE=", 25 | "owner": "nixos", 26 | "repo": "nixpkgs", 27 | "rev": "b25d37292b5b6a56a6a508d4632feceb52266333", 28 | "type": "github" 29 | }, 30 | "original": { 31 | "owner": "nixos", 32 | "repo": "nixpkgs", 33 | "type": "github" 34 | } 35 | }, 36 | "root": { 37 | "inputs": { 38 | "zig2nix": "zig2nix" 39 | } 40 | }, 41 | "systems": { 42 | "locked": { 43 | "lastModified": 1681028828, 44 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 45 | "owner": "nix-systems", 46 | "repo": "default", 47 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 48 | "type": "github" 49 | }, 50 | "original": { 51 | "owner": "nix-systems", 52 | "repo": "default", 53 | "type": "github" 54 | } 55 | }, 56 | "zig2nix": { 57 | "inputs": { 58 | "flake-utils": "flake-utils", 59 | "nixpkgs": "nixpkgs" 60 | }, 61 | "locked": { 62 | "lastModified": 1743144458, 63 | "narHash": "sha256-0vS/7AWx4O7vI7kJ156tk+nahxQb+HXd/CiFx6ZPBQE=", 64 | "owner": "Cloudef", 65 | "repo": "zig2nix", 66 | "rev": "de3fa1e6475471ca6c76ba9a88dfa4df2befe13c", 67 | "type": "github" 68 | }, 69 | "original": { 70 | "owner": "Cloudef", 71 | "repo": "zig2nix", 72 | "type": "github" 73 | } 74 | } 75 | }, 76 | "root": "root", 77 | "version": 7 78 | } 79 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "mach engine flake"; 3 | inputs.zig2nix.url = "github:Cloudef/zig2nix"; 4 | 5 | outputs = { zig2nix, ... }: with builtins; let 6 | flake-utils = zig2nix.inputs.flake-utils; 7 | outputs = (flake-utils.lib.eachDefaultSystem (system: let 8 | #! Structures. 9 | 10 | bootstrapZigEnv = let 11 | zig-env = zig2nix.zig-env.${system}; 12 | in (zig-env {}).pkgs.callPackage zig-env; 13 | 14 | # Mach nominated Zig versions. 15 | # 16 | zigv = let 17 | zig-env = zig2nix.zig-env.${system}; 18 | callPackage = (zig-env {}).pkgs.callPackage; 19 | in import ./src/versions.nix { 20 | inherit (zig-env {}) zigHook; 21 | zigBin = callPackage "${zig2nix}/src/zig/bin.nix"; 22 | zigSrc = callPackage "${zig2nix}/src/zig/src.nix"; 23 | }; 24 | 25 | autofix-for-zig = zig: pkgs.writeShellApplication { 26 | name = "zig-autofix"; 27 | runtimeInputs = with pkgs; [ zig gnused gnugrep ]; 28 | text = '' 29 | if [[ ! -d "$1" ]]; then 30 | printf 'error: no such directory: %s\n' "$@" 31 | exit 1 32 | fi 33 | 34 | cd "$@" 35 | has_wontfix=0 36 | 37 | while { 38 | IFS=$':' read -r file line col msg; 39 | } do 40 | if [[ "$msg" ]]; then 41 | case "$msg" in 42 | *"local variable is never mutated") 43 | printf 'autofix: %s\n' "$file:$line:$col:$msg" 1>&2 44 | sed -i "''${line}s/var/const/" "$file" 45 | ;; 46 | *) 47 | printf 'wontfix: %s\n' "$file:$line:$col:$msg" 1>&2 48 | has_wontfix=1 49 | ;; 50 | esac 51 | fi 52 | done < <(zig build 2>&1 | grep "error:") 53 | 54 | exit $has_wontfix 55 | ''; 56 | }; 57 | 58 | #:! Helper function for building and running Mach projects. 59 | #:! For more options see zig-env from 60 | mach-env = { 61 | # Zig version to use. Normally there is no need to change this. 62 | zig ? zigv.latest, 63 | ... 64 | } @attrs: let 65 | env = bootstrapZigEnv (attrs // { inherit zig; }); 66 | 67 | #! mach nativeBuildInputs for a target 68 | machNativeBuildInputs = []; 69 | 70 | #! mach buildInputs for a target 71 | machBuildInputsForTarget = target: []; 72 | 73 | #! mach zigWrapperLibs for a target 74 | machWrapperLibsForTarget = target: with env.binaryPkgsForTarget target; [] 75 | ++ env.pkgs.lib.optionals ((env.target target).os == "linux") [ 76 | vulkan-loader libGL 77 | xorg.libX11 xorg.libXext xorg.libXfixes xorg.libXi xorg.libXrender 78 | xorg.libXrandr xorg.libXinerama xorg.libXcursor xorg.xorgproto 79 | wayland-scanner wayland libxkbcommon libdecor 80 | alsa-lib pulseaudio 81 | ]; 82 | 83 | #! All mach dependencies required for building, linking and running 84 | machDeps = machNativeBuildInputs 85 | ++ (machBuildInputsForTarget system) 86 | ++ (machWrapperLibsForTarget system); 87 | 88 | # Package a mach project 89 | machPackage = env.pkgs.callPackage (env.pkgs.callPackage ./src/package.nix { 90 | inherit (env) target; 91 | inherit machNativeBuildInputs machBuildInputsForTarget machWrapperLibsForTarget; 92 | zigPackage = env.package; 93 | }); 94 | in (env // { 95 | #! --- Outputs of mach-env {} function. 96 | #! access: (mach-env {}).thing 97 | 98 | inherit machNativeBuildInputs machBuildInputsForTarget machWrapperLibsForTarget machDeps; 99 | 100 | #! Flake app helper (without root dir restriction). 101 | app-no-root = deps: script: env.app-no-root (deps ++ machDeps) script; 102 | 103 | #! Flake app helper. 104 | app = deps: script: env.app (deps ++ machDeps) script; 105 | 106 | #! Creates dev shell. 107 | mkShell = { 108 | nativeBuildInputs ? [], 109 | ... 110 | } @attrs: env.mkShell (attrs // { 111 | nativeBuildInputs = nativeBuildInputs ++ machDeps; 112 | }); 113 | 114 | #! Packages mach project. 115 | #! For more information see the flake at 116 | package = machPackage; 117 | 118 | #! Update Mach deps in build.zig.zon 119 | #! Handy helper if you decide to update mach-flake 120 | #! This does not update your build.zig.zon2json-lock file 121 | updateMachDeps = let 122 | mach = (env.fromZON ./templates/engine/build.zig.zon).dependencies.mach; 123 | in with pkgs; env.app [ gnused jq env.zig2nix ] '' 124 | replace() { 125 | while { 126 | read -r url; 127 | read -r hash; 128 | } do 129 | sed -i -e "s;$url;$2;" -e "s;$hash;$3;" build.zig.zon 130 | done < <(zig2nix zon2json build.zig.zon | jq -r ".dependencies.\"$1\" | .url, .hash") 131 | } 132 | replace mach "${mach.url}" "${mach.hash}" 133 | ''; 134 | 135 | #! QOI - The “Quite OK Image Format” for fast, lossless image compression 136 | #! Packages the `qoiconv` binary. 137 | #! 138 | extraPkgs.qoi = env.pkgs.callPackage ./packages/qoi.nix {}; 139 | 140 | #! Autofix tool 141 | #! https://github.com/ziglang/zig/issues/17584 142 | extraPkgs.autofix = autofix-for-zig zig; 143 | }); 144 | 145 | # Default mach env used for tests and automation 146 | test-env = mach-env {}; 147 | test-app = test-env.app-bare; 148 | pkgs = test-env.pkgs; 149 | 150 | test = removeAttrs (pkgs.callPackage src/test.nix { 151 | inherit test-app; 152 | zig-env = test-env; 153 | }) [ "override" "overrideDerivation" "overrideAttrs" ]; 154 | 155 | mach = removeAttrs (pkgs.callPackage src/mach.nix { 156 | inherit test-app; 157 | inherit (test-env) zig zig2nix; 158 | }) [ "override" "overrideDerivation" "overrideAttrs" ]; 159 | 160 | flake-outputs = pkgs.callPackage (import ./src/outputs.nix) { 161 | inherit zigv mach-env; 162 | }; 163 | in with pkgs.lib; { 164 | #! --- Architecture dependent flake outputs. 165 | #! access: `mach.outputs.thing.${system}` 166 | 167 | #! Helper function for building and running Mach projects. 168 | inherit mach-env; 169 | 170 | #! Expose mach nominated zig versions and extra packages. 171 | #! 172 | packages = (mapAttrs' (k: v: nameValuePair ("zig-mach-" + k) v) zigv) // test-env.extraPkgs; 173 | 174 | # Generates flake apps for all the zig versions. 175 | apps = flake-outputs.apps // { 176 | default = flake-outputs.apps.latest; 177 | 178 | # Backwards compatibility 179 | zon2json = flake-outputs.apps.zon2json-latest; 180 | zon2json-lock = flake-outputs.apps.zon2json-lock-latest; 181 | zon2nix = flake-outputs.apps.zon2nix-latest; 182 | 183 | # nix run .#update-versions 184 | update-versions = test-app [ pkgs.jq test-env.zig2nix ] '' 185 | tmp="$(mktemp)" 186 | trap 'rm -f "$tmp"' EXIT 187 | curl -sSL https://machengine.org/zig/index.json |\ 188 | jq 'with_entries(select(.key|(startswith("mach-") or endswith("-mach"))))' |\ 189 | sed 's/mach-//;s/-mach//' |\ 190 | zig2nix versions - > "$tmp" 191 | cp -f "$tmp" src/versions.nix 192 | ''; 193 | 194 | # nix run .#readme 195 | readme = let 196 | project = "Mach Engine Flake"; 197 | in with pkgs; test-app [ gawk gnused test-env.zig2nix jq ] (replaceStrings ["`"] ["\\`"] '' 198 | zonrev() { 199 | zig2nix zon2json templates/"$1"/build.zig.zon | jq -e --arg k "$2" -r '.dependencies."\($k)".url' |\ 200 | sed 's,^.*/\([0-9a-f]*\).*,\1,' 201 | } 202 | cat < templates/engine/flake.nix 20 | sed -i "s#@SED_ZIG_BIN@#mach-app#" templates/engine/flake.nix 21 | sed 's/mach-engine-project/mach-core-project/g' templates/flake.nix > templates/core/flake.nix 22 | sed -i "s#@SED_REPLACE_REV@#$flake_rev#" templates/core/flake.nix 23 | sed -i "s#@SED_ZIG_BIN@#mach-core-app#" templates/core/flake.nix 24 | ''; 25 | 26 | # nix run .#mach-update 27 | update = test-app [ coreutils gnused git zig jq zig2nix ] '' 28 | tmpdir="$(mktemp -d)" 29 | trap 'rm -rf "$tmpdir"' EXIT 30 | 31 | generate_zig_zon() { 32 | cat < templates/engine/build.zig.zon 68 | 69 | rm -rf templates/core/src 70 | cp -rf "$tmpdir"/mach/examples/core-triangle templates/core/src 71 | git add templates/core/src 72 | generate mach-core-project mach "$rev" > templates/core/build.zig.zon 73 | 74 | mach_update=1 75 | fi 76 | 77 | if [[ $mach_update == 0 ]]; then 78 | echo "Templates are up-to-date" 79 | exit 0 80 | fi 81 | 82 | nix run .#update-versions 83 | nix run .#mach-update-flakes -- force 84 | for var in engine core; do 85 | (cd templates/"$var"; nix run --override-input mach ../.. .#zig2nix -- zon2lock) 86 | # Call using nix run because update-versions may change the mach nominated zig version 87 | nix run .#autofix -- templates/"$var" 88 | done 89 | 90 | nix run .#readme > README.md 91 | ''; 92 | } 93 | -------------------------------------------------------------------------------- /src/outputs.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib 3 | , zigv 4 | , mach-env 5 | }: 6 | 7 | with lib; 8 | with builtins; 9 | 10 | { 11 | apps = mergeAttrsList (attrValues (mapAttrs (k: zig: let 12 | env = mach-env { inherit zig; }; 13 | in { 14 | "${k}" = env.app-no-root [] ''zig "$@"''; 15 | "zig2nix-${k}" = env.app-no-root [] ''zig2nix "$@"''; 16 | 17 | # Backwards compatiblity 18 | "zon2json-${k}" = env.app-no-root [] ''zig2nix zon2json "$@"''; 19 | "zon2json-lock-${k}" = env.app-no-root [] ''zig2nix zon2lock "$@"''; 20 | "zon2nix-${k}" = env.app-no-root [] ''zig2nix zon2nix "$@"''; 21 | }) zigv)); 22 | 23 | devShells = mergeAttrsList (attrValues (mapAttrs (k: zig: let 24 | env = mach-env { inherit zig; }; 25 | in { 26 | "${k}" = env.mkShell {}; 27 | }) zigv)); 28 | } 29 | -------------------------------------------------------------------------------- /src/package.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib 3 | , zigPackage 4 | , machNativeBuildInputs 5 | , machBuildInputsForTarget 6 | , machWrapperLibsForTarget 7 | , target 8 | }: 9 | 10 | { 11 | stdenvNoCC 12 | , zigTarget ? null 13 | , zigPreferMusl ? false 14 | , zigWrapperLibs ? [] 15 | , nativeBuildInputs ? [] 16 | , buildInputs ? [] 17 | , ... 18 | } @userAttrs: 19 | 20 | with builtins; 21 | with lib; 22 | 23 | let 24 | config = 25 | if zigPreferMusl then 26 | replaceStrings ["-gnu"] ["-musl"] stdenvNoCC.targetPlatform.config 27 | else stdenvNoCC.targetPlatform.config; 28 | default-target = (target config).zig; 29 | resolved-target = if zigTarget != null then zigTarget else default-target; 30 | in zigPackage (userAttrs // { 31 | nativeBuildInputs = nativeBuildInputs ++ machNativeBuildInputs; 32 | buildInputs = buildInputs ++ (machBuildInputsForTarget resolved-target); 33 | zigWrapperLibs = zigWrapperLibs ++ (machWrapperLibsForTarget resolved-target); 34 | }) 35 | -------------------------------------------------------------------------------- /src/test.nix: -------------------------------------------------------------------------------- 1 | { 2 | lib 3 | , test-app 4 | , zig-env 5 | , buildPlatform 6 | }: 7 | 8 | with builtins; 9 | with lib; 10 | 11 | { 12 | # nix run .#test-package 13 | package = let 14 | # These targets are ignored for now as they don't compile 15 | blacklist = 16 | [ 17 | "armv6l-linux" "armv7l-linux" "x86_64-freebsd" "riscv64-linux" "powerpc64le-linux" "i686-linux" 18 | # (zig std) disabled due to miscompilations 19 | "aarch64-linux" 20 | ] 21 | ++ optionals (!buildPlatform.isDarwin) [ "aarch64-darwin" ]; 22 | targets = subtractLists blacklist systems.flakeExposed; 23 | in test-app [] (concatStrings (map (nix: let 24 | engine = zig-env.package { 25 | zigTarget = (zig-env.target nix).zig; 26 | src = cleanSource ../templates/engine; 27 | zigBuildFlags = [ "-Doptimize=ReleaseSmall" ]; 28 | }; 29 | core = zig-env.package { 30 | zigTarget = (zig-env.target nix).zig; 31 | src = cleanSource ../templates/core; 32 | zigBuildFlags = [ "-Doptimize=ReleaseSmall" ]; 33 | }; 34 | in '' 35 | echo "engine (${nix}): ${engine}" 36 | echo "core (${nix}): ${core}" 37 | '') targets)); 38 | 39 | # nix run .#test-templates 40 | templates = test-app [] '' 41 | for var in engine core; do 42 | nix flake check --keep-going 43 | printf -- 'run .#zig2nix (%s)\n' "$var" 44 | (cd templates/"$var"; nix run --override-input mach ../.. .#zig2nix -- help; printf '\n') 45 | printf -- 'run .#updateMachDeps (%s)\n' "$var" 46 | (cd templates/"$var"; nix run --override-input mach ../.. .#updateMachDeps; printf '\n') 47 | printf -- 'run .#test (%s)\n' "$var" 48 | (cd templates/"$var"; nix run --override-input mach ../.. .#test) 49 | printf -- 'build . (%s)\n' "$var" 50 | (cd templates/"$var"; nix build -L --override-input mach ../.. .) 51 | rm -f templates/"$var"/result 52 | rm -rf templates/"$var"/zig-out 53 | rm -rf templates/"$var"/zig-cache 54 | done 55 | ''; 56 | 57 | # nix run .#test-all 58 | all = test-app [] '' 59 | nix flake check --keep-going 60 | nix run -L .#test-templates 61 | nix run -L .#test-package 62 | ''; 63 | } 64 | -------------------------------------------------------------------------------- /src/versions.nix: -------------------------------------------------------------------------------- 1 | { 2 | zigHook, 3 | zigBin, 4 | zigSrc, 5 | }: 6 | 7 | let 8 | bin = release: zigBin { inherit zigHook release; }; 9 | src = release: zigSrc { inherit zigHook release; }; 10 | 11 | meta-latest = { 12 | version = "latest"; 13 | zigVersion = "0.14.0-dev.2577+271452d22"; 14 | date = "2024-12-30"; 15 | docs = "https://ziglang.org/documentation/master/"; 16 | stdDocs = "https://ziglang.org/documentation/master/std/"; 17 | machDocs = "https://machengine.org/docs/nominated-zig"; 18 | machNominated = "2024-12-30"; 19 | 20 | src = { 21 | tarball = "https://pkg.machengine.org/zig/zig-0.14.0-dev.2577+271452d22.tar.xz"; 22 | shasum = "a979e021e3be89f45eccf6d081032da03afc674db753ab400ad8c85b7ee3c089"; 23 | size = 17415084; 24 | }; 25 | 26 | bootstrap = { 27 | tarball = "https://pkg.machengine.org/zig/zig-bootstrap-0.14.0-dev.2577+271452d22.tar.xz"; 28 | shasum = "e89811ad94fc63b4b65314d03cee4313e04e9db2eb38d6b95cfc262f054461be"; 29 | size = 47683004; 30 | }; 31 | 32 | x86_64-darwin = { 33 | tarball = "https://pkg.machengine.org/zig/zig-macos-x86_64-0.14.0-dev.2577+271452d22.tar.xz"; 34 | shasum = "19e0b3673fd16609f7ce504faadb1c988270c2ed7cb250a7a9cb74beb22a4c23"; 35 | size = 50641584; 36 | }; 37 | 38 | aarch64-darwin = { 39 | tarball = "https://pkg.machengine.org/zig/zig-macos-aarch64-0.14.0-dev.2577+271452d22.tar.xz"; 40 | shasum = "034d395256d9f8b9f4e9fb07bc3428336b5138853dc2d518898fa0fa8fab434f"; 41 | size = 45544344; 42 | }; 43 | 44 | x86_64-linux = { 45 | tarball = "https://pkg.machengine.org/zig/zig-linux-x86_64-0.14.0-dev.2577+271452d22.tar.xz"; 46 | shasum = "7be6abdebfa970c6138d165b348d0464e84f16f531e71cb20c0e052fae1d8c8d"; 47 | size = 48706328; 48 | }; 49 | 50 | aarch64-linux = { 51 | tarball = "https://pkg.machengine.org/zig/zig-linux-aarch64-0.14.0-dev.2577+271452d22.tar.xz"; 52 | shasum = "cafbc9b83e624d8e7e55c41991c2c8d33b52d25661d94c27f236fb622ce168e4"; 53 | size = 44578188; 54 | }; 55 | 56 | armv7l-linux = { 57 | tarball = "https://pkg.machengine.org/zig/zig-linux-armv7a-0.14.0-dev.2577+271452d22.tar.xz"; 58 | shasum = "ce4a447027be85577f7a739a09345931572dd69f9dc68d5b53d1cf667bfaf664"; 59 | size = 45783832; 60 | }; 61 | 62 | riscv64-linux = { 63 | tarball = "https://pkg.machengine.org/zig/zig-linux-riscv64-0.14.0-dev.2577+271452d22.tar.xz"; 64 | shasum = "99ee8d18a6f9a513f203a2d8e0024edd8fee710b9ae267ba238bbb98cedbb754"; 65 | size = 47684988; 66 | }; 67 | 68 | powerpc64le-linux = { 69 | tarball = "https://pkg.machengine.org/zig/zig-linux-powerpc64le-0.14.0-dev.2577+271452d22.tar.xz"; 70 | shasum = "1404f4b51b861883145b4757f94c46e9656b0c6b9e00ccd7e8499df691a32974"; 71 | size = 48376852; 72 | }; 73 | 74 | i686-linux = { 75 | tarball = "https://pkg.machengine.org/zig/zig-linux-x86-0.14.0-dev.2577+271452d22.tar.xz"; 76 | shasum = "f9a4f54b3f014a704793725e79f9ed377b87af681a8a947804d14d2bf954eb82"; 77 | size = 51273288; 78 | }; 79 | 80 | loongarch64-linux = { 81 | tarball = "https://pkg.machengine.org/zig/zig-linux-loongarch64-0.14.0-dev.2577+271452d22.tar.xz"; 82 | shasum = "b70062294fb49e857f5bba0154c08966973080766af12e1b68dbfab743f0550d"; 83 | size = 45450020; 84 | }; 85 | 86 | x86_64-mingw32 = { 87 | tarball = "https://pkg.machengine.org/zig/zig-windows-x86_64-0.14.0-dev.2577+271452d22.zip"; 88 | shasum = "23f0c4a4f789b6e1a82861bc14ea80652ba1d75784fcca55e74d50be24cf60e9"; 89 | size = 83182005; 90 | }; 91 | 92 | aarch64-mingw32 = { 93 | tarball = "https://pkg.machengine.org/zig/zig-windows-aarch64-0.14.0-dev.2577+271452d22.zip"; 94 | shasum = "3563af9bf14a8e510c02c7858320db712348557b71a7d9844d8a960363207518"; 95 | size = 79117742; 96 | }; 97 | 98 | i686-mingw32 = { 99 | tarball = "https://pkg.machengine.org/zig/zig-windows-x86-0.14.0-dev.2577+271452d22.zip"; 100 | shasum = "f51180c3423093cf5f908686c4c0db8f091fafe22debfa1ffbcdf0260e713ece"; 101 | size = 84906339; 102 | }; 103 | }; 104 | 105 | meta-2024_11_0 = { 106 | version = "2024.11.0"; 107 | zigVersion = "0.14.0-dev.2577+271452d22"; 108 | date = "2024-12-30"; 109 | docs = "https://ziglang.org/documentation/master/"; 110 | stdDocs = "https://ziglang.org/documentation/master/std/"; 111 | machDocs = "https://machengine.org/docs/nominated-zig"; 112 | machNominated = "2024-12-30"; 113 | 114 | src = { 115 | tarball = "https://pkg.machengine.org/zig/zig-0.14.0-dev.2577+271452d22.tar.xz"; 116 | shasum = "a979e021e3be89f45eccf6d081032da03afc674db753ab400ad8c85b7ee3c089"; 117 | size = 17415084; 118 | }; 119 | 120 | bootstrap = { 121 | tarball = "https://pkg.machengine.org/zig/zig-bootstrap-0.14.0-dev.2577+271452d22.tar.xz"; 122 | shasum = "e89811ad94fc63b4b65314d03cee4313e04e9db2eb38d6b95cfc262f054461be"; 123 | size = 47683004; 124 | }; 125 | 126 | x86_64-darwin = { 127 | tarball = "https://pkg.machengine.org/zig/zig-macos-x86_64-0.14.0-dev.2577+271452d22.tar.xz"; 128 | shasum = "19e0b3673fd16609f7ce504faadb1c988270c2ed7cb250a7a9cb74beb22a4c23"; 129 | size = 50641584; 130 | }; 131 | 132 | aarch64-darwin = { 133 | tarball = "https://pkg.machengine.org/zig/zig-macos-aarch64-0.14.0-dev.2577+271452d22.tar.xz"; 134 | shasum = "034d395256d9f8b9f4e9fb07bc3428336b5138853dc2d518898fa0fa8fab434f"; 135 | size = 45544344; 136 | }; 137 | 138 | x86_64-linux = { 139 | tarball = "https://pkg.machengine.org/zig/zig-linux-x86_64-0.14.0-dev.2577+271452d22.tar.xz"; 140 | shasum = "7be6abdebfa970c6138d165b348d0464e84f16f531e71cb20c0e052fae1d8c8d"; 141 | size = 48706328; 142 | }; 143 | 144 | aarch64-linux = { 145 | tarball = "https://pkg.machengine.org/zig/zig-linux-aarch64-0.14.0-dev.2577+271452d22.tar.xz"; 146 | shasum = "cafbc9b83e624d8e7e55c41991c2c8d33b52d25661d94c27f236fb622ce168e4"; 147 | size = 44578188; 148 | }; 149 | 150 | armv7l-linux = { 151 | tarball = "https://pkg.machengine.org/zig/zig-linux-armv7a-0.14.0-dev.2577+271452d22.tar.xz"; 152 | shasum = "ce4a447027be85577f7a739a09345931572dd69f9dc68d5b53d1cf667bfaf664"; 153 | size = 45783832; 154 | }; 155 | 156 | riscv64-linux = { 157 | tarball = "https://pkg.machengine.org/zig/zig-linux-riscv64-0.14.0-dev.2577+271452d22.tar.xz"; 158 | shasum = "99ee8d18a6f9a513f203a2d8e0024edd8fee710b9ae267ba238bbb98cedbb754"; 159 | size = 47684988; 160 | }; 161 | 162 | powerpc64le-linux = { 163 | tarball = "https://pkg.machengine.org/zig/zig-linux-powerpc64le-0.14.0-dev.2577+271452d22.tar.xz"; 164 | shasum = "1404f4b51b861883145b4757f94c46e9656b0c6b9e00ccd7e8499df691a32974"; 165 | size = 48376852; 166 | }; 167 | 168 | i686-linux = { 169 | tarball = "https://pkg.machengine.org/zig/zig-linux-x86-0.14.0-dev.2577+271452d22.tar.xz"; 170 | shasum = "f9a4f54b3f014a704793725e79f9ed377b87af681a8a947804d14d2bf954eb82"; 171 | size = 51273288; 172 | }; 173 | 174 | loongarch64-linux = { 175 | tarball = "https://pkg.machengine.org/zig/zig-linux-loongarch64-0.14.0-dev.2577+271452d22.tar.xz"; 176 | shasum = "b70062294fb49e857f5bba0154c08966973080766af12e1b68dbfab743f0550d"; 177 | size = 45450020; 178 | }; 179 | 180 | x86_64-mingw32 = { 181 | tarball = "https://pkg.machengine.org/zig/zig-windows-x86_64-0.14.0-dev.2577+271452d22.zip"; 182 | shasum = "23f0c4a4f789b6e1a82861bc14ea80652ba1d75784fcca55e74d50be24cf60e9"; 183 | size = 83182005; 184 | }; 185 | 186 | aarch64-mingw32 = { 187 | tarball = "https://pkg.machengine.org/zig/zig-windows-aarch64-0.14.0-dev.2577+271452d22.zip"; 188 | shasum = "3563af9bf14a8e510c02c7858320db712348557b71a7d9844d8a960363207518"; 189 | size = 79117742; 190 | }; 191 | 192 | i686-mingw32 = { 193 | tarball = "https://pkg.machengine.org/zig/zig-windows-x86-0.14.0-dev.2577+271452d22.zip"; 194 | shasum = "f51180c3423093cf5f908686c4c0db8f091fafe22debfa1ffbcdf0260e713ece"; 195 | size = 84906339; 196 | }; 197 | }; 198 | 199 | meta-2024_10_0 = { 200 | version = "2024.10.0"; 201 | zigVersion = "0.14.0-dev.1911+3bf89f55c"; 202 | date = "2024-10-14"; 203 | docs = "https://ziglang.org/documentation/master/"; 204 | stdDocs = "https://ziglang.org/documentation/master/std/"; 205 | machDocs = "https://machengine.org/docs/nominated-zig"; 206 | machNominated = "2024-10-14"; 207 | 208 | src = { 209 | tarball = "https://pkg.machengine.org/zig/zig-0.14.0-dev.1911+3bf89f55c.tar.xz"; 210 | shasum = "53b40ced023a41631014931c1141d9d4245ce41b674c46c34beceb2ba24ba9f9"; 211 | size = 17611756; 212 | }; 213 | 214 | bootstrap = { 215 | tarball = "https://pkg.machengine.org/zig/zig-bootstrap-0.14.0-dev.1911+3bf89f55c.tar.xz"; 216 | shasum = "213284ce3259ac6ebd085f6f3d4e3d25dc855de2d39975d3c094fbfde2662a21"; 217 | size = 47879500; 218 | }; 219 | 220 | x86_64-darwin = { 221 | tarball = "https://pkg.machengine.org/zig/zig-macos-x86_64-0.14.0-dev.1911+3bf89f55c.tar.xz"; 222 | shasum = "07dab7e71d61465bebed305d2c8bfae53c5f3b9422dd8e481f1b04bf3812c54b"; 223 | size = 50747736; 224 | }; 225 | 226 | aarch64-darwin = { 227 | tarball = "https://pkg.machengine.org/zig/zig-macos-aarch64-0.14.0-dev.1911+3bf89f55c.tar.xz"; 228 | shasum = "fde79992e2f60d8a9155cf0d177c7c84db2a5729f716419660fc75f5d1ed2a95"; 229 | size = 46759892; 230 | }; 231 | 232 | x86_64-linux = { 233 | tarball = "https://pkg.machengine.org/zig/zig-linux-x86_64-0.14.0-dev.1911+3bf89f55c.tar.xz"; 234 | shasum = "73347307b8fcc4d5aab92b7c39f41740ae7b8ee2a82912aecb8cbbf7b6f899fd"; 235 | size = 48853352; 236 | }; 237 | 238 | aarch64-linux = { 239 | tarball = "https://pkg.machengine.org/zig/zig-linux-aarch64-0.14.0-dev.1911+3bf89f55c.tar.xz"; 240 | shasum = "d37e7c596b0bb86e3160eb0f25c8951d7f31ed78dd3f127c701fa9ff95b49298"; 241 | size = 44868320; 242 | }; 243 | 244 | armv7l-linux = { 245 | tarball = "https://pkg.machengine.org/zig/zig-linux-armv7a-0.14.0-dev.1911+3bf89f55c.tar.xz"; 246 | shasum = "ceacc87fd821a252fe15c34b4ab0539deea001b7f83837ff468126f743e1752c"; 247 | size = 45885272; 248 | }; 249 | 250 | riscv64-linux = { 251 | tarball = "https://pkg.machengine.org/zig/zig-linux-riscv64-0.14.0-dev.1911+3bf89f55c.tar.xz"; 252 | shasum = "9cde06923f402ad564cbb6fcedf07d011fa810525cdb40a6bec8cbb3f4151be4"; 253 | size = 47458608; 254 | }; 255 | 256 | powerpc64le-linux = { 257 | tarball = "https://pkg.machengine.org/zig/zig-linux-powerpc64le-0.14.0-dev.1911+3bf89f55c.tar.xz"; 258 | shasum = "7cb2d169d4849f556582751a62ca2f77e38c86a1798a805e3586e1062deafcd1"; 259 | size = 48400260; 260 | }; 261 | 262 | i686-linux = { 263 | tarball = "https://pkg.machengine.org/zig/zig-linux-x86-0.14.0-dev.1911+3bf89f55c.tar.xz"; 264 | shasum = "d8b7587cab34b25191f77c769557f174fe6f140c4b6ff230a41606b912cdc60f"; 265 | size = 54107716; 266 | }; 267 | 268 | loongarch64-linux = { 269 | tarball = "https://pkg.machengine.org/zig/zig-linux-loongarch64-0.14.0-dev.1911+3bf89f55c.tar.xz"; 270 | shasum = "e7fb9c63895d2ec536dc0f7bf16ca3d71e4daff8a5d9e7fb629fc4092015c295"; 271 | size = 45260020; 272 | }; 273 | 274 | x86_64-mingw32 = { 275 | tarball = "https://pkg.machengine.org/zig/zig-windows-x86_64-0.14.0-dev.1911+3bf89f55c.zip"; 276 | shasum = "10141d62ecdc41784cf24912dbcdc4fbafd8cac7b3818c7fe3ea4d1ab9bccfc5"; 277 | size = 82910190; 278 | }; 279 | 280 | aarch64-mingw32 = { 281 | tarball = "https://pkg.machengine.org/zig/zig-windows-aarch64-0.14.0-dev.1911+3bf89f55c.zip"; 282 | shasum = "9a600ae56d40782f174204f4715bf6f3eadf536146dc794bbbd9a662b2dae70b"; 283 | size = 78930721; 284 | }; 285 | 286 | i686-mingw32 = { 287 | tarball = "https://pkg.machengine.org/zig/zig-windows-x86-0.14.0-dev.1911+3bf89f55c.zip"; 288 | shasum = "65caad6ed7bb9e50cbc35e0c886fdd78b4cd325d97967d41fe76cafc1cc02ad8"; 289 | size = 87169135; 290 | }; 291 | }; 292 | 293 | meta-0_4_0 = { 294 | version = "0.4.0"; 295 | zigVersion = "0.13.0-dev.351+64ef45eb0"; 296 | date = "2024-06-01"; 297 | docs = "https://ziglang.org/documentation/master/"; 298 | stdDocs = "https://ziglang.org/documentation/master/std/"; 299 | machDocs = "https://machengine.org/docs/nominated-zig"; 300 | machNominated = "2024-06-01"; 301 | 302 | src = { 303 | tarball = "https://pkg.machengine.org/zig/zig-0.13.0-dev.351+64ef45eb0.tar.xz"; 304 | shasum = "6db25e78eca948664d4b1b1eb6b5ca6c471e0bf32b8fd19cc7c925b4d957f097"; 305 | size = 17199760; 306 | }; 307 | 308 | bootstrap = { 309 | tarball = "https://pkg.machengine.org/zig/zig-bootstrap-0.13.0-dev.351+64ef45eb0.tar.xz"; 310 | shasum = "ff545922a63807aa812dcabf37feb47d2641ab2d9f354bc03c610ee2bc69ac9e"; 311 | size = 46433700; 312 | }; 313 | 314 | x86_64-darwin = { 315 | tarball = "https://pkg.machengine.org/zig/zig-macos-x86_64-0.13.0-dev.351+64ef45eb0.tar.xz"; 316 | shasum = "7de18dfc05fc989629311727470f22af9e9e75cb52997c333938eef666e4396e"; 317 | size = 48835880; 318 | }; 319 | 320 | aarch64-darwin = { 321 | tarball = "https://pkg.machengine.org/zig/zig-macos-aarch64-0.13.0-dev.351+64ef45eb0.tar.xz"; 322 | shasum = "fef4c33cc8b2c9af1caf47df98786c6bc049dd70ec6c05c794a3273b2937801b"; 323 | size = 44895124; 324 | }; 325 | 326 | x86_64-linux = { 327 | tarball = "https://pkg.machengine.org/zig/zig-linux-x86_64-0.13.0-dev.351+64ef45eb0.tar.xz"; 328 | shasum = "351bcaa1b43db30dc24fb7f34dc598fd7ee4d571f164a4e9bc6dac6f6e6e3c56"; 329 | size = 47116964; 330 | }; 331 | 332 | aarch64-linux = { 333 | tarball = "https://pkg.machengine.org/zig/zig-linux-aarch64-0.13.0-dev.351+64ef45eb0.tar.xz"; 334 | shasum = "20b9602db87482a1b03ca61acaac6acc17e6e3dc2e46d3521430a6aac3e8c4ef"; 335 | size = 43108620; 336 | }; 337 | 338 | armv7l-linux = { 339 | tarball = "https://pkg.machengine.org/zig/zig-linux-armv7a-0.13.0-dev.351+64ef45eb0.tar.xz"; 340 | shasum = "4c1dac2c4fc37e355da42fcab12b77b27ff3fecf1d238d1e4049e8e513a7c539"; 341 | size = 44044840; 342 | }; 343 | 344 | riscv64-linux = { 345 | tarball = "https://pkg.machengine.org/zig/zig-linux-riscv64-0.13.0-dev.351+64ef45eb0.tar.xz"; 346 | shasum = "141e40bf24e783926b3d76510a1a87e8f875247d4fe877faf14f908fdd2ddeb9"; 347 | size = 45564236; 348 | }; 349 | 350 | powerpc64le-linux = { 351 | tarball = "https://pkg.machengine.org/zig/zig-linux-powerpc64le-0.13.0-dev.351+64ef45eb0.tar.xz"; 352 | shasum = "03839298a9c98aeb9b56e98d7c589909b6c279178dffe714fd9a3c325718ec98"; 353 | size = 46546392; 354 | }; 355 | 356 | i686-linux = { 357 | tarball = "https://pkg.machengine.org/zig/zig-linux-x86-0.13.0-dev.351+64ef45eb0.tar.xz"; 358 | shasum = "85051749303503c0da45a8554283f71fce949372f203c6392138842040fe8ea7"; 359 | size = 52054076; 360 | }; 361 | 362 | x86_64-mingw32 = { 363 | tarball = "https://pkg.machengine.org/zig/zig-windows-x86_64-0.13.0-dev.351+64ef45eb0.zip"; 364 | shasum = "7be394a9fa1e131ecd948cd0137a72fcde18afdca7c4420333057974dfee5b7d"; 365 | size = 79621321; 366 | }; 367 | 368 | aarch64-mingw32 = { 369 | tarball = "https://pkg.machengine.org/zig/zig-windows-aarch64-0.13.0-dev.351+64ef45eb0.zip"; 370 | shasum = "d2b2d5a61258222467e0de8615675e2e66e184dc36c142adcf628246c97636a4"; 371 | size = 75584259; 372 | }; 373 | 374 | i686-mingw32 = { 375 | tarball = "https://pkg.machengine.org/zig/zig-windows-x86-0.13.0-dev.351+64ef45eb0.zip"; 376 | shasum = "f63946af192ddc40ec9ea7af8a7ed56119d19afc42d0106715e994a37d1cd96c"; 377 | size = 83726392; 378 | }; 379 | }; 380 | 381 | meta-2024_5_0 = { 382 | version = "2024.5.0"; 383 | zigVersion = "0.13.0-dev.351+64ef45eb0"; 384 | date = "2024-06-01"; 385 | docs = "https://ziglang.org/documentation/master/"; 386 | stdDocs = "https://ziglang.org/documentation/master/std/"; 387 | machDocs = "https://machengine.org/docs/nominated-zig"; 388 | machNominated = "2024-06-01"; 389 | 390 | src = { 391 | tarball = "https://pkg.machengine.org/zig/zig-0.13.0-dev.351+64ef45eb0.tar.xz"; 392 | shasum = "6db25e78eca948664d4b1b1eb6b5ca6c471e0bf32b8fd19cc7c925b4d957f097"; 393 | size = 17199760; 394 | }; 395 | 396 | bootstrap = { 397 | tarball = "https://pkg.machengine.org/zig/zig-bootstrap-0.13.0-dev.351+64ef45eb0.tar.xz"; 398 | shasum = "ff545922a63807aa812dcabf37feb47d2641ab2d9f354bc03c610ee2bc69ac9e"; 399 | size = 46433700; 400 | }; 401 | 402 | x86_64-darwin = { 403 | tarball = "https://pkg.machengine.org/zig/zig-macos-x86_64-0.13.0-dev.351+64ef45eb0.tar.xz"; 404 | shasum = "7de18dfc05fc989629311727470f22af9e9e75cb52997c333938eef666e4396e"; 405 | size = 48835880; 406 | }; 407 | 408 | aarch64-darwin = { 409 | tarball = "https://pkg.machengine.org/zig/zig-macos-aarch64-0.13.0-dev.351+64ef45eb0.tar.xz"; 410 | shasum = "fef4c33cc8b2c9af1caf47df98786c6bc049dd70ec6c05c794a3273b2937801b"; 411 | size = 44895124; 412 | }; 413 | 414 | x86_64-linux = { 415 | tarball = "https://pkg.machengine.org/zig/zig-linux-x86_64-0.13.0-dev.351+64ef45eb0.tar.xz"; 416 | shasum = "351bcaa1b43db30dc24fb7f34dc598fd7ee4d571f164a4e9bc6dac6f6e6e3c56"; 417 | size = 47116964; 418 | }; 419 | 420 | aarch64-linux = { 421 | tarball = "https://pkg.machengine.org/zig/zig-linux-aarch64-0.13.0-dev.351+64ef45eb0.tar.xz"; 422 | shasum = "20b9602db87482a1b03ca61acaac6acc17e6e3dc2e46d3521430a6aac3e8c4ef"; 423 | size = 43108620; 424 | }; 425 | 426 | armv7l-linux = { 427 | tarball = "https://pkg.machengine.org/zig/zig-linux-armv7a-0.13.0-dev.351+64ef45eb0.tar.xz"; 428 | shasum = "4c1dac2c4fc37e355da42fcab12b77b27ff3fecf1d238d1e4049e8e513a7c539"; 429 | size = 44044840; 430 | }; 431 | 432 | riscv64-linux = { 433 | tarball = "https://pkg.machengine.org/zig/zig-linux-riscv64-0.13.0-dev.351+64ef45eb0.tar.xz"; 434 | shasum = "141e40bf24e783926b3d76510a1a87e8f875247d4fe877faf14f908fdd2ddeb9"; 435 | size = 45564236; 436 | }; 437 | 438 | powerpc64le-linux = { 439 | tarball = "https://pkg.machengine.org/zig/zig-linux-powerpc64le-0.13.0-dev.351+64ef45eb0.tar.xz"; 440 | shasum = "03839298a9c98aeb9b56e98d7c589909b6c279178dffe714fd9a3c325718ec98"; 441 | size = 46546392; 442 | }; 443 | 444 | i686-linux = { 445 | tarball = "https://pkg.machengine.org/zig/zig-linux-x86-0.13.0-dev.351+64ef45eb0.tar.xz"; 446 | shasum = "85051749303503c0da45a8554283f71fce949372f203c6392138842040fe8ea7"; 447 | size = 52054076; 448 | }; 449 | 450 | x86_64-mingw32 = { 451 | tarball = "https://pkg.machengine.org/zig/zig-windows-x86_64-0.13.0-dev.351+64ef45eb0.zip"; 452 | shasum = "7be394a9fa1e131ecd948cd0137a72fcde18afdca7c4420333057974dfee5b7d"; 453 | size = 79621321; 454 | }; 455 | 456 | aarch64-mingw32 = { 457 | tarball = "https://pkg.machengine.org/zig/zig-windows-aarch64-0.13.0-dev.351+64ef45eb0.zip"; 458 | shasum = "d2b2d5a61258222467e0de8615675e2e66e184dc36c142adcf628246c97636a4"; 459 | size = 75584259; 460 | }; 461 | 462 | i686-mingw32 = { 463 | tarball = "https://pkg.machengine.org/zig/zig-windows-x86-0.13.0-dev.351+64ef45eb0.zip"; 464 | shasum = "f63946af192ddc40ec9ea7af8a7ed56119d19afc42d0106715e994a37d1cd96c"; 465 | size = 83726392; 466 | }; 467 | }; 468 | 469 | meta-2024_3_0 = { 470 | version = "2024.3.0"; 471 | zigVersion = "0.12.0-dev.3180+83e578a18"; 472 | date = "2024-03-08"; 473 | docs = "https://ziglang.org/documentation/master/"; 474 | stdDocs = "https://ziglang.org/documentation/master/std/"; 475 | machDocs = "https://machengine.org/docs/nominated-zig"; 476 | machNominated = "2024-03-08"; 477 | 478 | src = { 479 | tarball = "https://pkg.machengine.org/zig/zig-0.12.0-dev.3180+83e578a18.tar.xz"; 480 | shasum = "f484f26899b872782f37603b633236abaca4005e26d544fcbdfa1eb0f2503217"; 481 | size = 17006740; 482 | }; 483 | 484 | bootstrap = { 485 | tarball = "https://pkg.machengine.org/zig/zig-bootstrap-0.12.0-dev.3180+83e578a18.tar.xz"; 486 | shasum = "9291c11044e2658fc945240d6c0ae1f809228a6bcf456be592009010b8e3456f"; 487 | size = 45451536; 488 | }; 489 | 490 | x86_64-darwin = { 491 | tarball = "https://pkg.machengine.org/zig/zig-macos-x86_64-0.12.0-dev.3180+83e578a18.tar.xz"; 492 | shasum = "3d2fe9d76e0bc72430d142cde671fc4f99919aad451d3582121b2746abb5791f"; 493 | size = 50374996; 494 | }; 495 | 496 | aarch64-darwin = { 497 | tarball = "https://pkg.machengine.org/zig/zig-macos-aarch64-0.12.0-dev.3180+83e578a18.tar.xz"; 498 | shasum = "c3d455129203fc5ebab77bf9ab4580f15a60f7d5a4a856ef9a1dc80aae856c02"; 499 | size = 46655260; 500 | }; 501 | 502 | x86_64-linux = { 503 | tarball = "https://pkg.machengine.org/zig/zig-linux-x86_64-0.12.0-dev.3180+83e578a18.tar.xz"; 504 | shasum = "66dd365aee3569e71940eb6fb2d47466f04b5ecb430aee74b9624b42ce17d6f6"; 505 | size = 48671208; 506 | }; 507 | 508 | aarch64-linux = { 509 | tarball = "https://pkg.machengine.org/zig/zig-linux-aarch64-0.12.0-dev.3180+83e578a18.tar.xz"; 510 | shasum = "6b4f85c6f5bdc0a9e05ef7d1f49d437c36d8a63d30dba152c83740c0547e38e4"; 511 | size = 45082920; 512 | }; 513 | 514 | armv7l-linux = { 515 | tarball = "https://pkg.machengine.org/zig/zig-linux-armv7a-0.12.0-dev.3180+83e578a18.tar.xz"; 516 | shasum = "35ed38c07acb8f03729dde067662b05cbeee529b6d105ca11b204c25323e13c1"; 517 | size = 45827420; 518 | }; 519 | 520 | riscv64-linux = { 521 | tarball = "https://pkg.machengine.org/zig/zig-linux-riscv64-0.12.0-dev.3180+83e578a18.tar.xz"; 522 | shasum = "1f81ed5e2d11a80d42cbc7b1b17b2b7f12b7a4cf14b439462fdc2eead3d0d199"; 523 | size = 47151216; 524 | }; 525 | 526 | powerpc64le-linux = { 527 | tarball = "https://pkg.machengine.org/zig/zig-linux-powerpc64le-0.12.0-dev.3180+83e578a18.tar.xz"; 528 | shasum = "29fb7a64797c939cada9db5740d2efdb3225425ca258e8cbb331135c31460d4b"; 529 | size = 48481048; 530 | }; 531 | 532 | i686-linux = { 533 | tarball = "https://pkg.machengine.org/zig/zig-linux-x86-0.12.0-dev.3180+83e578a18.tar.xz"; 534 | shasum = "c687559a1f810b1d252f45d980d6396755c4ff7e509836332fff9f62a9fc79fa"; 535 | size = 53685856; 536 | }; 537 | 538 | x86_64-mingw32 = { 539 | tarball = "https://pkg.machengine.org/zig/zig-windows-x86_64-0.12.0-dev.3180+83e578a18.zip"; 540 | shasum = "471acf6a4ea582720664159b0a2df8b32f1029d6681f80b7354cbb3c3d84b1e8"; 541 | size = 82811850; 542 | }; 543 | 544 | aarch64-mingw32 = { 545 | tarball = "https://pkg.machengine.org/zig/zig-windows-aarch64-0.12.0-dev.3180+83e578a18.zip"; 546 | shasum = "e48fd79741afff7567394ca53a90d75c8a4b6d36c7c76e701ec172a303db4b5e"; 547 | size = 79451816; 548 | }; 549 | 550 | i686-mingw32 = { 551 | tarball = "https://pkg.machengine.org/zig/zig-windows-x86-0.12.0-dev.3180+83e578a18.zip"; 552 | shasum = "40a429e933218590d12615bb1e5ca961ffbc5719e061d6e9d3893c043e559d6f"; 553 | size = 87426453; 554 | }; 555 | }; 556 | 557 | meta-0_3_0 = { 558 | version = "0.3.0"; 559 | zigVersion = "0.12.0-dev.2063+804cee3b9"; 560 | date = "2024-01-07"; 561 | docs = "https://ziglang.org/documentation/master/"; 562 | stdDocs = "https://ziglang.org/documentation/master/std/"; 563 | machDocs = "https://machengine.org/docs/nominated-zig"; 564 | machNominated = "2024-01-07"; 565 | 566 | src = { 567 | tarball = "https://pkg.machengine.org/zig/zig-0.12.0-dev.2063+804cee3b9.tar.xz"; 568 | shasum = "9838d42d47b7b8a0a38e87049830e528f5a6eaf5f2ccda40177dd8e2c293af78"; 569 | size = 15989148; 570 | }; 571 | 572 | bootstrap = { 573 | tarball = "https://pkg.machengine.org/zig/zig-bootstrap-0.12.0-dev.2063+804cee3b9.tar.xz"; 574 | shasum = "56867d20e287285a62552d2e3547b62c34b680192bb4ae2472faa1a910ba7b14"; 575 | size = 44431944; 576 | }; 577 | 578 | x86_64-darwin = { 579 | tarball = "https://pkg.machengine.org/zig/zig-macos-x86_64-0.12.0-dev.2063+804cee3b9.tar.xz"; 580 | shasum = "1d40ebfec0e72db3fa666e9a997841fd96a704e3b1fc84391dfd7366bf443899"; 581 | size = 49454960; 582 | }; 583 | 584 | aarch64-darwin = { 585 | tarball = "https://pkg.machengine.org/zig/zig-macos-aarch64-0.12.0-dev.2063+804cee3b9.tar.xz"; 586 | shasum = "46d0fe89a0357b9f54ea5b15526db04926a9209b871b6d0abd4c7da1cc65acee"; 587 | size = 45908952; 588 | }; 589 | 590 | x86_64-linux = { 591 | tarball = "https://pkg.machengine.org/zig/zig-linux-x86_64-0.12.0-dev.2063+804cee3b9.tar.xz"; 592 | shasum = "4c450d5817da7914b27be2147f9740ebdf186cc933ae87ddb2a8eaa130d02d57"; 593 | size = 47204444; 594 | }; 595 | 596 | aarch64-linux = { 597 | tarball = "https://pkg.machengine.org/zig/zig-linux-aarch64-0.12.0-dev.2063+804cee3b9.tar.xz"; 598 | shasum = "98957f7dce0331cd8e605a703ee29432ef2f8a5117da5e4ed3b1a80923c46fe3"; 599 | size = 43545248; 600 | }; 601 | 602 | armv7l-linux = { 603 | tarball = "https://pkg.machengine.org/zig/zig-linux-armv7a-0.12.0-dev.2063+804cee3b9.tar.xz"; 604 | shasum = "213673b0ba8b3e3c0323eb6a1fd33fe8dca9c7a66b5b0f3908dd0f41b365ddff"; 605 | size = 44295524; 606 | }; 607 | 608 | riscv64-linux = { 609 | tarball = "https://pkg.machengine.org/zig/zig-linux-riscv64-0.12.0-dev.2063+804cee3b9.tar.xz"; 610 | shasum = "8573478f89c3de971e6ed69eb6defee473ae7197aefeec3ed77bb04918789a6b"; 611 | size = 45538828; 612 | }; 613 | 614 | powerpc64le-linux = { 615 | tarball = "https://pkg.machengine.org/zig/zig-linux-powerpc64le-0.12.0-dev.2063+804cee3b9.tar.xz"; 616 | shasum = "8e12deafb740dab817e3c7b3cc7ab99192d7036bc759684f6fcdb28c85fb7f24"; 617 | size = 46905304; 618 | }; 619 | 620 | powerpc-linux = { 621 | tarball = "https://pkg.machengine.org/zig/zig-linux-powerpc-0.12.0-dev.2063+804cee3b9.tar.xz"; 622 | shasum = "92821ba18a3720df6f91ee54642e65dbdf62b1fb03380a0c89e4eb581671776c"; 623 | size = 46634964; 624 | }; 625 | 626 | i686-linux = { 627 | tarball = "https://pkg.machengine.org/zig/zig-linux-x86-0.12.0-dev.2063+804cee3b9.tar.xz"; 628 | shasum = "b437eaf626190bb6d2cf4a0eab91ec2850461aec809f681445183a15808697b3"; 629 | size = 52236508; 630 | }; 631 | 632 | x86_64-mingw32 = { 633 | tarball = "https://pkg.machengine.org/zig/zig-windows-x86_64-0.12.0-dev.2063+804cee3b9.zip"; 634 | shasum = "8dc5ecd7a0871d1d024e50fffdb51f0aef96c7023d9a935c598610a51f3c725c"; 635 | size = 79920855; 636 | }; 637 | 638 | aarch64-mingw32 = { 639 | tarball = "https://pkg.machengine.org/zig/zig-windows-aarch64-0.12.0-dev.2063+804cee3b9.zip"; 640 | shasum = "299d5455cbb4a2370a6675a79f32b01956ffbdda8d70bb78e8a1671940ecd971"; 641 | size = 76499584; 642 | }; 643 | 644 | i686-mingw32 = { 645 | tarball = "https://pkg.machengine.org/zig/zig-windows-x86-0.12.0-dev.2063+804cee3b9.zip"; 646 | shasum = "cab356caec718b6237e83d4c84bc278d06e84bda76c13d4aed2c211ab204de3b"; 647 | size = 84448695; 648 | }; 649 | }; 650 | 651 | meta-2024_1_0 = { 652 | version = "2024.1.0"; 653 | zigVersion = "0.12.0-dev.2063+804cee3b9"; 654 | date = "2024-01-07"; 655 | docs = "https://ziglang.org/documentation/master/"; 656 | stdDocs = "https://ziglang.org/documentation/master/std/"; 657 | machDocs = "https://machengine.org/docs/nominated-zig"; 658 | machNominated = "2024-01-07"; 659 | 660 | src = { 661 | tarball = "https://pkg.machengine.org/zig/zig-0.12.0-dev.2063+804cee3b9.tar.xz"; 662 | shasum = "9838d42d47b7b8a0a38e87049830e528f5a6eaf5f2ccda40177dd8e2c293af78"; 663 | size = 15989148; 664 | }; 665 | 666 | bootstrap = { 667 | tarball = "https://pkg.machengine.org/zig/zig-bootstrap-0.12.0-dev.2063+804cee3b9.tar.xz"; 668 | shasum = "56867d20e287285a62552d2e3547b62c34b680192bb4ae2472faa1a910ba7b14"; 669 | size = 44431944; 670 | }; 671 | 672 | x86_64-darwin = { 673 | tarball = "https://pkg.machengine.org/zig/zig-macos-x86_64-0.12.0-dev.2063+804cee3b9.tar.xz"; 674 | shasum = "1d40ebfec0e72db3fa666e9a997841fd96a704e3b1fc84391dfd7366bf443899"; 675 | size = 49454960; 676 | }; 677 | 678 | aarch64-darwin = { 679 | tarball = "https://pkg.machengine.org/zig/zig-macos-aarch64-0.12.0-dev.2063+804cee3b9.tar.xz"; 680 | shasum = "46d0fe89a0357b9f54ea5b15526db04926a9209b871b6d0abd4c7da1cc65acee"; 681 | size = 45908952; 682 | }; 683 | 684 | x86_64-linux = { 685 | tarball = "https://pkg.machengine.org/zig/zig-linux-x86_64-0.12.0-dev.2063+804cee3b9.tar.xz"; 686 | shasum = "4c450d5817da7914b27be2147f9740ebdf186cc933ae87ddb2a8eaa130d02d57"; 687 | size = 47204444; 688 | }; 689 | 690 | aarch64-linux = { 691 | tarball = "https://pkg.machengine.org/zig/zig-linux-aarch64-0.12.0-dev.2063+804cee3b9.tar.xz"; 692 | shasum = "98957f7dce0331cd8e605a703ee29432ef2f8a5117da5e4ed3b1a80923c46fe3"; 693 | size = 43545248; 694 | }; 695 | 696 | armv7l-linux = { 697 | tarball = "https://pkg.machengine.org/zig/zig-linux-armv7a-0.12.0-dev.2063+804cee3b9.tar.xz"; 698 | shasum = "213673b0ba8b3e3c0323eb6a1fd33fe8dca9c7a66b5b0f3908dd0f41b365ddff"; 699 | size = 44295524; 700 | }; 701 | 702 | riscv64-linux = { 703 | tarball = "https://pkg.machengine.org/zig/zig-linux-riscv64-0.12.0-dev.2063+804cee3b9.tar.xz"; 704 | shasum = "8573478f89c3de971e6ed69eb6defee473ae7197aefeec3ed77bb04918789a6b"; 705 | size = 45538828; 706 | }; 707 | 708 | powerpc64le-linux = { 709 | tarball = "https://pkg.machengine.org/zig/zig-linux-powerpc64le-0.12.0-dev.2063+804cee3b9.tar.xz"; 710 | shasum = "8e12deafb740dab817e3c7b3cc7ab99192d7036bc759684f6fcdb28c85fb7f24"; 711 | size = 46905304; 712 | }; 713 | 714 | powerpc-linux = { 715 | tarball = "https://pkg.machengine.org/zig/zig-linux-powerpc-0.12.0-dev.2063+804cee3b9.tar.xz"; 716 | shasum = "92821ba18a3720df6f91ee54642e65dbdf62b1fb03380a0c89e4eb581671776c"; 717 | size = 46634964; 718 | }; 719 | 720 | i686-linux = { 721 | tarball = "https://pkg.machengine.org/zig/zig-linux-x86-0.12.0-dev.2063+804cee3b9.tar.xz"; 722 | shasum = "b437eaf626190bb6d2cf4a0eab91ec2850461aec809f681445183a15808697b3"; 723 | size = 52236508; 724 | }; 725 | 726 | x86_64-mingw32 = { 727 | tarball = "https://pkg.machengine.org/zig/zig-windows-x86_64-0.12.0-dev.2063+804cee3b9.zip"; 728 | shasum = "8dc5ecd7a0871d1d024e50fffdb51f0aef96c7023d9a935c598610a51f3c725c"; 729 | size = 79920855; 730 | }; 731 | 732 | aarch64-mingw32 = { 733 | tarball = "https://pkg.machengine.org/zig/zig-windows-aarch64-0.12.0-dev.2063+804cee3b9.zip"; 734 | shasum = "299d5455cbb4a2370a6675a79f32b01956ffbdda8d70bb78e8a1671940ecd971"; 735 | size = 76499584; 736 | }; 737 | 738 | i686-mingw32 = { 739 | tarball = "https://pkg.machengine.org/zig/zig-windows-x86-0.12.0-dev.2063+804cee3b9.zip"; 740 | shasum = "cab356caec718b6237e83d4c84bc278d06e84bda76c13d4aed2c211ab204de3b"; 741 | size = 84448695; 742 | }; 743 | }; 744 | in 745 | { 746 | latest = bin meta-latest; 747 | src-latest = src meta-latest; 748 | "2024_11_0" = bin meta-2024_11_0; 749 | src-2024_11_0 = src meta-2024_11_0; 750 | "2024_10_0" = bin meta-2024_10_0; 751 | src-2024_10_0 = src meta-2024_10_0; 752 | "0_4_0" = bin meta-0_4_0; 753 | src-0_4_0 = src meta-0_4_0; 754 | "2024_5_0" = bin meta-2024_5_0; 755 | src-2024_5_0 = src meta-2024_5_0; 756 | "2024_3_0" = bin meta-2024_3_0; 757 | src-2024_3_0 = src meta-2024_3_0; 758 | "0_3_0" = bin meta-0_3_0; 759 | src-0_3_0 = src meta-0_3_0; 760 | "2024_1_0" = bin meta-2024_1_0; 761 | src-2024_1_0 = src meta-2024_1_0; 762 | } 763 | -------------------------------------------------------------------------------- /templates/core/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /templates/core/.gitignore: -------------------------------------------------------------------------------- 1 | # This file is for zig-specific build artifacts. 2 | # If you have OS-specific or editor-specific files to ignore, 3 | # such as *.swp or .DS_Store, put those in your global 4 | # ~/.gitignore and put this in your ~/.gitconfig: 5 | # 6 | # [core] 7 | # excludesfile = ~/.gitignore 8 | # 9 | # Cheers! 10 | # -andrewrk 11 | 12 | .zig-cache/ 13 | zig-cache/ 14 | zig-out/ 15 | /release/ 16 | /debug/ 17 | /build/ 18 | /build-*/ 19 | /docgen_tmp/ 20 | -------------------------------------------------------------------------------- /templates/core/README.md: -------------------------------------------------------------------------------- 1 | # mach-core starter project 2 | 3 | We walked through the [mach-core getting started guide](https://machengine.org/core/getting-started) and committed the result to this repository. 4 | 5 | To run it, see [these instructions](https://machengine.org/core/getting-started/#building-your-project) 6 | 7 | Feel free to use this start project as you see fit! 8 | 9 | ## Questions? Ran into an issue? 10 | 11 | Make sure you're using a [supported Zig version](https://machengine.org/about/zig-version/) 12 | 13 | There are two ways to get help: 14 | 15 | * [File a GitHub issue](https://github.com/hexops/mach/issues) 16 | * [Join our Discord](https://machengine.org/discord) and create a thread in `#help` 17 | -------------------------------------------------------------------------------- /templates/core/build.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | 3 | pub fn build(b: *std.Build) void { 4 | const target = b.standardTargetOptions(.{}); 5 | const optimize = b.standardOptimizeOption(.{}); 6 | 7 | // Create our Mach app module, where all our code lives. 8 | const app_mod = b.createModule(.{ 9 | .root_source_file = b.path("src/App.zig"), 10 | .optimize = optimize, 11 | .target = target, 12 | }); 13 | 14 | // Add Mach import to our app. 15 | const mach_dep = b.dependency("mach", .{ 16 | .target = target, 17 | .optimize = optimize, 18 | }); 19 | app_mod.addImport("mach", mach_dep.module("mach")); 20 | 21 | // Have Mach create the executable for us 22 | const exe = @import("mach").addExecutable(mach_dep.builder, .{ 23 | .name = "mach-core-app", 24 | .app = app_mod, 25 | .target = target, 26 | .optimize = optimize, 27 | }); 28 | b.installArtifact(exe); 29 | 30 | // Run the app when `zig build run` is invoked 31 | const run_cmd = b.addRunArtifact(exe); 32 | run_cmd.step.dependOn(b.getInstallStep()); 33 | if (b.args) |args| { 34 | run_cmd.addArgs(args); 35 | } 36 | const run_step = b.step("run", "Run the app"); 37 | run_step.dependOn(&run_cmd.step); 38 | 39 | // Run tests when `zig build test` is run 40 | const app_unit_tests = b.addTest(.{ 41 | .root_module = app_mod, 42 | }); 43 | const run_app_unit_tests = b.addRunArtifact(app_unit_tests); 44 | const test_step = b.step("test", "Run unit tests"); 45 | test_step.dependOn(&run_app_unit_tests.step); 46 | } 47 | -------------------------------------------------------------------------------- /templates/core/build.zig.zon: -------------------------------------------------------------------------------- 1 | .{ 2 | .name = "mach-core-project", 3 | .version = "0.1.0", 4 | .paths = .{ 5 | "build.zig.zon", 6 | "build.zig", 7 | "src", 8 | }, 9 | .dependencies = .{ 10 | .mach = .{ 11 | .url = "https://pkg.machengine.org/mach/af1cf9865bbd7e79e05c1a86560945afd2342891.tar.gz", 12 | .hash = "1220e3e557f8659f4b30c66280bcd226d295c59aa4a3e9d2947d575aa202c05acdda", 13 | }, 14 | }, 15 | } 16 | -------------------------------------------------------------------------------- /templates/core/build.zig.zon2json-lock: -------------------------------------------------------------------------------- 1 | { 2 | "1220e3e557f8659f4b30c66280bcd226d295c59aa4a3e9d2947d575aa202c05acdda": { 3 | "name": "mach", 4 | "url": "https://pkg.machengine.org/mach/af1cf9865bbd7e79e05c1a86560945afd2342891.tar.gz", 5 | "hash": "sha256-q790hhfXPsehqpCAu4IcE2pcmxNRQYFtQ6A5aF15gO8=" 6 | }, 7 | "1220adfccce3dbc4e4fa8650fdaec110a676f6b8a1462ed6ef422815207f8288e9d2": { 8 | "name": "mach_freetype", 9 | "url": "https://pkg.machengine.org/mach-freetype/d63efa5534c17f3a12ed3d327e0ad42a64adc20a.tar.gz", 10 | "hash": "sha256-SWpwVMrXQGSRHHnDuCNP0kxjlziDJ+UcEiOjonrTRlU=" 11 | }, 12 | "12204cba3a237cd2c4ab983f5a28d9b54e7a9912d8c7c6e38e23140b0171d6e1ebf8": { 13 | "name": "freetype", 14 | "url": "https://pkg.machengine.org/freetype/972cd37bccecae2cc9f54cf0b562263a13209d02.tar.gz", 15 | "hash": "sha256-3wo3u1zniDJJFX292CY+mxh9kEgqGGa501e1+bWuzo0=" 16 | }, 17 | "122031789a7c6364c2f99164c1183661bb5fe914ad7336cc224039c7fba649f35c47": { 18 | "name": "brotli", 19 | "url": "https://pkg.machengine.org/brotli/10961426f03016e273f4f4653eae907e9e2339b6.tar.gz", 20 | "hash": "sha256-fKHDFopY8WCcOO3/5eR/qTFoUX8nt8ARjKcGtVhpyXo=" 21 | }, 22 | "1220203218ac17e497f3399e08115e73cb9505f1b9f07738eb0c5cc38ca443dec953": { 23 | "name": "harfbuzz", 24 | "url": "https://pkg.machengine.org/harfbuzz/c514da98afcf5d9ad6854a7f09192f9ecfaeb061.tar.gz", 25 | "hash": "sha256-Ky7muGbrekp6Ecoyow35GMBVjPEGux8EOPIt+YVPw70=" 26 | }, 27 | "1220521ff5b01885da9b3cba75b607b315f60ae351594ee9e4a270b164374889fea0": { 28 | "name": "font_assets", 29 | "url": "https://pkg.machengine.org/font-assets/b2336a29b1ae633d47452a2041b258e9538ef5f0.tar.gz", 30 | "hash": "sha256-kbYQwFLIeCfEx4/n2NQa5ot7rXu8IlnSQedVHMWPi+c=" 31 | }, 32 | "12203675829014e69be2ea7c126ecf25d403009d336b7ca5f6e7c4ccede826c8e597": { 33 | "name": "mach_objc", 34 | "url": "https://pkg.machengine.org/mach-objc/79b6f80c32b14948554958afe72dace261b14afc.tar.gz", 35 | "hash": "sha256-bcBJnu1zDs123offi7G3BdLjltB4E171Nhf43IqdX4Y=" 36 | }, 37 | "122098b9174895f9708bc824b0f9e550c401892c40a900006459acf2cbf78acd99bb": { 38 | "name": "xcode_frameworks", 39 | "url": "https://pkg.machengine.org/xcode-frameworks/9a45f3ac977fd25dff77e58c6de1870b6808c4a7.tar.gz", 40 | "hash": "sha256-jWMT0p7klpkgX9GOUNAhrR2e6Ej7MobbqT5ZxJrNQoM=" 41 | }, 42 | "1220334a0e3480fef60443cef8b519d08b4dbf16ba37d98a7b77647fa4b7761b6048": { 43 | "name": "directx_headers", 44 | "url": "https://pkg.machengine.org/directx-headers/eae9b3b8a84a32ae9e67025fd64e8d8b7755e628.tar.gz", 45 | "hash": "sha256-DxojbEE0VMxbrufyikigVczWL+lRYAIQmN+CZxQVvfc=" 46 | }, 47 | "1220c30350b7b45f4623aeaf1c5b2c9ceda5d626de2ff5a3f2f54e4a68a80358426b": { 48 | "name": "opengl_headers", 49 | "url": "https://pkg.machengine.org/opengl-headers/d0b37fdc3b039ba5b430110545f398f0278c5396.tar.gz", 50 | "hash": "sha256-AMZLidycaj5OfHuLYtxYFP4dM0OkzS566Ff3g3AF2IY=" 51 | }, 52 | "12208333c8b3551908b66b8a421e7127bdf0c1806063836576283860eff99c99c521": { 53 | "name": "vulkan_zig_generated", 54 | "url": "https://pkg.machengine.org/vulkan-zig-generated/4134f910302a71731d8d32c91cfc1bc914e6d26b.tar.gz", 55 | "hash": "sha256-34CIyqNjrfIyNYyNdx9Lyw644P/RmB0GDOygZaQ1Uqk=" 56 | }, 57 | "12209e63e7efddd85cca44cbb13d20ef30c72ff4c409372dd75a128a354b27e9dc4c": { 58 | "name": "linux_audio_headers", 59 | "url": "https://pkg.machengine.org/linux-audio-headers/81f1f13828a8b62467200ba2a0b0d911c4d089a7.tar.gz", 60 | "hash": "sha256-Qd3XbMTkOVcLN+v8HHsExcsxj+m5exkmJzCfuaH+mZo=" 61 | }, 62 | "1220563c3d5603a02e61293c2c0223e01a3f298fb606bf0d108293b925434970a207": { 63 | "name": "wayland_headers", 64 | "url": "https://pkg.machengine.org/wayland-headers/7c53e7483c3cfb5c6780ae542c9f5cfa712a826a.tar.gz", 65 | "hash": "sha256-uGIvMyp+xR1jQXTDr6RqYl40Ukiw9l3fW1t6XpYztPY=" 66 | }, 67 | "1220083b369e019a5efbd188a58a25759c09a126e1847200ff9e88f5ccbd2dc846e3": { 68 | "name": "x11_headers", 69 | "url": "https://pkg.machengine.org/x11-headers/bc049ff07d31014d4d409cc328c3feb57c9b9a83.tar.gz", 70 | "hash": "sha256-G1nqFsWSQ5wOiKagy53jpiHesDpYU4kUSbrzi3er4tw=" 71 | }, 72 | "12201b874ac217853e59f55477b96cb7a66d43a5930ed9b4f0cfc7113efc8f5a6449": { 73 | "name": "zigimg", 74 | "url": "https://github.com/zigimg/zigimg/archive/48bfe6d413a5b3723a7bcf36f1fabbba30efef68.tar.gz", 75 | "hash": "sha256-dnfzMqAZIAYBqbJY+igMzxfsoKkNViZcki7eP+f/zII=" 76 | }, 77 | "12202e4cc38985a37bcf4804f29ec2fcba162410eee777d96ecdbb2c4260b14b7e68": { 78 | "name": "mach_opus", 79 | "url": "https://pkg.machengine.org/mach-opus/32712fd091636037959720ee00036a060816a4f0.tar.gz", 80 | "hash": "sha256-xxNG1UQz3Oom+pKYTsXPD58dZ3SVoT1xSLzQEgZKXD0=" 81 | }, 82 | "12202b922b88245c86d7a28ce31f43c62b994aebec5dbaec0ec8d703093e07bdc334": { 83 | "name": "opusfile", 84 | "url": "https://pkg.machengine.org/opusfile/3eb6f231cb7bfed63d68e5b6bfdd5b08adb64223.tar.gz", 85 | "hash": "sha256-g0Xh6x/kfjmKQ3GLqvgvRDKEvsFC/MbSZiz13dQMuwE=" 86 | }, 87 | "1220c5f74686b95ba088b4349592b61d8b0cd91294a4a7ace5bb7d2398059062f109": { 88 | "name": "opus", 89 | "url": "https://pkg.machengine.org/opus/c15a0c4c0b7cc2028a8f953588cfafe827b8b608.tar.gz", 90 | "hash": "sha256-RTs6V1PUyM3Go7GwbHQCMh0bgTdisqkguGGIfvWX5jY=" 91 | }, 92 | "1220eacee464baa636d82fd965f76ad63dab75b1b69e692270ae8e3615bebc012648": { 93 | "name": "ogg", 94 | "url": "https://pkg.machengine.org/ogg/65a455b417485ee0cd44a6b3d4540bfc6d5771cb.tar.gz", 95 | "hash": "sha256-lCzRzzGOB1q8HHPwnaI3vLrcMKqpQwfgYS3J868Pc4E=" 96 | }, 97 | "1220a330daee6fe10a02a6b981903877b2fab74afb64068a66f1f8a8135096a8e08a": { 98 | "name": "opusenc", 99 | "url": "https://pkg.machengine.org/opusenc/456cbba13168cc5b999e19256bc78e977ce18fc8.tar.gz", 100 | "hash": "sha256-eQQ7FozkE7coJHB6O8vAzhxtVe/RBVPbNocGRHld2n8=" 101 | }, 102 | "12204101e99906bee0fde5f82682bc822744a6f879dbf45374bebd92458492313df9": { 103 | "name": "mach_example_assets", 104 | "url": "https://pkg.machengine.org/mach-example-assets/dbc61a1470579a7834530567011227b1e680f2af.tar.gz", 105 | "hash": "sha256-VtOoakejYqjl3INufnSTch3gEXbrhth6ryGzSfgqXSs=" 106 | } 107 | } -------------------------------------------------------------------------------- /templates/core/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "mach-core-project flake"; 3 | 4 | inputs = { 5 | mach.url = "github:Cloudef/mach-flake?rev=e1d2d888d5333ba6e8ad44458dc7af690bac9f7f"; 6 | }; 7 | 8 | outputs = { mach, ... }: let 9 | flake-utils = mach.inputs.zig2nix.inputs.flake-utils; 10 | in (flake-utils.lib.eachDefaultSystem (system: let 11 | # Mach flake helper 12 | # Check the flake.nix in mach-flake project for more options: 13 | # 14 | env = mach.outputs.mach-env.${system} {}; 15 | in with builtins; with env.pkgs.lib; rec { 16 | # Produces clean binaries meant to be ship'd outside of nix 17 | # e.g. nix build .#foreign 18 | packages.foreign = env.package { 19 | src = cleanSource ./.; 20 | zigBuildFlags = [ "-Doptimize=ReleaseSmall" ]; 21 | 22 | # Packages required for compiling 23 | nativeBuildInputs = with env.pkgs; []; 24 | 25 | # Packages required for linking 26 | buildInputs = with env.pkgs; []; 27 | }; 28 | 29 | # nix build . 30 | packages.default = packages.foreign.overrideAttrs (attrs: { 31 | # Executables required for runtime 32 | # These packages will be added to the PATH 33 | zigWrapperBins = with env.pkgs; []; 34 | 35 | # Libraries required for runtime 36 | # These packages will be added to the LD_LIBRARY_PATH 37 | zigWrapperLibs = with env.pkgs; []; 38 | }); 39 | 40 | # For bundling with nix bundle for running outside of nix 41 | # example: https://github.com/ralismark/nix-appimage 42 | apps.bundle = { 43 | type = "app"; 44 | program = "${packages.foreign}/bin/mach-core-app"; 45 | }; 46 | 47 | # nix run . 48 | apps.default = env.app [] "zig build run -- \"$@\""; 49 | 50 | # nix run .#build 51 | apps.build = env.app [] "zig build \"$@\""; 52 | 53 | # nix run .#test 54 | apps.test = env.app [] "zig build test -- \"$@\""; 55 | 56 | # nix run .#updateMachDeps 57 | apps.updateMachDeps = env.updateMachDeps; 58 | 59 | # nix run .#zig2nix 60 | apps.zig2nix = env.app [] "zig2nix \"$@\""; 61 | 62 | # nix develop 63 | devShells.default = env.mkShell { 64 | # Packages required for compiling, linking and running 65 | # Libraries added here will be automatically added to the LD_LIBRARY_PATH and PKG_CONFIG_PATH 66 | nativeBuildInputs = with env.pkgs; []; 67 | }; 68 | })); 69 | } 70 | -------------------------------------------------------------------------------- /templates/core/src/App.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | const mach = @import("mach"); 3 | const gpu = mach.gpu; 4 | 5 | const App = @This(); 6 | 7 | // The set of Mach modules our application may use. 8 | pub const Modules = mach.Modules(.{ 9 | mach.Core, 10 | App, 11 | }); 12 | 13 | pub const mach_module = .app; 14 | 15 | pub const mach_systems = .{ .main, .init, .tick, .deinit }; 16 | 17 | pub const main = mach.schedule(.{ 18 | .{ mach.Core, .init }, 19 | .{ App, .init }, 20 | .{ mach.Core, .main }, 21 | }); 22 | 23 | window: mach.ObjectID, 24 | title_timer: mach.time.Timer, 25 | pipeline: *gpu.RenderPipeline, 26 | 27 | pub fn init( 28 | core: *mach.Core, 29 | app: *App, 30 | app_mod: mach.Mod(App), 31 | ) !void { 32 | core.on_tick = app_mod.id.tick; 33 | core.on_exit = app_mod.id.deinit; 34 | 35 | const window = try core.windows.new(.{ 36 | .title = "core-triangle", 37 | }); 38 | 39 | // Store our render pipeline in our module's state, so we can access it later on. 40 | app.* = .{ 41 | .window = window, 42 | .title_timer = try mach.time.Timer.start(), 43 | .pipeline = undefined, 44 | }; 45 | } 46 | 47 | fn setupPipeline(core: *mach.Core, app: *App, window_id: mach.ObjectID) !void { 48 | var window = core.windows.getValue(window_id); 49 | defer core.windows.setValueRaw(window_id, window); 50 | 51 | // Create our shader module 52 | const shader_module = window.device.createShaderModuleWGSL("shader.wgsl", @embedFile("shader.wgsl")); 53 | defer shader_module.release(); 54 | 55 | // Blend state describes how rendered colors get blended 56 | const blend = gpu.BlendState{}; 57 | 58 | // Color target describes e.g. the pixel format of the window we are rendering to. 59 | const color_target = gpu.ColorTargetState{ 60 | .format = window.framebuffer_format, 61 | .blend = &blend, 62 | }; 63 | 64 | // Fragment state describes which shader and entrypoint to use for rendering fragments. 65 | const fragment = gpu.FragmentState.init(.{ 66 | .module = shader_module, 67 | .entry_point = "frag_main", 68 | .targets = &.{color_target}, 69 | }); 70 | 71 | // Create our render pipeline that will ultimately get pixels onto the screen. 72 | const label = @tagName(mach_module) ++ ".init"; 73 | const pipeline_descriptor = gpu.RenderPipeline.Descriptor{ 74 | .label = label, 75 | .fragment = &fragment, 76 | .vertex = gpu.VertexState{ 77 | .module = shader_module, 78 | .entry_point = "vertex_main", 79 | }, 80 | }; 81 | app.pipeline = window.device.createRenderPipeline(&pipeline_descriptor); 82 | } 83 | 84 | // TODO(object): window-title 85 | // try updateWindowTitle(core); 86 | 87 | pub fn tick(app: *App, core: *mach.Core) void { 88 | while (core.nextEvent()) |event| { 89 | switch (event) { 90 | .window_open => |ev| { 91 | try setupPipeline(core, app, ev.window_id); 92 | }, 93 | .close => core.exit(), 94 | else => {}, 95 | } 96 | } 97 | 98 | const window = core.windows.getValue(app.window); 99 | 100 | // Grab the back buffer of the swapchain 101 | // TODO(Core) 102 | const back_buffer_view = window.swap_chain.getCurrentTextureView().?; 103 | defer back_buffer_view.release(); 104 | 105 | // Create a command encoder 106 | const label = @tagName(mach_module) ++ ".tick"; 107 | 108 | const encoder = window.device.createCommandEncoder(&.{ .label = label }); 109 | defer encoder.release(); 110 | 111 | // Begin render pass 112 | const sky_blue_background = gpu.Color{ .r = 0.776, .g = 0.988, .b = 1, .a = 1 }; 113 | const color_attachments = [_]gpu.RenderPassColorAttachment{.{ 114 | .view = back_buffer_view, 115 | .clear_value = sky_blue_background, 116 | .load_op = .clear, 117 | .store_op = .store, 118 | }}; 119 | const render_pass = encoder.beginRenderPass(&gpu.RenderPassDescriptor.init(.{ 120 | .label = label, 121 | .color_attachments = &color_attachments, 122 | })); 123 | defer render_pass.release(); 124 | 125 | // Draw 126 | render_pass.setPipeline(app.pipeline); 127 | render_pass.draw(3, 1, 0, 0); 128 | 129 | // Finish render pass 130 | render_pass.end(); 131 | 132 | // Submit our commands to the queue 133 | var command = encoder.finish(&.{ .label = label }); 134 | defer command.release(); 135 | window.queue.submit(&[_]*gpu.CommandBuffer{command}); 136 | 137 | // update the window title every second 138 | // if (app.title_timer.read() >= 1.0) { 139 | // app.title_timer.reset(); 140 | // // TODO(object): window-title 141 | // // try updateWindowTitle(core); 142 | // } 143 | } 144 | 145 | pub fn deinit(app: *App) void { 146 | app.pipeline.release(); 147 | } 148 | 149 | // TODO(object): window-title 150 | // fn updateWindowTitle(core: *mach.Core) !void { 151 | // try core.printTitle( 152 | // core.main_window, 153 | // "core-custom-entrypoint [ {d}fps ] [ Input {d}hz ]", 154 | // .{ 155 | // // TODO(Core) 156 | // core.frameRate(), 157 | // core.inputRate(), 158 | // }, 159 | // ); 160 | // core.schedule(.update); 161 | // } 162 | -------------------------------------------------------------------------------- /templates/core/src/shader.wgsl: -------------------------------------------------------------------------------- 1 | @vertex fn vertex_main( 2 | @builtin(vertex_index) VertexIndex : u32 3 | ) -> @builtin(position) vec4 { 4 | var pos = array, 3>( 5 | vec2( 0.0, 0.5), 6 | vec2(-0.5, -0.5), 7 | vec2( 0.5, -0.5) 8 | ); 9 | return vec4(pos[VertexIndex], 0.0, 1.0); 10 | } 11 | 12 | @fragment fn frag_main() -> @location(0) vec4 { 13 | return vec4(1.0, 0.0, 0.0, 1.0); 14 | } 15 | -------------------------------------------------------------------------------- /templates/engine/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /templates/engine/.gitignore: -------------------------------------------------------------------------------- 1 | # This file is for zig-specific build artifacts. 2 | # If you have OS-specific or editor-specific files to ignore, 3 | # such as *.swp or .DS_Store, put those in your global 4 | # ~/.gitignore and put this in your ~/.gitconfig: 5 | # 6 | # [core] 7 | # excludesfile = ~/.gitignore 8 | # 9 | # Cheers! 10 | # -andrewrk 11 | 12 | .zig-cache/ 13 | zig-cache/ 14 | zig-out/ 15 | /release/ 16 | /debug/ 17 | /build/ 18 | /build-*/ 19 | /docgen_tmp/ 20 | -------------------------------------------------------------------------------- /templates/engine/build.zig: -------------------------------------------------------------------------------- 1 | const std = @import("std"); 2 | 3 | pub fn build(b: *std.Build) void { 4 | const target = b.standardTargetOptions(.{}); 5 | const optimize = b.standardOptimizeOption(.{}); 6 | 7 | // Create our Mach app module, where all our code lives. 8 | const app_mod = b.createModule(.{ 9 | .root_source_file = b.path("src/App.zig"), 10 | .optimize = optimize, 11 | .target = target, 12 | }); 13 | 14 | // Add Mach import to our app. 15 | const mach_dep = b.dependency("mach", .{ 16 | .target = target, 17 | .optimize = optimize, 18 | }); 19 | app_mod.addImport("mach", mach_dep.module("mach")); 20 | 21 | // Have Mach create the executable for us 22 | const exe = @import("mach").addExecutable(mach_dep.builder, .{ 23 | .name = "mach-app", 24 | .app = app_mod, 25 | .target = target, 26 | .optimize = optimize, 27 | }); 28 | b.installArtifact(exe); 29 | 30 | // Run the app when `zig build run` is invoked 31 | const run_cmd = b.addRunArtifact(exe); 32 | run_cmd.step.dependOn(b.getInstallStep()); 33 | if (b.args) |args| { 34 | run_cmd.addArgs(args); 35 | } 36 | const run_step = b.step("run", "Run the app"); 37 | run_step.dependOn(&run_cmd.step); 38 | 39 | // Run tests when `zig build test` is run 40 | const app_unit_tests = b.addTest(.{ 41 | .root_module = app_mod, 42 | }); 43 | const run_app_unit_tests = b.addRunArtifact(app_unit_tests); 44 | const test_step = b.step("test", "Run unit tests"); 45 | test_step.dependOn(&run_app_unit_tests.step); 46 | } 47 | -------------------------------------------------------------------------------- /templates/engine/build.zig.zon: -------------------------------------------------------------------------------- 1 | .{ 2 | .name = "mach-engine-project", 3 | .version = "0.1.0", 4 | .paths = .{ 5 | "build.zig.zon", 6 | "build.zig", 7 | "src", 8 | }, 9 | .dependencies = .{ 10 | .mach = .{ 11 | .url = "https://pkg.machengine.org/mach/af1cf9865bbd7e79e05c1a86560945afd2342891.tar.gz", 12 | .hash = "1220e3e557f8659f4b30c66280bcd226d295c59aa4a3e9d2947d575aa202c05acdda", 13 | }, 14 | }, 15 | } 16 | -------------------------------------------------------------------------------- /templates/engine/build.zig.zon2json-lock: -------------------------------------------------------------------------------- 1 | { 2 | "1220e3e557f8659f4b30c66280bcd226d295c59aa4a3e9d2947d575aa202c05acdda": { 3 | "name": "mach", 4 | "url": "https://pkg.machengine.org/mach/af1cf9865bbd7e79e05c1a86560945afd2342891.tar.gz", 5 | "hash": "sha256-q790hhfXPsehqpCAu4IcE2pcmxNRQYFtQ6A5aF15gO8=" 6 | }, 7 | "1220adfccce3dbc4e4fa8650fdaec110a676f6b8a1462ed6ef422815207f8288e9d2": { 8 | "name": "mach_freetype", 9 | "url": "https://pkg.machengine.org/mach-freetype/d63efa5534c17f3a12ed3d327e0ad42a64adc20a.tar.gz", 10 | "hash": "sha256-SWpwVMrXQGSRHHnDuCNP0kxjlziDJ+UcEiOjonrTRlU=" 11 | }, 12 | "12204cba3a237cd2c4ab983f5a28d9b54e7a9912d8c7c6e38e23140b0171d6e1ebf8": { 13 | "name": "freetype", 14 | "url": "https://pkg.machengine.org/freetype/972cd37bccecae2cc9f54cf0b562263a13209d02.tar.gz", 15 | "hash": "sha256-3wo3u1zniDJJFX292CY+mxh9kEgqGGa501e1+bWuzo0=" 16 | }, 17 | "122031789a7c6364c2f99164c1183661bb5fe914ad7336cc224039c7fba649f35c47": { 18 | "name": "brotli", 19 | "url": "https://pkg.machengine.org/brotli/10961426f03016e273f4f4653eae907e9e2339b6.tar.gz", 20 | "hash": "sha256-fKHDFopY8WCcOO3/5eR/qTFoUX8nt8ARjKcGtVhpyXo=" 21 | }, 22 | "1220203218ac17e497f3399e08115e73cb9505f1b9f07738eb0c5cc38ca443dec953": { 23 | "name": "harfbuzz", 24 | "url": "https://pkg.machengine.org/harfbuzz/c514da98afcf5d9ad6854a7f09192f9ecfaeb061.tar.gz", 25 | "hash": "sha256-Ky7muGbrekp6Ecoyow35GMBVjPEGux8EOPIt+YVPw70=" 26 | }, 27 | "1220521ff5b01885da9b3cba75b607b315f60ae351594ee9e4a270b164374889fea0": { 28 | "name": "font_assets", 29 | "url": "https://pkg.machengine.org/font-assets/b2336a29b1ae633d47452a2041b258e9538ef5f0.tar.gz", 30 | "hash": "sha256-kbYQwFLIeCfEx4/n2NQa5ot7rXu8IlnSQedVHMWPi+c=" 31 | }, 32 | "12203675829014e69be2ea7c126ecf25d403009d336b7ca5f6e7c4ccede826c8e597": { 33 | "name": "mach_objc", 34 | "url": "https://pkg.machengine.org/mach-objc/79b6f80c32b14948554958afe72dace261b14afc.tar.gz", 35 | "hash": "sha256-bcBJnu1zDs123offi7G3BdLjltB4E171Nhf43IqdX4Y=" 36 | }, 37 | "122098b9174895f9708bc824b0f9e550c401892c40a900006459acf2cbf78acd99bb": { 38 | "name": "xcode_frameworks", 39 | "url": "https://pkg.machengine.org/xcode-frameworks/9a45f3ac977fd25dff77e58c6de1870b6808c4a7.tar.gz", 40 | "hash": "sha256-jWMT0p7klpkgX9GOUNAhrR2e6Ej7MobbqT5ZxJrNQoM=" 41 | }, 42 | "1220334a0e3480fef60443cef8b519d08b4dbf16ba37d98a7b77647fa4b7761b6048": { 43 | "name": "directx_headers", 44 | "url": "https://pkg.machengine.org/directx-headers/eae9b3b8a84a32ae9e67025fd64e8d8b7755e628.tar.gz", 45 | "hash": "sha256-DxojbEE0VMxbrufyikigVczWL+lRYAIQmN+CZxQVvfc=" 46 | }, 47 | "1220c30350b7b45f4623aeaf1c5b2c9ceda5d626de2ff5a3f2f54e4a68a80358426b": { 48 | "name": "opengl_headers", 49 | "url": "https://pkg.machengine.org/opengl-headers/d0b37fdc3b039ba5b430110545f398f0278c5396.tar.gz", 50 | "hash": "sha256-AMZLidycaj5OfHuLYtxYFP4dM0OkzS566Ff3g3AF2IY=" 51 | }, 52 | "12208333c8b3551908b66b8a421e7127bdf0c1806063836576283860eff99c99c521": { 53 | "name": "vulkan_zig_generated", 54 | "url": "https://pkg.machengine.org/vulkan-zig-generated/4134f910302a71731d8d32c91cfc1bc914e6d26b.tar.gz", 55 | "hash": "sha256-34CIyqNjrfIyNYyNdx9Lyw644P/RmB0GDOygZaQ1Uqk=" 56 | }, 57 | "12209e63e7efddd85cca44cbb13d20ef30c72ff4c409372dd75a128a354b27e9dc4c": { 58 | "name": "linux_audio_headers", 59 | "url": "https://pkg.machengine.org/linux-audio-headers/81f1f13828a8b62467200ba2a0b0d911c4d089a7.tar.gz", 60 | "hash": "sha256-Qd3XbMTkOVcLN+v8HHsExcsxj+m5exkmJzCfuaH+mZo=" 61 | }, 62 | "1220563c3d5603a02e61293c2c0223e01a3f298fb606bf0d108293b925434970a207": { 63 | "name": "wayland_headers", 64 | "url": "https://pkg.machengine.org/wayland-headers/7c53e7483c3cfb5c6780ae542c9f5cfa712a826a.tar.gz", 65 | "hash": "sha256-uGIvMyp+xR1jQXTDr6RqYl40Ukiw9l3fW1t6XpYztPY=" 66 | }, 67 | "1220083b369e019a5efbd188a58a25759c09a126e1847200ff9e88f5ccbd2dc846e3": { 68 | "name": "x11_headers", 69 | "url": "https://pkg.machengine.org/x11-headers/bc049ff07d31014d4d409cc328c3feb57c9b9a83.tar.gz", 70 | "hash": "sha256-G1nqFsWSQ5wOiKagy53jpiHesDpYU4kUSbrzi3er4tw=" 71 | }, 72 | "12201b874ac217853e59f55477b96cb7a66d43a5930ed9b4f0cfc7113efc8f5a6449": { 73 | "name": "zigimg", 74 | "url": "https://github.com/zigimg/zigimg/archive/48bfe6d413a5b3723a7bcf36f1fabbba30efef68.tar.gz", 75 | "hash": "sha256-dnfzMqAZIAYBqbJY+igMzxfsoKkNViZcki7eP+f/zII=" 76 | }, 77 | "12202e4cc38985a37bcf4804f29ec2fcba162410eee777d96ecdbb2c4260b14b7e68": { 78 | "name": "mach_opus", 79 | "url": "https://pkg.machengine.org/mach-opus/32712fd091636037959720ee00036a060816a4f0.tar.gz", 80 | "hash": "sha256-xxNG1UQz3Oom+pKYTsXPD58dZ3SVoT1xSLzQEgZKXD0=" 81 | }, 82 | "12202b922b88245c86d7a28ce31f43c62b994aebec5dbaec0ec8d703093e07bdc334": { 83 | "name": "opusfile", 84 | "url": "https://pkg.machengine.org/opusfile/3eb6f231cb7bfed63d68e5b6bfdd5b08adb64223.tar.gz", 85 | "hash": "sha256-g0Xh6x/kfjmKQ3GLqvgvRDKEvsFC/MbSZiz13dQMuwE=" 86 | }, 87 | "1220c5f74686b95ba088b4349592b61d8b0cd91294a4a7ace5bb7d2398059062f109": { 88 | "name": "opus", 89 | "url": "https://pkg.machengine.org/opus/c15a0c4c0b7cc2028a8f953588cfafe827b8b608.tar.gz", 90 | "hash": "sha256-RTs6V1PUyM3Go7GwbHQCMh0bgTdisqkguGGIfvWX5jY=" 91 | }, 92 | "1220eacee464baa636d82fd965f76ad63dab75b1b69e692270ae8e3615bebc012648": { 93 | "name": "ogg", 94 | "url": "https://pkg.machengine.org/ogg/65a455b417485ee0cd44a6b3d4540bfc6d5771cb.tar.gz", 95 | "hash": "sha256-lCzRzzGOB1q8HHPwnaI3vLrcMKqpQwfgYS3J868Pc4E=" 96 | }, 97 | "1220a330daee6fe10a02a6b981903877b2fab74afb64068a66f1f8a8135096a8e08a": { 98 | "name": "opusenc", 99 | "url": "https://pkg.machengine.org/opusenc/456cbba13168cc5b999e19256bc78e977ce18fc8.tar.gz", 100 | "hash": "sha256-eQQ7FozkE7coJHB6O8vAzhxtVe/RBVPbNocGRHld2n8=" 101 | }, 102 | "12204101e99906bee0fde5f82682bc822744a6f879dbf45374bebd92458492313df9": { 103 | "name": "mach_example_assets", 104 | "url": "https://pkg.machengine.org/mach-example-assets/dbc61a1470579a7834530567011227b1e680f2af.tar.gz", 105 | "hash": "sha256-VtOoakejYqjl3INufnSTch3gEXbrhth6ryGzSfgqXSs=" 106 | } 107 | } -------------------------------------------------------------------------------- /templates/engine/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "mach-engine-project flake"; 3 | 4 | inputs = { 5 | mach.url = "github:Cloudef/mach-flake?rev=e1d2d888d5333ba6e8ad44458dc7af690bac9f7f"; 6 | }; 7 | 8 | outputs = { mach, ... }: let 9 | flake-utils = mach.inputs.zig2nix.inputs.flake-utils; 10 | in (flake-utils.lib.eachDefaultSystem (system: let 11 | # Mach flake helper 12 | # Check the flake.nix in mach-flake project for more options: 13 | # 14 | env = mach.outputs.mach-env.${system} {}; 15 | in with builtins; with env.pkgs.lib; rec { 16 | # Produces clean binaries meant to be ship'd outside of nix 17 | # e.g. nix build .#foreign 18 | packages.foreign = env.package { 19 | src = cleanSource ./.; 20 | zigBuildFlags = [ "-Doptimize=ReleaseSmall" ]; 21 | 22 | # Packages required for compiling 23 | nativeBuildInputs = with env.pkgs; []; 24 | 25 | # Packages required for linking 26 | buildInputs = with env.pkgs; []; 27 | }; 28 | 29 | # nix build . 30 | packages.default = packages.foreign.overrideAttrs (attrs: { 31 | # Executables required for runtime 32 | # These packages will be added to the PATH 33 | zigWrapperBins = with env.pkgs; []; 34 | 35 | # Libraries required for runtime 36 | # These packages will be added to the LD_LIBRARY_PATH 37 | zigWrapperLibs = with env.pkgs; []; 38 | }); 39 | 40 | # For bundling with nix bundle for running outside of nix 41 | # example: https://github.com/ralismark/nix-appimage 42 | apps.bundle = { 43 | type = "app"; 44 | program = "${packages.foreign}/bin/mach-app"; 45 | }; 46 | 47 | # nix run . 48 | apps.default = env.app [] "zig build run -- \"$@\""; 49 | 50 | # nix run .#build 51 | apps.build = env.app [] "zig build \"$@\""; 52 | 53 | # nix run .#test 54 | apps.test = env.app [] "zig build test -- \"$@\""; 55 | 56 | # nix run .#updateMachDeps 57 | apps.updateMachDeps = env.updateMachDeps; 58 | 59 | # nix run .#zig2nix 60 | apps.zig2nix = env.app [] "zig2nix \"$@\""; 61 | 62 | # nix develop 63 | devShells.default = env.mkShell { 64 | # Packages required for compiling, linking and running 65 | # Libraries added here will be automatically added to the LD_LIBRARY_PATH and PKG_CONFIG_PATH 66 | nativeBuildInputs = with env.pkgs; []; 67 | }; 68 | })); 69 | } 70 | -------------------------------------------------------------------------------- /templates/engine/src/App.zig: -------------------------------------------------------------------------------- 1 | const mach = @import("mach"); 2 | const math = mach.math; 3 | const Renderer = @import("Renderer.zig"); 4 | 5 | const vec3 = math.vec3; 6 | const vec2 = math.vec2; 7 | const Vec2 = math.Vec2; 8 | const Vec3 = math.Vec3; 9 | 10 | const App = @This(); 11 | 12 | // The set of Mach modules our application may use. 13 | pub const Modules = mach.Modules(.{ 14 | mach.Core, 15 | App, 16 | @import("Renderer.zig"), 17 | }); 18 | 19 | pub const mach_module = .app; 20 | 21 | pub const mach_systems = .{ .main, .init, .deinit, .tick }; 22 | 23 | // Global state for our app module. 24 | timer: mach.time.Timer, 25 | player: mach.ObjectID, 26 | direction: Vec2 = vec2(0, 0), 27 | spawning: bool = false, 28 | spawn_timer: mach.time.Timer, 29 | 30 | pub const main = mach.schedule(.{ 31 | .{ mach.Core, .init }, 32 | .{ App, .init }, 33 | .{ mach.Core, .main }, 34 | }); 35 | 36 | pub const deinit = mach.schedule(.{ 37 | .{ Renderer, .deinit }, 38 | }); 39 | 40 | pub fn init( 41 | core: *mach.Core, 42 | app: *App, 43 | app_mod: mach.Mod(App), 44 | renderer: *Renderer, 45 | ) !void { 46 | core.on_tick = app_mod.id.tick; 47 | core.on_exit = app_mod.id.deinit; 48 | 49 | const window = try core.windows.new(.{ 50 | .title = "custom renderer", 51 | }); 52 | renderer.window = window; 53 | 54 | // Create our player entity. 55 | const player = try renderer.objects.new(.{ 56 | .position = vec3(0, 0, 0), 57 | .scale = 1.0, 58 | }); 59 | 60 | app.* = .{ 61 | .timer = try mach.time.Timer.start(), 62 | .spawn_timer = try mach.time.Timer.start(), 63 | .player = player, 64 | }; 65 | } 66 | 67 | pub fn tick( 68 | core: *mach.Core, 69 | renderer: *Renderer, 70 | renderer_mod: mach.Mod(Renderer), 71 | app: *App, 72 | ) !void { 73 | var direction = app.direction; 74 | var spawning = app.spawning; 75 | while (core.nextEvent()) |event| { 76 | switch (event) { 77 | .key_press => |ev| { 78 | switch (ev.key) { 79 | .left => direction.v[0] -= 1, 80 | .right => direction.v[0] += 1, 81 | .up => direction.v[1] += 1, 82 | .down => direction.v[1] -= 1, 83 | .space => spawning = true, 84 | else => {}, 85 | } 86 | }, 87 | .key_release => |ev| { 88 | switch (ev.key) { 89 | .left => direction.v[0] += 1, 90 | .right => direction.v[0] -= 1, 91 | .up => direction.v[1] -= 1, 92 | .down => direction.v[1] += 1, 93 | .space => spawning = false, 94 | else => {}, 95 | } 96 | }, 97 | .window_open => |_| { 98 | renderer_mod.call(.init); 99 | }, 100 | .close => core.exit(), 101 | else => {}, 102 | } 103 | } 104 | 105 | // Keep track of which direction we want the player to move based on input, and whether we want 106 | // to be spawning entities. 107 | // 108 | // Note that app. simply returns a pointer to a global singleton of the struct defined 109 | // by this file, so we can access fields defined at the top of this file. 110 | app.direction = direction; 111 | app.spawning = spawning; 112 | 113 | // Get the current player position 114 | var player = renderer.objects.getValue(app.player); 115 | defer renderer.objects.setValue(app.player, player); 116 | 117 | // If we want to spawn new entities, then spawn them now. The timer just makes spawning rate 118 | // independent of frame rate. 119 | if (spawning and app.spawn_timer.read() > 1.0 / 60.0) { 120 | _ = app.spawn_timer.lap(); // Reset the timer 121 | for (0..5) |_| { 122 | // Spawn a new object at the same position as the player, but smaller in scale. 123 | const new_obj = try renderer.objects.new(.{ 124 | .position = player.position, 125 | .scale = 1.0 / 6.0, 126 | }); 127 | 128 | // Parent the object to the player, we'll make children 'follow' the parent below. 129 | try renderer.objects.addChild(app.player, new_obj); 130 | } 131 | } 132 | 133 | // Multiply by delta_time to ensure that movement is the same speed regardless of the frame rate. 134 | const delta_time = app.timer.lap(); 135 | 136 | // Calculate the player position, by moving in the direction the player wants to go 137 | // by the speed amount. 138 | const speed = 1.0; 139 | player.position.v[0] += direction.x() * speed * delta_time; 140 | player.position.v[1] += direction.y() * speed * delta_time; 141 | 142 | // Find the children of the player and make them 'follow' the player position. 143 | var children = try renderer.objects.getChildren(app.player); 144 | defer children.deinit(); 145 | for (children.items) |child_id| { 146 | if (!renderer.objects.is(child_id)) continue; 147 | var child = renderer.objects.getValue(child_id); 148 | defer renderer.objects.setValue(child_id, child); 149 | 150 | // Nested query to find all the other follower entities that we should move away from. 151 | // We will avoid all other follower entities if we're too close to them. 152 | // This is not very efficient, but it works! 153 | const close_dist = 1.0 / 15.0; 154 | var avoidance = Vec3.splat(0); 155 | var avoidance_div: f32 = 1.0; 156 | 157 | var children2 = try renderer.objects.getChildren(app.player); 158 | defer children2.deinit(); 159 | for (children2.items) |child2_id| { 160 | if (!renderer.objects.is(child2_id)) continue; 161 | if (child_id == child2_id) continue; 162 | const child2 = renderer.objects.getValue(child2_id); 163 | if (child.position.dist(&child2.position) < close_dist) { 164 | avoidance = avoidance.sub(&child.position.dir(&child2.position, 0.0000001)); 165 | avoidance_div += 1.0; 166 | } 167 | } 168 | 169 | // Avoid the player if we're too close to it 170 | var avoid_player_multiplier: f32 = 1.0; 171 | if (child.position.dist(&player.position) < close_dist * 6.0) { 172 | avoidance = avoidance.sub(&child.position.dir(&player.position, 0.0000001)); 173 | avoidance_div += 1.0; 174 | avoid_player_multiplier = 4.0; 175 | } 176 | 177 | // Determine our new position, taking into account things we want to avoid 178 | const move_speed = 1.0 * delta_time; 179 | var new_position = child.position.add(&avoidance.divScalar(avoidance_div).mulScalar(move_speed * avoid_player_multiplier)); 180 | 181 | // Try to move towards the center of the world if we don't need to avoid something else 182 | child.position = new_position.lerp(&vec3(0, 0, 0), move_speed / avoidance_div); 183 | } 184 | 185 | renderer_mod.call(.renderFrame); 186 | } 187 | -------------------------------------------------------------------------------- /templates/engine/src/Renderer.zig: -------------------------------------------------------------------------------- 1 | const mach = @import("mach"); 2 | const gpu = mach.gpu; 3 | const math = mach.math; 4 | 5 | const Vec3 = math.Vec3; 6 | 7 | pub const mach_module = .renderer; 8 | 9 | pub const mach_systems = .{ .init, .deinit, .renderFrame }; 10 | 11 | const Renderer = @This(); 12 | 13 | const num_bind_groups = 1024 * 32; 14 | 15 | // uniform bind group offset must be 256-byte aligned 16 | const uniform_offset = 256; 17 | 18 | const UniformBufferObject = extern struct { 19 | offset: Vec3, 20 | scale: f32, 21 | }; 22 | 23 | window: mach.ObjectID, 24 | pipeline: *gpu.RenderPipeline, 25 | bind_groups: [num_bind_groups]*gpu.BindGroup, 26 | uniform_buffer: *gpu.Buffer, 27 | 28 | objects: mach.Objects(.{}, struct { 29 | position: Vec3, 30 | scale: f32, 31 | }), 32 | 33 | pub fn init( 34 | core: *mach.Core, 35 | renderer: *Renderer, 36 | ) !void { 37 | const window = core.windows.getValue(renderer.window); 38 | const device = window.device; 39 | const shader_module = device.createShaderModuleWGSL("shader.wgsl", @embedFile("shader.wgsl")); 40 | defer shader_module.release(); 41 | 42 | // Fragment state 43 | const blend = gpu.BlendState{}; 44 | const color_target = gpu.ColorTargetState{ 45 | .format = window.framebuffer_format, 46 | .blend = &blend, 47 | .write_mask = gpu.ColorWriteMaskFlags.all, 48 | }; 49 | const fragment = gpu.FragmentState.init(.{ 50 | .module = shader_module, 51 | .entry_point = "frag_main", 52 | .targets = &.{color_target}, 53 | }); 54 | 55 | const label = @tagName(mach_module) ++ ".init"; 56 | const uniform_buffer = device.createBuffer(&.{ 57 | .label = label ++ " uniform buffer", 58 | .usage = .{ .copy_dst = true, .uniform = true }, 59 | .size = @sizeOf(UniformBufferObject) * uniform_offset * num_bind_groups, 60 | .mapped_at_creation = .false, 61 | }); 62 | 63 | const bind_group_layout_entry = gpu.BindGroupLayout.Entry.initBuffer(0, .{ .vertex = true }, .uniform, true, 0); 64 | const bind_group_layout = device.createBindGroupLayout( 65 | &gpu.BindGroupLayout.Descriptor.init(.{ 66 | .label = label, 67 | .entries = &.{bind_group_layout_entry}, 68 | }), 69 | ); 70 | defer bind_group_layout.release(); 71 | 72 | var bind_groups: [num_bind_groups]*gpu.BindGroup = undefined; 73 | for (bind_groups, 0..) |_, i| { 74 | bind_groups[i] = device.createBindGroup( 75 | &gpu.BindGroup.Descriptor.init(.{ 76 | .label = label, 77 | .layout = bind_group_layout, 78 | .entries = &.{gpu.BindGroup.Entry.initBuffer(0, uniform_buffer, uniform_offset * i, @sizeOf(UniformBufferObject), @sizeOf(UniformBufferObject))}, 79 | }), 80 | ); 81 | } 82 | 83 | const bind_group_layouts = [_]*gpu.BindGroupLayout{bind_group_layout}; 84 | const pipeline_layout = device.createPipelineLayout(&gpu.PipelineLayout.Descriptor.init(.{ 85 | .label = label, 86 | .bind_group_layouts = &bind_group_layouts, 87 | })); 88 | defer pipeline_layout.release(); 89 | 90 | const pipeline = device.createRenderPipeline(&gpu.RenderPipeline.Descriptor{ 91 | .label = label, 92 | .fragment = &fragment, 93 | .layout = pipeline_layout, 94 | .vertex = gpu.VertexState{ 95 | .module = shader_module, 96 | .entry_point = "vertex_main", 97 | }, 98 | }); 99 | 100 | renderer.* = .{ 101 | .window = renderer.window, 102 | .objects = renderer.objects, 103 | .pipeline = pipeline, 104 | .bind_groups = bind_groups, 105 | .uniform_buffer = uniform_buffer, 106 | }; 107 | } 108 | 109 | pub fn deinit( 110 | renderer: *Renderer, 111 | ) !void { 112 | renderer.pipeline.release(); 113 | for (renderer.bind_groups) |bind_group| bind_group.release(); 114 | renderer.uniform_buffer.release(); 115 | } 116 | 117 | pub fn renderFrame( 118 | core: *mach.Core, 119 | renderer: *Renderer, 120 | ) !void { 121 | const window = core.windows.getValue(renderer.window); 122 | 123 | // Grab the back buffer of the swapchain 124 | // TODO(Core) 125 | const back_buffer_view = window.swap_chain.getCurrentTextureView().?; 126 | defer back_buffer_view.release(); 127 | 128 | // Create a command encoder 129 | const label = @tagName(mach_module) ++ ".tick"; 130 | const encoder = window.device.createCommandEncoder(&.{ .label = label }); 131 | defer encoder.release(); 132 | 133 | // Update uniform buffer 134 | var num_objects: usize = 0; 135 | var objs = renderer.objects.slice(); 136 | while (objs.next()) |obj_id| { 137 | const obj = renderer.objects.getValue(obj_id); 138 | const ubo = UniformBufferObject{ 139 | .offset = obj.position, 140 | .scale = obj.scale, 141 | }; 142 | encoder.writeBuffer(renderer.uniform_buffer, uniform_offset * num_objects, &[_]UniformBufferObject{ubo}); 143 | num_objects += 1; 144 | } 145 | 146 | // Begin render pass 147 | const sky_blue_background = gpu.Color{ .r = 0.776, .g = 0.988, .b = 1, .a = 1 }; 148 | const color_attachments = [_]gpu.RenderPassColorAttachment{.{ 149 | .view = back_buffer_view, 150 | .clear_value = sky_blue_background, 151 | .load_op = .clear, 152 | .store_op = .store, 153 | }}; 154 | const render_pass = encoder.beginRenderPass(&gpu.RenderPassDescriptor.init(.{ 155 | .label = label, 156 | .color_attachments = &color_attachments, 157 | })); 158 | defer render_pass.release(); 159 | 160 | // Draw 161 | for (renderer.bind_groups[0..num_objects]) |bind_group| { 162 | render_pass.setPipeline(renderer.pipeline); 163 | render_pass.setBindGroup(0, bind_group, &.{0}); 164 | render_pass.draw(3, 1, 0, 0); 165 | } 166 | 167 | // Finish render pass 168 | render_pass.end(); 169 | 170 | // Submit our commands to the queue 171 | var command = encoder.finish(&.{ .label = label }); 172 | defer command.release(); 173 | window.queue.submit(&[_]*gpu.CommandBuffer{command}); 174 | } 175 | -------------------------------------------------------------------------------- /templates/engine/src/shader.wgsl: -------------------------------------------------------------------------------- 1 | // TODO(important): docs 2 | struct Uniform { 3 | pos: vec4, 4 | scale: f32, 5 | }; 6 | 7 | @group(0) @binding(0) var in : Uniform; 8 | 9 | @vertex fn vertex_main( 10 | @builtin(vertex_index) VertexIndex : u32 11 | ) -> @builtin(position) vec4 { 12 | var positions = array, 3>( 13 | vec2( 0.0, 0.1), 14 | vec2(-0.1, -0.1), 15 | vec2( 0.1, -0.1) 16 | ); 17 | var pos = positions[VertexIndex]; 18 | return vec4((pos*in.scale)+in.pos.xy, 0.0, 1.0); 19 | } 20 | 21 | @fragment fn frag_main() -> @location(0) vec4 { 22 | return vec4(1.0, 0.0, 0.0, 0.0); 23 | } 24 | -------------------------------------------------------------------------------- /templates/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "mach-engine-project flake"; 3 | 4 | inputs = { 5 | mach.url = "github:Cloudef/mach-flake?rev=@SED_REPLACE_REV@"; 6 | }; 7 | 8 | outputs = { mach, ... }: let 9 | flake-utils = mach.inputs.zig2nix.inputs.flake-utils; 10 | in (flake-utils.lib.eachDefaultSystem (system: let 11 | # Mach flake helper 12 | # Check the flake.nix in mach-flake project for more options: 13 | # 14 | env = mach.outputs.mach-env.${system} {}; 15 | in with builtins; with env.pkgs.lib; rec { 16 | # Produces clean binaries meant to be ship'd outside of nix 17 | # e.g. nix build .#foreign 18 | packages.foreign = env.package { 19 | src = cleanSource ./.; 20 | zigBuildFlags = [ "-Doptimize=ReleaseSmall" ]; 21 | 22 | # Packages required for compiling 23 | nativeBuildInputs = with env.pkgs; []; 24 | 25 | # Packages required for linking 26 | buildInputs = with env.pkgs; []; 27 | }; 28 | 29 | # nix build . 30 | packages.default = packages.foreign.overrideAttrs (attrs: { 31 | # Executables required for runtime 32 | # These packages will be added to the PATH 33 | zigWrapperBins = with env.pkgs; []; 34 | 35 | # Libraries required for runtime 36 | # These packages will be added to the LD_LIBRARY_PATH 37 | zigWrapperLibs = with env.pkgs; []; 38 | }); 39 | 40 | # For bundling with nix bundle for running outside of nix 41 | # example: https://github.com/ralismark/nix-appimage 42 | apps.bundle = { 43 | type = "app"; 44 | program = "${packages.foreign}/bin/@SED_ZIG_BIN@"; 45 | }; 46 | 47 | # nix run . 48 | apps.default = env.app [] "zig build run -- \"$@\""; 49 | 50 | # nix run .#build 51 | apps.build = env.app [] "zig build \"$@\""; 52 | 53 | # nix run .#test 54 | apps.test = env.app [] "zig build test -- \"$@\""; 55 | 56 | # nix run .#updateMachDeps 57 | apps.updateMachDeps = env.updateMachDeps; 58 | 59 | # nix run .#zig2nix 60 | apps.zig2nix = env.app [] "zig2nix \"$@\""; 61 | 62 | # nix develop 63 | devShells.default = env.mkShell { 64 | # Packages required for compiling, linking and running 65 | # Libraries added here will be automatically added to the LD_LIBRARY_PATH and PKG_CONFIG_PATH 66 | nativeBuildInputs = with env.pkgs; []; 67 | }; 68 | })); 69 | } 70 | --------------------------------------------------------------------------------