Skip to content

Need a way to disambiguate dependency artifacts with the same name #20377

Description

@alexrp

(There was some earlier discussion on this on the Zig Discord.)

Right now, if a dependency project has multiple artifacts with the same name, you're going to hit this panic:

zig/lib/std/Build.zig

Lines 1855 to 1871 in 451550e

pub fn artifact(d: *Dependency, name: []const u8) *Step.Compile {
var found: ?*Step.Compile = null;
for (d.builder.install_tls.step.dependencies.items) |dep_step| {
const inst = dep_step.cast(Step.InstallArtifact) orelse continue;
if (mem.eql(u8, inst.artifact.name, name)) {
if (found != null) panic("artifact name '{s}' is ambiguous", .{name});
found = inst.artifact;
}
}
return found orelse {
for (d.builder.install_tls.step.dependencies.items) |dep_step| {
const inst = dep_step.cast(Step.InstallArtifact) orelse continue;
log.info("available artifact: '{s}'", .{inst.artifact.name});
}
panic("unable to find artifact '{s}'", .{name});
};
}

There are legitimate reasons to have artifacts with the same name. For example, in my case, I'm building both a static and shared library. They have the same name because I want them to end up as libfoo.so and libfoo.a. I think the build system needs some way for dep.artifact("foo") to work in this scenario.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions