Open
Description
Zig Version
0.14.1
Steps to Reproduce and Observed Behavior
Setup
Create two zig projects. Project A is a dependency of project B. Project A has a c_mod
which is created from a addTranslateC
call.
Project B has a module which depends on Project A. Project B uses the Project A import which depends on the translate C.
Error Steps
Run the following in Project B
zig build --cache-dir ./.other_cache
This produces the following error:
failed to check cache: './.other_cache/o/9518a4980110663bd82e69c066c1180d/index.zig' file_hash FileNotFound
It also creates the ./.zig-cache
dir, which is where the generated file is.
If I run zig build
without the --cache-dir
flag, then this works as expected.
File overview
A)
> pwd
~/tmp/dep
> ls
build.zig build.zig.zon index.h root.zig zig-out
> cat build.zig
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const c_mod = b.addTranslateC(.{
.root_source_file = b.path("index.h"),
.target = target,
.optimize = optimize,
}).createModule();
const mod = b.addModule("mymod", .{
.root_source_file = b.path("root.zig"),
.target = target,
.optimize = optimize,
});
mod.addImport("c-import", c_mod);
b.installArtifact(b.addLibrary(.{
.name = "mylib",
.root_module = mod,
}));
}
> cat index.h
int add(int, int);
> cat root.zig
const c = @import("c-import");
pub fn add(a: i32, b: i32) i32 {
return c.add(a, b);
}
B)
> pwd
~/tmp/proj
> ls
build.zig build.zig.zon main.zig
> cat build.zig
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const dep = b.dependency("dep", .{
.target = target,
.optimize = optimize,
});
const mod = b.createModule(.{
.root_source_file = b.path("main.zig"),
.target = target,
.optimize = optimize,
});
mod.addImport("dep", dep.module("mymod"));
const my_exe = b.addExecutable(.{
.name = "main",
.root_module = mod,
});
b.installArtifact(my_exe);
}
> cat main.zig
const std = @import("std");
const dep = @import("dep");
pub fn main() void {
std.debug.print("{d}\n", .{dep.add(1, 2)});
}
Expected Behavior
The dependency uses ./.other-cache
when it generates the translate-c file