#TODO compiling, not tested further
[source]
git = "https://github.com/willnode/zig"
branch = "zig-0.15.2-redox"

[build]
template = "custom"
dependencies = [
  "llvm21",
  "zstd"
]

dev-dependencies = [
  "llvm21.dev",
  "llvm21.runtime",
  "clang21",
  "clang21.dev",
  "lld21.dev",
  "lld21",
  "host:libarchive",
  "host:zig",
]

script = """
DYNAMIC_INIT
export PATH="${COOKBOOK_BUILD}:${PATH}"

mkdir -p "${COOKBOOK_STAGE}"/usr/lib/zig  "${COOKBOOK_STAGE}"/usr/bin
ln -s "../lib/zig/bin/zig" "${COOKBOOK_STAGE}"/usr/bin/zig

if [ "$TARGET" != "$COOKBOOK_HOST_TARGET" ]; then

ARCH="${GNU_TARGET%%-*}"
OS=$(echo "${TARGET}" | cut -d - -f3-4)
rsync -a "${COOKBOOK_SOURCE}"/* ./

zig build \
  --prefix "${COOKBOOK_STAGE}/usr/lib/zig" \
  --search-prefix "${COOKBOOK_SYSROOT}/usr" \
  -Dflat \
  -Dstatic-llvm \
  -Doptimize=ReleaseFast \
  -Dstrip \
  -Dforce-link-libc \
  -Dtarget="$ARCH-$OS" \
  -Dcpu="baseline" \
  -Dversion-string="0.15.2" \
  -Duse-zig-libcxx \
  -Dno-langref \
  -Dno-test

else 

COOKBOOK_SOURCE="${COOKBOOK_BUILD}"
COOKBOOK_STAGE="${COOKBOOK_STAGE}/usr/lib/zig"
cookbook_cmake -DCMAKE_INSTALL_PREFIX=/ -DZIG_NO_TEST=On

fi
"""
