#Install artifact to non-prefix path

1 messages · Page 1 of 1 (latest)

patent knoll
#

Zig build seems to strongly prefer installing things into the prefix, however I want to install something to a path outside of the prefix, relative to the package root directory (ie. the directory containing build.zig) instead.

The only way I can see is to overwrite b.lib_dir, however I'd rather avoid that if possible, since it's just one specific library I need to install to this custom location.
I don't currently have any other libraries in my project, but that's not a guarantee so I'd rather find a better solution.

#

The only thing I can think of is computing the path relative to the prefix using std.fs.path.relative, then using .{ .dest_dir = .{ .override = .{ .custom = path_relative_to_prefix } } } which kind of sucks, but might work I guess?

winter junco
#

You can do something like this b.getInstallStep().dependOn(&b.addInstallFileWithDir(b.path("src/main.zig"), .{ .custom = "../" }, "install.zig").step);
Though I don't know if it works with other packages importing yours.

patent knoll
#

This is what I've come up with. It's kinda gross but it does work:

    const client_outpath_prefix_relative = try std.fs.path.relative(
        b.allocator,
        b.install_prefix,
        try b.build_root.join(b.allocator, &.{"project/lib"}),
    );
    const client_install = b.addInstallArtifact(client, .{
        .dest_dir = .{ .override = .{ .custom = client_outpath_prefix_relative } },
    });
    b.getInstallStep().dependOn(&client_install.step);
hybrid zenith
#

Zig does not want you to to take away control of the install prefix from the user, so there's no way of hard-coding the install prefix this without messing with internal APIs.

#

If it's a single file (or just a few files and not a directory tree), the closest thing officially supported is std.Build.Step.WriteFile.addCopyFileToSource, which copies a file to a location relative to the build root

patent knoll
#

I completely forgot WriteFile had that functionality

hybrid zenith
#

it's a really dumb api, there's even a comment in there that says so

patent knoll
#

It's better than my hack ^-^

#

Even if I do have to manually re-add the library suffix worry

hybrid zenith
#

out of curiosity, why do you need to install this library that way?

patent knoll
#

Godot

#

It needs the library to be output into the godot project

#

kind of sucks, but it's better than trying to work around it another way