-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Cannot use local package with nested local dependency #20508
Comments
The first error,
is because you're missing The second error,
is likely a similar issue within One of the Zig communities would be a good place to get more support on getting this working. |
You need to add this part: // Really is a "exe.root_module.addIncludePath"
exe.addIncludePath(b.path("../../../Users/User/include"));
exe.addLibraryPath(b.path("../../../Users/User/lib"));
// Really is a "exe.root_module.link_libc = true"
exe.linkLibC();
// ...
exe.root_module.addImport("dungeon_weld", module); To fn addDependencies(compile: *std.Build.Step.Compile, dep_module: *std.Build.Module) void {
compile.addIncludePath(b.path("../../../Users/User/include"));
compile.addLibraryPath(b.path("../../../Users/User/lib"));
compile.linkLibC();
compile.root_module.addImport("dungeon_weld", dep_module);
}
// pub fn build...
addDependencies(lib, module);
addDependencies(exe, module);
addDependencies(exe_unit_tests, module); |
BTW this PR #20388 adds new way to create compile steps out of existing root module, so your code could be much more simpler with new API: const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const package = b.dependency("dungeon_weld", .{
.target = target,
.optimize = optimize,
});
const mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
mod.addIncludePath(b.path("../../../Users/User/include"));
mod.addLibraryPath(b.path("../../../Users/User/lib"));
mod.addImport("dungeon_weld", package.module("dungeon_weld"));
const lib = b.addLibrary(.{
.name = "tower_of_embers",
.root_module = mod,
.linkage = .static,
});
b.installArtifact(lib);
const exe = b.addExecutable2(.{
.name = "tower_of_embers",
.root_module = mod,
});
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const lib_unit_tests = b.addTest2(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const exe_unit_tests = b.addTest2(.{
.root_module = mod,
});
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
test_step.dependOn(&run_exe_unit_tests.step);
} Does this explanation makes sense to you? |
@BratishkaErik & @ianprime0509 I appreciate the help. I would like to figure out how to do this with the stable release of 0.13.0 After adding the module to the lib, the This is the error I get:
Here is the current const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lib = b.addStaticLibrary(.{
.name = "tower_of_embers",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const package = b.dependency("dungeon_weld", .{
.target = target,
.optimize = optimize,
});
const module = package.module("dungeon_weld");
addDependencies(b, lib, module);
b.installArtifact(lib);
const exe = b.addExecutable(.{
.name = "tower_of_embers",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
addDependencies(b, exe, module);
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const lib_unit_tests = b.addTest(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
addDependencies(b, lib_unit_tests, module);
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const exe_unit_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
addDependencies(b, exe_unit_tests, module);
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
test_step.dependOn(&run_exe_unit_tests.step);
}
fn addDependencies(b: *std.Build, compile: *std.Build.Step.Compile, dep_module: *std.Build.Module) void {
compile.addIncludePath(b.path("../../../Users/Jeff/include"));
compile.addLibraryPath(b.path("../../../Users/Jeff/lib"));
compile.linkLibC();
compile.root_module.addImport("dungeon_weld", dep_module);
} Here is the build file for the const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const lib = b.addStaticLibrary(.{ .name = "dungeon_weld", .root_source_file = b.path("src/main.zig"), .optimize = optimize, .target = target });
lib.linkSystemLibrary("SDL2");
lib.linkSystemLibrary("SDL2_image");
lib.linkSystemLibrary("SDL2main");
lib.linkSystemLibrary("c");
_ = b.addModule("dungeon_weld", .{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const package = b.dependency("SDL", .{
.target = target,
.optimize = optimize,
});
const module = package.module("SDL");
addDependencies(b, lib, module);
b.installArtifact(lib);
const run_cmd = b.addRunArtifact(lib);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const lib_unit_tests = b.addTest(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
addDependencies(b, lib_unit_tests, module);
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const exe_unit_tests = b.addTest(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
addDependencies(b, exe_unit_tests, module);
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
test_step.dependOn(&run_exe_unit_tests.step);
}
fn addDependencies(b: *std.Build, compile: *std.Build.Step.Compile, dep_module: *std.Build.Module) void {
compile.addIncludePath(b.path("../../../Users/Jeff/include"));
compile.addLibraryPath(b.path("../../../Users/Jeff/lib"));
compile.linkLibC();
compile.root_module.addImport("SDL", dep_module);
}
|
Here is your problem. Main build.zig uses the module that you export using b.addModule, but you don't link or import anything to it (even discards instead) so it complains that it can't find SDL nodule. Just assign this module to some variable and call |
@BratishkaErik That fixed the issue. Interesting. I am confused by the redundancy. Why does the import needed to added to both the module, as well as the lib? |
Zig Version
0.13.0
Steps to Reproduce and Observed Behavior
I am trying to figure out how to build an exe with a locally created
zig
package that depends on another local package. I've been trying to figure out how to do this for a couple years now. Still have never figured it out. Before I resorted to using Gyro becausezigmod
does not support installing local packages (It's still broken). Now Gyro has been archived so I am left with nothing but usingzon
, which feels practically impossible.The only relevant official documentation I've been able to find is here https://github.com/ziglang/zig/blob/master/doc/build.zig.zon.md which does not mention anything about nested dependencies.
I have a game engine library that I have built myself called
dungeon_weld
This depends on another package calledSDL
. I had to modify theSDL
package because it was not being maintained, so this is also a local package which I am storing inside the folderdungeon_weld/libs/SDL.zig
If I run
zig build
inside thedungeon_weld
package, it completes and there are no issues. But if I run the command in my game folder, I get this output:I have a
build.zig.zon
in all 3 folders. One inSDL
folder, one in dungeon_weld folder, and one in the game. Here is the one for the game. I assume that the dependencySDL
being listed in thebuild.zig.zon
andbuild.zig
inside thedungeon_weld
package is sufficient, so I left it out in the game folder. However, I have tried including it anyways, and I get the same error:Here is the build file for the game:
Expected Behavior
It should finish building with
zig build
The text was updated successfully, but these errors were encountered: