MKaama
MKaama

Reputation: 1919

How to change the local cache directory for the zig build system?

Motivation: my source files are on a network (samba) share.

zig build

fails with

error: Unexpected

. To overcome it (otherwise I have to delete the ./zig-cache/ folder before every build) and to save time (and potentially the SSD drive) I want to use RAMdrive for the local cache. I modified my build.zig like this:

const std=@import("std");
const Builder=@import("std").build.Builder;

pub fn build(b:*Builder) void {
    b.cache_root=.{.path="I:/my_build_cache",.handle=std.fs.openDirAbsolute("I:/",.{}) catch unreachable};
    const target=b.standardTargetOptions(.{});
[...]

where I:/ is my RAMdrive. It kind of works (one time), but does not solve my problem, because zig still creates the ./zig-cache/ folder to build the build.exe which then uses I:/my_build_cache for the other artifacts. For context, this is on Windows, but a solution for Linux is equally welcome. Can I set up some environment variables to influence zig.exe earlier in the build process or (worst case) give it some command-line argument to specify the local cache directory?

Upvotes: 4

Views: 2027

Answers (2)

MKaama
MKaama

Reputation: 1919

Specify ZIG_LOCAL_CACHE_DIR to set other directory for local cache

https://wiki.gentoo.org/wiki/Zig#Environment_variables

Answer provided by BratishkaErik on https://t.me/ziglang_en

Upvotes: 5

N00byEdge
N00byEdge

Reputation: 1136

zig build --help | grep cache
  --cache-dir [path]           Override path to local Zig cache directory
  --global-cache-dir [path]    Override path to global Zig cache directory

So yeah, just an alternative solution for people who don't want to use the environment variable like mentioned in the other answer

Upvotes: 4

Related Questions