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

How to install liblua.a? #18

Closed
atweiden opened this issue May 30, 2023 · 2 comments
Closed

How to install liblua.a? #18

atweiden opened this issue May 30, 2023 · 2 comments

Comments

@atweiden
Copy link

liblua.a is available in the zig-cache/ directory after running ziglua.compileAndCreateModule in my project’s build.zig. Can ziglua possibly install liblua.a into zig-out/? This would help in doing Zig-Go interop — I’d like Go to link against this liblua.a. Perhaps there’s a way of doing this from my project’s build.zig

@natecraddock
Copy link
Owner

Hi @atweiden!

This is a known issue (see #13). The package manager that will be part of the 0.11.0 release has some of the pieces required for this to work, but we are still waiting on a PR to be merged.

Once the package manager can handle exposing data other than Zig modules, this will become easy. The code would look something like this in a build.zig.

const ziglua = b.dependency("ziglua", .{
    .target = target,
    .optimize = optimize,
});

// here is the library "liblua.a" and can be linked against anything you need, or written to a file
ziglua.artifact("lua");

There may be a way to get this fixed sooner, but I am inclined to wait until the package manager properly supports this use case. Let me know if I misunderstood anything!

@natecraddock
Copy link
Owner

natecraddock commented Aug 3, 2023

Hi @atweiden, sorry for the long wait on this.

This is now fixed and I tested to verify this works. The readme has been updated with build instructions that use the new package manager. Here is an example that shows how to link the artifact with your project, and how to write the lua library artifact to the output folder.

// build.zig.zon
.{
    .name = "array",
    .version = "0.0.1",
    .dependencies = .{
        .ziglua = .{
            .url = "https://github.com/natecraddock/ziglua/archive/ab111adb06d2d4dc187ee9e1e352617ca8659155.tar.gz",
            .hash = "12206cf9e90462ee6e14f593ea6e0802b9fe434429ba10992a1451e32900f741005c",
        },
    }
}

// build.zig
const std = @import("std");

pub fn build(b: *std.build.Builder) void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const ziglua = b.dependency("ziglua", .{
        .target = target,
        .optimize = optimize,
    });

    const lib = b.addSharedLibrary(.{
        .name = "array",
        .root_source_file = .{ .path = "src/array.zig" },
        .target = target,
        .optimize = optimize,
    });

    // These lines link lua to the output library
    lib.addModule("ziglua", ziglua.module("ziglua"));
    lib.linkLibrary(ziglua.artifact("lua"));

    // This line installs liblua to the zig-out/lib/ directory
    b.installArtifact(ziglua.artifact("lua"));

    b.installArtifact(lib);
}

Let me know if you need anything else!

@atweiden atweiden closed this as completed Aug 4, 2023
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

2 participants