|
| 1 | +version: "3.0" |
| 2 | + |
| 3 | +set: ['e', 'u', 'pipefail'] |
| 4 | +shopt: ['globstar'] |
| 5 | + |
| 6 | +vars: |
| 7 | + ZIG_CORE_DIR: "{{.ROOT_DIR}}/zig-core" |
| 8 | + ZIG_OUT_DIR: "{{.ZIG_CORE_DIR}}/zig-out" |
| 9 | + ZIG_CACHE_DIR: "{{.ZIG_CORE_DIR}}/.zig-cache" |
| 10 | + PINNED_ZIG: |
| 11 | + sh: grep '^zig ' {{.ROOT_DIR}}/.tool-versions 2>/dev/null | awk '{print $2}' || true |
| 12 | + # Resolved through mise against the pinned version rather than PATH, which may |
| 13 | + # hold an IDE-bundled zig or a mise default for a different version. |
| 14 | + ZIG: |
| 15 | + sh: | |
| 16 | + pin="{{.PINNED_ZIG}}" |
| 17 | + if [ -n "$pin" ] && command -v mise &> /dev/null; then |
| 18 | + mise which zig --tool "zig@$pin" 2>/dev/null || true |
| 19 | + fi |
| 20 | + # Explicit target triple for the cross-compile task, e.g. TARGET=aarch64-macos |
| 21 | + TARGET: '{{.TARGET | default ""}}' |
| 22 | + |
| 23 | +tasks: |
| 24 | + _check-zig-version: |
| 25 | + internal: true |
| 26 | + desc: "Verify the pinned zig resolves and matches .tool-versions" |
| 27 | + cmds: |
| 28 | + - | |
| 29 | + mise_bin="{{.ZIG}}" |
| 30 | + if [ ! -x "$mise_bin" ]; then |
| 31 | + if ! command -v mise &> /dev/null; then |
| 32 | + echo "error: zig {{.PINNED_ZIG}} not found and mise is not on PATH." >&2 |
| 33 | + echo " Expected: {{.PINNED_ZIG}} (pinned in .tool-versions)" >&2 |
| 34 | + echo " Fix: install mise (https://mise.jdx.dev), then run: mise install zig" >&2 |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | + echo "error: zig {{.PINNED_ZIG}} (pinned in .tool-versions) is not installed." >&2 |
| 38 | + echo " Fix: mise install zig" >&2 |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | + found=$("$mise_bin" version 2>/dev/null) |
| 42 | + if [ "$found" != "{{.PINNED_ZIG}}" ]; then |
| 43 | + echo "error: zig version mismatch." >&2 |
| 44 | + echo " Expected: {{.PINNED_ZIG}} (pinned in .tool-versions)" >&2 |
| 45 | + echo " Found: ${found:-unknown} ($mise_bin)" >&2 |
| 46 | + echo " Fix: mise install zig@{{.PINNED_ZIG}}" >&2 |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | + echo "zig $found -> $mise_bin" |
| 50 | +
|
| 51 | + format: |
| 52 | + desc: "Format Zig source files" |
| 53 | + deps: [_check-zig-version] |
| 54 | + cmds: |
| 55 | + - '{{.ZIG}} fmt {{.ZIG_CORE_DIR}}/' |
| 56 | + |
| 57 | + lint: |
| 58 | + desc: "Check Zig formatting without making changes" |
| 59 | + deps: [_check-zig-version] |
| 60 | + cmds: |
| 61 | + - '{{.ZIG}} fmt --check {{.ZIG_CORE_DIR}}/' |
| 62 | + |
| 63 | + test: |
| 64 | + desc: "Run Zig unit tests" |
| 65 | + deps: [_check-zig-version] |
| 66 | + cmds: |
| 67 | + - cd {{.ZIG_CORE_DIR}} && {{.ZIG}} build test |
| 68 | + |
| 69 | + build: |
| 70 | + desc: "Build zig-core sidecar (debug)" |
| 71 | + deps: [_check-zig-version] |
| 72 | + cmds: |
| 73 | + - cd {{.ZIG_CORE_DIR}} && {{.ZIG}} build |
| 74 | + sources: |
| 75 | + - "{{.ZIG_CORE_DIR}}/src/**/*.zig" |
| 76 | + - "{{.ZIG_CORE_DIR}}/build.zig" |
| 77 | + - "{{.ZIG_CORE_DIR}}/build.zig.zon" |
| 78 | + generates: |
| 79 | + - "{{.ZIG_OUT_DIR}}/bin/mt-zig-core" |
| 80 | + |
| 81 | + cross-compile: |
| 82 | + desc: "Cross-compile zig-core for a Zig target triple (TARGET required)" |
| 83 | + summary: | |
| 84 | + Cross-compile the zig-core sidecar for an explicit Zig target triple. |
| 85 | +
|
| 86 | + task zig:cross-compile TARGET=aarch64-macos |
| 87 | + task zig:cross-compile TARGET=x86_64-macos |
| 88 | + task zig:cross-compile TARGET=x86_64-linux |
| 89 | + task zig:cross-compile TARGET=x86_64-windows |
| 90 | + deps: [_check-zig-version] |
| 91 | + preconditions: |
| 92 | + - sh: test -n "{{.TARGET}}" |
| 93 | + msg: | |
| 94 | + TARGET is not set. Pass a Zig target triple, e.g.: |
| 95 | + task zig:cross-compile TARGET=aarch64-macos |
| 96 | + task zig:cross-compile TARGET=x86_64-macos |
| 97 | + task zig:cross-compile TARGET=x86_64-linux |
| 98 | + task zig:cross-compile TARGET=x86_64-windows |
| 99 | + cmds: |
| 100 | + - cd {{.ZIG_CORE_DIR}} && {{.ZIG}} build -Dtarget={{.TARGET}} |
| 101 | + |
| 102 | + clean: |
| 103 | + desc: "Clean Zig build artifacts" |
| 104 | + cmds: |
| 105 | + - rm -rf {{.ZIG_OUT_DIR}} |
| 106 | + - rm -rf {{.ZIG_CACHE_DIR}} |
| 107 | + silent: true |
0 commit comments