Skip to content

ability to construct a LazyPath out of any file from a dependency package #16643

@andrewrk

Description

@andrewrk

The idea here is that you can put an arbitrary file contents in your build.zig.zon, like this:

.{
    .dependencies = .{
        .foo = .{
            .url = "https://example.com/foobar.tar.gz",
            .hash = "12209e851f7e2c6ba2f01de3e11b1771f03e49666065320abd8414aac152bfa75fae",
        },
    },
}

Normally, at this point, one would activate the build.zig script of the dependency like this:

    const foo_dep = b.dependency("foo", .{
        .target = target,
        .optimize = optimize,
        // ...other options...
    });

However, this issue is about the use case where the dependency is not a zig package, but a bundle of arbitrary files.

The idea is that you can access arbitrary files as std.Build.LazyPath objects, like this:

pub fn build(b: *std.Build) !void {
    // ...

    const lazy_path = b.dependencyPath("foo", "path/inside/dependency.txt");

    // now you can pass it anywhere a lazy path is accepted:
    run_step.addFileArg(lazy_path);

    // or you can access the file directly from build script logic:
    const contents = try std.fs.readFileAlloc(lazy_path.resolve());

    // ...
}

Using it via the LazyPath API would help with #14597, because resolution of the path would force the package to be downloaded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.zig build systemstd.Build, the build runner, `zig build` subcommand, package management

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions