Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zig package manager and importing local zig projects into other zig apps #15

Open
microapiframework opened this issue Feb 17, 2024 · 0 comments

Comments

@microapiframework
Copy link

microapiframework commented Feb 17, 2024

Hey all.

I am attempting to work on a zig library that will eventually be shared/public and published. But in the interim, I am using a test app to flesh it out. I have used a local app in the same library and things work there. I am now trying to ensure I understand how to import this library in to other apps outside this library project. So I have a sibling zig project set up. It has a build.zig and build.zig.zon. In build.zig.zon I have a dependency with a path in it (not url/hash), which is mapped to ../mylibrary which is the sibling directory (root) of my library, where build.zig and build.zig.zon are also found.

In the test app build.zig I set up the dependency and add it just as I did in my library which depends on a 3rd party module.

In my test app, when I build I continually get the "panic: unable to find module 'mylibrary'

test app build.zig.zon:

.{
    .name = "myapp",
    .version = "1.0.0", 
    .paths = .{"src"},
    .dependencies = .{
        .my_lib = .{
            .path = "../mylib",
        },
    },
}

test app build.zig:


const std = @import("std");

pub fn build(b: *std.Build) void {
    const optimize = b.standardOptimizeOption(.{});
    const target = b.standardTargetOptions(.{
        .default_target = .{ .abi = .musl, .os_tag = .wasi, .cpu_arch = .wasm32 },
    });

    const mylib_module = b.dependency("my_lib", .{ .target = target, .optimize = optimize }).module("mylib");

    var lib = b.addExecutable(.{
        .name = "myapp",
        .root_source_file = .{ .path = "src/main.zig" },
        .target = target,
        .optimize = optimize,
    });

    lib.rdynamic = true;
    lib.entry = .disabled;
    b.installArtifact(lib);
    plugin.root_module.addImport("mylib", mylib_module);

    const lib_example_step = b.step("myapp", "Build myapp");
    lib_example_step.dependOn(b.getInstallStep());
}

So one thing I am not sure of.. with the whole build.zig.zon and package management, when referring to a path in build.zig.zon, which I assume is the root path where the module exists.. the build.zig in THAT path needs to have the SAME name as defined in the test app build.zig dependency declaration? Or does that matter in any way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant