Skip to content

Can not @import dependencies in build.zig scripts #19357

@urso

Description

@urso

Zig Version

0.12.0-dev.3381+7057bffc1

Steps to Reproduce and Observed Behavior

Unexpected error importing a package dependencie in build scripts.

build.zig.zon:

.{
    .name = "my_extension",
    .version = "0.1.0",
    .paths = .{
        "src",
    },
    .dependencies = .{
        .pgzx = .{
            .url = "https://github.com/xataio/pgzx/archive/main.tar.gz",
            .hash = "1220af8396f144d87259e959493e54d27f52006bab3905a349d2bc96130b437faaed",
        },
    },
}

build.zig:

const std = @import("std");
const pgzx = @import("pgzx");

pub fn build(b: *std.Build) void {
    _ = b;
    _ = pgzx;
}

Error message:

$ zig/build/stage3/bin/zig build
xxxx/build.zig:2:22: error: no module named 'pgzx' available within module root.@build
const pgzx = @import("pgzx");

Expected Behavior

According to #14279 it seems that it shall be possible to import package dependencies in build scripts. This allows projects to share some common build utilities with downstream projects. We used that mechanism, but it seems to have been regressed recently.

Note: It is still possible to import a package that is referenced by path:

    .dependencies = .{
        .pgzx = .{
            .path = "./../pgzx",
        },
    },

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorzig build systemstd.Build, the build runner, `zig build` subcommand, package management

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions