Skip to content

Packages depending on other packages doesn't work #855

Description

@Hejsil

Three file example:
a.zig:

const b = @import("b");
pub fn main() void { b.something(); }

b.zig:

const c = @import("c");
pub fn something() void { c.something(); }

c.zig:

pub fn something() void { }

build.zig:

const std = @import("std");

pub fn build(b: *std.Build) void {
    const optimize = b.standardOptimizeOption(.{});
    const exe = b.addExecutable(.{
        .name = "a",
        .root_source_file = .{ .path = "a.zig" },
        .optimize = optimize,
    });
    const mod_c = b.addModule("c", .{
        .source_file = .{ .path = "c.zig" },
    });
    const mod_b = b.addModule("b", .{
        .source_file = .{ .path = "b.zig" },
        .dependencies = &.{
            .{
                .name = "c",
                .module = mod_c,
            },
        },
    });
    exe.addModule("b", mod_b);

    b.default_step.dependOn(&exe.step);
}

When using zig build I get:

b.zig:1:11: error: unable to find 'c'
const c = @import("c");

I've looked around in build.zig, but it doesn't seem like there is a way to add package path c.zig to b. Actually, it seems that build.zig just passes the info to the zig compiler through command line args:

zig build-exe a.zig --cache-dir zig-cache --output zig-cache/a --name a --pkg-begin b b.zig --pkg-end --pkg-begin c c.zig --pkg-end

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

    contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions