#How do we install a compiled dynamic library in a specific directory with an absolute path?

1 messages · Page 1 of 1 (latest)

low wyvern
#

I know that inside the function addInstallArtifact, .dest_dir.override is defined to be a path relative to the prefix, so the path should not be passed as an absolute path.

But I can't find the option to overwrite the prefix.

Warm regards.

const std = @import("std");

const buffer_size: comptime_int = 128;
var path_buffer: [buffer_size]u8 = undefined;

pub fn build(b: *std.Build) !void {
    const path_slice = try checkInstallDir(&path_buffer);
    // std.debug.print("{s}\n", .{path_slice});
    // `path_slice` would be "/User/<username>/.zig/lib/"
    // which is equivalent to "~/.zig/lib/"

    // some stuff

    const lib = b.addSharedLibrary(.{
        .name = "dylib",
        .root_source_file = b.path("src/root.zig"),
        .target = target,
        .optimize = .ReleaseSafe,
    });

    const install = b.addInstallArtifact(lib, .{
        .dest_dir = .{
            // This installs the .dylib file to the specific dir.
            .override = .{ .custom = "../../../.zig/lib/" },
            // This failed.
            // .override = .{ .custom = path_slice },
        },
    });

    b.default_step.dependOn(&install.step);
    // setup test steps
    return;
}
grizzled ether
#

afaik it can't be an absolute path

#

best you can do is override the prefix in the zig build command

#

but it's counter to zig goals to allow installing to an absolute path

#

(as far as I know)

low wyvern
grizzled ether
#

its just not very portable to allow it

#

if you *really* want, you can copy the output file to where you want

#

with a system command, or maybe you don't even need that

low wyvern
#

I wonder how those relatively mature projects deal with it.

grizzled ether
#

the solution is to just not do it

#

or override the prefix in zig build --prefix=

low wyvern
low wyvern
sturdy vale
#

Create a step that calls zig build again with the prefix you want 🧠

low wyvern