Skip to content

please don't write to the packages dir #9

@silversquirl

Description

@silversquirl

this code unconditionally writes to the packages directory at configure time:

libgit2/build.zig

Lines 434 to 452 in 0a30de3

// Fix the test fixture file permissions. This is necessary because Zig does
// not respect the execute permission on arbitrary files it extracts from dependencies.
// Since we need those files to have the execute permission set for tests to
// run successfully, we need to patch them before we bake them into the
// test executable. While modifying the global cache is hacky, it wont break
// hashes for the same reason above. -blurrycat 3/31/25
for ([_]std.Build.LazyPath{
libgit_root.path(b, "tests/resources/filemodes/exec_on"),
libgit_root.path(b, "tests/resources/filemodes/exec_off2on_staged"),
libgit_root.path(b, "tests/resources/filemodes/exec_off2on_workdir"),
libgit_root.path(b, "tests/resources/filemodes/exec_on_untracked"),
}) |lazy| {
const path = lazy.getPath2(b, null);
const file = try std.fs.cwd().openFile(path, .{
.mode = .read_write,
});
defer file.close();
try file.setPermissions(.{ .inner = .{ .mode = 0o755 } });
}

the comment at least acknowledges that it probably shouldn't be doing this, but it fails to understand the reason why: while the hashes may not be affected, this code can actually cause the entire build script to fail, even when not running tests, because the packages directory may be read-only.

for example, when building a zig package with nix, the dependencies are fetched ahead of time, into a read-only directory in /nix/store. then, separately, the package is built using zig build --system /nix/store/<name of packages dir>, which causes zig to look for packages in that directory, instead of in the global cache. since it's read-only, the code above fails with an error at configure time, and aborts the entire build despite never even having been asked to run the test suite.

please don't write to the packages dir :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions