Search code examples
zig

import zig package from another zig package


I can import an package in my executable with exe.addPackagePath("name", "path") and usae it with const name = @import("name");. Now I want to include the package in another package, but I don´t understand how. Can I create an object for the package to set addPackagePath() on?


Solution

  • Instead of using addPackagePath, create Pkg structs directly (this way you will be able to specify sub-depencencies), and then use addPackage.

    Here's an usage example of Pkg:
    https://github.com/zig-community/Zig-Showdown/blob/main/build.zig#L6-L62

    And here's how the structs are added to the executable:
    https://github.com/zig-community/Zig-Showdown/blob/main/build.zig#L112-L118