Incremental Builds
Track source file modifications and only rebuild when something changes. This is especially useful for large projects where full rebuilds are expensive.
@desc "Build with caching - only rebuilds when sources change"task build: @needs zig @cache src/*.zig build.zig build.zig.zon @pre echo "Building..." zig build @post echo "Build complete!"
@desc "Optimized release build with caching"task build-release: @needs zig @cache src/*.zig build.zig zig build -Doptimize=ReleaseFast
@desc "Clean and rebuild from scratch"task rebuild: [clean, build] echo "Rebuild complete"
@desc "Remove build artifacts"task clean: @ignore rm -rf zig-out .zig-cache .jakeHow @cache Works
Section titled “How @cache Works”The @cache directive tracks file modification times. When you run a task:
- Jake checks if any of the specified files have changed since the last run
- If nothing changed, the task is skipped with “up to date”
- If files changed, the task runs normally
File Targets for Automatic Caching
Section titled “File Targets for Automatic Caching”For even smarter caching, use file targets instead of task:
# File target - only rebuilds when dependencies are newer than outputfile dist/app.js: src/**/*.ts tsconfig.json npx tsc
file dist/styles.css: src/**/*.css postcss.config.js npx postcss src/styles.css -o dist/styles.css
# Task that depends on file targetstask build: [dist/app.js, dist/styles.css] echo "Build complete!"File targets automatically track:
- Whether the output file exists
- Whether any dependency is newer than the output
- Glob patterns like
src/**/*.ts
# First run - full buildjake build
# Second run - skipped if no changesjake build# Output: "build: up to date"
# After editing a source filejake build# Output: builds again